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 18:27:23 -0700
I am already asking for only one channel. Perhaps I should have
included the channel map code earlier...
================================
// set channel map
inputChannelMap = NULL;
inputNumChannelsInMap = desiredFormat.mChannelsPerFrame; // 1 channel
UInt32 mapSize = inputNumChannelsInMap * sizeof(SInt32);
inputChannelMap = (SInt32 *)malloc(mapSize);
int i;
for(i = 0; i < inputNumChannelsInMap; ++i)
{
inputChannelMap[i] = -1;
}
inputChannelMap[0] = (SInt32)inputChannel;
================================
inputNumChannelsInMap gets set to the desiredFormat.mChannelsPerFrame,
which is equal to 1.
On 2004 Jun 25, at 18:03, William Stewart wrote:
Your channel map has to be the same number of channels that you are
asking AudioUnitRender for (that is the destination Doug was talking
about earlier)...
So, if you are pulling AudioUnitRender for 2 channels, then your
channel map has 2 channels in it, and each of these entries describes
which channel of the device you want in your 2 channels...
Bill
On 25/06/2004, at 4:33 PM, Daniel Todd Currie wrote:
(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
NOOO... this does not set the device format... This sets your client
format - its a transformation of what the device's format is which you
cannot set here (for the AUHAL's input side, the device format is
element 1, Input scope - your call above where you are getting the
sample rate of the device)
So, here you are asking for 1 channel, so your channel map should be
one channel big...
Bill
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.
--
mailto:email@hidden
tel: +1 408 974 4056
_______________________________________________________________________
_
__
Culture Ship Names:
Ravished By The Sheer Implausibility Of That Last Statement [GSV]
I said, I've Got A Big Stick [OU]
Inappropiate Response [OU]
Far Over The Borders Of Insanity And Still Accelerating [Eccentric]
_______________________________________________________________________
_
__
_______________________________________________
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.