2011-01-11 2 views

답변

6

ExtAudioFileGetProperty를 사용하여 기존 m4a 오디오 파일에서 ASBD를 가져올 수 있습니다.

자세한 내용은 Click here.

+0

그렇다면 m4a 파일에서 ExtAudioFileGetProperty를 실행했을 때의 결과는 무엇입니까? – user1021430

0

파일의 ASBD를 2 가지 (적어도) 다른 방법으로 가져올 수 있습니다. 'ExtAudioFileGetProperty'또는 'AudioFileGetProperty'를 사용할 수 있습니다.

AudioFileGetProperty :

NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"sample" ofType:@"m4a"]; 
CFURLRef soundFileURL = (__bridge CFURLRef)[NSURL fileURLWithPath:soundFilePath]; 

if (soundFileURL != nil) { 

    AudioFileID audioFile; 
    OSStatus theError = noErr; 

    theError = AudioFileOpenURL(soundFileURL, 
           kAudioFileReadPermission, 
           0, 
           &audioFile); 
    if(theError != noErr) { 
     printf("AudioFileOpenURL failed!"); 
     return; 
    } 

    AudioStreamBasicDescription asbd; 
    UInt32 size = sizeof(asbd); 
    theError = AudioFileGetProperty(audioFile, kAudioFilePropertyDataFormat, &size, &asbd); 

    if(theError != noErr) { 
     printf("kAudioFilePropertyDataFormat failed!"); 
     return; 
    } else { 
     printf("Sample Rate : %f\n", asbd.mSampleRate); 
     /* 
     Float64    mSampleRate; 
     AudioFormatID  mFormatID; 
     AudioFormatFlags mFormatFlags; 
     UInt32    mBytesPerPacket; 
     UInt32    mFramesPerPacket; 
     UInt32    mBytesPerFrame; 
     UInt32    mChannelsPerFrame; 
     UInt32    mBitsPerChannel; 
     UInt32    mReserved; 
     */ 
    } 
} 

ExtAudioFileGetProperty : 당신이 그들을 발견하면

NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"sample" ofType:@"m4a"]; 
CFURLRef soundFileURL = (__bridge CFURLRef)[NSURL fileURLWithPath:soundFilePath]; 

if (soundFileURL != nil) { 
    OSStatus theError = noErr; 

    ExtAudioFileRef fileRef; 
    theError = ExtAudioFileOpenURL(soundFileURL, &fileRef); 

    if(theError != noErr) { 
     printf("ExtAudioFileOpenURL failed!"); 
     return; 
    } 

    AudioStreamBasicDescription asbd; 
    UInt32 size = sizeof(asbd); 
    theError = ExtAudioFileGetProperty(fileRef, kExtAudioFileProperty_FileDataFormat, &size, &asbd); 
} 
관련 문제