首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用ExtAudioFileWrite ios将流式mp3数据包的缓冲区写入wav文件

使用ExtAudioFileWrite ios将流式mp3数据包的缓冲区写入wav文件
EN

Stack Overflow用户
提问于 2017-05-07 18:31:25
回答 1查看 238关注 0票数 1

我正在开发一个在线广播应用程序,我设法使用AudioQueueServices播放来自Icecast服务器的流式mp3数据包,我正在努力实现一个录制功能。

由于流是mp3格式的,所以我不能使用AudioFileWritePackets将音频数据包直接写入文件。

为了利用扩展音频的自动转换,我使用ExtAudioWriteFile来写入wav文件。我已经使用FileStreamOpen回调函数AudioFileStream_PropertyListenerProc和目标格式设置了传入数据包的AudioStreamBasicDescription。我填充了manually.The代码,成功地创建了文件并将数据包写入其中,但在回放时,我听到的是白噪声;以下是我的代码

代码语言:javascript
运行
复制
// 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);
         }

    }

我的问题是:

我的方法正确吗?我可以以这种方式将mp3数据包写入wav文件吗?如果是,我错过了什么??

如果我的方法是错的,请告诉我你认为正确的任何其他方法。朝正确的方向推动对我来说已经足够了

我非常感谢我读过的每一个问题,所以我可以在这个主题上动手,我也仔细查看了苹果转换文件的例子,但我不能弄清楚我错过了什么,提前感谢任何帮助

EN

回答 1

Stack Overflow用户

发布于 2017-05-07 19:08:18

为什么不将原始mp3数据包直接写入文件?根本不使用ExtAudioFile

它们将形成有效的mp3文件,并且将比等效的wav文件小得多。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43830424

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档