我正在开发一个使用Portaudio和opus的VOIP客户端。我从麦克风中读取一帧中的每一帧,并把它放在一个列表中,列表中的第一个元素,并解码它-encode -pop -read
如果我做同样的事情而不编码我的声音,它会工作得很好。但是当我使用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);
}我不能更改库,我必须使用Opus。采样率是48000,每个缓冲区的帧数是480,我尝试了单声道和立体声。
我做错了什么?
发布于 2012-12-02 00:43:53
我自己解决了这个问题,我更改了配置:采样率为24000,每个缓冲区的帧数仍然是480。
发布于 2018-10-13 22:56:37
6年后,我将为像我这样的未来谷歌人发布一个答案:
我遇到了非常类似的问题,并通过将PortAudio样本类型更改为paInt32并从opus_decode_float切换到opus_decode来修复它
https://stackoverflow.com/questions/13660796
复制相似问题