alsa: add option to force a samplerate

This commit is contained in:
Wim Taymans 2020-09-16 15:14:26 +02:00
parent e5f7e040dc
commit 1bf6dead10
5 changed files with 13 additions and 0 deletions

View file

@ -222,6 +222,7 @@ struct spa_audio_info_raw {
#define SPA_KEY_AUDIO_CHANNEL "audio.channel" /**< an audio channel as string,
* Ex. "FL" */
#define SPA_KEY_AUDIO_CHANNELS "audio.channels" /**< an audio channel count as int */
#define SPA_KEY_AUDIO_RATE "audio.rate" /**< an audio sample rate as int */
struct spa_audio_info_dsp {
enum spa_audio_format format; /*< format, one of the DSP formats in enum spa_audio_format_dsp */

View file

@ -763,6 +763,8 @@ impl_init(const struct spa_handle_factory *factory,
snprintf(this->props.device, 63, "%s", info->items[i].value);
} else if (!strcmp(info->items[i].key, SPA_KEY_AUDIO_CHANNELS)) {
this->default_channels = atoi(info->items[i].value);
} else if (!strcmp(info->items[i].key, SPA_KEY_AUDIO_RATE)) {
this->default_rate = atoi(info->items[i].value);
}
}

View file

@ -782,6 +782,8 @@ impl_init(const struct spa_handle_factory *factory,
snprintf(this->props.device, 63, "%s", info->items[i].value);
} else if (!strcmp(info->items[i].key, SPA_KEY_AUDIO_CHANNELS)) {
this->default_channels = atoi(info->items[i].value);
} else if (!strcmp(info->items[i].key, SPA_KEY_AUDIO_RATE)) {
this->default_rate = atoi(info->items[i].value);
}
}
return 0;

View file

@ -341,6 +341,13 @@ spa_alsa_enum_format(struct state *state, int seq, uint32_t start, uint32_t num,
CHECK(snd_pcm_hw_params_get_rate_min(params, &min, &dir), "get_rate_min");
CHECK(snd_pcm_hw_params_get_rate_max(params, &max, &dir), "get_rate_max");
if (state->default_rate != 0) {
if (min < state->default_rate)
min = state->default_rate;
if (max > state->default_rate)
max = state->default_rate;
}
spa_pod_builder_prop(&b, SPA_FORMAT_AUDIO_rate, 0);
spa_pod_builder_push_choice(&b, &f[1], SPA_CHOICE_None, 0);

View file

@ -104,6 +104,7 @@ struct state {
struct spa_audio_info current_format;
unsigned int default_channels;
unsigned int default_rate;
snd_pcm_uframes_t buffer_frames;
snd_pcm_uframes_t period_frames;