Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mumble-voip/mumblekit.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmilio Pavia <emilio.pavia@gmail.com>2015-11-26 13:04:42 +0300
committerEmilio Pavia <emilio.pavia@gmail.com>2015-11-26 13:09:23 +0300
commit09bc67dc28a0a9d0a1c127d72438db17e3f13d9b (patch)
tree054ce847c3887c4c69016e2e0686c63f88624b87 /src/MKiOSAudioDevice.m
parentabc36e730251139104889203826a192797230692 (diff)
Fix a bug with buffer size calculation in the AudioUnit inputCallback
This commit fix an error in the formula used to check if the buffer is too small. Moreover the AudioUnitRender function modifies the mDataByteSize members with the actual read bytes count. This makes the buffer continuosly reallocated even if not necessary. This commit reset the mDataByteSize member to the actual buffer size.
Diffstat (limited to 'src/MKiOSAudioDevice.m')
-rw-r--r--src/MKiOSAudioDevice.m9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/MKiOSAudioDevice.m b/src/MKiOSAudioDevice.m
index 1d5aca8..1124ce4 100644
--- a/src/MKiOSAudioDevice.m
+++ b/src/MKiOSAudioDevice.m
@@ -38,7 +38,7 @@ static OSStatus inputCallback(void *udata, AudioUnitRenderActionFlags *flags, co
b->mData = calloc(1, b->mDataByteSize);
}
- if (dev->_buflist.mBuffers->mDataByteSize < (nframes/dev->_micSampleSize)) {
+ if (dev->_buflist.mBuffers->mDataByteSize < (dev->_micSampleSize * nframes)) {
NSLog(@"MKiOSAudioDevice: Buffer too small. Allocating more space.");
AudioBuffer *b = dev->_buflist.mBuffers;
free(b->mData);
@@ -46,6 +46,12 @@ static OSStatus inputCallback(void *udata, AudioUnitRenderActionFlags *flags, co
b->mData = calloc(1, b->mDataByteSize);
}
+ /*
+ AudioUnitRender modifies the mDataByteSize members with the
+ actual read bytes count. We need to write it back otherwise
+ we'll reallocate the buffer even if not needed.
+ */
+ UInt32 dataByteSize = dev->_buflist.mBuffers->mDataByteSize;
err = AudioUnitRender(dev->_audioUnit, flags, ts, busnum, nframes, &dev->_buflist);
if (err != noErr) {
#ifndef TARGET_IPHONE_SIMULATOR
@@ -53,6 +59,7 @@ static OSStatus inputCallback(void *udata, AudioUnitRenderActionFlags *flags, co
#endif
return err;
}
+ dev->_buflist.mBuffers->mDataByteSize = dataByteSize;
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
short *buf = (short *) dev->_buflist.mBuffers->mData;