首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用ExtAudioFile编写ALAC文件会产生比AIFF更大的文件

用ExtAudioFile编写ALAC文件会产生比AIFF更大的文件
EN

Stack Overflow用户
提问于 2013-12-18 01:30:46
回答 1查看 218关注 0票数 1

我试图从内存中保存的数据中写入ALAC文件。如果我将文件写为AIFF,则文件为43.5MB。如果我把文件写成ALAC,结果是73.9MB。这两个文件发挥完美,但显然ALAC应该比AIFF小。(顺便说一句,当我使用iTunes将AIFF转换为ALAC时,生成的文件是28‘d,这与我所期望的无损压缩格式大致相同)

最明显的区别是ALAC每个样本的位数不足。

我是否错过了一些压缩设置,或者一些可以使ALAC文件更小的设置?

数据以非交错浮动的形式存储在内存中,这是处理格式设置的代码。

代码语言:javascript
复制
_outputFormat.mSampleRate = 44100
_outputFormat.mFormatID = <either kAudioFormatLinearPCM or kAudioFormatAppleLossless>;
_outputFormat.mChannelsPerFrame = 2;

if (_outputFormat.mFormatID == kAudioFormatLinearPCM) {
    _outputFormat.mBitsPerChannel = 16;
    _outputFormat.mBytesPerPacket = _outputFormat.mChannelsPerFrame * (_outputFormat.mBitsPerChannel / 8);
    _outputFormat.mFramesPerPacket = 1;
    _outputFormat.mBytesPerFrame = _outputFormat.mBytesPerPacket;
    _outputFormat.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;

    if (_isBigEndian) {
        _outputFormat.mFormatFlags |= kLinearPCMFormatFlagIsBigEndian;
    }
} else {
    size = sizeof(_outputFormat);
    err = AudioFormatGetProperty(kAudioFormatProperty_FormatInfo, 0, NULL, &size, &_outputFormat);
    if (check_status_is_error(err, "AudioFileGetProperty")) {
        self = nil;
        return nil;
    }
}

CFURLRef urlRef = (__bridge CFURLRef)_url;

err = ExtAudioFileCreateWithURL(urlRef,
                                <either kAudioFileAIFFType or kAudioFileM4AType>,
                                &(_outputFormat),
                                NULL, kAudioFileFlags_EraseFile, &(_outputFile));
if (check_status_is_error(err, "ExtAudioFileCreateWithURL")) {
    self = nil;
    return nil;
}

AudioStreamBasicDescription clientFormat;

clientFormat.mFormatID = kAudioFormatLinearPCM;
clientFormat.mFormatFlags = kAudioFormatFlagsAudioUnitCanonical;
clientFormat.mSampleRate = _outputFormat.mSampleRate;
clientFormat.mChannelsPerFrame = _outputFormat.mChannelsPerFrame;
clientFormat.mFramesPerPacket = 1;
clientFormat.mBytesPerFrame = 4;
clientFormat.mBytesPerPacket = 4;
clientFormat.mBitsPerChannel = 8 * sizeof(AudioUnitSampleType);

size = sizeof(clientFormat);
err = ExtAudioFileSetProperty(_outputFile, 
                              kExtAudioFileProperty_ClientDataFormat,
                              size, &clientFormat);
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-12-23 19:38:44

解决方案是在保存ALAC文件时将AudioStreamBasicDescription结构的AudioStreamBasicDescription设置为包含kAppleLosslessFormatFlag_16BitSourceData

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

https://stackoverflow.com/questions/20648102

复制
相关文章

相似问题

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