Skip to content

Instantly share code, notes, and snippets.

@eeropic
Created May 25, 2017 17:15
Show Gist options
  • Select an option

  • Save eeropic/c57d2e8d6eba328b65d240a4d1b2e03b to your computer and use it in GitHub Desktop.

Select an option

Save eeropic/c57d2e8d6eba328b65d240a4d1b2e03b to your computer and use it in GitHub Desktop.
no description yet
include('http://eerojohannes.com/js/Tone.min.js')
include('http://eerojohannes.com/js/FileSaver.min.js')
//tone.js offline rendering example
//load the buffer for use in the convolver
var buffer = new Tone.Buffer("https://googlechrome.github.io/web-audio-samples/samples/audio/impulse-responses/chorus-feedback.wav");
Tone.loaded().then(function(){
return Tone.Offline(function(Transport){
var reverb = new Tone.Convolver(buffer).toMaster();
reverb.wet.value = 0.2;
var pannerA = new Tone.Panner(-1).connect(reverb);
var synthA = new Tone.Synth({
"envelope" : {
"attack" : 0.01,
"decay" : 5,
"sustain" : 0
},
"oscillator" : {
"type" : "sawtooth4"
}
}).connect(pannerA);
var seqA = new Tone.Sequence(function(time, note){
synthA.triggerAttack(note, time)
}, ["A4", "G4", "G#4", "F#4", "E4"], "8n").start(0);
seqA.loop = false;
var pannerB = new Tone.Panner(1).connect(reverb);
var synthB = new Tone.Synth({
"envelope" : {
"attack" : 0.001,
"decay" : 3,
"sustain" : 0
},
"oscillator" : {
"type" : "square8"
}
}).connect(pannerB);
var seqB = new Tone.Sequence(function(time, note){
synthB.triggerAttack(note, time)
}, ["G#4", "A4", "G4", "F4", "C4"], "8n").start("16n");
seqB.loop = false;
var bass = new Tone.MonoSynth({
"envelope" : {
"attack" : 0.01,
"decay" : 3,
"sustain" : 0.1
},
}).toMaster()
var bassSeq = new Tone.Sequence(function(time, note){
bass.triggerAttackRelease(note, "1n", time)
}, ["C2", "C2", "F1", "F1"], "4n").start(0);
bassSeq.loop = false;
Transport.bpm.value = 150;
Transport.start();
}, 7)
}).then(function(buffer){
//set the buffer once it's rendered
console.log(buffer)
//end tone.js offline example
//buffer to wav code by kevin cennis using recorderjs
// assuming a var named `buffer` exists and is an AudioBuffer instance
// start a new worker
// we can't use Recorder directly, since it doesn't support what we're trying to do
var worker = new Worker('http://eerojohannes.com/js/recorderWorker.js');
// initialize the new worker
worker.postMessage({
command: 'init',
config: {sampleRate: 44100}
});
// callback for `exportWAV`
worker.onmessage = function( e ) {
var blob = e.data;
// this is would be your WAV blob
console.log(e)
saveAs(blob, "thing.wav");
};
// send the channel data from our buffer to the worker
worker.postMessage({
command: 'record',
buffer: [
buffer.getChannelData(0),
buffer.getChannelData(1)
]
});
// ask the worker for a WAV
worker.postMessage({
command: 'exportWAV',
type: 'audio/wav'
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment