Skip to content

Instantly share code, notes, and snippets.

@Ridwy
Created May 8, 2013 10:06
Show Gist options
  • Save Ridwy/5539522 to your computer and use it in GitHub Desktop.
Save Ridwy/5539522 to your computer and use it in GitHub Desktop.
// extract RAW PCM
NSURL* url = [[NSBundle mainBundle] URLForResource:@"" withExtension:@"mp3"];
AVAsset* asset = [AVAsset assetWithURL:url];
NSError* err = nil;
AVAssetReader* reader = [[AVAssetReader alloc] initWithAsset:asset error:&err];
if (!err) {
AVAssetReaderAudioMixOutput* output = [[AVAssetReaderAudioMixOutput alloc]
initWithAudioTracks:[asset tracksWithMediaType:AVMediaTypeAudio]
audioSettings:nil];
[reader addOutput:output];
[reader startReading];
CMSampleBufferRef sampleBuffer = NULL;
while (1) {
sampleBuffer = [output copyNextSampleBuffer];
if (sampleBuffer == NULL) break; // there are no more sample buffers available
CMBlockBufferRef blockBuffer = NULL;
AudioBufferList audioBufferList;
OSStatus status = CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer(sampleBuffer,
NULL,
&audioBufferList,
sizeof(audioBufferList),
NULL,
NULL,
0,
&blockBuffer);
if (status == noErr) {
// ここでAudioBufferListから読み出す処理など
}
if (sampleBuffer) CFRelease(sampleBuffer);
if (blockBuffer) CFRelease(blockBuffer);
if (status != noErr) break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment