Re: hardcoded microphone buffering in iPhone?
Re: hardcoded microphone buffering in iPhone?
- Subject: Re: hardcoded microphone buffering in iPhone?
- From: Nate <email@hidden>
- Date: Mon, 24 Nov 2008 01:36:03 -0800
Hi Inca,
Thanks for the AU RemoteIO tip! It seems to be notifying properly and not buffering internally, however there doesn't appear to be a mechanism for setting the buffer size. Is this right? The default buffer size is small enough for my needs so this is ok, but I would like to set it explicitly. If it is ever larger than the size I need then my app will not work properly.
Am I missing something or is AU RemoteIO completely undocumented? I had to cobble it together from the one or two code snippets scattered across the internet. That this isn't documented and that the 8kb hardcoded buffering of AQS isn't documented wasted a significant amount of my time, as the chew marks on my monitor can attest. I certainly hope that not all iPhone programming is this fun.
-Nate
On Mon, Nov 24, 2008 at 12:24 AM, Inca Rose
<email@hidden> wrote:
Hi Nate;
I remember when working with AQS that I was unable to control the mic buffer.
But you can use Audio Unit remoteIO, there you have more control and granularity on the amount
of media returned to the callback. It will not be always what you ask, but will be very close 90% of the time.
Inca
On Nov 24, 2008, at 10:00 AM, Nate wrote:
Hi Inca Rose,
I'm using Audio Queue Services. I have written a simple test case, which I will include at the end of this email.
I will look at the other API you mentioned. I am used to using Core Audio on OS X and found I couldn't use that on the iPhone, but I didn't realize there was another option.
Thanks,
-Nate
#import <AudioToolbox/AudioToolbox.h>
static NSDate *testTime;
static void microphoneCallback (
void *inUserData,
AudioQueueRef inAudioQueue,
AudioQueueBufferRef inBuffer,
const AudioTimeStamp *inStartTime,
UInt32 inNumPackets,
const AudioStreamPacketDescription *inPacketDesc
) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
if (testTime) {
printf("time: %f\n", -[testTime timeIntervalSinceNow]);
[testTime release];
testTime = nil;
}
testTime = [NSDate date];
[testTime retain];
[pool release];
AudioQueueEnqueueBuffer(inAudioQueue, inBuffer, 0, NULL);
}
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(UIApplication *)application {
UInt32 sessionCategory = kAudioSessionCategory_RecordAudio;
AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory);
AudioQueueRef queue;
AudioStreamBasicDescription format;
format.mSampleRate = 22050;
format.mFormatID = kAudioFormatLinearPCM;
format.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;
format.mChannelsPerFrame = 1;
format.mBitsPerChannel = 16;
format.mBytesPerFrame = format.mChannelsPerFrame * sizeof(SInt16);
format.mBytesPerPacket = format.mBytesPerFrame;
format.mFramesPerPacket = 1;
AudioQueueNewInput(&format, microphoneCallback, self, NULL, NULL, 0, &queue);
AudioSessionSetActive(true);
int bufferByteSize = 2048;
int bufferIndex;
for (bufferIndex = 0; bufferIndex < 1; ++bufferIndex) {
AudioQueueBufferRef buffer;
AudioQueueAllocateBuffer(queue, bufferByteSize, &buffer);
AudioQueueEnqueueBuffer(queue, buffer, 0, NULL);
}
AudioQueueStart(queue, NULL);
}
@end
On Sun, Nov 23, 2008 at 11:33 PM, Inca Rose
<email@hidden> wrote:
Which API are you using, Audio Buffer Queues or Audio Units RemoteIO?
Regards
Inca Rose
On Nov 24, 2008, at 4:39 AM, Nate wrote:
I tell the iPhone mic to open at 22050hz sample rate with a 2048 byte buffer. My callback gets called with 2048 bytes with this many seconds between calls...
0.185520
0.000077
0.000041
0.000039
0.185546
0.000075
0.000043
0.000042
It looks like it's internally buffering 8192 bytes, then hitting my callback 4 times with 2048 each time. Is this true? How can I get it to call my callback as soon as it collects 2048 bytes? IE, every ~0.046 seconds.
FWIW, I am seeing this behavior in the simulator (2.2), I don't have an actual iPhone at the moment to try it on.
Thanks,
-Nate
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (
email@hidden)
Help/Unsubscribe/Update your Subscription:
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden