Cracked - method chaining/CSS-style selector web audio library
Cracked:支持方法链式调用/CSS样式选择器的 Web Audio 库
billorcutt / **i_dropped_my_phone_the_screen_cracked ** Public
web audio, cracked. idroppedmyphonethescreencracked.tumblr.com
License
MIT license 327 stars 15 forks
billorcutt/i_dropped_my_phone_the_screen_cracked
master BranchesTags Go to file Code
I Dropped My Phone The Screen Cracked
I Dropped My Phone The Screen Cracked 是一个 web audio 库,它使用方法链式调用和 CSS 样式选择器来简化在浏览器中创建、配置和连接音频节点的过程。以下是一个简单的 "hello world" 示例:
//create and connect sine and system out. start the sine
__().sine().dac().play();
以及一个稍微复杂点的例子:
//create and connect a sine oscillator (frequency of 180), lowpass,
//compressor and system output (level of .5).
__().sine(180).lowpass({frequency:160,q:5,id:"lp1"}).compressor().dac(.5);
//select the sine using its type and change the detune to 10
__("sine").detune(10);
//use the id to get a reference to the lowpass
//filter and set the frequency to 600
__("#lp1").frequency(600);
//create and connect a sawtooth oscillator, waveshaper & compressor
//and connect the compressor to the existing dac we created above.
__().saw(800).waveshaper().compressor().connect("dac");
//change the ratio of both compressors to 12
__("compressor").attr("ratio",12);
//start the sine and the sawtooth
__("sine,saw").start();
音频节点链可以使用 macros 封装为单元:
//define a simple macro named "microsynth"
__().begin("microsynth").sine().gain().end("microsynth").dac();
//change the frequency of the sine
__("microsynth").frequency(100);
//start it up
__("microsynth").start();
而且 macros 可以被包裹在简单的工厂函数中来创建 plugins,从而可以实例化实例,将它们连接到其他节点,单独或分组寻址它们,将它们嵌套在其他 macros 中等等。
//define a plugin called microsynth
cracked.microsynth = function(params) {
//pass any params to begin() so they can associated with the instance
__().begin("microsynth",params).sine().gain(0).end("microsynth");
//return cracked so we can chain methods
return cracked;
}
//create two instances with different ids
__().microsynth({id:"micro1"}).lowpass().dac();
__().microsynth({id:"micro2"}).lowpass().connect("dac");
//change the frequency in the first
__("#micro1").frequency(1200);
//change the frequency in the second
__("#micro2").frequency(600);
//set the gain in both and start them
__("microsynth").volume(1).start();
总的来说, I Dropped My Phone The Screen Cracked 的目标是简洁、明了,并在不模糊的情况下尽可能简短,并使音频编码像模块化修补一样直观,以便噪声制造者可以专注于保持其怪异和乐趣。
如果您有兴趣了解更多信息,可以查看单页 overview、完整的源代码 documentation、Reddit interview、一些 press,以及适用于 Mac 或 Linux 的有用应用程序来 try it all out。
此外,还有 cat pictures。
如果您想做出贡献,可以发送评论至 info@fastinversesquare.com,针对错误或功能增强打开一个 issue,或者最好提交一个 pull request。
关于
web audio, cracked. idroppedmyphonethescreencracked.tumblr.com
Topics
music music-library web-audio synthesis html5-audio audio-library electronic-music computer-music