Reputation: 2358
I want to generate a sound using a bunch of oscillators and record that sound for future playback. A simplified version of my setup currently looks like this:
Oscillator -> Gain -> ScriptProcessor* -> Destination (for recording)
BufferSource -> Destination* (for playback)
* marks the actual final node.
The ScriptProcessor node is there just to record whatever it's passed to it - it doesn't pass anything to the Destination, which makes me wonder: why do I need to connect everything to the Destination or else it won't work? Is there a better way to record data than using a ScriptProcessor node? If I don't have to connect the thing to Destination then can I speed up the generation of the sound? For a 10 second sine wave I have to wait 10 seconds for it to generate. Can I generate it faster than real-audible-time and play it back slower?
Upvotes: 0
Views: 119
Reputation: 13908
You want to use an OfflineAudioContext. You create it with the same sampleRate as your live context and the resulting buffer length you want, create your nodes in it, tell it to start rendering and when it's done it gives you an AudioBuffer back that you can use to play back in your live context.
Upvotes: 2