2013-08-19 5 views
6

ExtAudioFileRead関数を使用して、オーディオファイルをメモリに読み込みます。しかし、コード-50に間違いがあることがわかりました。つまり、間違ったパラメータを関数に渡します。しかし、どちらが間違ったパラメータであるかわかりません。iOSのExtAudioFileReadエラーコード-50の下に落ちる

オーディオファイルのデータフォーマットは、alac、sampleRate 44100k、2チャンネルです。

私のコードを以下に示します。

ExtAudioFileRef recordFile; 
OSStatus error = noErr; 
error = ExtAudioFileOpenURL((CFURLRef)file, &recordFile); 
checkError(error, "open file"); 

SInt64 frameCount; 
UInt32 size = sizeof(frameCount); 
error = ExtAudioFileGetProperty(recordFile, kExtAudioFileProperty_FileLengthFrames, &size, &frameCount); 
checkError(error, "get frameTotlal"); 

soundStruct *sound = &_sound; 
sound->frameCount = frameCount; 
sound->isStereo = true; 
sound->audioDataLeft = (SInt16 *)calloc(frameCount, sizeof(SInt16)); 
sound->audioDataRight = (SInt16 *)calloc(frameCount, sizeof(SInt16)); 

AudioStreamBasicDescription desc; 
UInt32 descSize = sizeof(desc); 
error = ExtAudioFileGetProperty(recordFile, kExtAudioFileProperty_FileDataFormat, &descSize, &desc); 


[self printASBD:desc]; 

UInt32 channels = desc.mChannelsPerFrame; 

error = ExtAudioFileSetProperty(recordFile, kExtAudioFileProperty_ClientDataFormat, sizeof(inFormat), &inFormat); 

AudioBufferList *bufferList; 
bufferList = (AudioBufferList *)malloc(sizeof(AudioBufferList) + sizeof(AudioBuffer) * (channels - 1)); 

AudioBuffer emptyBuff = {0}; 
size_t arrayIndex; 
for (arrayIndex = 0; arrayIndex < channels; arrayIndex ++) { 
    bufferList->mBuffers[arrayIndex] = emptyBuff; 
} 

bufferList->mBuffers[0].mData = sound->audioDataLeft; 
bufferList->mBuffers[0].mNumberChannels = 1; 
bufferList->mBuffers[0].mDataByteSize = frameCount * sizeof(SInt16); 
if (channels == 2) { 
    bufferList->mBuffers[1].mData = sound->audioDataRight; 
    bufferList->mBuffers[1].mNumberChannels = 1; 
    bufferList->mBuffers[1].mDataByteSize = frameCount * sizeof(SInt16); 
    bufferList->mNumberBuffers = 2; 
} 

UInt32 count = (UInt32)frameCount; 

error = ExtAudioFileRead(recordFile, &count, bufferList); 
checkError(error, "reading"); // Get a -50 error 

free(bufferList); 
ExtAudioFileDispose(recordFile); 

答えて

2

良い質問を。

このエラーは、ExtAudioFileSetPropertyへの呼び出しでSTEREOクライアントデータ形式を使用するMONOファイルExtAudioFileReadが発生したときに発生しました。

私はExtAudioFileReadがモノラルファイルをステレオファイルに自動的にアップコンバートすると考えられます。不一致がある場合、この-50エラーで失敗します。

モノファイルのステレオをまたはに設定してください(モノファイルの場合はinFormat.mChannelsPerFrame=1)。

アップコンバートしない場合は、データの単一のモノラルチャンネルからL/Rチャンネルを書き込んで、オーディオ機能のモノラルファイルを考慮する必要があります。

関連する問題