[Speex-dev] Speex/Linux/ALSA
Jean-Marc Valin
Jean-Marc.Valin
Wed Jul 14 10:36:56 PDT 2004
> ALSA - Advanced Linux Sound Architecture
Actually, Speex doesn't care if you use ALSA, OSS or a hand
transcription from an oscilloscope...
> With the speex API, I can create an executable, but when I run it,
> speex_bits_write always returns 38 bytes no matter what I send it.
> Here are some details of what I am doing, some questions I have,
> and hopefully someone can point out what I am doing wrong.
What do you expect? Speex uses 20 ms frames and defaults to 15000 kbps
(unless you change that). At that rate, a frame is 38 bytes, that's it.
> The ALSA call to snd_pcm_hw_params_set_format is setting the sound
> format to unsigned 8 bit SND_PCM_FORMAT_U8
>
> Q - Do I have to use 16 bit for speex?
Yes. Actually, version 1.0.x takes floats (converted from 16-bit data).
In version 1.1.x, you can also use speex_encode_int(), which takes
16-bit values (short) directly.
> The ALSA call to snd_pcm_hw_params_set_rate_near is setting the
> rate to 11025 hz, the lowest I have been successful with.
Speex is only optimal for 8 kHz and 16 kHz (anything else will be
sub-optimal). I suggest using those.
> Q - how does this correlate to speex narrow and wide modes?
narrowband is 8 kHz, wideband is 16 kHz.
> The ALSA call to snd_pcm_hw_params_set_channels is setting it to
> a single channel (MONO)
I don't care.
> The ALSA call to snd_pcm_hw_params_set_periods is setting this
> to 2. Periods used to be called fragments.
I don't care.
> The ALSA call to snd_pcm_hw_params_set_buffer_size is setting this
> to the period size (8192) times the number of periods (2)
See above.
> The ALSA call to snd_pcm_readi has been tried with the number of frames
> set to 100, 160, 200, 2000. It puts the data read into an unsigned char
> array.
Remember that speex_encode takes 160 samples for narrowband and 320
samples for wideband (use speex_encoder_ctl with SPEEX_GET_FRAME_SIZE to
find out). See, the call to speex_encode has no length argument, that's
because the length is already decided (there's no way to guess how many
samples are in your pointer!).
> After capturing the data, I copy the unsigned char array into a float array
> and follow the example code in sampleenc.c
Never convert u-law directly into float (use a u-law to leanear
conversion)!
> speex_bits_reset(&bits);
> speex_encode(state, floatbuf, &bits);
> cbytes = speex_bits_write(&bits, comprbuf, BUFSIZE);
>
> cbytes always returns 38 no matter what the frames are set to in the
> ALSA snd_pcm_readi call.
Pretty normal.
> I do know that valid sound in the unsigned char array returned from the
> ALSA snd_pcm_readi call is less than 0x7A, and anything above 0x7A is
> background noise or silence.
>
> Q - is this inverted for speex?
Speex doesn't use u-law at all.
Jean-Marc
--
Jean-Marc Valin
http://www.xiph.org/~jm/
LABORIUS
Universit? de Sherbrooke, Qu?bec, Canada
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Ceci est une partie de message
=?ISO-8859-1?Q?num=E9riquement?= =?ISO-8859-1?Q?_sign=E9e=2E?=
Url : http://lists.xiph.org/pipermail/speex-dev/attachments/20040714/ef70c2a9/attachment.pgp
More information about the Speex-dev
mailing list