Portaudio + Opus编码/解码音频输入

Waw*_*a08 5 c++ audio voip portaudio opus

我正在使用Portaudio和opus在VOIP客户端上工作.我从一个帧中读取麦克风 - 使用Opus对每个帧进行编码并将其放入列表--pop列表中的第一个元素并对其进行解码 - 使用portaudio读取它

如果我在没有编码声音的情况下做同样的事情,那么效果很好.但是当我使用Opus时我的声音很糟糕,我无法理解声音(这对于voip客户端来说是不好的)

HandlerOpus::HandlerOpus(int sample_rate, int num_channels)
    {
        this->num_channels = num_channels;
        this->enc = opus_encoder_create(sample_rate, num_channels, OPUS_APPLICATION_VOIP, &this->error);
        this->dec = opus_decoder_create(sample_rate, num_channels, &this->error);

        opus_int32 rate;

        opus_encoder_ctl(enc, OPUS_GET_BANDWIDTH(&rate));
        this->encoded_data_size = rate;
    }

    HandlerOpus::~HandlerOpus(void)
    {
        opus_encoder_destroy(this->enc);
        opus_decoder_destroy(this->dec);
    }

    unsigned char *HandlerOpus::encodeFrame(const float *frame, int frame_size)
    {
        unsigned char *compressed_buffer;
        int ret;

        compressed_buffer = new (unsigned char[this->encoded_data_size]);
        ret = opus_encode_float(this->enc, frame, frame_size, compressed_buffer, this->encoded_data_size);
        return (compressed_buffer);
    }

    float *HandlerOpus::decodeFrame(const unsigned char *data, int frame_size)
    {
        int ret;
        float *frame = new (float[frame_size * this->num_channels]);

        opus_packet_get_nb_channels(data);
        ret = opus_decode_float(this->dec, data, this->encoded_data_size, frame, frame_size, 0);
        return (frame);
    }
Run Code Online (Sandbox Code Playgroud)

我无法更改我必须使用Opus的库.采样率为48000,每个缓冲区的帧数为480,我尝试使用单声道和立体声.

我究竟做错了什么?

Waw*_*a08 1

我自己解决了这个问题,我更改了配置:采样率更改为 24000,每个缓冲区的帧数仍然是 480。

  • 您能否在这里提供有关修复的更多见解?您使用的数据包尺寸是多少?根据答案,听起来您正在寻找 20ms 的数据包,但仅以 48kHz 采样率提供 10ms 的音频。将其更改为 24kHz 意味着 480 个样本现在覆盖 20ms。这准确吗?或者我错过了什么? (3认同)