• 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
AudioConverter buffer size questions
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

AudioConverter buffer size questions


  • Subject: AudioConverter buffer size questions
  • From: Stephen Davis <email@hidden>
  • Date: Thu, 23 Feb 2006 01:39:21 -0800

I'm having some trouble setting up a converter to do SRC with fixed- length input buffers. For example, I'm converting 96 kHz 16-bit integer stereo to 44.1 khz 32-bit float stereo and I'm reading from the input file in fixed-size buffers, say 16 KB.

So, I set up my converter with the appropriate formats such that calling CAShow() on it gives me:

AudioConverter 0x3abb234 [0x65943d0]:
PCMConverter 0x6594580
Input: 2 ch, 96000 Hz, 'lpcm' (0x0000000E) 16-bit big-endian signed integer
Output: 2 ch, 96000 Hz, 'lpcm' (0x0000000B) 32-bit big-endian float
SampleRateConverter 0x6594660
Input: 2 ch, 96000 Hz, 'lpcm' (0x0000000B) 32-bit big-endian float
Output: 2 ch, 44100 Hz, 'lpcm' (0x0000000B) 32-bit big-endian float


I have 16 KB input buffers which equals 4096 sample frames of input. I want to give this to the converter each time and pull out whatever it will give me. Ideally, I'd like to set things up properly so that I use up the entire input buffer each time I call AudioConverterFillComplexBuffer().

After setting the SRC quality property to "max", I ask the converter for its kAudioConverterPropertyCalculateOutputBufferSize property while giving it 16384 as its input target. According to the comments in AudioConverter.h:

"a UInt32 that on input holds a size in bytes that is desired for the input
data. On output, it will hold the size in bytes of the output buffer
required to hold the output data that will be generated. Note that some
converters cannot do this calculation."


It returns 14872 which says to me that giving it a buffer of 16384 input bytes will return at most 14872 output bytes. That's all well and good. However, if I call AudioConverterFillComplexBuffer() like so:

		reqFrames = 14872 / outputFormat.mBytesPerFrame;
		status = AudioConverterFillComplexBuffer( ..., &reqFrames, ... )

In my fill proc, the converter rarely asks for the entire input buffer (16192 bytes, 16176, etc.) BUT it will return 14872 output bytes. Since that's the size of my output buffer, I can't take any more output frames if I call it again to have it eat the rest of the input buffer.

Should I be calculating my output buffer size differently? It seems like I would need to ask for more output frames in order to have it eat the entire input buffer but that would violate the max output size I was given.

There is some sample code in the core audio reference docs (http:// developer.apple.com/documentation/MusicAudio/Reference/CoreAudio/ index.html in the "Using Audio Converter" section) that looks like:

while( /* ... While there is data left to be converted ... */ )
{
    UInt32 ioOutputDataPacketSize = kRequestPackets;

OSStatus err = AudioConverterFillComplexBuffer(converter, inputProcPtr,
userData, &ioOutputDataPacketSize, &bufferList, NULL);
}


The comments surrounding this code say to "keep calling until the input data is exhausted" and I could do that but it would be violating the 14872 byte max output size. Any solution I have come up with so far feels like a kludge so I'm hoping there is a better way or something obvious I'm missing.

thanks,
stephen

BTW, I can handle the 48 frame priming or not and it makes no difference to this particular problem.

_______________________________________________
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


  • Prev by Date: Hardware Plugins
  • Next by Date: The legacy of kAudioUnitRenderAction_OutputIsSilence
  • Previous by thread: Re: Hardware Plugins
  • Next by thread: The legacy of kAudioUnitRenderAction_OutputIsSilence
  • Index(es):
    • Date
    • Thread