• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Help with AUHAL & AudioConverter
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help with AUHAL & AudioConverter


  • Subject: Re: Help with AUHAL & AudioConverter
  • From: Doug Wyatt <email@hidden>
  • Date: Wed, 8 Feb 2006 11:02:16 -0800

It's tricky to do sample rate conversion on input.

At the HAL/AUHAL level, every I/O cycle provides some number of samples of input which must be completely processed during that I/O cycle; they'll be overwritten with new samples on the next I/O cycle. You can think of the I/O cycle as "pushing" samples to you.

By contrast, AudioConverter is designed to "pull" samples; you say how many output samples you want to produce and only the input necessary to produce that output is consumed. It is possible to push a precise amount of input through an AudioConverter but that's where it's tricky -- you call FillComplexBuffer repeatedly, advancing the output pointer(s), until the input is exhausted, and then return a private error code from the input proc. At this point, the converter will return whatever output has been produced, along with that error code.

Your example has an output rate of 48000 so if the hardware's set to anything else you are doing a rate conversion. Assuming you are... then problem #1 in your code is that you're trying to pull as many output samples as there are input samples. Depending on whether you're upsampling or downsampling, you'll either run out of input or fail to consume it all.

Some possible causes of paramErr...
- inInputDataProc, ioOutputDataPacketSize, or outOutputData is NULL (not the case)
- one of your output buffers' mData is NULL or mDataByteSize is 0 <-- check this
- your output buffer list's mNumberBuffers has fewer buffers than required by the output format (your output format requires 1 ... so could it be 0?)



But I think it would be more straightforward to move the converter out of the input proc -- I'd only put one here if I knew that the only conversion I wanted was float->int, no rate conversion. I'd keep the ring buffer in floats at the hardware sample rate, and then have an audio converter to do the rate conversion and float->int when reading from the ring buffer.


If the user changes input devices, that gets handled fairly transparently unless the rate changes. Whichever way you do things, you will definitely need to be prepared for that. The way to handle this is to call AudioUnitAddPropertyListener on the input AUHAL, for kAudioUnitProperty_StreamFormat on the input scope of element 1 -- this corresponds to the input hardware format.

HTH,
Doug



On Feb 7, 2006, at 19:50, Stephen Shaw wrote:

Thank you Bill, I had read in TN2091 that the AUHAL contained a converter and I had considered using it by setting the output format, but I was concerned about the dest format. I was also confused that if the user selects another input device or changes the samplerate, that I might still need an external Audio Converter.

The destination I'm trying to reach is

            outputASBD.mSampleRate      = 48000;// khz

            outputASBD.mFormatID          = kAudioFormatLinearPCM;

outputASBD.mFormatFlags = kAudioFormatFlagIsPacked | kAudioFormatFlagIsSignedInteger;

            outputASBD.mBytesPerPacket = 4;

            outputASBD.mFramesPerPacket = 1;

            outputASBD.mBytesPerFrame = 4;

            outputASBD.mChannelsPerFrame = 2;

            outputASBD.mBitsPerChannel = sizeof (SInt16) * 8;

            outputASBD.mReserved = 0;



I have a subsystem that expects the audio in that format and it has its own timer to pull the data. So what I was planing on doing was using the AudioRingBuffer to store the audio until it was pulled from the destination sub-system's timer routine. What I was trying to set up in my InputProc callback was:


err= AudioUnitRender(pDevice->mInputUnit,

ioActionFlags,

inTimeStamp,

inBusNumber,

inNumberFrames, //# of frames requested

pDevice->mpInputBufferList);// Audio Buffer List to hold data

            checkErr( err);



            UInt32 convertFrames = inNumberFrames;

err = AudioConverterFillComplexBuffer (pDevice- >mConvertRef, ACComplexInputProc, pDevice, &convertFrames, pDevice- >mpConvertBufferList, NULL);

pDevice->mpRingBuffer->Store (pDevice- >mpConvertBufferList, convertFrames , SInt64 (inTimeStamp- >mSampleTime));



but I was getting a -50 error returned from the call to FillComplexBuffer.



Thank you again for you valuable help,



Stephen
Macintosh Virtual PC Engineer




________________________________

From: William Stewart [mailto:email@hidden]
Sent: Tue 2/7/2006 6:04 PM
To: Stephen Shaw
Cc: CoreAudio API
Subject: Re: Help with AUHAL & AudioConverter



Stephen

What format do you need?

If your sample rate is the same (but you want say an interleaved or
int format), then you can actually have the AU do the format
conversion for you.

If the sample rate is different, then you will need to do the
conversion externally to the AU's render call.

The question though, is really too general to answer.

What are you doing with the audio input? If you are writing a file,
then you can use the ExtAF API and just give it the format that you
have - it will do all necessary conversions for you.

If you want the audio in some format in order to do some post-
processing or other activities with, then you need a more complex
solution - probably you will need to buffer the audio input you have
from the device (there are some AudioBuffer Ring Buffer code in
PubicUtility)... Then you run some other thread and use whatever
services you need to convert that audio to the format you want. The
AUHAL does NOT buffer audio, so you really can't call its render call
from an AudioConvFill's InputProc directly - at least there would
need to be a lot of gymnastics about getting the notifications and
time stamps right, etc...

Bill

On 07/02/2006, at 4:51 PM, Stephen Shaw wrote:

Using the ComplexPlayThru as an example, I'm able to get a AUHAL
set up which supplies me with audio input.  I'm still trying to
discern the best way of taking this input and converting it to the
format I need.  It looks like there's two options:

In the AUHAL input callback I can call the AudioUnitRender to
acquire the data and then call AudioConverterFillComplexBuffer to
convert it, or I could call AudioUnitRender from the AudioConveter
callback routine and return the acquired data to the converter from
there.  One problem I see with the second option is I loose access
to the TimeStamp parameter in order to call AudioUnitRender.

I would really appreciate any help, tips or pointers anyone can
provide me since I've got a feature deadline pressing.

Stephen
Macintosh Virtual PC Engineer
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40apple.com


This email sent to email@hidden

--
mailto:email@hidden
tel: +1 408 974 4056
______________________________________________________________________ __
__
"Much human ingenuity has gone into finding the ultimate Before.
The current state of knowledge can be summarized thus:
In the beginning, there was nothing, which exploded" - Terry Pratchett
______________________________________________________________________ __
__




_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40apple.com


This email sent to email@hidden

-- Doug Wyatt Core Audio, Apple

_______________________________________________
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


References: 
 >Help with AUHAL & AudioConverter (From: Stephen Shaw <email@hidden>)
 >Re: Help with AUHAL & AudioConverter (From: William Stewart <email@hidden>)
 >RE: Help with AUHAL & AudioConverter (From: "Stephen Shaw" <email@hidden>)

  • Prev by Date: Mixer Units Documentation
  • Next by Date: RE: MIDI NoteOn velocity 0
  • Previous by thread: RE: Help with AUHAL & AudioConverter
  • Next by thread: Book suggestions, docs etc...
  • Index(es):
    • Date
    • Thread