XSL
XSL

Reputation: 3055

Getting the AVAssetReader's Sample Data

I'm trying to get the PCM data from an MP3. I'm using AVAssetReaderOutput and it seems to reading the data fine.

while(true)
{
    nextBuffer = [assetReaderOutput copyNextSampleBuffer];

    if(nextBuffer)
    {

       countsample = CMSampleBufferGetNumSamples(nextBuffer);
       NSLog(@"%i", countsample);
    }

}

I noticed that if I add up countsample, it equates to the number of seconds in the song (assuming 44100hz sample rate). For this reason, I'm sure the reading is being handled perfectly. What I'd like to do, however, is perform various DSP filters on this data but I need to do it on the sample information itself. How can I access the sample data? Also, I noticed that the CMSampleBufferGetNumSamples always returned 8192 except at the end of the song. Is there a way to increase/decrease this read rate? Thank you

Upvotes: 2

Views: 1409

Answers (1)

zaph
zaph

Reputation: 112857

Append the data to a NSMutableData object.

NSMutabelData *samples = [NSMutabelData data];
while(countsample)
{
    nextBuffer = [assetReaderOutput copyNextSampleBuffer];
    if(nextBuffer)
    {
       countsample = CMSampleBufferGetNumSamples(nextBuffer);
       [samples appendBytes:nextBuffer length:countsample];
    }
}

countsample and nextBuffer are assumed to already exist in your code.

Upvotes: 3

Related Questions