[Speex-dev] WaveIn/WaveOut and Speex

Erik de Castro Lopo mle+la at mega-nerd.com
Mon Nov 5 12:18:14 PST 2007


Evgueni Tsygankov wrote:

> Again, thank you for helping me. I know this might seem like a 
> trivial matter to you and other experts in the field,

Sorry, Jean Marc and many others, including me, care very little 
about an crappy OS produced by that company in the US which has been
convicted of (but not punished for) anti-competitive behaviour.

> but believe me, there are a lot of programmers, whose posts I saw
> on the web, who tried to use WaveIn/WaveOut and Speex and failed.

That has exactly zero to do with Speex and everything to do with
microsoft's profoundly crappy/stupid APIs and the incompetance of
programmers on the windows platform who are so used to their clicky
pointy IDEs that they can't even think for themselves.
 
> As I understand it, WaveIn just buffers audio data according to the
> bit rate specified. So, if we use waveFormat.wBitsPerSample = 8, 
> then each Char of the audio buffer describes an audio sample using
> 8 bits. On the output side, WaveOut expects each Char to describe an
> 8-bit audio sample as well. If we deal with 16-bit samples, then two
> Chars would describe a sample, and so on.

Like I said a profoundly crappy and stupid API that is confusing to
anyone who doesn't understand C pointers and the memory layout of
char and short arrays. 

> My question is on how to deal with Speex output -- if I get a float
> or a short from Speex' decode function, how does it map to audio
> samples described above? 

First off, don't use the float decoder, use shorts instead.

Define a unions as follows:

   union
   { char c [SAMPLE_COUNT * 2] ;
     short s [SAMPLE_COUNT] ;
   } buf;

Read from Speex into the buf.s array and then pass the buf.c array
to WaveOut.

For an example of how to do this, have a look at the sndfile-play.c
in the examples directory of libsndfile:

    http://www.mega-nerd.com/libsndfile/

Erik
-- 
-----------------------------------------------------------------
Erik de Castro Lopo
-----------------------------------------------------------------
"No Silicon Heaven?  Preposterous!  Where would
all the calculators go?" -- Kryten, Red Dwarf


More information about the Speex-dev mailing list