[alsa-devel] Changing the sample rate/channels of an already opened PCM stream
Hello,
I am the author of the command line music player Herrie (http://herrie.info/). For a long time folks have asked me to add support for OSS to Herrie, so this morning I decided to install Linux on a spare disk of mine (Ubuntu 7.04, FWIW) to hack on ALSA support for Herrie.
After (a real lot of) hours of reading code, reading the Doxygen stuff, etc. I now have a functional ALSA output module for Herrie. It was quite hard to get it working, so I guess I owe myself a beer! ;-)
Anyway, there still is one disadvantage to my module; each time I detect that a new track is going to be started that needs a different amount of channels or sample rate, I reopen the ALSA device, something that is just impossible. The reason why it's impossible: Herrie has a nifty chroot() functionality that allows users to trap the application in a certain directory.
I have been trying to get the device to reset so I can change the sample rate, but for some reason, it just gets ignored. Can someone explain me how it's possible to reset the sample rate after preparing the handle?
For your information, here's a link to the latest version of the source code of my ALSA module:
http://g-rave.nl/gitweb?p=herrie;a=blob;f=herrie/src/audio_output_alsa.c
Yours,
Ed Schouten wrote:
I have been trying to get the device to reset so I can change the sample rate, but for some reason, it just gets ignored. Can someone explain me how it's possible to reset the sample rate after preparing the handle?
The various snd_pcm_hw_params_set_xxx() functions choose some value for a parameter that has not yet been set, but they do not change a parameter once it has been set. To reset all parameters in a hw_params container, call snd_pcm_hw_params_any() again.
HTH Clemens
Hello Clemens,
* Clemens Ladisch cladisch@fastmail.net wrote:
Ed Schouten wrote:
I have been trying to get the device to reset so I can change the sample rate, but for some reason, it just gets ignored. Can someone explain me how it's possible to reset the sample rate after preparing the handle?
The various snd_pcm_hw_params_set_xxx() functions choose some value for a parameter that has not yet been set, but they do not change a parameter once it has been set. To reset all parameters in a hw_params container, call snd_pcm_hw_params_any() again.
Calling snd_pcm_hw_params_any() before changing the sample rate did the trick. Thanks a lot! :-)
Yours,
participants (2)
-
Clemens Ladisch
-
Ed Schouten