首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >线性PCM 16位到8位

线性PCM 16位到8位
EN

Stack Overflow用户
提问于 2013-08-20 14:14:51
回答 1查看 1.2K关注 0票数 0

我试着用苹果的例子"SpeakHere“的录音部分来达到我的目的。一切似乎都好,但我需要添加一个选项,实际上提供8位录音。这是根据规范,不允许任何音频设置,所以我需要某种形式的转换从16位。我想我需要把它放在回调函数中。

代码语言:javascript
复制
// ____________________________________________________________________________________
// AudioQueue callback function, called when an input buffers has been filled.
void AQRecorder::MyInputBufferHandler(  void *                              inUserData,
                                        AudioQueueRef                       inAQ,
                                        AudioQueueBufferRef                 inBuffer,
                                        const AudioTimeStamp *              inStartTime,
                                        UInt32                              inNumPackets,
                                        const AudioStreamPacketDescription* inPacketDesc)
{
    AQRecorder *aqr = (AQRecorder *)inUserData;
    try {
        if (inNumPackets > 0) {
            // write packets to file
            XThrowIfError(AudioFileWritePackets(aqr->mRecordFile, FALSE, inBuffer->mAudioDataByteSize,
                                             inPacketDesc, aqr->mRecordPacket, &inNumPackets, inBuffer->mAudioData),
                       "AudioFileWritePackets failed");
            aqr->mRecordPacket += inNumPackets;
        }

        // if we're not stopping, re-enqueue the buffe so that it gets filled again
        if (aqr->IsRunning())
            XThrowIfError(AudioQueueEnqueueBuffer(inAQ, inBuffer, 0, NULL), "AudioQueueEnqueueBuffer failed");
    } catch (CAXException e) {
        char buf[256];
        fprintf(stderr, "Error: %s (%s)\n", e.mOperation, e.FormatError(buf));
    }
}

但老实说我不知道该怎么做。任何想法都会感激的。

EN

回答 1

Stack Overflow用户

发布于 2013-08-20 15:13:31

为什么不尝试用类似的方法初始化音频队列呢?

代码语言:javascript
复制
    aqData.mDataFormat.mFormatID = kAudioFormatLinearPCM;        // 2
    aqData.mDataFormat.mSampleRate = 44100.0;                    // 3
    aqData.mDataFormat.mChannelsPerFrame = 1;                    // 4
    aqData.mDataFormat.mBitsPerChannel = 8;                     // 5
    aqData.mDataFormat.mBytesPerPacket =                         // 6
    aqData.mDataFormat.mBytesPerFrame =
    aqData.mDataFormat.mChannelsPerFrame * sizeof (SInt8);
    aqData.mDataFormat.mFramesPerPacket = 1;                     // 7

    AudioFileTypeID fileType = kAudioFileAIFFType;               // 8
    aqData.mDataFormat.mFormatFlags =                            // 9
    kLinearPCMFormatFlagIsBigEndian
    | kLinearPCMFormatFlagIsSignedInteger
    | kLinearPCMFormatFlagIsPacked; 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18337327

复制
相关文章

相似问题

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