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
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.
-rw-r--r--src/MKMacAudioDevice.m9
-rw-r--r--src/MKVoiceProcessingDevice.m9
-rw-r--r--src/MKiOSAudioDevice.m9
3 files changed, 24 insertions, 3 deletions
diff --git a/src/MKMacAudioDevice.m b/src/MKMacAudioDevice.m
index 24e7e22..2be75d1 100644
--- a/src/MKMacAudioDevice.m
+++ b/src/MKMacAudioDevice.m
@@ -45,7 +45,7 @@ static OSStatus inputCallback(void *udata, AudioUnitRenderActionFlags *flags, co
b->mData = calloc(1, b->mDataByteSize);
}
- if (dev->_recordBufList.mBuffers->mDataByteSize < (nframes/dev->_recordSampleSize)) {
+ if (dev->_recordBufList.mBuffers->mDataByteSize < (dev->_recordSampleSize * nframes)) {
NSLog(@"MKMacAudioDevice: Buffer too small. Allocating more space.");
AudioBuffer *b = dev->_recordBufList.mBuffers;
free(b->mData);
@@ -53,11 +53,18 @@ 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->_recordAudioUnit, flags, ts, busnum, nframes, &dev->_recordBufList);
if (err != noErr) {
NSLog(@"MKMacAudioDevice: AudioUnitRender failed. err = %ld", (unsigned long)err);
return err;
}
+ dev->_buflist.mBuffers->mDataByteSize = dataByteSize;
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
short *buf = (short *) dev->_recordBufList.mBuffers->mData;
diff --git a/src/MKVoiceProcessingDevice.m b/src/MKVoiceProcessingDevice.m
index 069fcaf..9105dab 100644
--- a/src/MKVoiceProcessingDevice.m
+++ b/src/MKVoiceProcessingDevice.m
@@ -53,7 +53,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(@"MKVoiceProcessingDevice: Buffer too small. Allocating more space.");
AudioBuffer *b = dev->_buflist.mBuffers;
free(b->mData);
@@ -61,11 +61,18 @@ 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) {
NSLog(@"MKVoiceProcessingDevice: AudioUnitRender failed. err = %li", (long int)err);
return err;
}
+ dev->_buflist.mBuffers->mDataByteSize = dataByteSize;
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
short *buf = (short *) dev->_buflist.mBuffers->mData;
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;