Created
August 6, 2013 13:19
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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