Re: iPhone AudioConverter and Audio File - Does anyone know how to use this on Audio Unit stuff
Re: iPhone AudioConverter and Audio File - Does anyone know how to use this on Audio Unit stuff
- Subject: Re: iPhone AudioConverter and Audio File - Does anyone know how to use this on Audio Unit stuff
- From: Doug Wyatt <email@hidden>
- Date: Fri, 15 Jan 2010 12:06:58 -0800
On Jan 15, 2010, at 11:27 , wm schauweker wrote:
> 1. Has anyone in the history of the world figured out with what magic incantation one can induce Audio Converter to accept Audio Unit samples as input?
Um, yes.
> o I managed to find an ASBD combination that allowed me to create an AudioConverter. This is NOT the combination I want, but it at least gets gives me a starting point. In particular, if I feed the following ASBD as both input format and output format, then AudioConverterNew returns without error. Note in passing that the function seems to hate AudioFormatFlagIsNonInterleaved.
>
> inputFormat.mSampleRate = 44100.0;
> inputFormat.mFormatID = kAudioFormatLinearPCM;
> inputFormat.mFramesPerPacket = 1;
> inputFormat.mChannelsPerFrame = 2;
> inputFormat.mBytesPerFrame = 4;
> inputFormat.mBytesPerPacket = 4;
> inputFormat.mBitsPerChannel = 16;
> inputFormat.mReserved = 0;
> inputFormat.mFormatFlags =
> kLinearPCMFormatFlagIsSignedInteger |
> kLinearPCMFormatFlagIsPacked |
> // kAudioFormatFlagIsNonInterleaved |
> 0;
From CoreAudioTypes.h:
In audio data a frame is one sample across all channels. In non-interleaved
audio, the per frame fields identify one channel. In interleaved audio, the per
frame fields identify the set of n channels.
So when you add the non-interleaved flag, mBytesPerFrame and mBytesPerPacket both most change from sizeof(SInt16) * mChannelsPerFrame to sizeof(SInt16). See what CAStreamBasicDescription::SetCanonical does based on the flag.
> o An interesting failure: I tried using the following, which is just fine for telling an Audio Unit how to emit output or accept input:
>
> CAStreamBasicDescription inputFormat;
> inputFormat.SetAUCanonical(2, false);
>
> (Fails when trying to create the converter.)
>
> (Also, checking the .h file: A CASBD is an ASBD.)
Did you set a sample rate? Is this is the source or destination format? What is the other format?
> o Another interesting failure: I tried brute force, applying all of the flags that seemed to make sense, including the few things I could glean by searching the internet. (I also tried leaving out the non-interleaved flag.)
>
> inputFormat.mSampleRate = 44100.0;
> inputFormat.mFormatID = kAudioFormatLinearPCM;
> inputFormat.mFramesPerPacket = 1;
> inputFormat.mChannelsPerFrame = 2;
> inputFormat.mBytesPerFrame = 4;
> inputFormat.mBytesPerPacket = 4;
> inputFormat.mBitsPerChannel = 16;
> inputFormat.mReserved = 0;
> inputFormat.mFormatFlags =
> kAudioFormatFlagIsSignedInteger |
> kAudioFormatFlagsNativeEndian |
> kLinearPCMFormatFlagIsNonInterleaved |
> kLinearPCMFormatFlagsSampleFractionShift |
> kLinearPCMFormatFlagsSampleFractionMask |
> 0
> ;
> (Failed when trying to create the converter.)
Really, stick with SetAUCanonical; if you really want to go down this route, go stare at the source to SetAUCanonical and CoreAudioTypes.h until you understand how nonsensical it is to be OR'ing a shift constant and a mask into the flags...
> 2. Has anyone figured out why ASBDs that pass AudioConverterNew would fail when passed to AudioFileCreateWithURL?
>
> o Admittedly nonsensically, I fed the following ASBD as input and output format to to AudioConverterNew:
>
> // Specify converted recording format.
> convertedFormat.mSampleRate = 44100.0;
> convertedFormat.mFormatID = kAudioFormatLinearPCM;
> convertedFormat.mFramesPerPacket = 1;
> convertedFormat.mChannelsPerFrame = 2;
> convertedFormat.mBytesPerFrame = 4;
> convertedFormat.mBytesPerPacket = 4;
> convertedFormat.mBitsPerChannel = 16;
> convertedFormat.mReserved = 0;
> convertedFormat.mFormatFlags =
> kLinearPCMFormatFlagIsSignedInteger |
> kLinearPCMFormatFlagIsPacked |
> // kAudioFormatFlagIsNonInterleaved |
> 0;
>
> I then fed it to AudioFileCreate..., Along with a URL to create a WAV file.
>
> It threw a format exception.
That format looks okay for 16-bit stereo in WAV, as long as the non-interleaved flag is indeed clear. What else did you pass to AudioFileCreate and exactly what did it return?
Doug
_______________________________________________
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