index.js
function toAudioBuffer (buffer, format) {
	if (!isNormalized(format)) format = normalize(format)

	buffer = convert(buffer, format, {
		channels: format.channels,
		sampleRate: format.sampleRate,
		interleaved: false,
		float: true
	})

	var len = Math.floor(buffer.byteLength * .25 / format.channels)

	var audioBuffer = new AudioBuffer(null, {
		length: len,
		numberOfChannels: format.channels,
		sampleRate: format.sampleRate
	})

	var step = len * 4
	for (var channel = 0; channel < format.channels; channel++) {
		var offset = channel * step
		var data = new Float32Array(buffer.slice(offset, offset + step))
		audioBuffer.getChannelData(channel).set(data)
	}

	return audioBuffer
}
function toAudioBuffer (buffer, format) {
	if (!isNormalized(format)) format = normalize(format)

	buffer = convert(buffer, format, {
		channels: format.channels,
		sampleRate: format.sampleRate,
		interleaved: false,
		float: true
	})

	var len = Math.floor(buffer.byteLength * .25 / format.channels)

	var audioBuffer = new AudioBuffer(null, {
		length: len,
		numberOfChannels: format.channels,
		sampleRate: format.sampleRate
	})

	var step = len * 4
	for (var channel = 0; channel < format.channels; channel++) {
		var offset = channel * step
		var data = new Float32Array(buffer.slice(offset, offset + step))
		audioBuffer.getChannelData(channel).set(data)
	}

	return audioBuffer
}
function toAudioBuffer ( buffer , format ) { if ( ! isNormalized ( format ) ) format = normalize ( format ) buffer = convert ( buffer , format , { channels : format . channels , sampleRate : format . sampleRate , interleaved : false , float : true } ) var len = Math . floor ( buffer . byteLength * .25 / format . channels ) var audioBuffer = new AudioBuffer ( null , { length : len , numberOfChannels : format . channels , sampleRate : format . sampleRate } ) var step = len * 4 for ( var channel = 0 ; channel < format . channels ; channel ++ ) { var offset = channel * step var data = new Float32Array ( buffer . slice ( offset , offset + step ) ) audioBuffer . getChannelData ( channel ) . set ( data ) } return audioBuffer }
Convert Buffer to AudioBuffer with specified format
Convert Buffer to AudioBuffer with specified format