summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThierry Bultel <thierry.bultel@iot.bzh>2018-06-07 15:03:37 +0200
committerThierry Bultel <thierry.bultel@iot.bzh>2018-06-07 15:03:37 +0200
commitbefd8460d00b50e2c6f21768a76b20ce94d6728f (patch)
tree3bb7767db907032e3c85018ee69f73d8a7d22c5b
parentf21bd1bdcc64e688a156231aa8cf67c49ce1871c (diff)
Code cleanup and fixed some typos
Signed-off-by: Thierry Bultel <thierry.bultel@iot.bzh>
-rw-r--r--plugins/alsa/alsa-api-pcm.c76
-rw-r--r--plugins/alsa/alsa-core-pcm.c4
-rw-r--r--plugins/alsa/alsa-plug-vol.c4
3 files changed, 48 insertions, 36 deletions
diff --git a/plugins/alsa/alsa-api-pcm.c b/plugins/alsa/alsa-api-pcm.c
index 5bd6dca..b0ad019 100644
--- a/plugins/alsa/alsa-api-pcm.c
+++ b/plugins/alsa/alsa-api-pcm.c
@@ -33,7 +33,7 @@ STATIC int CONVERT_PERCENT(long val, long min, long max) {
if (range == 0)
return 0;
val -= min;
- tmp = rint((double) val / (double) range * 100);
+ tmp = (int)rint((double) val / (double) range * 100);
return tmp;
}
@@ -326,42 +326,52 @@ PUBLIC AlsaPcmHwInfoT * ApiPcmSetParams(SoftMixerT *mixer, const char *uid, json
if (!format) {
params->format = SND_PCM_FORMAT_S16_LE;
params->formatS = "S16_LE";
- } else {
- params->formatS = strdup(format);
- if (!strcasecmp(format, "S16_LE")) params->format = SND_PCM_FORMAT_S16_LE;
- else if (!strcasecmp(format, "S16_BE")) params->format = SND_PCM_FORMAT_S16_BE;
- else if (!strcasecmp(format, "U16_LE")) params->format = SND_PCM_FORMAT_U16_LE;
- else if (!strcasecmp(format, "U16_BE")) params->format = SND_PCM_FORMAT_U16_BE;
- else if (!strcasecmp(format, "S32_LE")) params->format = SND_PCM_FORMAT_S32_LE;
- else if (!strcasecmp(format, "S32_BE")) params->format = SND_PCM_FORMAT_S32_BE;
- else if (!strcasecmp(format, "U32_LE")) params->format = SND_PCM_FORMAT_U32_LE;
- else if (!strcasecmp(format, "U32_BE")) params->format = SND_PCM_FORMAT_U32_BE;
- else if (!strcasecmp(format, "S24_LE")) params->format = SND_PCM_FORMAT_S24_LE;
- else if (!strcasecmp(format, "S24_BE")) params->format = SND_PCM_FORMAT_S24_BE;
- else if (!strcasecmp(format, "U24_LE")) params->format = SND_PCM_FORMAT_U24_LE;
- else if (!strcasecmp(format, "U24_BE")) params->format = SND_PCM_FORMAT_U24_BE;
- else if (!strcasecmp(format, "S8")) params->format = SND_PCM_FORMAT_S8;
- else if (!strcasecmp(format, "U8")) params->format = SND_PCM_FORMAT_U8;
- else if (!strcasecmp(format, "FLOAT_LE")) params->format = SND_PCM_FORMAT_FLOAT_LE;
- else if (!strcasecmp(format, "FLOAT_BE")) params->format = SND_PCM_FORMAT_FLOAT_LE;
- else {
- AFB_ApiNotice(mixer->api, "ApiPcmSetParams:%s(params) unsupported format 'S16_LE|S32_L|...' format=%s", uid, format);
- goto OnErrorExit;
- }
+ goto check_access;
+ }
+ params->formatS = strdup(format);
+#define FORMAT_CHECK(arg) if (!strcmp(format,#arg)) { params->format = SND_PCM_FORMAT_##arg; goto check_access; }
+
+ FORMAT_CHECK(S16_LE);
+ FORMAT_CHECK(S16_BE);
+ FORMAT_CHECK(U16_LE);
+ FORMAT_CHECK(U16_BE);
+ FORMAT_CHECK(S32_BE);
+ FORMAT_CHECK(S32_LE);
+ FORMAT_CHECK(U32_BE);
+ FORMAT_CHECK(U32_LE);
+ FORMAT_CHECK(S24_BE);
+ FORMAT_CHECK(S24_LE);
+ FORMAT_CHECK(U24_BE);
+ FORMAT_CHECK(U24_LE);
+ FORMAT_CHECK(S8);
+ FORMAT_CHECK(U8);
+ FORMAT_CHECK(FLOAT_LE);
+ FORMAT_CHECK(FLOAT_BE);
+
+ AFB_ApiNotice(mixer->api, "ApiPcmSetParams:%s(params) unsupported format 'S16_LE|S32_L|...' format=%s", uid, format);
+ goto OnErrorExit;
+
+check_access:
+ AFB_ApiNotice(mixer->api, "THIERRY ApiPcmSetParams:%s format set to SND_PCM_FORMAT_%s",uid, params->formatS);
+
+#define ACCESS_CHECK(arg) if (!strcmp(access,#arg)) { params->access = SND_PCM_ACCESS_##arg; goto success;}
+
+ if (!access) {
+ params->access = SND_PCM_ACCESS_RW_INTERLEAVED;
+ goto success;
}
- if (!access) params->access = SND_PCM_ACCESS_RW_INTERLEAVED;
- else if (!strcasecmp(access, "MMAP_INTERLEAVED")) params->access = SND_PCM_ACCESS_MMAP_INTERLEAVED;
- else if (!strcasecmp(access, "MMAP_NONINTERLEAVED")) params->access = SND_PCM_ACCESS_MMAP_NONINTERLEAVED;
- else if (!strcasecmp(access, "MMAP_COMPLEX")) params->access = SND_PCM_ACCESS_MMAP_COMPLEX;
- else if (!strcasecmp(access, "RW_INTERLEAVED")) params->access = SND_PCM_ACCESS_RW_INTERLEAVED;
- else if (!strcasecmp(access, "RW_NONINTERLEAVED")) params->access = SND_PCM_ACCESS_RW_NONINTERLEAVED;
+ ACCESS_CHECK(MMAP_INTERLEAVED);
+ ACCESS_CHECK(MMAP_NONINTERLEAVED);
+ ACCESS_CHECK(MMAP_COMPLEX);
+ ACCESS_CHECK(RW_INTERLEAVED);
+ ACCESS_CHECK(RW_NONINTERLEAVED);
- else {
- AFB_ApiNotice(mixer->api, "ApiPcmSetParams:%s(params) unsupported access 'RW_INTERLEAVED|MMAP_INTERLEAVED|MMAP_COMPLEX' access=%s", uid, access);
- goto OnErrorExit;
- }
+ AFB_ApiNotice(mixer->api, "ApiPcmSetParams:%s(params) unsupported access 'RW_INTERLEAVED|MMAP_INTERLEAVED|MMAP_COMPLEX' access=%s", uid, access);
+ goto OnErrorExit;
+success:
+ AFB_ApiNotice(mixer->api, "THIERRY ApiPcmSetParams:%s access set to %s", uid, access);
return params;
OnErrorExit:
diff --git a/plugins/alsa/alsa-core-pcm.c b/plugins/alsa/alsa-core-pcm.c
index 3362377..e4936e5 100644
--- a/plugins/alsa/alsa-core-pcm.c
+++ b/plugins/alsa/alsa-core-pcm.c
@@ -67,7 +67,7 @@ PUBLIC int AlsaPcmConf(SoftMixerT *mixer, AlsaPcmCtlT *pcm, AlsaPcmHwInfoT *opts
snd_pcm_format_t format;
snd_pcm_access_t access;
- // retrieve hadware config from PCM
+ // retrieve hardware config from PCM
snd_pcm_hw_params_alloca(&pxmHwParams);
snd_pcm_hw_params_any(pcm->handle, pxmHwParams);
@@ -102,6 +102,8 @@ PUBLIC int AlsaPcmConf(SoftMixerT *mixer, AlsaPcmCtlT *pcm, AlsaPcmHwInfoT *opts
}
}
+
+
if (opts->channels) {
if ((error = snd_pcm_hw_params_set_channels(pcm->handle, pxmHwParams, opts->channels)) < 0) {
AFB_ApiError(mixer->api, "AlsaPcmConf: mixer=%s cardid=%s Set_Channels=%d Fail error=%s",mixer->uid, pcm->cid.cardid, opts->channels, snd_strerror(error));
diff --git a/plugins/alsa/alsa-plug-vol.c b/plugins/alsa/alsa-plug-vol.c
index ab06cc1..25e382f 100644
--- a/plugins/alsa/alsa-plug-vol.c
+++ b/plugins/alsa/alsa-plug-vol.c
@@ -20,7 +20,7 @@
#include "alsa-softmixer.h"
-ALSA_PLUG_PROTO(softvol); // stream uses solftvol plugin
+ALSA_PLUG_PROTO(softvol); // stream uses softvol plugin
PUBLIC AlsaPcmCtlT *AlsaCreateSoftvol(SoftMixerT *mixer, AlsaStreamAudioT *stream, AlsaSndZoneT *zone, AlsaSndCtlT *sndcard, char* ctlName, int max, int open) {
snd_config_t *streamConfig, *elemConfig, *slaveConfig, *controlConfig,*pcmConfig;
@@ -95,4 +95,4 @@ OnErrorExit:
AlsaDumpCtlConfig(mixer, "plug-softvol", streamConfig, 1);
AFB_ApiNotice(mixer->api, "AlsaCreateSoftvol:%s(stream) OnErrorExit\n", stream->uid);
return NULL;
-} \ No newline at end of file
+}