Skip to content

Instantly share code, notes, and snippets.

@goonzoid
Created August 6, 2013 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goonzoid/6164370 to your computer and use it in GitHub Desktop.
Save goonzoid/6164370 to your computer and use it in GitHub Desktop.
Naively sum a non-interleaved buffer of stereo, floating-point audio to mono using the Accelerate framework. See http://dsp.stackexchange.com/a/2485 for suggestion of a more sophisticated approach.
@import Accelerate;
static float* monoDataFromStereoNonInterleaved(const float *stereoData, size_t length) {
vDSP_Length numberOfSamples = length / sizeof(float) / 2;
const float *leftChannel = stereoData;
const float *rightChannel = leftChannel + numberOfSamples;
size_t monoDataLength = length / 2;
float *monoData = malloc(monoDataLength);
vDSP_vadd(leftChannel, 1, rightChannel, 1, monoData, 1, numberOfSamples);
float scale = 0.5;
vDSP_vsmul(monoData, 1, &scale, monoData, 1, numberOfSamples);
return monoData;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment