• 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: AudioConverterConvertBuffer sample?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: AudioConverterConvertBuffer sample?


  • Subject: Re: AudioConverterConvertBuffer sample?
  • From: Doug Wyatt <email@hidden>
  • Date: Mon, 4 Mar 2002 20:06:26 -0800

On Monday, March 4, 2002, at 03:24 , Ken Wieschhoff wrote:
// Get the description from the default input unit
mStreamInDesc = GetAudioParameters();

mStreamOutDesc.mSampleRate = 44.100;

I assume you mean 44100 -- or that the input is at 44.1 Hz too. Otherwise you're going to get a sample rate conversion and AudioConverterConvertBuffer will fail in exactly the way you're seeing, for a reason I'll explain in a minute.

mStreamOutDesc.mFormatID = kAudioFormatLinearPCM;
mStreamOutDesc.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger
| kLinearPCMFormatFlagIsBigEndian
| kLinearPCMFormatFlagIsPacked;
mStreamOutDesc.mBytesPerPacket = 4;
mStreamOutDesc.mFramesPerPacket = 1;
mStreamOutDesc.mBytesPerFrame = 4;
mStreamOutDesc.mChannelsPerFrame = 2;
mStreamOutDesc.mBitsPerChannel = 16;

err = AudioConverterNew ( mStreamInDesc,
&mStreamOutDesc,
&mConverter);

CheckError( err, "AudioConverterNew" );

:
:


void ConvertSample(void *inputBuffer, UInt32 inputBufferSize)
{
Handle audioBuffer = NULL;
OSErr err;
UInt32 ioOutputDataSize = inputBufferSize * 2; // make an extra big buffer
// in case the sample changes size


audioBuffer = NewHandle(inputBufferSize * 2);
HLock(audioBuffer);
err = AudioConverterConvertBuffer( mConverter,
inputBufferSize, inputBuffer,
&ioOutputDataSize, *audioBuffer);
CheckError( err, "AudioConverterConvertBuffer" );
// returns paramErr.....

Admittedly AudioConverterConvertBuffer has no documentation, which is doubly bad because *I* can't say for sure how it's supposed to handle "unusual" conditions without some thought. But, that said, the conditions under which it should work are when ioOutputDataSize, on entry, is exactly the number of output bytes generated from inputBufferSize.

So, either you're doing a sample rate conversion -- in which case you can't use this function as is, because with SRC the input/output buffer size ratio can vary in small, unpredictable amounts from buffer to buffer -- or you're asking for some other conversion such that the converter wants to produce something other than 2*inputBufferSize bytes of output for inputBufferSize bytes of input. You do know the formats so unless there's a sample rate conversion, you know the correct input/output ratio and should be able to use this function.

I'll write a bug so that we'll document the correct behavior of the function (and fix any discrepencies between the documentation and code ;-), but this is how it works in 10.1.*.

Doug

--
Doug Wyatt
work: email@hidden (CoreAudio)
personal: email@hidden http://www.sonosphere.com

"Temporal = temporary".
-- dsw
_______________________________________________
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.

  • Follow-Ups:
    • Interested in a shared solutions library?
      • From: email@hidden
    • Re: AudioConverterConvertBuffer sample?
      • From: Ken Wieschhoff <email@hidden>
    • Re: AudioConverterConvertBuffer sample?
      • From: "Jeremy@Verizon" <email@hidden>
References: 
 >Re: AudioConverterConvertBuffer sample? (From: Ken Wieschhoff <email@hidden>)

  • Prev by Date: Re: Beginning Sound on OSX
  • Next by Date: Re: AudioConverterConvertBuffer sample?
  • Previous by thread: Re: AudioConverterConvertBuffer sample?
  • Next by thread: Re: AudioConverterConvertBuffer sample?
  • Index(es):
    • Date
    • Thread