Re: Sample Rate Conversion using AudioConverter
Re: Sample Rate Conversion using AudioConverter
- Subject: Re: Sample Rate Conversion using AudioConverter
- From: Bill Stewart <email@hidden>
- Date: Mon, 9 Jun 2003 19:13:07 -0700
On Monday, June 9, 2003, at 02:35 PM, Tommy Braas wrote:
>
Bill,
>
>
You're a very funny guy! ;-)
I try, dismally pathetically really...
>
>
So, I have set up some code to use the AudioConverterFillComplexBuffer
>
and its callback.
>
>
New problems! I am probably setting something up incorrectly (or so I
>
hope...). When the callback is called, the
>
AudioBufferList.mBuffers[0].mData is NULL!
Yes - the input proc is giving you a place ot put the data, but not the
space to put it in... as it can't know how much input you are going to
give it...
In the SDK - have a look a AUBuffer - in the AUPublic directory...
renderABL.Allocate (theASBDesc, processPackets);
renderABL.PrepareBuffer (theASBDesc, processPackets);
This will prepare an AudioBufferList based on the description you give
it (which is your source description from the AudioConverterNew call)
and it will allocate the memory in the PrepareBuffer call.. (Allocate
actually allocates the BufferLIST, not the buffers themselves....)
PrepareNullBuffers will give you back the kind of buffer list you are
seeing now - ie. a buffer list with NULL mData values...
processPackets above is (for PCM) the number of sample frames you have
(say 512 - which if stereo is 512 left-right pairs)
Now - this is NOT the buffer list that you pass in when you call the
AudioConverterFillComplexBuffer - on this side (the output side) you
also have to allocate the memory that you want filled by the conversion
- so you can't pass a buffer list with NULL buffers there either...
Hmmm... I think its easy if I post a simple example - I'll do that
soon...
Bill
>
I have included the code below (Objective-C);
>
>
The file read method, with format conversion support;
>
>
ConversionInfo info;
>
info.audioFile = self;
>
info.fileOffset = offset;
>
>
UInt32 packetLength = *length/[_streamFormat bytesPerFrame]; //
>
_streamFormat is the destination format, not the source file format
>
>
audioBuffer->mNumberChannels = [_streamFormat channelsPerFrame];
>
// audioBuffer is defined elsewhere
>
audioBuffer->mDataByteSize = *length;
>
audioBuffer->mData = outBytes;
>
>
bufferList->mNumberBuffers = 1; // bufferList is defined elsewhere
>
bufferList->mBuffers[0] = *audioBuffer;
>
>
packetDescription->mStartOffset = 0; // packetDescription is
>
defined elsewhere
>
packetDescription->mLength = *length;
>
>
osStatus = AudioConverterFillComplexBuffer([converter
>
converter], ReadAudioConverterInputDataProc,
>
&info,
>
&packetLength,
>
bufferList, NULL); // I have tried using
>
both NULL (file is LPCM), and the above packetDescription
>
>
>
The callback;
>
>
OSStatus ReadAudioConverterInputDataProc( AudioConverterRef
>
inAudioConverter,
>
UInt32* ioNumberDataPackets,
>
AudioBufferList* ioData,
>
AudioStreamPacketDescription** outDataPacketDescription,
>
void* inUserData)
>
{
>
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
>
[conversionInfo->audioFile
>
readAudioConversionHandler:ioNumberDataPackets data:ioData
>
packetDescription:outDataPacketDescription userData:inUserData];
>
[pool release];
>
>
return 0;
>
}
>
>
Could someone please tell what I am doing wrong...I am fresh out of
>
ideas!
>
>
Thanks,
>
>
Tommy Braas
>
>
>
On Friday, Jun 6, 2003, at 18:49 US/Pacific, Bill Stewart wrote:
>
>
> Ummm... sample rate conversion on imaginary sample values...
>
>
>
> No - just because we'd run out of names (and the AudioBufferList is
>
> more complex than a void* blob of memory) - you should all be really
>
> thankful, we almost had to introduce
>
> AudioConverterFillReallyComplexBuffer :-) but we didn't:)
>
>
>
> Bill
>
>
>
> On Friday, June 6, 2003, at 12:27 PM, Tommy Braas wrote:
>
>
>
>> Bill and James,
>
>>
>
>> Thank you very much for your answers!
>
>>
>
>> I have one more question;
>
>>
>
>> Does the 'complex' part of the AudioConverterFillComplexBuffer
>
>> pertain to the buffers being complex (AudioBufferList*), or that it
>
>> expects the values to be complex? Maybe a dumb question, but since
>
>> the documentation leaves much to be desired, I feel compelled to >>> ask.
>
>>
>
>> Thanks again,
>
>>
>
>> Tommy Braas
>
>>
>
>>
>
>> On Friday, Jun 6, 2003, at 11:31 US/Pacific, Bill Stewart wrote:
>
>>
>
>>> And we've fixed this in our next release - we'll be returning an
>
>>> error for these invalid uses of convert buffer (something we should
>
>>> have done but missed in Jaguar)
>
>>>
>
>>> You might also look at the FillComplextBuffer version - if you are
>
>>> working with audio units (the V2 variety) then this takes and
>
>>> returns the data strcuture (AudioBufferList) that is used by these
>
>>> units... (If you're using a V1 unit, then the FillBuffer call is
>
>>> the appropriate one) - and if I'm confusing you - apologies! I'm
>
>>> confused myself sometimes:-)
>
>>>
>
>>> Bill
>
>>>
>
>>> On Friday, June 6, 2003, at 07:28 AM, James McCartney wrote:
>
>>>
>
>>>> You should not use AudioConverterConvertBuffer when you have a
>
>>>> sample rate conversion. Use AudioConverterFillBuffer or
>
>>>> AudioConverterFillComplexBuffer.
>
>>>>
>
>>>> Because in a sample rate conversion the output samples depend on
>
>>>> samples before and after them from the input, there is some
>
>>>> internal buffering that must happen which requires that you use
>
>>>> the pull model of these other conversion routines.
>
>>>>
>
>>>> AudioConverterConvertBuffer is only for conversions where there is
>
>>>> a 1:1 correspondence between input and output such as bit depth,
>
>>>> endian swap, int<->float, (de)interleaving...
>
>>>>
>
>>>>
>
>>>> On Friday, June 6, 2003, at 01:00 AM, Tommy Braas wrote:
>
>>>>
>
>>>>> I have been trying to figure out how to properly feed an instance
>
>>>>> of AudioConverter using AudioConverterConvertBuffer(...).
>
>>>>
>
>>>>
>
>>>> -- --- james mccartney
>
>>>> _______________________________________________
>
>>>> 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
>
>>>
>
>>> ____________________________________________________________________
>
>>> ______
>
>>> "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
>
>>> ____________________________________________________________________
>
>>> ______
>
>>> _______________________________________________
>
>>> 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
>
>
>
> ______________________________________________________________________
>
> ____
>
> "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
>
> ______________________________________________________________________
>
> ____
>
> _______________________________________________
>
> 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
________________________________________________________________________
__
"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
________________________________________________________________________
__
_______________________________________________
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.