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 00:00:55 -0800
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:
This email sent to
email@hidden
_______________________________________________
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