key-and-pad

? Fun experiment with the Web Audio API ?

Github星跟蹤圖

A Web Audio experiment, featuring a keyboard-controlled synthesizer and a mouse-controlled X/Y pad (eg. kaoss pad). Built with React and Redux.

Make some music!


Web Audio Reconciler

Key&Pad uses the Web Audio API to generate oscillators and effects. I needed some way for these nodes to be updated when the state in the Redux store changed, so I took inspiration from React and wrote a reconciler.

It subscribes to the store, and whenever a change is published, it calculates the minimum change needed to update the Web Audio nodes.

Oscillators are cheap and disposable. When a note is played or released, we can simply scrap all existing oscillators and recreate them from the Redux state.

When dragging on the X/Y pad, though, effect parameters change incredibly fast, so a bit more precision is required. Thankfully, the currently-active effect is available in Redux state, so it's simply a matter of switching on the effect name, and applying the new amount.

I'm quite pleased with this approach. We're maintaining a single source of truth by having Redux state hold the data needed to build the Web Audio nodes, and our reconciler ensures that updates are performant and straightforward. A single function controls every possible update, and the changes that flow through from Redux to the imperative Web Audio API are easy to follow.

Redux VCR

This synth was developed in tandem with Redux VCR, an ambitious and experimental devtool that records user sessions so they can be played back by app developers.

DAWs like Ableton Live have an interesting "record" option. Rather than record the resulting audio, it instead records the sequence of MIDI actions needed to construct the audio. This way, recordings can be edited and tweaked, and they're a much smaller file size.

It occurred to me that Redux functions in a very similar manner; If you store all of your app state in redux, you can simply replay those actions in realtime to re-create the session on the fly.

I really wanted to see what people would create with Key&Pad, and this tool allows me to anonymously collect and watch what people do; not just the resulting audio, but also the notes pressed, the X/Y pad updates, etc.

Typically, Redux VCR's recorded sessions would only be viewable by developers and administrators. Because Key&Pad records no personal information, though, its cassettes can be replayed by anybody. Simply visit this secret URL and interact with the VCR :)

Special Thanks

The Web Audio API is immensely powerful, but it gives you the primitives needed to construct advanced effects. For the most part, I deferred this task to the makers of Tuna.js and Soundbank.

If anyone else is working with Web Audio, I recommend both of these tools.

主要指標

概覽
名稱與所有者joshwcomeau/key-and-pad
主編程語言JavaScript
編程語言HTML (語言數: 4)
平台
許可證
所有者活动
創建於2016-07-23 19:28:38
推送於2022-12-12 07:44:58
最后一次提交2020-03-27 09:28:56
發布數0
用户参与
星數364
關注者數9
派生數25
提交數272
已啟用問題?
問題數2
打開的問題數1
拉請求數0
打開的拉請求數16
關閉的拉請求數4
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?