Cracked——一个支持方法链和CSS选择器风格的Web Audio库
Cracked – Method chaining/CSS-style selector web audio library

原始链接: https://github.com/billorcutt/i_dropped_my_phone_the_screen_cracked

I Dropped My Phone The Screen Cracked是一个网页音频库,旨在实现浏览器中直观的音频创作。它使用方法链和CSS样式选择器简化了音频节点的操作,使得创建、配置和连接音频元素变得容易。 无需编写复杂的Web Audio API代码,只需编写简洁的代码行,例如`__().sine().dac().play()`即可生成连接到输出的正弦波。该库支持音频效果、压缩器等,所有这些都可以使用清晰的语法进行连接。选择器如`__("sine")`或`__("#lp1")`允许您定位和修改特定的节点。 该库利用宏将音频节点链封装成可重用的单元,从而实现模块化设计和插件创建。这些宏可以被实例化、连接,单独或作为一组进行寻址,并可以嵌套以实现复杂的音效设计。其目标是模拟模块化合成器的连接体验,从而促进网页音频的创造力和实验性。

Hacker News 最新 | 过去 | 评论 | 提问 | 展示 | 招聘 | 提交 登录 Cracked - 基于方法链/CSS 选择器风格的 Web Audio 库 (github.com/billorcutt) 7 分,来自 stephenhandley,32 分钟前 | 隐藏 | 过去 | 收藏 | 2 条评论 stephenhandley 32 分钟前 | 下一条 [–] 基于 WebAudio 的库,提供快速搭建 Web Audio 图表的方法。桌面端包装器: https://github.com/billorcutt/CrackedCat 示例: https://idroppedmyphonethescreencracked.tumblr.com/ 回复 wesz 22 分钟前 | 上一条 [–] 太棒了!我将用它为我的鼓模式/贝斯线网站制作原型合成器。 回复 指导原则 | 常见问题 | 列表 | API | 安全 | 法律 | 申请 YC | 联系我们 搜索:
相关文章
  • 使用Web Audio API生成可变占空比方波 2025-04-07
  • (评论) 2024-05-23
  • (评论) 2024-05-02
  • (评论) 2025-03-17
  • 2025-05-14

  • 原文

    I Dropped My Phone The Screen Cracked is a web audio library that uses method chaining and CSS-style selectors to simplify creating, configuring and connecting audio nodes in the browser. Here's hello world:

    //create and connect sine and system out. start the sine
    __().sine().dac().play();

    and a slightly more complex example:

    //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();

    Audio node chains can be encapsulated as units using 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();

    and macros can be wrapped in simple factory functions to create plugins, making it possible to instantiate instances, connect them to other nodes, address them individually or as a group, nest them within other macros, etc.

    //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();

    Generally, the goal of I Dropped My Phone The Screen Cracked is simplicity, brevity without obscurity and making audio coding as intuitive as patching a modular, so that noise makers can focus on keeping it weird and fun.

    If you're interested in knowing more, there's a one page overview, full source documentation, a Reddit interview, some press, and a useful app for Mac or Linux to try it all out.

    Also cat pictures.

    If you'd like to contribute, you can send a comment to [email protected], open an issue for bugs or feature enhancements or best of all, submit a pull request.

    联系我们 contact @ memedata.com