• 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: Getting PCM data from MP3/AAC/ALAC File (William Bates)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting PCM data from MP3/AAC/ALAC File (William Bates)


  • Subject: Re: Getting PCM data from MP3/AAC/ALAC File (William Bates)
  • From: Daniel Staudigel <email@hidden>
  • Date: Wed, 24 Dec 2008 00:19:12 -0800
  • Resent-cc: Roni Music <email@hidden>
  • Resent-date: Wed, 24 Dec 2008 00:22:37 -0800
  • Resent-from: Daniel Staudigel <email@hidden>
  • Resent-message-id: <email@hidden>
  • Resent-to: email@hidden

Wow! This is step 1! This code actually works on the mac side (still no luck on the iPhone side). Tacking on the following read-in code, I get well-bounded floating point values.


UInt32 kSrcBufSize = 32768;
char srcBuffer[kSrcBufSize];
memset(srcBuffer, 0, kSrcBufSize);

// do the read and write - the conversion is done on and by the write call
while (1)
{
AudioBufferList fillBufList;
fillBufList.mNumberBuffers = 1;
fillBufList.mBuffers[0].mNumberChannels = fileFmt.mChannelsPerFrame;
fillBufList.mBuffers[0].mDataByteSize = kSrcBufSize;
fillBufList.mBuffers[0].mData = srcBuffer;

// client format is always linear PCM - so here we determine how many frames of lpcm
// we can read/write given our buffer size
UInt32 numFrames = (kSrcBufSize / clientFmt.mBytesPerFrame);

printf("READING %i FRAMES (",numFrames);

extAudioFile.Read(numFrames, &fillBufList);

printf("got %i frames)\n",numFrames);
for(int i = 0 ; i < numFrames ; i++) {
/*short left = ((short*)srcBuffer)[i*2+0];
short right = ((short*)srcBuffer)[i*2+1];

printf("%5i of %5i : L: %i\tR: %i\n",i,numFrames,left,right);*/

float left = ((float *)srcBuffer)[i*2+0];
float right = ((float *)srcBuffer)[i*2+1];

printf("%4i of %4i [%f,%f]\n",i,numFrames,left,right);
}

//err = ExtAudioFileWrite(outfile, numFrames, &fillBufList);
}


The commented-out printf statements in the readout for-loop are the UInt16 reading bits for getting data out on iPhone. On the iPhone i get two effects:

Readout only happens in single-frame chunks (much less than the thousands requested), the perm error happens where it was described, and the readout is total bogus.

Daniel

On Dec 23, 2008, at 9:38 AM, Roni Music wrote:

I've followed this thread and I have never had any success in getting ExtAudioFile to decode an mp3 file on the iPhone

here is the most simple example I could come up with


#include "CAXException.h" #include "CAStreamBasicDescription.h" #include "CAAudioChannelLayout.h" #include "CAExtAudioFile.h"


void TestExtAudioFile(const char *fpath) { printf ("TestExtAudioFile() file: %s\n", fpath);

try
{
CFURLRef sndFile = CFURLCreateFromFileSystemRepresentation(NULL, (const UInt8 *)fpath, strlen(fpath), false);
if (!sndFile)
XThrowIfError (!sndFile, "can't parse file path");


CAExtAudioFile extAudioFile;
extAudioFile.OpenURL(sndFile);
CFRelease (sndFile);

CAStreamBasicDescription fileFmt = extAudioFile.GetFileDataFormat();
printf ("File format: "); fileFmt.Print();

CAStreamBasicDescription clientFmt;
clientFmt.mSampleRate = 44100.0;

clientFmt.SetCanonical(2, false/*bool interleaved*/);

extAudioFile.SetClientFormat(clientFmt); // fails with a 'perm' error

printf ("Client format: "); clientFmt.Print();
}

catch (CAXException e)
{
char buf[256];
fprintf(stderr, "Error: %s (%s)\n", e.mOperation, e.FormatError(buf));
}

}

Any comments?

Rolf





_______________________________________________
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

_______________________________________________ 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
References: 
 >Re: Getting PCM data from MP3/AAC/ALAC File (William Bates) (From: "Roni Music" <email@hidden>)

  • Prev by Date: Re: Changing AudioConverter sample rates on the fly
  • Next by Date: Few sample rate conversion questions
  • Previous by thread: Re: Getting PCM data from MP3/AAC/ALAC File (William Bates)
  • Next by thread: Custom audio channels names in coreaudio
  • Index(es):
    • Date
    • Thread