Skip to content

Instantly share code, notes, and snippets.

@beefchimi
Created October 22, 2017 22:03
Show Gist options
  • Save beefchimi/169f00d75d4073c6b0a704c6264887e4 to your computer and use it in GitHub Desktop.
Save beefchimi/169f00d75d4073c6b0a704c6264887e4 to your computer and use it in GitHub Desktop.
Reverse an audioBuffer
export default function reverseBuffer(buffer, context) {
const reverse = context.createBuffer(
buffer.numberOfChannels,
buffer.length,
buffer.sampleRate
);
for (let channels = 0; channels < buffer.numberOfChannels; channels++) {
const dest = reverse.getChannelData(channels);
const src = buffer.getChannelData(channels);
for (let sampleFrames = 0; sampleFrames < buffer.length; sampleFrames++) {
dest[sampleFrames] = src[buffer.length - sampleFrames];
}
}
return reverse;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment