Warn about ALSA errors
always set the smaple rate set buffer size
This commit is contained in:
@@ -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_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_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_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();
|
CString LoadALSA();
|
||||||
void UnloadALSA();
|
void UnloadALSA();
|
||||||
|
|||||||
@@ -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_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_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_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_pcm_hwsync, (snd_pcm_t *pcm));
|
||||||
FUNC(int, snd_ctl_pcm_next_device, (snd_ctl_t *ctl, int *device));
|
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));
|
FUNC(int, snd_ctl_pcm_info, (snd_ctl_t *ctl, snd_pcm_info_t * info));
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
#define ALSA_CHECK(x) \
|
#define ALSA_CHECK(x) \
|
||||||
if ( err < 0 ) { LOG->Info("ALSA9: %s: %s", x, dsnd_strerror(err)); return false; }
|
if ( err < 0 ) { LOG->Info("ALSA9: %s: %s", x, dsnd_strerror(err)); return false; }
|
||||||
#define ALSA_ASSERT(x) \
|
#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()
|
bool Alsa9Buf::SetHWParams()
|
||||||
{
|
{
|
||||||
@@ -45,15 +45,21 @@ bool Alsa9Buf::SetHWParams()
|
|||||||
err = dsnd_pcm_hw_params_set_channels(pcm, hwparams, 2);
|
err = dsnd_pcm_hw_params_set_channels(pcm, hwparams, 2);
|
||||||
ALSA_CHECK("dsnd_pcm_hw_params_set_channels");
|
ALSA_CHECK("dsnd_pcm_hw_params_set_channels");
|
||||||
|
|
||||||
if( samplerate != Alsa9Buf::DYNAMIC_SAMPLERATE )
|
/* 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;
|
unsigned int rate = samplerate;
|
||||||
err = dsnd_pcm_hw_params_set_rate_near(pcm, hwparams, &rate, 0);
|
err = dsnd_pcm_hw_params_set_rate_near(pcm, hwparams, &rate, 0);
|
||||||
ALSA_CHECK("dsnd_pcm_hw_params_set_rate_near");
|
ALSA_CHECK("dsnd_pcm_hw_params_set_rate_near");
|
||||||
|
|
||||||
if( (int) rate != samplerate )
|
if( (int) rate != samplerate )
|
||||||
LOG->Warn("Alsa9Buf::SetHWParams: Couldn't get %ihz (got %ihz instead)", samplerate, rate);
|
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 */
|
/* write the hardware parameters to the device */
|
||||||
err = dsnd_pcm_hw_params( pcm, hwparams );
|
err = dsnd_pcm_hw_params( pcm, hwparams );
|
||||||
|
|||||||
Reference in New Issue
Block a user