Unable to playback captured audio using USB sound card
1
vote
1
answer
2577
views
I am trying to capture and play audio using C program. For this I [got this tutorial.]. Here is the program which I am running:-
/**
* Jan Newmarch
*/
#define PERIOD_SIZE 1024
#define BUF_SIZE (PERIOD_SIZE * 2)
#include
#include
#include
void print_pcm_state(snd_pcm_t *handle, char *name) {
switch (snd_pcm_state(handle)) {
case SND_PCM_STATE_OPEN:
printf("state open %s\n", name);
break;
case SND_PCM_STATE_SETUP:
printf("state setup %s\n", name);
break;
case SND_PCM_STATE_PREPARED:
printf("state prepare %s\n", name);
break;
case SND_PCM_STATE_RUNNING:
printf("state running %s\n", name);
break;
case SND_PCM_STATE_XRUN:
printf("state xrun %s\n", name);
break;
default:
printf("state other %s\n", name);
break;
}
}
int setparams(snd_pcm_t *handle, char *name) {
snd_pcm_hw_params_t *hw_params;
int err;
if ((err = snd_pcm_hw_params_malloc (&hw_params)) /etc/modprobe.d/alsa-base.conf
Here are the changes :-
I replace
options snd_usb_audio index=-2
options snd_hda_intel index=-1
with
options snd_usb_audio index=-1
options snd_hda_intel index=-2
And I replace
# Keep snd-usb-audio from beeing loaded as first soundcard
options snd-usb-audio index=-1
with
# Keep snd-usb-audio from beeing loaded as first soundcard
options snd-usb-audio index=-1
Now, when i run my code , I got this output:-
Rate for playback is 48000
period size now 1024
period size 1024
buffer size 2048
Rate for capture is 48000
cannot set channel count (Invalid argument)
So, can anyone tell me what else should I do to run my code using sound card.
Note:- I run command
aplay -l
and got this output:-
card 0: Device [USB PnP Sound Device], device 0: USB Audio [USB Audio]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 1: PCH [HDA Intel PCH], device 0: ALC221 Analog [ALC221 Analog]
Subdevices: 1/1
Subdevice #0: subdevice #0
Asked by tabish
(510 rep)
Apr 19, 2016, 09:07 AM
Last activity: Apr 26, 2025, 09:02 AM
Last activity: Apr 26, 2025, 09:02 AM