[opus] WAVE PCM to OPUS and back

Stepan Melnichuk stepan.melnichuk at sibers.com
Thu Oct 25 06:41:32 PDT 2012


Hello,

I have an p2p voice chat application using WAVE PCM (winmm). Now i am 
trying to add opus encoding to it to send it over the TCP/IP and then 
decoding it back to play - but without success (without opus it works ok)

Here is an example of my code. I get message from input device then 
encode with opus then decode it back to output wave header and play. 
Doing it i hear only noise in my headphones. So how can i use Opus in 
this way? Thanks in advance

WAVEFORMATEX waveform;
waveform.cbSize = 0;
waveform.wFormatTag = WAVE_FORMAT_PCM;
waveform.nChannels = 2;
waveform.wBitsPerSample = 8;
waveform.nSamplesPerSec = 48000;
waveform.nBlockAlign = waveform.nChannels * (waveform.wBitsPerSample >> 3);
waveform.nAvgBytesPerSec = waveform.nSamplesPerSec * waveform.nBlockAlign;

#define BUFSIZE 512

...

case  MM_WIM_DATA:
             {
                 WAVEHDR *Hdr = (WAVEHDR *) msg.lParam;
                  int  opusRes;
                 m_opusEncoder = opus_encoder_create(48000, 2, OPUS_APPLICATION_AUDIO, &opusRes);
                 m_opusDecoder = opus_decoder_create(48000, 2, &opusRes);
  
                 unsigned  char  data[BUFSIZE];
                 opus_int32 dataLength = opus_encode(m_opusEncoder, (short*)Hdr->lpData, 80, data, BUFSIZE);

                 dataLength = opus_decode(m_opusDecoder, (unsigned  char*)data, dataLength, (short*)WaveHdrOut.lpData, BUFSIZE, 0);

                 waveOutWrite(hWaveOut, &WaveHdrOut,sizeof(WAVEHDR));

-- 
Best regards,

  Stepan Melnichuk

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.xiph.org/pipermail/opus/attachments/20121025/e65d2547/attachment.htm 


More information about the opus mailing list