iphone - 如何将压缩的声音文件转换为未压缩的文件

标签 iphone objective-c audio core-audio

我想在iPhone / ipad应用程序中解压缩压缩的声音文件。
在我的应用程序中,我具有要转换为.wav格式的.m4a文件。
通过代码怎么可能?

最佳答案

您可以使用ExtAudioFile执行此操作:

CFURLRef url = /* ... */;
ExtAudioFileRef eaf;
OSStatus err = ExtAudioFileOpenURL((CFURLRef)url, &eaf);
if(noErr != err)
  /* handle error */

AudioStreamBasicDescription format;
format.mSampleRate = 44100;
format.mFormatID = kAudioFormatLinearPCM;
format.mFormatFlags = kAudioFormatFormatFlagIsPacked;
format.mBitsPerChannel = 16;
format.mChannelsPerFrame = 2;
format.mBytesPerFrame = format.mChannelsPerFrame * 2;
format.mFramesPerPacket = 1;
format.mBytesPerPacket = format.mFramesPerPacket * format.mBytesPerFrame;

err = ExtAudioFileSetProperty(eaf, kExtAudioFileProperty_ClientDataFormat, sizeof(format), &format);

/* Read the file contents */

显然,我只是随意选择16位整数立体声作为检索格式,但希望这个想法很明确。您只需要告诉ExtAudioFile您想要哪种音频数据格式,它就会自动从文件格式转换为您请求的(客户端)格式。

苹果在http://developer.apple.com/library/mac/#samplecode/ConvertFile/Introduction/Intro.html上拥有更多示例代码

关于iphone - 如何将压缩的声音文件转换为未压缩的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5648255/

相关文章:

iphone - 在 UITextView 上使用 NSLayoutConstraint 会将 contentSize 重置为 {0,0}

ios - 从后台重新启动位置更新

objective-c - AVAudioPlayer audioPlayerDidFinishPlaying :successfully: not called

objective-c - 使用 block 在 `self` 上保留循环

python - 从原始WAV音频中获取信号的正负分量

audio - 使用ALSA插件dsnoop时出错

android - Html5输入类型数字格式化

ios - 下载文件时 UIProgressview 不改变

audio - FFmpeg 音频 channel 再矩阵(5.1 到立体声)

iphone - 从iphone实时发送音频到服务器?