Skip to content

Instantly share code, notes, and snippets.

@AdrienFromToulouse
Created August 10, 2016 05:29
Show Gist options
  • Save AdrienFromToulouse/46740802f6acd50430404de66b0b9d46 to your computer and use it in GitHub Desktop.
Save AdrienFromToulouse/46740802f6acd50430404de66b0b9d46 to your computer and use it in GitHub Desktop.
const fs = require('fs');
module.exports = (audioContext) => {
const buffer = fs.readFileSync('/tmp/MixTwoDifferentChannels.wav');
return audioContext.decodeAudioData(buffer).then((audioBuffer) => {
const bufSrc = audioContext.createBufferSource();
const panNode = audioContext.createStereoPanner();
// mostly on the left
panNode.pan.value = 0.9;
// if channelCount is set to 2 it fails to apply the correct panning.
panNode.channelCount = 1;
bufSrc.buffer = audioBuffer;
bufSrc.connect(panNode);
panNode.connect(audioContext.destination);
bufSrc.start(0);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment