【问题标题】:How to convert a compressed sound file to uncompressed file如何将压缩的声音文件转换为未压缩的文件
【发布时间】:2011-04-13 11:14:38
【问题描述】:

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

【问题讨论】:

  • 你的意思是转换格式吗?压缩后,您将无法提高采样声音的质量/分辨率。
  • 对,其实我想知道压缩文件的波形

标签: iphone objective-c audio core-audio


【解决方案1】:

您可以使用 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 您希望音频数据采用什么格式,它就会自动从文件格式转换为您请求的(客户端)格式。

Apple 在http://developer.apple.com/library/mac/#samplecode/ConvertFile/Introduction/Intro.html 上有更广泛的示例代码

【讨论】:

  • 当我在上面尝试你的确切代码时(在修复格式标志中的口吃之后)我得到一个“fmt?”错误。知道问题可能是什么吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-06
  • 2019-02-24
  • 1970-01-01
  • 1970-01-01
  • 2013-08-28
  • 1970-01-01
相关资源
最近更新 更多