html5 sound,html - Sound effects in JavaScript / HTML5 - Stack Overflow

For game authoring, one of the best solutions is to use a library which solves the many problems we face when writing code for the web, such as howler.js. howler.js abstracts the great (but low-level) Web Audio API into an easy to use framework. It will attempt to fall back to HTML5 Audio Element if Web Audio API is unavailable.

var sound = new Howl({

urls: ['sound.mp3', 'sound.ogg']

}).play();

// it also provides calls for spatial/3d audio effects (most browsers)

sound.pos3d(0.1,0.3,0.5);

Another great library is wad.js, which is especially useful for producing synth audio, such as music and effects. For example:

var saw = new Wad({source : 'sawtooth'})

saw.play({

volume : 0.8,

wait : 0, // Time in seconds between calling play() and actually triggering the note.

loop : false, // This overrides the value for loop on the constructor, if it was set.

pitch : 'A4', // A4 is 440 hertz.

label : 'A', // A label that identifies this note.

env : {hold : 9001},

panning : [1, -1, 10],

filter : {frequency : 900},

delay : {delayTime : .8}

})

Another library similar to Wad.js is "Sound for Games", it has more focus on effects production, while providing a similar set of functionality through a relatively distinct (and perhaps more concise feeling) API:

function shootSound() {

soundEffect(

1046.5, //frequency

0, //attack

0.3, //decay

"sawtooth", //waveform

1, //Volume

-0.8, //pan

0, //wait before playing

1200, //pitch bend amount

false, //reverse bend

0, //random pitch range

25, //dissonance

[0.2, 0.2, 2000], //echo array: [delay, feedback, filter]

undefined //reverb array: [duration, decay, reverse?]

);

}

Summary

Each of these libraries are worth a look, whether you need to play back a single sound file, or perhaps create your own html-based music editor, effects generator, or video game.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值