ALSA: snd_pcm_hw_params() failure - Invalid argument
I am working on a ALSA project, and I have a TV tunner card plugged intot the PCI interface. I try to capture the audio from the tunner card, and the followings are the code:
Code:
Code:
set audioTunner channels success! -ay |
Quote:
One thing you can try to narrow down the cause is to print out the actual value of the error from 'err = snd_pcm_hw_params...' and then look it up in errno.h. Good luck. Pete |
Pete:
Thanks for your suggestion. I just confirmed that audio data of S16_LE (signed 16, little-endian) is correct, 32K sample rate is also fine. I just printed out the err num = -22. I did a search and have not found errno.h yet. Do you happen to have the link for errno.h? I am using Fedora Linux 2.6. Thanks again, -ay |
Quote:
Here are a few more things to try: 1) Make sure you have access mode set to interleaved, like so: Code:
if ((err = snd_pcm_hw_params_set_access (capture_handle, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) { 2) After setting all the values in the hw_params, try getting them via their corresponding functions and printing them out before sending them to the handle. This way, you'll be sure that all the values you set are there. Good luck! Pete |
I have added a few printf commands to query the tv tuner card status. Please see the code and the output.
Code:
//open tunerAudio and set parameters Code:
[root@mu153097 dtvScan]# ./kwaud |
I found the problem was caused by not setting the proper buffersize and period size. After calling the snd_pcm_hw_params_set_buffer_size() and snd_pcm_hw_params_set_period_size(). It worked fine. See the following output:
Code:
access mode set as INTERLEAVED success! |
Quote:
Glad you got it working! P |
snd_pcm_hw_params_set_format : error: -22
I am also getting the same error: -22 for snd_pcm_hw_params_set_format with SND_PCM_FORMAT_S16_LE. Could some please explain how to set proper parameters (like buffer size, period size...). Did these these parameters depends on audio card (hardware specific)?
please check the code below i am using now. code: snd_pcm_t *pcm; assert(snd_pcm_open(&pcm, name, SND_PCM_STREAM_CAPTURE, 0) == 0); snd_pcm_hw_params_t *pcm_hw_params; assert(snd_pcm_hw_params_malloc(&pcm_hw_params) == 0); assert(snd_pcm_hw_params_any(pcm, pcm_hw_params) == 0); assert(snd_pcm_hw_params_set_access(pcm, pcm_hw_params, SND_PCM_ACCESS_MMAP_INTERLEAVED) == 0); assert(snd_pcm_hw_params_set_buffer_size(pcm, pcm_hw_params, 16384) == 0); assert(snd_pcm_hw_params_set_period_size(pcm, pcm_hw_params, (snd_pcm_uframes_t){ 1024 }, (int){ 0 }) == 0); assert(snd_pcm_hw_params_set_format(pcm, pcm_hw_params, SND_PCM_FORMAT_S16_LE) == 0); |
All times are GMT -5. The time now is 10:53 PM. |