lib/alsa/HwSetup: return effective parameters
This commit is contained in:
@@ -176,11 +176,14 @@ SetupSampleFormat(snd_pcm_t *pcm, snd_pcm_hw_params_t *hwparams,
|
||||
return err;
|
||||
}
|
||||
|
||||
void
|
||||
SetupHw(snd_pcm_t *pcm, snd_pcm_hw_params_t *hwparams,
|
||||
HwResult
|
||||
SetupHw(snd_pcm_t *pcm,
|
||||
unsigned buffer_time, unsigned period_time,
|
||||
AudioFormat &audio_format, PcmExport::Params ¶ms)
|
||||
{
|
||||
snd_pcm_hw_params_t *hwparams;
|
||||
snd_pcm_hw_params_alloca(&hwparams);
|
||||
|
||||
int err;
|
||||
unsigned int period_time_ro = period_time;
|
||||
|
||||
@@ -285,6 +288,26 @@ SetupHw(snd_pcm_t *pcm, snd_pcm_hw_params_t *hwparams,
|
||||
if (err < 0)
|
||||
throw FormatRuntimeError("snd_pcm_hw_params() failed: %s",
|
||||
snd_strerror(-err));
|
||||
|
||||
HwResult result;
|
||||
|
||||
err = snd_pcm_hw_params_get_format(hwparams, &result.format);
|
||||
if (err < 0)
|
||||
throw FormatRuntimeError("snd_pcm_hw_params_get_format() failed: %s",
|
||||
snd_strerror(-err));
|
||||
|
||||
err = snd_pcm_hw_params_get_buffer_size(hwparams, &result.buffer_size);
|
||||
if (err < 0)
|
||||
throw FormatRuntimeError("snd_pcm_hw_params_get_buffer_size() failed: %s",
|
||||
snd_strerror(-err));
|
||||
|
||||
err = snd_pcm_hw_params_get_period_size(hwparams, &result.period_size,
|
||||
nullptr);
|
||||
if (err < 0)
|
||||
throw FormatRuntimeError("snd_pcm_hw_params_get_period_size() failed: %s",
|
||||
snd_strerror(-err));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace Alsa
|
||||
|
@@ -29,6 +29,11 @@ struct AudioFormat;
|
||||
|
||||
namespace Alsa {
|
||||
|
||||
struct HwResult {
|
||||
snd_pcm_format_t format;
|
||||
snd_pcm_uframes_t buffer_size, period_size;
|
||||
};
|
||||
|
||||
/**
|
||||
* Wrapper for snd_pcm_hw_params().
|
||||
*
|
||||
@@ -38,8 +43,8 @@ namespace Alsa {
|
||||
* by this function
|
||||
* @param params to be modified by this function
|
||||
*/
|
||||
void
|
||||
SetupHw(snd_pcm_t *pcm, snd_pcm_hw_params_t *hwparams,
|
||||
HwResult
|
||||
SetupHw(snd_pcm_t *pcm,
|
||||
unsigned buffer_time, unsigned period_time,
|
||||
AudioFormat &audio_format, PcmExport::Params ¶ms);
|
||||
|
||||
|
Reference in New Issue
Block a user