audiocogs / aurora.js

JavaScript audio decoding framework
http://audiocogs.org/codecs
1.26k stars 185 forks source link

How do I decode to raw, resample to 44,1khz and split stereo into dual mono buffers? #202

Open Jurek-Raben opened 6 years ago

Jurek-Raben commented 6 years ago

How do I decode to raw, resample to 44,1khz and split stereo into dual mono buffers? Would like to have a working example for within a browser.

Tried this, but errors on " this.context.createBuffer":

asset2.decodeToBuffer(function(buffer)

{ var channels = asset2.format.channelsPerFrame; var samples = buffer.length/channels; var audioBuf = this.context.createBuffer(channels, samples, asset2.format.sampleRate); audioChans[i] = []; for(var i2 = 0; i2 < channels; i2++) { audioChans[i].push(audioBuf.getChannelData(i2)); } for(var i2 = 0; i2 < buffer.length; i2++) { audioChans[i][i2 % channels][Math.round(i2/channels)] = buffer[i2]; }

Also is there a working browser exmaple for using the resampler?