How to lock the sample rate ?
On the Echoaudio cards the sample rate is a global setting, so I need a way to prevent an app to change the rate if someone else already set it (the card han several devices/subdevices). I was thinking to put a simple "if (IsAudioOpen()) rate_min=rate_max=current_rate;" in pcm_open callback, but this solution is racy. Also what am I supposed to do about external clock ? I can't read its value and it teoretically can change at any moment.
--
Giuliano.
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
Quoted 5 lines · Giuliano Pochini
On the Echoaudio cards the sample rate is a global setting, so I need a way to prevent an app to change the rate if someone else already set it (the card han several devices/subdevices). I was thinking to put a simple "if (
IsAudioOpen()) rate_min=rate_max=current_rate;" inpcm_opencallback, but this solution is racy.
Yes, but I don't see a better solution for "auto" rate settings. Also, it would be probably good to create a control which can "fix" the rate to a value (ICE1712 driver already has this feature).
Quoted 2 lines
Also what am I supposed to do about external clock ? I can't read its value and it teoretically can change at any moment.
Yes, I return an error when the rate is other than agreed with application in the PDAudioCF driver. I think that it's only valid solution. But if you cannot obtain the rate from hardware, then it might be problematic.
Jaroslav
-----
Jaroslav Kysela <[email protected]>
Linux Kernel Sound Maintainer
ALSA Project, SuSE Labs
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
Quoted 7 lines · Jaroslav Kysela
Quoted 5 lines · Giuliano Pochini
On the Echoaudio cards the sample rate is a global setting, so I need a way to prevent an app to change the rate if someone else already set it (the card han several devices/subdevices). I was thinking to put a simple "if (
IsAudioOpen()) rate_min=rate_max=current_rate;" inpcm_opencallback, but this solution is racy.
Talking about race conditions you could use a variable which is set to 0 at the beginning. Now if app wants to set a rate it does atomic compare and increase (cmpxchg on x86) instruction so only one app could set rate. The other could only read memorized rate settins and report an error if rate is different.
Regards
Signature · 11 lines
Adam Tla/lka mailto:[email protected] ^v^ ^v^ ^v^ System & Network Administration Group ~~~~~~ Computer Center, Gdansk University of Technology, Poland PGP public key: finger [email protected] ------------------------------------------------------- This SF.Net email is sponsored by: IBM Linux Tutorials Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
Quoted 8 lines · Adam Tla/lka
Quoted 7 lines · Jaroslav Kysela
Quoted 5 lines · Giuliano Pochini
On the Echoaudio cards the sample rate is a global setting, so I need a way to prevent an app to change the rate if someone else already set it (the card han several devices/subdevices). I was thinking to put a simple "if (
IsAudioOpen()) rate_min=rate_max=current_rate;" inpcm_opencallback, but this solution is racy.
Quoted 5 lines
Talking about race conditions you could use a variable which is set to 0 at the beginning. Now if app wants to set a rate it does atomic compare and increase (cmpxchg on x86) instruction so only one app could set rate. The other could only read memorized rate settins and report an error if rate is different.
We have already a number of locking features in kernel (spinlocks, mutexes, atomic integer operations, atomic bitmap operations etc).
Jaroslav
-----
Jaroslav Kysela <[email protected]>
Linux Kernel Sound Maintainer
ALSA Project, SuSE Labs
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
Quoted 11 lines · On 06-Mar-2004 Adam Tla/lka wrote:
Quoted 5 lines
Quoted 5 lines
On the Echoaudio cards the sample rate is a global setting, so I need a way to prevent an app to change the rate if someone else already set it (the card han several devices/subdevices). I was thinking to put a simple "if (
IsAudioOpen()) rate_min=rate_max=current_rate;" inpcm_opencallback, but this solution is racy.Talking about race conditions you could use a variable which is set to 0 at the beginning. Now if app wants to set a rate it does atomic compare and increase (cmpxchg on x86) instruction so only one app could set rate. The other could only read memorized rate settins and report an error if rate is different.
No, I wasn't clear enough.
If I add the "if (IsAudioOpen())..." in the pcm_open() function it works as long as the firts applications which set the sample rate don't changes it again. Furthermore, noone, but the firt app, can change the sample rate until all substream are closed. But there is another case where the above method fails. Let's suppose there are two application, A and B. They both do pcm_open(). Since nobody has set the sample rate yet, the driver says that all sample rates in the range 8k-96k can be choosed (the driver set hw constraints in the open callback). Then A sets 44100. But B still believes it can do 8-96 and it sets 48000. Everything goes fine until B tries to start the substream (that is the prepare() callback is called). At this point there are two possibilites: 1) The call fails and the application can't know why. 2) The call succeeds and it changes the sample rate of all running substreams.
--
Giuliano.
-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click