speaker-test: Fix floating-point exception bug

The period_size an buffer_size parameters must be taken after calling
snd_pcm_hw_params().  Otherwise they could be undefined numbers.
For example, period_size gets 0 when pcsp driver is used, resulting in
a floating-point exception error.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
Takashi Iwai 2008-11-26 14:27:24 +01:00
parent 6232f1c96c
commit 0d6134450e

View file

@ -422,6 +422,14 @@ static int set_hwparams(snd_pcm_t *handle, snd_pcm_hw_params_t *params, snd_pcm_
return err;
}
}
/* write the parameters to device */
err = snd_pcm_hw_params(handle, params);
if (err < 0) {
fprintf(stderr, _("Unable to set hw params for playback: %s\n"), snd_strerror(err));
return err;
}
snd_pcm_hw_params_get_buffer_size(params, &buffer_size);
snd_pcm_hw_params_get_period_size(params, &period_size, NULL);
printf(_("was set period_size = %lu\n"),period_size);
@ -431,13 +439,6 @@ static int set_hwparams(snd_pcm_t *handle, snd_pcm_hw_params_t *params, snd_pcm_
return -EINVAL;
}
/* write the parameters to device */
err = snd_pcm_hw_params(handle, params);
if (err < 0) {
fprintf(stderr, _("Unable to set hw params for playback: %s\n"), snd_strerror(err));
return err;
}
return 0;
}