• 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
kAudioFilePropertyAudioDataPacketCount Broken for WAV files in iOS 4.2(.1)?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

kAudioFilePropertyAudioDataPacketCount Broken for WAV files in iOS 4.2(.1)?


  • Subject: kAudioFilePropertyAudioDataPacketCount Broken for WAV files in iOS 4.2(.1)?
  • From: Christopher Liscio <email@hidden>
  • Date: Fri, 3 Dec 2010 09:48:19 -0500

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

  • Follow-Ups:
    • Re: kAudioFilePropertyAudioDataPacketCount Broken for WAV files in iOS 4.2(.1)?
      • From: Christopher Liscio <email@hidden>
    • Re: kAudioFilePropertyAudioDataPacketCount Broken for WAV files in iOS 4.2(.1)?
      • From: Paul Davis <email@hidden>
  • Prev by Date: Re: no sound on Power PC G4
  • Next by Date: Re: kAudioFilePropertyAudioDataPacketCount Broken for WAV files in iOS 4.2(.1)?
  • Previous by thread: Re: Another question on capturing audio played back by a software
  • Next by thread: Re: kAudioFilePropertyAudioDataPacketCount Broken for WAV files in iOS 4.2(.1)?
  • Index(es):
    • Date
    • Thread