First let me introduce myself: Sr Computer Scientist 20+ yrs SW/HW development Audio Rookie < 60 days Intel based computer Soundblaster 128 PCI Linux Fedora Core 2 ALSA - Advanced Linux Sound Architecture ALSA provides the audio and MIDI functionality to the Linux operating system as of Fedora Core 2 and is the future of Linux (so I have been told) http://www.alsa-project.org/ I have read the documentation for Speex and installed speex on my platform. Prior to attempting compression, my software captured audio, stored it, retrieved it and could play it back. The ALSA aplay utility could also replay the files that were stored. The next obvious step is compression. I have yet to correlate the ASLA terminology with the terminology used in the speex documentation, and this is probably my biggest problem. 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. 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? 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. Q - how does this correlate to speex narrow and wide modes? The ALSA call to snd_pcm_hw_params_set_channels is setting it to a single channel (MONO) The ALSA call to snd_pcm_hw_params_set_periods is setting this to 2. Periods used to be called fragments. 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) 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. After capturing the data, I copy the unsigned char array into a float array and follow the example code in sampleenc.c 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. 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?
> ALSA - Advanced Linux Sound ArchitectureActually, 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.cNever 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
If you're an audio rookie, might I suggest using portaudio instead of trying to program to ALSA (or OSS) directly. Even if portability doesn't interest you, it's also a much more straightforward API. *PortAudio* - an Open-Source Cross-Platform Audio API <http://www.portaudio.com/> Craft, Jerry wrote:>First let me introduce myself: >Sr Computer Scientist >20+ yrs SW/HW development >Audio Rookie < 60 days > >Intel based computer >Soundblaster 128 PCI >Linux Fedora Core 2 >ALSA - Advanced Linux Sound Architecture > >ALSA provides the audio and MIDI functionality to the Linux operating system >as of Fedora Core 2 and is the future of Linux (so I have been told) >http://www.alsa-project.org/ > >I have read the documentation for Speex and installed speex on my platform. >Prior to attempting compression, my software captured audio, stored it, >retrieved it and could play it back. The ALSA aplay utility could also >replay the files that were stored. The next obvious step is compression. > >I have yet to correlate the ASLA terminology with the terminology used >in the speex documentation, and this is probably my biggest problem. > >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. > >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? > >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. > >Q - how does this correlate to speex narrow and wide modes? > >The ALSA call to snd_pcm_hw_params_set_channels is setting it to >a single channel (MONO) > >The ALSA call to snd_pcm_hw_params_set_periods is setting this >to 2. Periods used to be called fragments. > >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) > >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. > >After capturing the data, I copy the unsigned char array into a float array >and follow the example code in sampleenc.c > >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. > >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-dev mailing list >Speex-dev@xiph.org >http://lists.xiph.org/mailman/listinfo/speex-dev > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.xiph.org/pipermail/speex-dev/attachments/20040714/2598ddc9/attachment.htm
Seemingly Similar Threads
- Newbie problem with ices2
- libao alsa output
- 3 commits - autogen.sh configure.ac player/.gitignore player/Makefile.am player/swfdec_playback_alsa.c player/swfdec_playback.c player/swfdec_playback_none.c
- crash: can't start 3d app =((
- Newbie problem with ices2