Hi,
I have written a small application to record sample..
1. When i set snd_pcm_hw_params_set_access to SND_PCM_ACCESS_RW_INTERLEAVED, and snd_pcm_hw_params_get_access i got snd_pcm_hw_params_get_access.
2. When i set the buffer size near it is always setting at 0. fails at snd_pcm_hw_params (capture_handle, hw_params)) with error -22.
Here is the code and output:
CODE :
-------------------
if ((err = snd_pcm_open (&capture_handle, pcm_name, stream,open_mode)) < 0) {
fprintf (stderr, "cannot open audio device %s \n",
snd_strerror (err));
exit (1);
}
printf("\n snd_pcm_open DONE \n");
err = snd_output_stdio_attach(&log, stderr, 0);
if ((err = snd_pcm_hw_params_malloc (&hw_params)) < 0) {
fprintf (stderr, "cannot allocate hardware parameter structure (%s)\n",
snd_strerror (err));
exit (1);
}
fprintf (stderr, "cannot open audio device %s \n",
snd_strerror (err));
exit (1);
}
printf("\n snd_pcm_open DONE \n");
err = snd_output_stdio_attach(&log, stderr, 0);
if ((err = snd_pcm_hw_params_malloc (&hw_params)) < 0) {
fprintf (stderr, "cannot allocate hardware parameter structure (%s)\n",
snd_strerror (err));
exit (1);
}
printf("\n snd_pcm_hw_params_malloc DONE \n");
if ((err = snd_pcm_hw_params_any (capture_handle, hw_params)) < 0) {
fprintf (stderr, "cannot initialize hardware parameter structure (%s)\n",
snd_strerror (err));
exit (1);
}
printf("\n snd_pcm_hw_params_any DONE \n");
if ((err = snd_pcm_hw_params_set_format (capture_handle, hw_params, SND_PCM_FORMAT_S16_LE)) < 0) {
fprintf (stderr, "cannot set sample format (%s)\n",
snd_strerror (err));
exit (1);
}
printf("\n snd_pcm_hw_params_set_format DONE \n");
if ((err = snd_pcm_hw_params_set_access (capture_handle, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) {
fprintf (stderr, "cannot set access type (%s)\n",
snd_strerror (err));
exit (1);
}
printf("\n snd_pcm_hw_params_set_access DONE \n");
snd_pcm_hw_params_get_access(hw_params, (snd_pcm_access_t *) &val);
printf("captureAudio access type = %s\n", snd_pcm_access_name((snd_pcm_access_t)val));
if ((err = snd_pcm_hw_params_any (capture_handle, hw_params)) < 0) {
fprintf (stderr, "cannot initialize hardware parameter structure (%s)\n",
snd_strerror (err));
exit (1);
}
printf("\n snd_pcm_hw_params_any DONE \n");
if ((err = snd_pcm_hw_params_set_format (capture_handle, hw_params, SND_PCM_FORMAT_S16_LE)) < 0) {
fprintf (stderr, "cannot set sample format (%s)\n",
snd_strerror (err));
exit (1);
}
printf("\n snd_pcm_hw_params_set_format DONE \n");
if ((err = snd_pcm_hw_params_set_access (capture_handle, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) {
fprintf (stderr, "cannot set access type (%s)\n",
snd_strerror (err));
exit (1);
}
printf("\n snd_pcm_hw_params_set_access DONE \n");
snd_pcm_hw_params_get_access(hw_params, (snd_pcm_access_t *) &val);
printf("captureAudio access type = %s\n", snd_pcm_access_name((snd_pcm_access_t)val));
if ((err = snd_pcm_hw_params_set_rate_near (capture_handle, hw_params, &hwparams.rate , 0)) < 0) {
fprintf (stderr, "cannot set sample rate (%s)\n",
snd_strerror (err));
exit (1);
}
printf("\n snd_pcm_hw_params_set_rate_near DONE \n");
if ((err = snd_pcm_hw_params_set_channels (capture_handle, hw_params, 2)) < 0) {
fprintf (stderr, "cannot set channel count (%s)\n",
snd_strerror (err));
exit (1);
}
fprintf (stderr, "cannot set channel count (%s)\n",
snd_strerror (err));
exit (1);
}
printf("\n snd_pcm_hw_params_set_channels DONE \n");
err = snd_pcm_hw_params_set_buffer_size_near(capture_handle, hw_params,
&buffer_frames);
if (err < 0)
{
fprintf (stderr, "cannot set buffer_size (%s)\n",
snd_strerror (err));
exit (1);
}
printf("\n snd_pcm_hw_params_set_buffer_size_near %d DONE \n", (int)buffer_frames);
err = snd_pcm_hw_params_get_buffer_size(hw_params, &buffer_size);
if (err < 0) {
printf("Unable to get buffer size %s\n", snd_strerror(err));
&buffer_frames);
if (err < 0)
{
fprintf (stderr, "cannot set buffer_size (%s)\n",
snd_strerror (err));
exit (1);
}
printf("\n snd_pcm_hw_params_set_buffer_size_near %d DONE \n", (int)buffer_frames);
err = snd_pcm_hw_params_get_buffer_size(hw_params, &buffer_size);
if (err < 0) {
printf("Unable to get buffer size %s\n", snd_strerror(err));
}
err = snd_pcm_hw_params_set_period_size_near(capture_handle, hw_params, &period_size, &dir);
if (err < 0) {
printf("Unable to set buffer size %s\n", snd_strerror(err));
err = snd_pcm_hw_params_set_period_size_near(capture_handle, hw_params, &period_size, &dir);
if (err < 0) {
printf("Unable to set buffer size %s\n", snd_strerror(err));
}
printf(" Ln %d : get buffer size %d \n", __LINE__, (int) buffer_size);
// FOR DEBUGGING SHOULD BE REMOVED LATER : GSS
// FOR DEBUGGING SHOULD BE REMOVED LATER : GSS
//display captureAudio card parameters
printf(" handler name = %s\n", snd_pcm_name(capture_handle));
printf("captureAudio pcm state = %s\n",
snd_pcm_state_name(snd_pcm_state(capture_handle)));
printf(" handler name = %s\n", snd_pcm_name(capture_handle));
printf("captureAudio pcm state = %s\n",
snd_pcm_state_name(snd_pcm_state(capture_handle)));
snd_pcm_hw_params_get_access(hw_params, (snd_pcm_access_t *) &val);
printf("captureAudio access type = %s\n", snd_pcm_access_name((snd_pcm_access_t)val));
printf("captureAudio access type = %s\n", snd_pcm_access_name((snd_pcm_access_t)val));
snd_pcm_hw_params_get_format(hw_params,(snd_pcm_format_t *) &val);
printf("captureAudio format = %s (%s)\n", snd_pcm_format_name((snd_pcm_format_t) val),
snd_pcm_format_description((snd_pcm_format_t) val));
printf("captureAudio format = %s (%s)\n", snd_pcm_format_name((snd_pcm_format_t) val),
snd_pcm_format_description((snd_pcm_format_t) val));
snd_pcm_hw_params_get_format(hw_params, (snd_pcm_format_t *)&val);
printf("format = '%s' (%s)\n", snd_pcm_format_name((snd_pcm_format_t)val),
snd_pcm_format_description((snd_pcm_format_t)val));
printf("format = '%s' (%s)\n", snd_pcm_format_name((snd_pcm_format_t)val),
snd_pcm_format_description((snd_pcm_format_t)val));
snd_pcm_hw_params_get_channels(hw_params, &val);
printf("channels = %d\n", val);
printf("channels = %d\n", val);
snd_pcm_hw_params_get_rate(hw_params, &val1, &dir);
printf("rate = %d bps\n", val);
printf("rate = %d bps\n", val);
snd_pcm_hw_params_get_period_time(hw_params, & val1, &dir);
printf("period time = %d us\n", val);
printf("period time = %d us\n", val);
snd_pcm_hw_params_get_period_size(hw_params, (snd_pcm_uframes_t *)&frames, &dir);
printf("period size = %d frames\n", (int)frames);
printf("period size = %d frames\n", (int)frames);
snd_pcm_hw_params_get_buffer_time(hw_params, &val1, &dir);
printf("buffer time = %d us\n", val);
printf("buffer time = %d us\n", val);
snd_pcm_hw_params_get_buffer_size(hw_params,(snd_pcm_uframes_t *) &val);
printf("buffer size = %d frames\n", val);
printf("buffer size = %d frames\n", val);
snd_pcm_hw_params_get_periods(hw_params, &val1, &dir);
printf("periods per buffer = %d frames\n", val);
if ((err = snd_pcm_hw_params (capture_handle, hw_params)) < 0) {
fprintf (stderr, "cannot set parameters (%s)\n",
snd_strerror (err));
printf("\n snd_pcm_hw_params FAILED :err :%d \n", err);
exit (1);
}
printf("\n snd_pcm_hw_params DONE \n");
printf("periods per buffer = %d frames\n", val);
if ((err = snd_pcm_hw_params (capture_handle, hw_params)) < 0) {
fprintf (stderr, "cannot set parameters (%s)\n",
snd_strerror (err));
printf("\n snd_pcm_hw_params FAILED :err :%d \n", err);
exit (1);
}
printf("\n snd_pcm_hw_params DONE \n");
bits_per_sample = snd_pcm_format_physical_width(hwparams.format);
snd_pcm_hw_params_get_period_size(hw_params, &chunk_size, 0);
snd_pcm_hw_params_get_buffer_size(hw_params, &buffer_size);
bits_per_frame = bits_per_sample * hwparams.channels;
chunk_bytes = chunk_size * bits_per_frame / 8;
printf("\nchunk_size : %d \n", (int)chunk_size);
printf("\n chunk_bytes :%d bits_per_frame :%dbits_per_sample :%d \n", chunk_bytes, bits_per_frame, bits_per_sample);
snd_pcm_hw_params_get_buffer_size(hw_params, &buffer_size);
bits_per_frame = bits_per_sample * hwparams.channels;
chunk_bytes = chunk_size * bits_per_frame / 8;
printf("\nchunk_size : %d \n", (int)chunk_size);
printf("\n chunk_bytes :%d bits_per_frame :%dbits_per_sample :%d \n", chunk_bytes, bits_per_frame, bits_per_sample);
snd_pcm_hw_params_free (hw_params);
printf("\n snd_SW and HW parameted set DONE \n");
OUTPUT:
snd_pcm_open DONE
snd_pcm_hw_params_malloc DONE
snd_pcm_hw_params_any DONE
snd_pcm_hw_params_set_format DONE
snd_pcm_hw_params_set_access DONE
snd_pcm_hw_params_set_rate_near DONE
snd_pcm_hw_params_set_channels DONE
snd_pcm_hw_params_set_buffer_size_near 0 DONE
Ln 177 : get buffer size 0
handler name = default
captureAudio pcm state = OPEN
captureAudio access type = MMAP_COMPLEX
captureAudio format = S16_LE (Signed 16 bit Little Endian)
format = 'S16_LE' (Signed 16 bit Little Endian)
channels = 2
rate = 2 bps
period time = 2 us
period size = 0 frames
buffer time = 2 us
buffer size = 2 frames
periods per buffer = 2 frames
Ln 177 : get buffer size 0
handler name = default
captureAudio pcm state = OPEN
captureAudio access type = MMAP_COMPLEX
captureAudio format = S16_LE (Signed 16 bit Little Endian)
format = 'S16_LE' (Signed 16 bit Little Endian)
channels = 2
rate = 2 bps
period time = 2 us
period size = 0 frames
buffer time = 2 us
buffer size = 2 frames
periods per buffer = 2 frames
cannot set parameters ((null))
printf Error = ffffffea
snd_pcm_hw_params FAILED :err :-22
printf Error = ffffffea
snd_pcm_hw_params FAILED :err :-22
--------------------------------------------------
What is the issue here?
need ur inputs on this issue.
------------------------------------------------------------------------------ Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)! Finally, a world-class log management solution at an even better price-free! Download using promo code Free_Logger_4_Dev2Dev. Offer expires February 28th, so secure your free ArcSight Logger TODAY! http://p.sf.net/sfu/arcsight-sfd2d
_______________________________________________ Alsa-user mailing list Alsa-user@xxxxxxxxxxxxxxxxxxxxx https://lists.sourceforge.net/lists/listinfo/alsa-user