1 year ago
#300403
Alexandru Rusu
ALSA ignores configuration
I have an audio box that can be connected via USB to my laptop.
I've written a C application that uses the ALSA API to open a communication channel with this audio box.
The communication should be established at 8kHz, running with a 10ms period size (that is 80 samples).
- If I'm connecting the audio box to my laptop and then start the app, it seems that the min period size supported is 170 (e.g.
snd_pcm_hw_params_get_period_size_min
sets min period size to 170), whilesnd_pcm_hw_params_set_period_size_near
sets the period size to 170.
Looking to /proc/asound/name-of-the-card/stream0
, I can see Momentary freq = 48000 Hz (0x30.0000)
, but the sampling rate requested by me is 8kHz.
Also, snd_pcm_hw_params_set_rate_near
call, is not changing the value that I've passed.
- By starting the app first and then connecting the audio box to my laptop,
snd_pcm_hw_params_get_period_size_min
sets the min period size to 16 and when callingsnd_pcm_hw_params_set_period_size_near
, the period size is set to 80 (which represents what I want to achieve).
Checking again /proc/asound/name-of-the-card/stream0
, I can see Momentary freq = 8000 Hz (0x8.0000)
, that is correct.
I have to mention that my app is trying to open the card associated with the audio box and if the operation doesn't succeed, is retrying the open it every 200ms until succeeds.
My feeling is that in the second case when the period size is set accordingly, my application sets the configuration before the system does (I'm not sure if the system does this).
I've tried to modify defaults.pcm.dmix.rate
to 8000 in /usr/share/alsa/alsa.conf
, but in this case the period size that is returned by acting as in the first scenario is 1024.
Below are some configurations from /usr/share/alsa/alsa.conf
if this helps.
defaults.pcm.minperiodtime 5000 # in us
defaults.pcm.ipc_key 5678293
defaults.pcm.ipc_gid audio
defaults.pcm.ipc_perm 0666
defaults.pcm.dmix.max_periods 0
defaults.pcm.dmix.channels 2
defaults.pcm.dmix.rate 48000
Is there a config file that has a higher priority than what I want to configure via the API?
c
linux
linux-kernel
alsa
libalsa
0 Answers
Your Answer