Reputation: 657
I am building an audio recording app for iPhone in which I use remote audio units. After performing some audio analysis on incoming buffers I write the buffers to disk using:
ExtAudioFileWriteAsync
However, the problem I have is that the recorded buffers are quieter than I would like.
I would like to increase the volume of the buffers by manually multiplying them by a volume factor just prior to writing to disk. Can anyone please explain to me the best way to do this?
(For various reasons, a manual adjustment at the final stage is more attractive than changing any of the audio unit properties, which otherwise work well for my application.)
Thanks in advance!!
Upvotes: 3
Views: 3673
Reputation: 16966
You can use Accelerate.framework
to do this quickly and easily. Since you are using AudioUnits I assume you have deinterleaved float buffers so something like this should work:
float desiredGain = 1.06f; // or whatever linear gain you'd like
AudioBufferList *ioData; // audio from somewhere
for(UInt32 bufferIndex = 0; bufferIndex < ioData->mNumberBuffers; ++bufferIndex) {
float *rawBuffer = (float *)ioData->mBuffers[bufferIndex].mData;
vDSP_Length frameCount = ioData->mBuffers[bufferIndex].mDataByteSize / sizeof(float); // if you don't have it already
vDSP_vsmul(rawBuffer, 1, &desiredGain, rawBuffer, 1, frameCount);
}
Upvotes: 8
Reputation: 40380
You might be over thinking this problem. :-) You just need to loop over the values in your buffer and multiply each one by the desired gain factor.
Upvotes: 0