title: Portaudio + Opus encoding / decoding audio input
body: <p>I'm working on a VOIP client using Portaudio and opus.
  I read from the microphone in a frame 
  -encode each frame with Opus and put it in a list
  -pop the first element from the list and decode it
  -read it with portaudio</p>
  
  <p>If i do the same thing without encoding my sound it works great. But when I use Opus my sound is bad, I can't understand the voice (which is bad for a voip client)</p>
  
  <pre><code>HandlerOpus::HandlerOpus(int sample_rate, int num_channels)
      {
          this-&gt;num_channels = num_channels;
          this-&gt;enc = opus_encoder_create(sample_rate, num_channels, OPUS_APPLICATION_VOIP, &amp;this-&gt;error);
          this-&gt;dec = opus_decoder_create(sample_rate, num_channels, &amp;this-&gt;error);
  
          opus_int32 rate;
  
          opus_encoder_ctl(enc, OPUS_GET_BANDWIDTH(&amp;rate));
          this-&gt;encoded_data_size = rate;
      }
  
      HandlerOpus::~HandlerOpus(void)
      {
          opus_encoder_destroy(this-&gt;enc);
          opus_decoder_destroy(this-&gt;dec);
      }
  
      unsigned char *HandlerOpus::encodeFrame(const float *frame, int frame_size)
      {
          unsigned char *compressed_buffer;
          int ret;
  
          compressed_buffer = new (unsigned char[this-&gt;encoded_data_size]);
          ret = opus_encode_float(this-&gt;enc, frame, frame_size, compressed_buffer, this-&gt;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-&gt;num_channels]);
  
          opus_packet_get_nb_channels(data);
          ret = opus_decode_float(this-&gt;dec, data, this-&gt;encoded_data_size, frame, frame_size, 0);
          return (frame);
      }
  </code></pre>
  
  <p>I can't change the library I have to use Opus.
  The sample rate is 48000 and the frames per buffer is 480 and I tried in mono and stereo.</p>
  
  <p>What am I doing wrong?</p>