Created
May 8, 2013 10:06
-
-
Save Ridwy/5539522 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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