0

オーディオを 40ms のセグメントで録音しようとしています。Audio Queue Interface は 40ms オーディオ フレームを処理できますか? 「はい」の場合、どうすればそれを達成できますか?

ありがとう。

4

1 に答える 1

0

はい、可能です。configure AudioQueue を設定する必要があります。

基本的に、AudioQueue Buffer サイズは 40ms に設定する必要があるため、およそ

int AQRecorder::ComputeRecordBufferSize(const AudioStreamBasicDescription *format, float seconds)
{
    int packets, frames, bytes = 0;
    try {
        frames = (int)ceil(seconds * format->mSampleRate);

        if (format->mBytesPerFrame > 0)
            bytes = frames * format->mBytesPerFrame;
        else {
            UInt32 maxPacketSize;
            if (format->mBytesPerPacket > 0)
                maxPacketSize = format->mBytesPerPacket;    // constant packet size
            else {
                UInt32 propertySize = sizeof(maxPacketSize);
                XThrowIfError(AudioQueueGetProperty(mQueue, kAudioQueueProperty_MaximumOutputPacketSize, &maxPacketSize,
                                                    &propertySize), "couldn't get queue's maximum output packet size");
            }
            if (format->mFramesPerPacket > 0)
                packets = frames / format->mFramesPerPacket;
            else
                packets = frames;   // worst-case scenario: 1 frame in a packet
            if (packets == 0)       // sanity check
                packets = 1;
            bytes = packets * maxPacketSize;
        }
    } catch (CAXException e) {
        char buf[256];
        return 0;
    }   
    return bytes;
}

フォーマットを設定するには、

void AQRecorder::SetupAudioFormat(UInt32 inFormatID)
{
    AudioStreamBasicDescription sRecordFormat;
    FillOutASBDForLPCM (sRecordFormat,
                        SAMPLING_RATE,
                        1,
                        8*BYTES_PER_PACKET,
                        8*BYTES_PER_PACKET,
                        false,
                        false
                        );
    memset(&mRecordFormat, 0, sizeof(mRecordFormat));

    mRecordFormat.SetFrom(sRecordFormat);
}

私の場合、これらのマクロの値は、

#define SAMPLING_RATE 16000
#define kNumberRecordBuffers    3
#define BYTES_PER_PACKET 2
于 2013-02-27T13:46:13.013 に答える