From 34e14865502ae5fc9ec32e1e14b0f076f9cb60fa Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Tue, 30 Dec 2003 08:13:44 +0000 Subject: [PATCH] Warn about ALSA errors always set the smaple rate set buffer size --- stepmania/src/arch/Sound/ALSA9Dynamic.h | 1 + stepmania/src/arch/Sound/ALSA9Functions.h | 4 ++++ stepmania/src/arch/Sound/ALSA9Helpers.cpp | 24 ++++++++++++++--------- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/stepmania/src/arch/Sound/ALSA9Dynamic.h b/stepmania/src/arch/Sound/ALSA9Dynamic.h index e0a98e57e3..9731644900 100644 --- a/stepmania/src/arch/Sound/ALSA9Dynamic.h +++ b/stepmania/src/arch/Sound/ALSA9Dynamic.h @@ -16,6 +16,7 @@ #define dsnd_pcm_sw_params_alloca(ptr) { assert(ptr); *ptr = (snd_pcm_sw_params_t *) alloca(dsnd_pcm_sw_params_sizeof()); memset(*ptr, 0, dsnd_pcm_sw_params_sizeof()); } #define dsnd_pcm_info_alloca(ptr) { assert(ptr); *ptr = (snd_pcm_info_t *) alloca(dsnd_pcm_info_sizeof()); memset(*ptr, 0, dsnd_pcm_info_sizeof()); } #define dsnd_ctl_card_info_alloca(ptr) { assert(ptr); *ptr = (snd_ctl_card_info_t *) alloca(dsnd_ctl_card_info_sizeof()); memset(*ptr, 0, dsnd_ctl_card_info_sizeof()); } +#define dsnd_pcm_status_alloca(ptr) do { assert(ptr); *ptr = (snd_pcm_status_t *) alloca(dsnd_pcm_status_sizeof()); memset(*ptr, 0, dsnd_pcm_status_sizeof()); } while (0) CString LoadALSA(); void UnloadALSA(); diff --git a/stepmania/src/arch/Sound/ALSA9Functions.h b/stepmania/src/arch/Sound/ALSA9Functions.h index adae2f4254..e94f313444 100644 --- a/stepmania/src/arch/Sound/ALSA9Functions.h +++ b/stepmania/src/arch/Sound/ALSA9Functions.h @@ -28,6 +28,10 @@ FUNC(int, snd_pcm_hw_params_set_access, (snd_pcm_t *pcm, snd_pcm_hw_params_t *pa FUNC(int, snd_pcm_hw_params_set_channels, (snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val)); FUNC(int, snd_pcm_hw_params_set_format, (snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_format_t val)); FUNC(int, snd_pcm_hw_params_set_rate_near, (snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir)); +FUNC(int, snd_pcm_hw_params_set_buffer_size_near, (snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val)); +FUNC(int, snd_pcm_status, (snd_pcm_t *pcm, snd_pcm_status_t *status)); +FUNC(snd_pcm_uframes_t, snd_pcm_status_get_avail, (const snd_pcm_status_t *obj)); +FUNC(size_t, snd_pcm_status_sizeof, (void)); FUNC(int, snd_pcm_hwsync, (snd_pcm_t *pcm)); FUNC(int, snd_ctl_pcm_next_device, (snd_ctl_t *ctl, int *device)); FUNC(int, snd_ctl_pcm_info, (snd_ctl_t *ctl, snd_pcm_info_t * info)); diff --git a/stepmania/src/arch/Sound/ALSA9Helpers.cpp b/stepmania/src/arch/Sound/ALSA9Helpers.cpp index 2c81c307ec..6d8cc91a22 100644 --- a/stepmania/src/arch/Sound/ALSA9Helpers.cpp +++ b/stepmania/src/arch/Sound/ALSA9Helpers.cpp @@ -9,7 +9,7 @@ #define ALSA_CHECK(x) \ if ( err < 0 ) { LOG->Info("ALSA9: %s: %s", x, dsnd_strerror(err)); return false; } #define ALSA_ASSERT(x) \ - if (err < 0) { LOG->Trace("ALSA9: %s: %s", x, dsnd_strerror(err)); } + if (err < 0) { LOG->Warn("ALSA9: %s: %s", x, dsnd_strerror(err)); } bool Alsa9Buf::SetHWParams() { @@ -45,15 +45,21 @@ bool Alsa9Buf::SetHWParams() err = dsnd_pcm_hw_params_set_channels(pcm, hwparams, 2); ALSA_CHECK("dsnd_pcm_hw_params_set_channels"); - if( samplerate != Alsa9Buf::DYNAMIC_SAMPLERATE ) - { - unsigned int rate = samplerate; - err = dsnd_pcm_hw_params_set_rate_near(pcm, hwparams, &rate, 0); - ALSA_CHECK("dsnd_pcm_hw_params_set_rate_near"); + /* Set the sample rate. We shouldn't need to set it if rate is DYNAMIC_SAMPLERATE, + * but I've had alsalib crashes if I don't. */ + if( samplerate == Alsa9Buf::DYNAMIC_SAMPLERATE ) + samplerate = 44100; + + unsigned int rate = samplerate; + err = dsnd_pcm_hw_params_set_rate_near(pcm, hwparams, &rate, 0); + ALSA_CHECK("dsnd_pcm_hw_params_set_rate_near"); - if( (int) rate != samplerate ) - LOG->Warn("Alsa9Buf::SetHWParams: Couldn't get %ihz (got %ihz instead)", samplerate, rate); - } + if( (int) rate != samplerate ) + LOG->Warn("Alsa9Buf::SetHWParams: Couldn't get %ihz (got %ihz instead)", samplerate, rate); + + snd_pcm_uframes_t buffersize = 1024*32; + err = dsnd_pcm_hw_params_set_buffer_size_near( pcm, hwparams, &buffersize ); + ALSA_CHECK("dsnd_pcm_hw_params_set_buffer_size_near"); /* write the hardware parameters to the device */ err = dsnd_pcm_hw_params( pcm, hwparams );