Updated to latest alsa-lib PCM API

This commit is contained in:
Jaroslav Kysela 2002-09-19 16:20:08 +00:00
parent 163c302a6a
commit 11080289c7
2 changed files with 30 additions and 23 deletions

View file

@ -13,12 +13,18 @@
/* Version number of package */ /* Version number of package */
#undef VERSION #undef VERSION
/* Using i386 architecture */
/* Architecture defines */
#undef __i386__ #undef __i386__
/* Using Alpha architecture */
#undef __alpha__ #undef __alpha__
#undef __ppc__
/* Using SPARC architecture */
#undef __sparc__ #undef __sparc__
/* Big-Endian */ /* Using PowerPC architecture */
#undef WORDS_BIGENDIAN #undef __ppc__
/* Using IA-64 architecture */
#undef __ia64__

View file

@ -20,6 +20,7 @@
#include <stdio.h> #include <stdio.h>
#include <errno.h> #include <errno.h>
#define ALSA_PCM_NEW_HW_PARAMS_API
#include <alsa/asoundlib.h> #include <alsa/asoundlib.h>
typedef signed short sint_16; typedef signed short sint_16;
@ -38,8 +39,7 @@ int output_open(output_t *output)
const char *pcm_name = output->pcm_name; const char *pcm_name = output->pcm_name;
char devstr[128]; char devstr[128];
snd_pcm_hw_params_t *params; snd_pcm_hw_params_t *params;
snd_pcm_sframes_t buffer_time; unsigned int rate, buffer_time, period_time, tmp;
snd_pcm_sframes_t period_time, tmp;
int err, step; int err, step;
snd_pcm_hw_params_alloca(&params); snd_pcm_hw_params_alloca(&params);
@ -126,14 +126,15 @@ int output_open(output_t *output)
fprintf(stderr, "Channels count non available"); fprintf(stderr, "Channels count non available");
goto __close; goto __close;
} }
err = snd_pcm_hw_params_set_rate_near(pcm, params, output->rate, 0); rate = output->rate;
err = snd_pcm_hw_params_set_rate_near(pcm, params, &rate, 0);
if (err < 0) { if (err < 0) {
fprintf(stderr, "Rate not available"); fprintf(stderr, "Rate not available");
goto __close; goto __close;
} }
buffer_time = snd_pcm_hw_params_set_buffer_time_near(pcm, params, buffer_time = 500000;
500000, 0); err = snd_pcm_hw_params_set_buffer_time_near(pcm, params, &buffer_time, 0);
if (buffer_time < 0) { if (err < 0) {
fprintf(stderr, "Buffer time not available"); fprintf(stderr, "Buffer time not available");
goto __close; goto __close;
} }
@ -141,19 +142,19 @@ int output_open(output_t *output)
period_time = 10000 * 2; period_time = 10000 * 2;
do { do {
period_time /= 2; period_time /= 2;
tmp = snd_pcm_hw_params_set_period_time_near(pcm, params, tmp = period_time;
period_time, 0); err = snd_pcm_hw_params_set_period_time_near(pcm, params, &tmp, 0);
if (tmp == period_time) { if (err < 0) {
period_time /= 3;
tmp = snd_pcm_hw_params_set_period_time_near(pcm, params,
period_time, 0);
if (tmp == period_time)
period_time = 10000 * 2;
}
if (period_time < 0) {
fprintf(stderr, "Period time not available"); fprintf(stderr, "Period time not available");
goto __close; goto __close;
} }
if (tmp == period_time) {
period_time /= 3;
tmp = period_time;
err = snd_pcm_hw_params_set_period_time_near(pcm, params, &tmp, 0);
if (tmp == period_time)
period_time = 10000 * 2;
}
} while (buffer_time == period_time && period_time > 10000); } while (buffer_time == period_time && period_time > 10000);
if (buffer_time == period_time) { if (buffer_time == period_time) {
fprintf(stderr, "Buffer time and period time match, could not use\n"); fprintf(stderr, "Buffer time and period time match, could not use\n");