Created
April 6, 2012 16:42
-
-
Save jussi-kalliokoski/2321217 to your computer and use it in GitHub Desktop.
audiolib.js: simple automation and effects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* First, we need a Sink */ | |
| var dev = Sink(); | |
| /* So, here we'll create an oscillator and an LFO to control the oscillator FM. */ | |
| var osc = audioLib.Oscillator(dev.sampleRate, 440); | |
| var lfo = audioLib.Oscillator(dev.sampleRate, 0.1); | |
| /* | |
| Then we'll put a delay effect after the oscillator. | |
| Note that we have to use createBufferBased() to make a multi-channel effect. | |
| Arguments are sampleRate, delayTime, feedback. | |
| */ | |
| var del = audioLib.Delay.createBufferBased(dev.channelCount, dev.sampleRate, 1777, 0.4); | |
| /* | |
| Set up the automation. | |
| First we tell what we want to automate, then what to automate it with, then how much and finally, what operation we'd like to use to automate. | |
| */ | |
| osc.addAutomation('fm', lfo, 1.0, 'assignment'); | |
| /* Now let's make it a little less loud */ | |
| osc.mix = 0.2; | |
| /* Setup a callback to fill the audio buffers */ | |
| dev.on('audioprocess', function (buffer, channelCount) { | |
| /* First off, we need to prepare the data for automation. This needs to be a buffer of the length of a single channel. */ | |
| lfo.generateBuffer(buffer.length / channelCount); | |
| /* Now, let's run the effects on the buffer */ | |
| osc.append(buffer, channelCount); | |
| del.append(buffer, channelCount); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment