Re: My AUHAL Output Audio Unit
Re: My AUHAL Output Audio Unit
- Subject: Re: My AUHAL Output Audio Unit
- From: Daniel Todd Currie <email@hidden>
- Date: Fri, 25 Jun 2004 16:33:39 -0700
(embedded response)
On 2004 Jun 25, at 14:58, Doug Wyatt wrote:
I'm pretty sure I have the channel map set up correctly now, but I'm
still getting buffers full of zeros.
What is in your channel map?
I am only trying to read one channel, so my channel map just looks like
inputChannelMap[0] = 0 or 1, depending on user input for the Built-in
Audio device.
Has anyone had this problem before? It seems like AudioUnitRender()
isn't writing any data to my AudioBufferList, but I have no idea why.
The simplest explanation is that the channel map or the stream
formats, or both, are not correct.
I set the AudioStreamBasicDescription desiredFormat as follows (based
largely on TN 2091):
================================
// get device format
size = sizeof(deviceFormat);
err = AudioUnitGetProperty(inputAudioUnit,
kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Input,
1,
&deviceFormat,
&size);
if (err != noErr)
{
NSLog(@"kAudioUnitProperty_StreamFormat error: %X", err);
return(NO);
}
desiredFormat.mSampleRate = deviceFormat.mSampleRate;
desiredFormat.mFormatID = kAudioFormatLinearPCM;
desiredFormat.mFormatFlags = kLinearPCMFormatFlagIsFloat |
kLinearPCMFormatFlagIsBigEndian | kLinearPCMFormatFlagIsPacked;
desiredFormat.mBytesPerPacket = 4;
desiredFormat.mFramesPerPacket = 1;
desiredFormat.mBytesPerFrame = 4;
desiredFormat.mChannelsPerFrame = 1;
desiredFormat.mBitsPerChannel = 32;
// set device format
err = AudioUnitSetProperty(inputAudioUnit,
kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Output,
1,
&desiredFormat,
sizeof(AudioStreamBasicDescription));
if(err != noErr)
{
NSLog(@"kAudioUnitProperty_StreamFormat error: %X", err);
return(NO);
}
================================
This should at least be the correct format for the Built-in Audio. Or
am I misunderstanding how the stream formats work as well? Since I am
setting the desired format, can't I set it to whatever I want it to be?
I thought this was one advantage of using AudioUnits, that it will
handle format conversions for me. What exactly do you mean that the
stream format could be incorrect?
Sorry to be hassling the list with these simple questions, but there is
no literature on the subject anywhere...
AudioUnitRender() is returning noErr, so could that even be the
problem?
Yes.
I also think my inputProc is screwed, because I am having to use all
these arrows in my code -> that I don't see in anyone else's stuff in
the docs or the archives. Here's my inputProc callback:
This is a C function, not an ObjC or C++ method. Accessing structures
in C requires arrows or stars and dots.
OSStatus recordIOProc(void *inRefcon,
AudioUnitRenderActionFlags *ioActionFlags,
const AudioTimeStamp *inTimeStamp,
UInt32 inBusNumber,
UInt32 inNumFrames,
AudioBufferList *ioData)
{
Recorder *client = (Recorder *)inRefcon;
OSStatus err = AudioUnitRender(client->inputAudioUnit,
ioActionFlags,
inTimeStamp,
inBusNumber,
inNumFrames,
client->inputBuffer);
if(err == noErr)
{
unsigned dataSize =
client->inputBuffer->mBuffers[0].mDataByteSize;
client->tempBuffer = client->inputBuffer->mBuffers[0].mData;
[client->aQueue
writeBytesWithoutBlockingFrom:client->tempBuffer length:dataSize];
return(noErr);
}
else return(err);
}
Rather than use render notifications etc., I elected to just pull the
buffer using an MTCircularQueue (from MTCoreAudio). This callback
worked when I was using a straight HAL implementation, but now I am
upgrading to AUHAL and need to do something a little different?
You have to set an input callback, and your input callback must call
AudioUnitRender. The input data is not available at any other time.
Your code is doing this much right -- if it wasn't, you would be
getting a cannotDoInCurrentContext error.
Doug
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.