summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorThierry Bultel <thierry.bultel@iot.bzh>2019-02-13 14:37:01 +0100
committerThierry Bultel <thierry.bultel@iot.bzh>2019-05-13 13:55:58 +0200
commit7520fbf30159a02366c56d0e91e5262a6b88fd37 (patch)
tree7cff87dc8c6210d642eb9595f7f64f1f084ff9ac /plugins
parent293fe6981f55aff68e42b668a565c5db65cc8468 (diff)
core-pcm: fixed channels setting issues
Recent tries on the minnow board have show that the setting of channels on a PCM must be done -after- the setting of the rate. When not doing that, there can be issues (really, complicated to find) around the boundaries values (open intervals) on the period bytes. Additionally, the number of channels can now be forced in the json file. Change-Id: I2c20853daadf9ccab06be6e04d1a185440f57780 Signed-off-by: Thierry Bultel <thierry.bultel@iot.bzh>
Diffstat (limited to 'plugins')
-rw-r--r--plugins/alsa/alsa-api-pcm.c12
-rw-r--r--plugins/alsa/alsa-core-pcm.c25
2 files changed, 24 insertions, 13 deletions
diff --git a/plugins/alsa/alsa-api-pcm.c b/plugins/alsa/alsa-api-pcm.c
index 0421119..464a725 100644
--- a/plugins/alsa/alsa-api-pcm.c
+++ b/plugins/alsa/alsa-api-pcm.c
@@ -384,8 +384,8 @@ PUBLIC void ApiPcmDelParams(SoftMixerT* mixer, AlsaPcmHwInfoT* params) {
}
PUBLIC void ApiPcmParamsShow(SoftMixerT * mixer, const char *msg, const AlsaPcmHwInfoT * params) {
- AFB_ApiInfo(mixer->api, "%s PARAMS: rate=%d, format=%d, formatString=%s",
- msg, params->rate, params->format, params->formatString);
+ AFB_ApiInfo(mixer->api, "%s PARAMS: rate=%d, format=%d, formatString=%s, channels %d",
+ msg, params->rate, params->format, params->formatString, params->channels);
}
@@ -408,10 +408,11 @@ PUBLIC AlsaPcmHwInfoT * ApiPcmSetParams(SoftMixerT *mixer, const char *uid, json
if (paramsJ) {
int error =
- wrap_json_unpack(paramsJ, "{s?i,s?s,s?s !}",
+ wrap_json_unpack(paramsJ, "{s?i,s?s,s?s,s?i !}",
"rate", &params->rate,
"format", &format,
- "access", &access);
+ "access", &access,
+ "channels", &params->channels);
if (error) {
AFB_ApiError(mixer->api, "%s: sndcard=%s invalid params=%s",
__func__, uid, json_object_get_string(paramsJ));
@@ -419,6 +420,9 @@ PUBLIC AlsaPcmHwInfoT * ApiPcmSetParams(SoftMixerT *mixer, const char *uid, json
}
}
+ AFB_API_NOTICE(mixer->api, "%s:%s rate set to %d", __func__, uid, params->rate);
+ AFB_API_NOTICE(mixer->api, "%s:%s channels set to %d", __func__, uid, params->channels);
+
// default format
if (!format) {
params->format = SND_PCM_FORMAT_S16_LE;
diff --git a/plugins/alsa/alsa-core-pcm.c b/plugins/alsa/alsa-core-pcm.c
index 9d46dcc..0e8f86f 100644
--- a/plugins/alsa/alsa-core-pcm.c
+++ b/plugins/alsa/alsa-core-pcm.c
@@ -136,7 +136,22 @@ PUBLIC int AlsaPcmConf(SoftMixerT *mixer, AlsaPcmCtlT *pcm, int mode) {
}
}
- if (opts->rate > 0 ) {
+ unsigned int * channels = &opts->channels;
+
+ if (*channels) {
+ AFB_API_DEBUG(mixer->api, "%s: Attempt to set %d channels", __func__, *channels);
+ if ((error = snd_pcm_hw_params_set_channels(pcm->handle, pxmHwParams, *channels)) < 0) {
+ AFB_API_ERROR(mixer->api,
+ "%s (%s): mixer=%s Set_Channels=%d Fail error=%s",
+ __func__, card, mixer->uid, *channels, snd_strerror(error));
+
+ AlsaDumpPcmParams(mixer, pxmHwParams);
+ goto OnErrorExit;
+ };
+ AFB_API_DEBUG(mixer->api, "%s: CHANNELS SET TO %d", __func__, *channels);
+ }
+
+ if (opts->rate > 0 ) {
AFB_ApiDebug(mixer->api,"%s (%s): set rate to %d", __func__, card, opts->rate);
unsigned int pcmRate = opts->rate;
@@ -158,14 +173,6 @@ PUBLIC int AlsaPcmConf(SoftMixerT *mixer, AlsaPcmCtlT *pcm, int mode) {
}
}
- if (opts->channels) {
- if ((error = snd_pcm_hw_params_set_channels(pcm->handle, pxmHwParams, opts->channels)) < 0) {
- AFB_ApiError(mixer->api,
- "%s (%s): mixer=%s Set_Channels=%d Fail error=%s",
- __func__, card, mixer->uid, opts->channels, snd_strerror(error));
- goto OnErrorExit;
- };
- }
/* The following code, that
* 1) sets period time/size; buffer time/size hardware params