2017-05-07 4 views
1

私はオンラインラジオアプリで作業しています。AudioQueueServicesを使用してIcecastサーバからストリーミングされたmp3パケットを再生できました。Streamed mp3パケットのバッファをExtAudioFileWrite iosを使用してwavファイルに書き込む

ストリーミングはmp3形式なので、AudioFileWritePacketsを使用してAudioパケットを直接ファイルに書き込むことはできません。

拡張オーディオの自動変換ExtAudioWriteFileを使用してwavファイルに書き出しています。私は、FileStreamOpenコールバック関数AudioFileStream_PropertyListenerProcを使用して、受信パケットのAudioStreamBasicDescriptionを設定しました。手動で設定された宛先の形式です。コードはファイルを正常に作成し、パケットを書き込みますが再生時には、ここで は私のコードは

// when the recording button is pressed this function creates the file and setup the asbd 
    -(void)startRecording{ 
     recording = true; 
     OSStatus status; 
     NSURL *baseUrl=[self applicationDocumentsDirectory];//returns the document direcotry of the app 
     NSURL *audioUrl = [NSURL URLWithString:@"Recorded.wav" relativeToURL:baseUrl]; 
     //asbd setup for the destination file/wav file 
     AudioStreamBasicDescription dstFormat; 
     dstFormat.mSampleRate=44100.0; 
     dstFormat.mFormatID=kAudioFormatLinearPCM; dstFormat.mFormatFlags=kAudioFormatFlagsNativeEndian|kAudioFormatFlagIsSignedInteger|kAudioFormatFlagIsPacked; 
     dstFormat.mBytesPerPacket=4; 
     dstFormat.mBytesPerFrame=4; 
     dstFormat.mFramesPerPacket=1; 
     dstFormat.mChannelsPerFrame=2; 
     dstFormat.mBitsPerChannel=16; 
     dstFormat.mReserved=0; 
     //creating the file  
     status = ExtAudioFileCreateWithURL(CFBridgingRetain(audioUrl), kAudioFileWAVEType, &(dstFormat), NULL, kAudioFileFlags_EraseFile, &recordingFilRef); 

     // tell the EXtAudio File ApI what format we will be sending samples 
     //recordasbd is the asbd of incoming packets populated in AudioFileStream_PropertyListenerProc 
     status = ExtAudioFileSetProperty(recordingFilRef, kExtAudioFileProperty_ClientDataFormat, sizeof(recordasbd), &recordasbd); 
    } 
    // a handler called by packetproc call back function in AudiofileStreamOpen 
    - (void)handlePacketsProc:(const void *)inInputData numberBytes:(UInt32)inNumberBytes numberPackets:(UInt32)inNumberPackets packetDescriptions:(AudioStreamPacketDescription *)inPacketDescriptions { 
    if(recording){ 
     // wrap the destination buffer in an audiobuffer list 
     convertedData.mNumberBuffers= 1; 
     convertedData.mBuffers[0].mNumberChannels = recordasbd.mChannelsPerFrame; 
     convertedData.mBuffers[0].mDataByteSize = inNumberBytes; 
     convertedData.mBuffers[0].mData = inInputData; 


     ExtAudioFileWrite(recordingFilRef,recordasbd.mFramesPerPacket * inNumberPackets, &convertedData); 
     } 

    } 

である私の質問は以下のとおりです。

ので、私は何をしないのです場合は、右私はwavファイルにmp3パケットをこのように書くことができます私のアプローチです??

私のアプローチは、あなたが考える他の方法がright.Aが正しい方向に微調整である私に教えてください間違っている場合、私はすべてのSO質問私を読んだことがある任意の助けとても感謝しています私

ための十分以上のものです私はこのトピックに私の手を得ることができました、私はまた、リンゴを密接に見てConvertfileの例を見ていましたが、私は何かを理解できませんでした 助けを先にありがとう

答えて

0

生のmp3パケットを直接ファイルに書いてみませんか? ExtAudioFileをまったく使用しないでください。

これらは有効なmp3ファイルを形成し、同等のwavファイルよりもはるかに小さくなります。

+0

アップルはmp3をサポートしていませんが、著作権の問題でアップル社はmp3をサポートしていません.AudiofileCreateWithurlはステータス 'fmt?'(kAudioConverterErr_FormatNotSupported)を返すので、wavに変換しようとしています。 –

+0

'fwrite'や' write'や 'NSFileHandle'のメソッドを使って生のパケットをファイルに書き出すことを意味します。 Appleはmp3データのエンコードをサポートしていませんが、指定していないためmp3データを持っているのでエンコーダは必要ありません。彼らはそれをデコードしてサポートします。 –

関連する問題