Evgueni,
Don't listen to this guy. The last thing someone confused about types
should use is a union. Listen, whatever types you're using, you're just
dealing with data in memory. For an array, it's just a big block of data in
memory. You need to know how that data is stored in memory. For audio data,
WAVEFORMATEX tells you that with its contents. Don't let types deceive you
-
focus on the format of the actual data. Know that Speex needs either floats
or shorts, with a sample rate of 8000/16000/32000 samples per second, and
that it's your responsibility to pass it data in this format. If the data
is
already in this format (for example, 16-bit 16kHz mono) you can cast the array
you provide to Speex from LPSTR or whatever to short, if you're using
Speex's
short-based API. Otherwise, you need to loop through your input array,
convert each sample to what Speex needs, and pass a converted buffer to Speex.
This is pretty basic stuff and has nothing to do with Windows or its APIs,
and everything to do with basic understanding of how audio data is stored
in memory.
Tom
Erik de Castro Lopo <mle+la@mega-nerd.com> wrote:>
> 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
> _______________________________________________
> Speex-dev mailing list
> Speex-dev@xiph.org
> http://lists.xiph.org/mailman/listinfo/speex-dev
>
>