2012-12-01 109 views
4

我正在使用Portaudio和opus的VOIP客户端上工作。 我从话筒帧 -encode阅读作品每一帧,并把它放在一个列表 -pop的第一个元素从列表中对其进行解码 与portaudioPortaudio + Opus编码/解码音频输入

-read,如果我做同样的事情没有编码我的声音它效果很好。但是当我使用作品我的声音不好,我无法理解的声音(这是坏的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); 
    } 

我不能改变我必须使用作品库。 采样率是48000,每个缓冲区的帧数是480​​,我尝试过单声道和立体声。

我在做什么错?

回答

1

我解决我自己,我改变了配置问题:采样率,以24000每缓冲框架仍然是480

+3

你能提供此修复一些更深入的了解?你使用什么尺寸的数据包?基于这个答案,这听起来像是你在寻找一个20ms的数据包,但只能以48kHz的采样率提供10ms的音频。将其改为24kHz意味着480个样本现在覆盖20ms。这是否准确?或者我错过了什么? – 2012-12-13 20:49:37