Re: kAudioFilePropertyAudioDataPacketCount Broken for WAV files in iOS 4.2(.1)?
Re: kAudioFilePropertyAudioDataPacketCount Broken for WAV files in iOS 4.2(.1)?
- Subject: Re: kAudioFilePropertyAudioDataPacketCount Broken for WAV files in iOS 4.2(.1)?
- From: Christopher Liscio <email@hidden>
- Date: Wed, 8 Dec 2010 17:27:46 -0500
Hi list,
I've dug into the issue further, and this appears to be an issue with the AVAssetExportSession class, and nothing in the AudioFile API. AIF and WAV files are left corrupted at the end of an export session.
The original rdar (rdar://8725926) has been updated with sample code and text to indicate the difference.
Sorry for the confusion, folks. (Though there's still a serious bug out there...)
Cheers,
Chris Liscio
http://supermegaultragroovy.com
Learn _your_ music with Capo: http://capoapp.com
On Dec 3, 2010, at 9:48 AM, Christopher Liscio wrote:
> Hi folks,
>
> A user reported an issue with Capo on the iPhone/iPad, claiming WAV files in his iTunes library weren't loading for him. Upon further investigation, I determined that my request for kAudioFilePropertyAudioDataPacketCount is now returning 0, where it used to work fine on earlier versions of iOS.
>
> My code is very similar to Apple's own sample code to request the frame count of an audio file (first by reading its packet count, then referring to the AudioFilePacketTableInfo struct.) For formats that specify mFramesPerPacket as 1, the packet count should be used as the number of frames in the file.
>
> I've tested the following formats with success:
>
> MP3
> ALAC
> M4A
>
> And LPCM fails, regardless of whether it's in a WAV or AIF container.
>
> If there is a workaround that you'd recommend I use, please let me know about it! Below my sig, you'll find the code I am using to determine the file's length in frames.
>
> I filed rdar://8725926 with the text of this email, so you CoreAudio guys can track it internally.
>
> Thanks,
>
> Chris Liscio
> http://supermegaultragroovy.com
> Learn _your_ music with Capo: http://capoapp.com
>
> - (SInt64)frameCount
> {
> AudioFileID afID = NULL;
> UInt32 size = sizeof(afID);
> NSXThrowError( ExtAudioFileGetProperty( mAudioFile, kExtAudioFileProperty_AudioFile, &size, &afID ) );
>
> UInt64 packetCount = 0;
> size = sizeof(packetCount);
> NSXThrowError( AudioFileGetProperty( afID, kAudioFilePropertyAudioDataPacketCount, &size, &packetCount ) );
>
> // CL - In iOS 4.2.1 (and 4.2), WAV and AIF files have a packetCount of 0, whereas they did not in iOS 4.1.
>
> AudioStreamBasicDescription fileDataFormat;
> size = sizeof( fileDataFormat );
> NSXThrowError( AudioFileGetProperty( afID, kAudioFilePropertyDataFormat, &size, &fileDataFormat ) );
>
> AudioFilePacketTableInfo pti;
> BOOL ptiValid = NO;
> memset( &pti, 0, sizeof( AudioFilePacketTableInfo ) );
> size = sizeof(pti);
> OSStatus err = AudioFileGetProperty( afID, kAudioFilePropertyPacketTableInfo, &size, &pti );
> if ( err == noErr ) {
> ptiValid = YES;
> } else {
> ptiValid = NO;
> }
>
> UInt64 totalFrames = 0;
> switch ( fileDataFormat.mFramesPerPacket ) {
> case 1:
> totalFrames = packetCount;
> break;
> case 0:
> {
> AudioFramePacketTranslation afpt = { .mFrame = 0, .mPacket = packetCount - 1, .mFrameOffsetInPacket = 0 };
> size = sizeof(afpt);
> NSXThrowError( AudioFileGetProperty( afID, kAudioFilePropertyPacketToFrame, &size, &afpt ) );
> totalFrames = afpt.mFrame;
> }
> break;
> default:
> totalFrames = packetCount * fileDataFormat.mFramesPerPacket;
> break;
> }
>
> if ( ptiValid ) {
> totalFrames -= ( pti.mPrimingFrames + pti.mRemainderFrames );
> }
>
> return totalFrames;
> }
>
_______________________________________________
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