* [PATCH 1/3] pcm: add support to get PCM sample rate from name @ 2017-05-31 13:46 guneshwor.o.singh 2017-05-31 13:46 ` [PATCH 2/3] topology: Add max rates definition guneshwor.o.singh ` (2 more replies) 0 siblings, 3 replies; 7+ messages in thread From: guneshwor.o.singh @ 2017-05-31 13:46 UTC (permalink / raw) To: alsa-devel, tiwai Cc: vinod.koul, mengdong.lin, Guneshwor Singh, liam.r.girdwood From: Guneshwor Singh <guneshwor.o.singh@intel.com> Get PCM sample rate from rate name similar to snd_pcm_format_value() which retrieves format from format name. Signed-off-by: Guneshwor Singh <guneshwor.o.singh@intel.com> --- include/pcm.h | 38 ++++++++++++++++++++++++++++++++++++++ src/pcm/pcm.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) diff --git a/include/pcm.h b/include/pcm.h index 0be1a321..81bc55b1 100644 --- a/include/pcm.h +++ b/include/pcm.h @@ -119,6 +119,43 @@ typedef enum _snd_pcm_access { SND_PCM_ACCESS_LAST = SND_PCM_ACCESS_RW_NONINTERLEAVED } snd_pcm_access_t; +/** PCM sample rate */ +typedef enum _snd_pcm_rates { + /** Unknown */ + SND_PCM_RATE_UNKNOWN = -1, + /** 5512 Hz sample rate */ + SND_PCM_RATE_5512 = 0, + /** 8000 Hz sample rate */ + SND_PCM_RATE_8000, + /** 11025 Hz sample rate */ + SND_PCM_RATE_11025, + /** 16000 Hz sample rate */ + SND_PCM_RATE_16000, + /** 22050 Hz sample rate */ + SND_PCM_RATE_22050, + /** 32000 Hz sample rate */ + SND_PCM_RATE_32000, + /** 44100 Hz sample rate */ + SND_PCM_RATE_44100, + /** 48000 Hz sample rate */ + SND_PCM_RATE_48000, + /** 64000 Hz sample rate */ + SND_PCM_RATE_64000, + /** 88200 Hz sample rate */ + SND_PCM_RATE_88200, + /** 96000 Hz sample rate */ + SND_PCM_RATE_96000, + /** 176400 Hz sample rate */ + SND_PCM_RATE_176400, + /** 192000 Hz sample rate */ + SND_PCM_RATE_192000, + /** continuous range within rate_min and rate_max */ + SND_PCM_RATE_CONTINUOUS = 30, + /** more continuous range */ + SND_PCM_RATE_KNOT = 31, + SND_PCM_RATE_LAST = SND_PCM_RATE_KNOT, +} snd_pcm_rates_t; + /** PCM sample format */ typedef enum _snd_pcm_format { /** Unknown */ @@ -1047,6 +1084,7 @@ const char *snd_pcm_format_description(const snd_pcm_format_t format); const char *snd_pcm_subformat_name(const snd_pcm_subformat_t subformat); const char *snd_pcm_subformat_description(const snd_pcm_subformat_t subformat); snd_pcm_format_t snd_pcm_format_value(const char* name); +snd_pcm_rates_t snd_pcm_rate_value(const char* name); const char *snd_pcm_tstamp_mode_name(const snd_pcm_tstamp_t mode); const char *snd_pcm_state_name(const snd_pcm_state_t state); diff --git a/src/pcm/pcm.c b/src/pcm/pcm.c index 200b10c2..bff1b949 100644 --- a/src/pcm/pcm.c +++ b/src/pcm/pcm.c @@ -1722,6 +1722,7 @@ static int __snd_pcm_poll_revents(snd_pcm_t *pcm, struct pollfd *pfds, #define START(v) [SND_PCM_START_##v] = #v #define HW_PARAM(v) [SND_PCM_HW_PARAM_##v] = #v #define SW_PARAM(v) [SND_PCM_SW_PARAM_##v] = #v +#define RATE(v) [SND_PCM_RATE_##v] = #v #define FORMAT(v) [SND_PCM_FORMAT_##v] = #v #define SUBFORMAT(v) [SND_PCM_SUBFORMAT_##v] = #v @@ -1754,6 +1755,24 @@ static const char *const snd_pcm_access_names[] = { ACCESS(RW_NONINTERLEAVED), }; +static const char *const snd_pcm_rate_names[] = { + RATE(5512), + RATE(8000), + RATE(11025), + RATE(16000), + RATE(22050), + RATE(32000), + RATE(44100), + RATE(48000), + RATE(64000), + RATE(88200), + RATE(96000), + RATE(176400), + RATE(192000), + RATE(CONTINUOUS), + RATE(KNOT), +}; + static const char *const snd_pcm_format_names[] = { FORMAT(S8), FORMAT(U8), @@ -1978,6 +1997,24 @@ const char *snd_pcm_format_description(snd_pcm_format_t format) } /** + * \brief get PCM sample rate from name + * \param name PCM sample rate name (case insensitive) + * \return PCM sample rate + */ +snd_pcm_rates_t snd_pcm_rate_value(const char* name) +{ + snd_pcm_rates_t rate; + for (rate = 0; rate <= SND_PCM_RATE_LAST; rate++) { + if (snd_pcm_rate_names[rate] && + strcasecmp(name, snd_pcm_rate_names[rate]) == 0) { + return rate; + } + } + + return SND_PCM_RATE_UNKNOWN; +} + +/** * \brief get PCM sample format from name * \param name PCM sample format name (case insensitive) * \return PCM sample format -- 2.13.0 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/3] topology: Add max rates definition 2017-05-31 13:46 [PATCH 1/3] pcm: add support to get PCM sample rate from name guneshwor.o.singh @ 2017-05-31 13:46 ` guneshwor.o.singh 2017-05-31 13:46 ` [PATCH 3/3] topology: Add parsing for rates from conf guneshwor.o.singh 2017-05-31 13:53 ` [PATCH 1/3] pcm: add support to get PCM sample rate from name Takashi Iwai 2 siblings, 0 replies; 7+ messages in thread From: guneshwor.o.singh @ 2017-05-31 13:46 UTC (permalink / raw) To: alsa-devel, tiwai Cc: vinod.koul, mengdong.lin, Guneshwor Singh, liam.r.girdwood From: Guneshwor Singh <guneshwor.o.singh@intel.com> Signed-off-by: Guneshwor Singh <guneshwor.o.singh@intel.com> --- include/sound/asoc.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/sound/asoc.h b/include/sound/asoc.h index 082c5429..a8accd01 100644 --- a/include/sound/asoc.h +++ b/include/sound/asoc.h @@ -26,6 +26,11 @@ #define SND_SOC_TPLG_MAX_FORMATS 16 /* + * Maximum number of PCM rates capability + */ +#define SND_SOC_TPLG_MAX_RATES 16 + +/* * Maximum number of PCM stream configs */ #define SND_SOC_TPLG_STREAM_CONFIG_MAX 8 -- 2.13.0 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/3] topology: Add parsing for rates from conf 2017-05-31 13:46 [PATCH 1/3] pcm: add support to get PCM sample rate from name guneshwor.o.singh 2017-05-31 13:46 ` [PATCH 2/3] topology: Add max rates definition guneshwor.o.singh @ 2017-05-31 13:46 ` guneshwor.o.singh 2017-05-31 13:53 ` [PATCH 1/3] pcm: add support to get PCM sample rate from name Takashi Iwai 2 siblings, 0 replies; 7+ messages in thread From: guneshwor.o.singh @ 2017-05-31 13:46 UTC (permalink / raw) To: alsa-devel, tiwai Cc: vinod.koul, mengdong.lin, Guneshwor Singh, liam.r.girdwood From: Guneshwor Singh <guneshwor.o.singh@intel.com> rate_min and rate_max are parsed currently, some drivers may also use rates to specify PCM stream capability. So add support to parse it. Signed-off-by: Guneshwor Singh <guneshwor.o.singh@intel.com> --- include/topology.h | 1 + src/topology/pcm.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/include/topology.h b/include/topology.h index ccb3a004..42d23762 100644 --- a/include/topology.h +++ b/include/topology.h @@ -534,6 +534,7 @@ extern "C" { * SectionPCMCapabilities."name" { * * formats "S24_LE,S16_LE" # Supported formats + * rates "48000" # Supported rates * rate_min "48000" # Max supported sample rate * rate_max "48000" # Min supported sample rate * channels_min "2" # Min number of channels diff --git a/src/topology/pcm.c b/src/topology/pcm.c index daef20e4..52165243 100644 --- a/src/topology/pcm.c +++ b/src/topology/pcm.c @@ -309,6 +309,29 @@ static int split_format(struct snd_soc_tplg_stream_caps *caps, char *str) return 0; } +static int split_rate(struct snd_soc_tplg_stream_caps *caps, char *str) +{ + char *s = NULL; + snd_pcm_rates_t rate; + int i = 0; + + s = strtok(str, ","); + while ((s) && (i < SND_SOC_TPLG_MAX_RATES)) { + rate = snd_pcm_rate_value(s); + + if (rate == SND_PCM_RATE_UNKNOWN) { + SNDERR("error: unsupported stream rate %s\n", s); + return -EINVAL; + } + + caps->rates |= 1 << rate; + s = strtok(NULL, ", "); + i++; + } + + return 0; +} + /* Parse pcm stream capabilities */ int tplg_parse_stream_caps(snd_tplg_t *tplg, snd_config_t *cfg, void *private ATTRIBUTE_UNUSED) @@ -360,6 +383,21 @@ int tplg_parse_stream_caps(snd_tplg_t *tplg, continue; } + if (strcmp(id, "rates") == 0) { + s = strdup(val); + if (!s) + return -ENOMEM; + + err = split_rate(sc, s); + free(s); + + if (err < 0) + return err; + + tplg_dbg("\t\t%s: %s\n", id, val); + continue; + } + if (strcmp(id, "rate_min") == 0) { sc->rate_min = atoi(val); tplg_dbg("\t\t%s: %d\n", id, sc->rate_min); -- 2.13.0 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 1/3] pcm: add support to get PCM sample rate from name 2017-05-31 13:46 [PATCH 1/3] pcm: add support to get PCM sample rate from name guneshwor.o.singh 2017-05-31 13:46 ` [PATCH 2/3] topology: Add max rates definition guneshwor.o.singh 2017-05-31 13:46 ` [PATCH 3/3] topology: Add parsing for rates from conf guneshwor.o.singh @ 2017-05-31 13:53 ` Takashi Iwai 2017-06-01 4:09 ` Singh, Guneshwor 2 siblings, 1 reply; 7+ messages in thread From: Takashi Iwai @ 2017-05-31 13:53 UTC (permalink / raw) To: guneshwor.o.singh; +Cc: vinod.koul, mengdong.lin, alsa-devel, liam.r.girdwood On Wed, 31 May 2017 15:46:44 +0200, <guneshwor.o.singh@intel.com> wrote: > > From: Guneshwor Singh <guneshwor.o.singh@intel.com> > > Get PCM sample rate from rate name similar to snd_pcm_format_value() which > retrieves format from format name. > > Signed-off-by: Guneshwor Singh <guneshwor.o.singh@intel.com> The enum is only for internal, so it shouldn't be exposed as a public API. I don't mind if it's only for alsa-lib internals, though. thanks, Takashi > --- > include/pcm.h | 38 ++++++++++++++++++++++++++++++++++++++ > src/pcm/pcm.c | 37 +++++++++++++++++++++++++++++++++++++ > 2 files changed, 75 insertions(+) > > diff --git a/include/pcm.h b/include/pcm.h > index 0be1a321..81bc55b1 100644 > --- a/include/pcm.h > +++ b/include/pcm.h > @@ -119,6 +119,43 @@ typedef enum _snd_pcm_access { > SND_PCM_ACCESS_LAST = SND_PCM_ACCESS_RW_NONINTERLEAVED > } snd_pcm_access_t; > > +/** PCM sample rate */ > +typedef enum _snd_pcm_rates { > + /** Unknown */ > + SND_PCM_RATE_UNKNOWN = -1, > + /** 5512 Hz sample rate */ > + SND_PCM_RATE_5512 = 0, > + /** 8000 Hz sample rate */ > + SND_PCM_RATE_8000, > + /** 11025 Hz sample rate */ > + SND_PCM_RATE_11025, > + /** 16000 Hz sample rate */ > + SND_PCM_RATE_16000, > + /** 22050 Hz sample rate */ > + SND_PCM_RATE_22050, > + /** 32000 Hz sample rate */ > + SND_PCM_RATE_32000, > + /** 44100 Hz sample rate */ > + SND_PCM_RATE_44100, > + /** 48000 Hz sample rate */ > + SND_PCM_RATE_48000, > + /** 64000 Hz sample rate */ > + SND_PCM_RATE_64000, > + /** 88200 Hz sample rate */ > + SND_PCM_RATE_88200, > + /** 96000 Hz sample rate */ > + SND_PCM_RATE_96000, > + /** 176400 Hz sample rate */ > + SND_PCM_RATE_176400, > + /** 192000 Hz sample rate */ > + SND_PCM_RATE_192000, > + /** continuous range within rate_min and rate_max */ > + SND_PCM_RATE_CONTINUOUS = 30, > + /** more continuous range */ > + SND_PCM_RATE_KNOT = 31, > + SND_PCM_RATE_LAST = SND_PCM_RATE_KNOT, > +} snd_pcm_rates_t; > + > /** PCM sample format */ > typedef enum _snd_pcm_format { > /** Unknown */ > @@ -1047,6 +1084,7 @@ const char *snd_pcm_format_description(const snd_pcm_format_t format); > const char *snd_pcm_subformat_name(const snd_pcm_subformat_t subformat); > const char *snd_pcm_subformat_description(const snd_pcm_subformat_t subformat); > snd_pcm_format_t snd_pcm_format_value(const char* name); > +snd_pcm_rates_t snd_pcm_rate_value(const char* name); > const char *snd_pcm_tstamp_mode_name(const snd_pcm_tstamp_t mode); > const char *snd_pcm_state_name(const snd_pcm_state_t state); > > diff --git a/src/pcm/pcm.c b/src/pcm/pcm.c > index 200b10c2..bff1b949 100644 > --- a/src/pcm/pcm.c > +++ b/src/pcm/pcm.c > @@ -1722,6 +1722,7 @@ static int __snd_pcm_poll_revents(snd_pcm_t *pcm, struct pollfd *pfds, > #define START(v) [SND_PCM_START_##v] = #v > #define HW_PARAM(v) [SND_PCM_HW_PARAM_##v] = #v > #define SW_PARAM(v) [SND_PCM_SW_PARAM_##v] = #v > +#define RATE(v) [SND_PCM_RATE_##v] = #v > #define FORMAT(v) [SND_PCM_FORMAT_##v] = #v > #define SUBFORMAT(v) [SND_PCM_SUBFORMAT_##v] = #v > > @@ -1754,6 +1755,24 @@ static const char *const snd_pcm_access_names[] = { > ACCESS(RW_NONINTERLEAVED), > }; > > +static const char *const snd_pcm_rate_names[] = { > + RATE(5512), > + RATE(8000), > + RATE(11025), > + RATE(16000), > + RATE(22050), > + RATE(32000), > + RATE(44100), > + RATE(48000), > + RATE(64000), > + RATE(88200), > + RATE(96000), > + RATE(176400), > + RATE(192000), > + RATE(CONTINUOUS), > + RATE(KNOT), > +}; > + > static const char *const snd_pcm_format_names[] = { > FORMAT(S8), > FORMAT(U8), > @@ -1978,6 +1997,24 @@ const char *snd_pcm_format_description(snd_pcm_format_t format) > } > > /** > + * \brief get PCM sample rate from name > + * \param name PCM sample rate name (case insensitive) > + * \return PCM sample rate > + */ > +snd_pcm_rates_t snd_pcm_rate_value(const char* name) > +{ > + snd_pcm_rates_t rate; > + for (rate = 0; rate <= SND_PCM_RATE_LAST; rate++) { > + if (snd_pcm_rate_names[rate] && > + strcasecmp(name, snd_pcm_rate_names[rate]) == 0) { > + return rate; > + } > + } > + > + return SND_PCM_RATE_UNKNOWN; > +} > + > +/** > * \brief get PCM sample format from name > * \param name PCM sample format name (case insensitive) > * \return PCM sample format > -- > 2.13.0 > > ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/3] pcm: add support to get PCM sample rate from name 2017-05-31 13:53 ` [PATCH 1/3] pcm: add support to get PCM sample rate from name Takashi Iwai @ 2017-06-01 4:09 ` Singh, Guneshwor 2017-06-01 5:55 ` Takashi Iwai 0 siblings, 1 reply; 7+ messages in thread From: Singh, Guneshwor @ 2017-06-01 4:09 UTC (permalink / raw) To: Takashi Iwai; +Cc: vinod.koul, mengdong.lin, alsa-devel, liam.r.girdwood On Wed, May 31, 2017 at 03:53:25PM +0200, Takashi Iwai wrote: > On Wed, 31 May 2017 15:46:44 +0200, > <guneshwor.o.singh@intel.com> wrote: > > > > From: Guneshwor Singh <guneshwor.o.singh@intel.com> > > > > Get PCM sample rate from rate name similar to snd_pcm_format_value() which > > retrieves format from format name. > > > > Signed-off-by: Guneshwor Singh <guneshwor.o.singh@intel.com> > > The enum is only for internal, so it shouldn't be exposed as a public > API. I don't mind if it's only for alsa-lib internals, though. > It is only for alsa-lib internals and required to be used in topology conf parsing. Is it okay to have the enum in src/topology/pcm.c ? > > thanks, > > Takashi > > > --- > > include/pcm.h | 38 ++++++++++++++++++++++++++++++++++++++ > > src/pcm/pcm.c | 37 +++++++++++++++++++++++++++++++++++++ > > 2 files changed, 75 insertions(+) > > > > diff --git a/include/pcm.h b/include/pcm.h > > index 0be1a321..81bc55b1 100644 > > --- a/include/pcm.h > > +++ b/include/pcm.h > > @@ -119,6 +119,43 @@ typedef enum _snd_pcm_access { > > SND_PCM_ACCESS_LAST = SND_PCM_ACCESS_RW_NONINTERLEAVED > > } snd_pcm_access_t; > > > > +/** PCM sample rate */ > > +typedef enum _snd_pcm_rates { > > + /** Unknown */ > > + SND_PCM_RATE_UNKNOWN = -1, > > + /** 5512 Hz sample rate */ > > + SND_PCM_RATE_5512 = 0, > > + /** 8000 Hz sample rate */ > > + SND_PCM_RATE_8000, > > + /** 11025 Hz sample rate */ > > + SND_PCM_RATE_11025, > > + /** 16000 Hz sample rate */ > > + SND_PCM_RATE_16000, > > + /** 22050 Hz sample rate */ > > + SND_PCM_RATE_22050, > > + /** 32000 Hz sample rate */ > > + SND_PCM_RATE_32000, > > + /** 44100 Hz sample rate */ > > + SND_PCM_RATE_44100, > > + /** 48000 Hz sample rate */ > > + SND_PCM_RATE_48000, > > + /** 64000 Hz sample rate */ > > + SND_PCM_RATE_64000, > > + /** 88200 Hz sample rate */ > > + SND_PCM_RATE_88200, > > + /** 96000 Hz sample rate */ > > + SND_PCM_RATE_96000, > > + /** 176400 Hz sample rate */ > > + SND_PCM_RATE_176400, > > + /** 192000 Hz sample rate */ > > + SND_PCM_RATE_192000, > > + /** continuous range within rate_min and rate_max */ > > + SND_PCM_RATE_CONTINUOUS = 30, > > + /** more continuous range */ > > + SND_PCM_RATE_KNOT = 31, > > + SND_PCM_RATE_LAST = SND_PCM_RATE_KNOT, > > +} snd_pcm_rates_t; > > + > > /** PCM sample format */ > > typedef enum _snd_pcm_format { > > /** Unknown */ > > @@ -1047,6 +1084,7 @@ const char *snd_pcm_format_description(const snd_pcm_format_t format); > > const char *snd_pcm_subformat_name(const snd_pcm_subformat_t subformat); > > const char *snd_pcm_subformat_description(const snd_pcm_subformat_t subformat); > > snd_pcm_format_t snd_pcm_format_value(const char* name); > > +snd_pcm_rates_t snd_pcm_rate_value(const char* name); > > const char *snd_pcm_tstamp_mode_name(const snd_pcm_tstamp_t mode); > > const char *snd_pcm_state_name(const snd_pcm_state_t state); > > > > diff --git a/src/pcm/pcm.c b/src/pcm/pcm.c > > index 200b10c2..bff1b949 100644 > > --- a/src/pcm/pcm.c > > +++ b/src/pcm/pcm.c > > @@ -1722,6 +1722,7 @@ static int __snd_pcm_poll_revents(snd_pcm_t *pcm, struct pollfd *pfds, > > #define START(v) [SND_PCM_START_##v] = #v > > #define HW_PARAM(v) [SND_PCM_HW_PARAM_##v] = #v > > #define SW_PARAM(v) [SND_PCM_SW_PARAM_##v] = #v > > +#define RATE(v) [SND_PCM_RATE_##v] = #v > > #define FORMAT(v) [SND_PCM_FORMAT_##v] = #v > > #define SUBFORMAT(v) [SND_PCM_SUBFORMAT_##v] = #v > > > > @@ -1754,6 +1755,24 @@ static const char *const snd_pcm_access_names[] = { > > ACCESS(RW_NONINTERLEAVED), > > }; > > > > +static const char *const snd_pcm_rate_names[] = { > > + RATE(5512), > > + RATE(8000), > > + RATE(11025), > > + RATE(16000), > > + RATE(22050), > > + RATE(32000), > > + RATE(44100), > > + RATE(48000), > > + RATE(64000), > > + RATE(88200), > > + RATE(96000), > > + RATE(176400), > > + RATE(192000), > > + RATE(CONTINUOUS), > > + RATE(KNOT), > > +}; > > + > > static const char *const snd_pcm_format_names[] = { > > FORMAT(S8), > > FORMAT(U8), > > @@ -1978,6 +1997,24 @@ const char *snd_pcm_format_description(snd_pcm_format_t format) > > } > > > > /** > > + * \brief get PCM sample rate from name > > + * \param name PCM sample rate name (case insensitive) > > + * \return PCM sample rate > > + */ > > +snd_pcm_rates_t snd_pcm_rate_value(const char* name) > > +{ > > + snd_pcm_rates_t rate; > > + for (rate = 0; rate <= SND_PCM_RATE_LAST; rate++) { > > + if (snd_pcm_rate_names[rate] && > > + strcasecmp(name, snd_pcm_rate_names[rate]) == 0) { > > + return rate; > > + } > > + } > > + > > + return SND_PCM_RATE_UNKNOWN; > > +} > > + > > +/** > > * \brief get PCM sample format from name > > * \param name PCM sample format name (case insensitive) > > * \return PCM sample format > > -- > > 2.13.0 > > > > ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/3] pcm: add support to get PCM sample rate from name 2017-06-01 4:09 ` Singh, Guneshwor @ 2017-06-01 5:55 ` Takashi Iwai 2017-06-01 5:59 ` Singh, Guneshwor 0 siblings, 1 reply; 7+ messages in thread From: Takashi Iwai @ 2017-06-01 5:55 UTC (permalink / raw) To: Singh, Guneshwor; +Cc: vinod.koul, mengdong.lin, alsa-devel, liam.r.girdwood On Thu, 01 Jun 2017 06:09:53 +0200, Singh, Guneshwor wrote: > > On Wed, May 31, 2017 at 03:53:25PM +0200, Takashi Iwai wrote: > > On Wed, 31 May 2017 15:46:44 +0200, > > <guneshwor.o.singh@intel.com> wrote: > > > > > > From: Guneshwor Singh <guneshwor.o.singh@intel.com> > > > > > > Get PCM sample rate from rate name similar to snd_pcm_format_value() which > > > retrieves format from format name. > > > > > > Signed-off-by: Guneshwor Singh <guneshwor.o.singh@intel.com> > > > > The enum is only for internal, so it shouldn't be exposed as a public > > API. I don't mind if it's only for alsa-lib internals, though. > > > It is only for alsa-lib internals and required to be used in topology > conf parsing. Is it okay to have the enum in src/topology/pcm.c ? That's OK, but include/sound/pcm.h is a public header to be exposed to outside. That should be avoided for local definitions. thanks, Takashi > > > > thanks, > > > > Takashi > > > > > --- > > > include/pcm.h | 38 ++++++++++++++++++++++++++++++++++++++ > > > src/pcm/pcm.c | 37 +++++++++++++++++++++++++++++++++++++ > > > 2 files changed, 75 insertions(+) > > > > > > diff --git a/include/pcm.h b/include/pcm.h > > > index 0be1a321..81bc55b1 100644 > > > --- a/include/pcm.h > > > +++ b/include/pcm.h > > > @@ -119,6 +119,43 @@ typedef enum _snd_pcm_access { > > > SND_PCM_ACCESS_LAST = SND_PCM_ACCESS_RW_NONINTERLEAVED > > > } snd_pcm_access_t; > > > > > > +/** PCM sample rate */ > > > +typedef enum _snd_pcm_rates { > > > + /** Unknown */ > > > + SND_PCM_RATE_UNKNOWN = -1, > > > + /** 5512 Hz sample rate */ > > > + SND_PCM_RATE_5512 = 0, > > > + /** 8000 Hz sample rate */ > > > + SND_PCM_RATE_8000, > > > + /** 11025 Hz sample rate */ > > > + SND_PCM_RATE_11025, > > > + /** 16000 Hz sample rate */ > > > + SND_PCM_RATE_16000, > > > + /** 22050 Hz sample rate */ > > > + SND_PCM_RATE_22050, > > > + /** 32000 Hz sample rate */ > > > + SND_PCM_RATE_32000, > > > + /** 44100 Hz sample rate */ > > > + SND_PCM_RATE_44100, > > > + /** 48000 Hz sample rate */ > > > + SND_PCM_RATE_48000, > > > + /** 64000 Hz sample rate */ > > > + SND_PCM_RATE_64000, > > > + /** 88200 Hz sample rate */ > > > + SND_PCM_RATE_88200, > > > + /** 96000 Hz sample rate */ > > > + SND_PCM_RATE_96000, > > > + /** 176400 Hz sample rate */ > > > + SND_PCM_RATE_176400, > > > + /** 192000 Hz sample rate */ > > > + SND_PCM_RATE_192000, > > > + /** continuous range within rate_min and rate_max */ > > > + SND_PCM_RATE_CONTINUOUS = 30, > > > + /** more continuous range */ > > > + SND_PCM_RATE_KNOT = 31, > > > + SND_PCM_RATE_LAST = SND_PCM_RATE_KNOT, > > > +} snd_pcm_rates_t; > > > + > > > /** PCM sample format */ > > > typedef enum _snd_pcm_format { > > > /** Unknown */ > > > @@ -1047,6 +1084,7 @@ const char *snd_pcm_format_description(const snd_pcm_format_t format); > > > const char *snd_pcm_subformat_name(const snd_pcm_subformat_t subformat); > > > const char *snd_pcm_subformat_description(const snd_pcm_subformat_t subformat); > > > snd_pcm_format_t snd_pcm_format_value(const char* name); > > > +snd_pcm_rates_t snd_pcm_rate_value(const char* name); > > > const char *snd_pcm_tstamp_mode_name(const snd_pcm_tstamp_t mode); > > > const char *snd_pcm_state_name(const snd_pcm_state_t state); > > > > > > diff --git a/src/pcm/pcm.c b/src/pcm/pcm.c > > > index 200b10c2..bff1b949 100644 > > > --- a/src/pcm/pcm.c > > > +++ b/src/pcm/pcm.c > > > @@ -1722,6 +1722,7 @@ static int __snd_pcm_poll_revents(snd_pcm_t *pcm, struct pollfd *pfds, > > > #define START(v) [SND_PCM_START_##v] = #v > > > #define HW_PARAM(v) [SND_PCM_HW_PARAM_##v] = #v > > > #define SW_PARAM(v) [SND_PCM_SW_PARAM_##v] = #v > > > +#define RATE(v) [SND_PCM_RATE_##v] = #v > > > #define FORMAT(v) [SND_PCM_FORMAT_##v] = #v > > > #define SUBFORMAT(v) [SND_PCM_SUBFORMAT_##v] = #v > > > > > > @@ -1754,6 +1755,24 @@ static const char *const snd_pcm_access_names[] = { > > > ACCESS(RW_NONINTERLEAVED), > > > }; > > > > > > +static const char *const snd_pcm_rate_names[] = { > > > + RATE(5512), > > > + RATE(8000), > > > + RATE(11025), > > > + RATE(16000), > > > + RATE(22050), > > > + RATE(32000), > > > + RATE(44100), > > > + RATE(48000), > > > + RATE(64000), > > > + RATE(88200), > > > + RATE(96000), > > > + RATE(176400), > > > + RATE(192000), > > > + RATE(CONTINUOUS), > > > + RATE(KNOT), > > > +}; > > > + > > > static const char *const snd_pcm_format_names[] = { > > > FORMAT(S8), > > > FORMAT(U8), > > > @@ -1978,6 +1997,24 @@ const char *snd_pcm_format_description(snd_pcm_format_t format) > > > } > > > > > > /** > > > + * \brief get PCM sample rate from name > > > + * \param name PCM sample rate name (case insensitive) > > > + * \return PCM sample rate > > > + */ > > > +snd_pcm_rates_t snd_pcm_rate_value(const char* name) > > > +{ > > > + snd_pcm_rates_t rate; > > > + for (rate = 0; rate <= SND_PCM_RATE_LAST; rate++) { > > > + if (snd_pcm_rate_names[rate] && > > > + strcasecmp(name, snd_pcm_rate_names[rate]) == 0) { > > > + return rate; > > > + } > > > + } > > > + > > > + return SND_PCM_RATE_UNKNOWN; > > > +} > > > + > > > +/** > > > * \brief get PCM sample format from name > > > * \param name PCM sample format name (case insensitive) > > > * \return PCM sample format > > > -- > > > 2.13.0 > > > > > > > ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/3] pcm: add support to get PCM sample rate from name 2017-06-01 5:55 ` Takashi Iwai @ 2017-06-01 5:59 ` Singh, Guneshwor 0 siblings, 0 replies; 7+ messages in thread From: Singh, Guneshwor @ 2017-06-01 5:59 UTC (permalink / raw) To: Takashi Iwai; +Cc: vinod.koul, mengdong.lin, alsa-devel, liam.r.girdwood On Thu, Jun 01, 2017 at 07:55:40AM +0200, Takashi Iwai wrote: > On Thu, 01 Jun 2017 06:09:53 +0200, > Singh, Guneshwor wrote: > > > > On Wed, May 31, 2017 at 03:53:25PM +0200, Takashi Iwai wrote: > > > On Wed, 31 May 2017 15:46:44 +0200, > > > <guneshwor.o.singh@intel.com> wrote: > > > > > > > > From: Guneshwor Singh <guneshwor.o.singh@intel.com> > > > > > > > > Get PCM sample rate from rate name similar to snd_pcm_format_value() which > > > > retrieves format from format name. > > > > > > > > Signed-off-by: Guneshwor Singh <guneshwor.o.singh@intel.com> > > > > > > The enum is only for internal, so it shouldn't be exposed as a public > > > API. I don't mind if it's only for alsa-lib internals, though. > > > > > It is only for alsa-lib internals and required to be used in topology > > conf parsing. Is it okay to have the enum in src/topology/pcm.c ? > > That's OK, but include/sound/pcm.h is a public header to be exposed to > outside. That should be avoided for local definitions. > Sure. I will rework and send a v2 patch. > > thanks, > > Takashi > > > > > > > > thanks, > > > > > > Takashi > > > > > > > --- > > > > include/pcm.h | 38 ++++++++++++++++++++++++++++++++++++++ > > > > src/pcm/pcm.c | 37 +++++++++++++++++++++++++++++++++++++ > > > > 2 files changed, 75 insertions(+) > > > > > > > > diff --git a/include/pcm.h b/include/pcm.h > > > > index 0be1a321..81bc55b1 100644 > > > > --- a/include/pcm.h > > > > +++ b/include/pcm.h > > > > @@ -119,6 +119,43 @@ typedef enum _snd_pcm_access { > > > > SND_PCM_ACCESS_LAST = SND_PCM_ACCESS_RW_NONINTERLEAVED > > > > } snd_pcm_access_t; > > > > > > > > +/** PCM sample rate */ > > > > +typedef enum _snd_pcm_rates { > > > > + /** Unknown */ > > > > + SND_PCM_RATE_UNKNOWN = -1, > > > > + /** 5512 Hz sample rate */ > > > > + SND_PCM_RATE_5512 = 0, > > > > + /** 8000 Hz sample rate */ > > > > + SND_PCM_RATE_8000, > > > > + /** 11025 Hz sample rate */ > > > > + SND_PCM_RATE_11025, > > > > + /** 16000 Hz sample rate */ > > > > + SND_PCM_RATE_16000, > > > > + /** 22050 Hz sample rate */ > > > > + SND_PCM_RATE_22050, > > > > + /** 32000 Hz sample rate */ > > > > + SND_PCM_RATE_32000, > > > > + /** 44100 Hz sample rate */ > > > > + SND_PCM_RATE_44100, > > > > + /** 48000 Hz sample rate */ > > > > + SND_PCM_RATE_48000, > > > > + /** 64000 Hz sample rate */ > > > > + SND_PCM_RATE_64000, > > > > + /** 88200 Hz sample rate */ > > > > + SND_PCM_RATE_88200, > > > > + /** 96000 Hz sample rate */ > > > > + SND_PCM_RATE_96000, > > > > + /** 176400 Hz sample rate */ > > > > + SND_PCM_RATE_176400, > > > > + /** 192000 Hz sample rate */ > > > > + SND_PCM_RATE_192000, > > > > + /** continuous range within rate_min and rate_max */ > > > > + SND_PCM_RATE_CONTINUOUS = 30, > > > > + /** more continuous range */ > > > > + SND_PCM_RATE_KNOT = 31, > > > > + SND_PCM_RATE_LAST = SND_PCM_RATE_KNOT, > > > > +} snd_pcm_rates_t; > > > > + > > > > /** PCM sample format */ > > > > typedef enum _snd_pcm_format { > > > > /** Unknown */ > > > > @@ -1047,6 +1084,7 @@ const char *snd_pcm_format_description(const snd_pcm_format_t format); > > > > const char *snd_pcm_subformat_name(const snd_pcm_subformat_t subformat); > > > > const char *snd_pcm_subformat_description(const snd_pcm_subformat_t subformat); > > > > snd_pcm_format_t snd_pcm_format_value(const char* name); > > > > +snd_pcm_rates_t snd_pcm_rate_value(const char* name); > > > > const char *snd_pcm_tstamp_mode_name(const snd_pcm_tstamp_t mode); > > > > const char *snd_pcm_state_name(const snd_pcm_state_t state); > > > > > > > > diff --git a/src/pcm/pcm.c b/src/pcm/pcm.c > > > > index 200b10c2..bff1b949 100644 > > > > --- a/src/pcm/pcm.c > > > > +++ b/src/pcm/pcm.c > > > > @@ -1722,6 +1722,7 @@ static int __snd_pcm_poll_revents(snd_pcm_t *pcm, struct pollfd *pfds, > > > > #define START(v) [SND_PCM_START_##v] = #v > > > > #define HW_PARAM(v) [SND_PCM_HW_PARAM_##v] = #v > > > > #define SW_PARAM(v) [SND_PCM_SW_PARAM_##v] = #v > > > > +#define RATE(v) [SND_PCM_RATE_##v] = #v > > > > #define FORMAT(v) [SND_PCM_FORMAT_##v] = #v > > > > #define SUBFORMAT(v) [SND_PCM_SUBFORMAT_##v] = #v > > > > > > > > @@ -1754,6 +1755,24 @@ static const char *const snd_pcm_access_names[] = { > > > > ACCESS(RW_NONINTERLEAVED), > > > > }; > > > > > > > > +static const char *const snd_pcm_rate_names[] = { > > > > + RATE(5512), > > > > + RATE(8000), > > > > + RATE(11025), > > > > + RATE(16000), > > > > + RATE(22050), > > > > + RATE(32000), > > > > + RATE(44100), > > > > + RATE(48000), > > > > + RATE(64000), > > > > + RATE(88200), > > > > + RATE(96000), > > > > + RATE(176400), > > > > + RATE(192000), > > > > + RATE(CONTINUOUS), > > > > + RATE(KNOT), > > > > +}; > > > > + > > > > static const char *const snd_pcm_format_names[] = { > > > > FORMAT(S8), > > > > FORMAT(U8), > > > > @@ -1978,6 +1997,24 @@ const char *snd_pcm_format_description(snd_pcm_format_t format) > > > > } > > > > > > > > /** > > > > + * \brief get PCM sample rate from name > > > > + * \param name PCM sample rate name (case insensitive) > > > > + * \return PCM sample rate > > > > + */ > > > > +snd_pcm_rates_t snd_pcm_rate_value(const char* name) > > > > +{ > > > > + snd_pcm_rates_t rate; > > > > + for (rate = 0; rate <= SND_PCM_RATE_LAST; rate++) { > > > > + if (snd_pcm_rate_names[rate] && > > > > + strcasecmp(name, snd_pcm_rate_names[rate]) == 0) { > > > > + return rate; > > > > + } > > > > + } > > > > + > > > > + return SND_PCM_RATE_UNKNOWN; > > > > +} > > > > + > > > > +/** > > > > * \brief get PCM sample format from name > > > > * \param name PCM sample format name (case insensitive) > > > > * \return PCM sample format > > > > -- > > > > 2.13.0 > > > > > > > > > > ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2017-06-01 5:59 UTC | newest] Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2017-05-31 13:46 [PATCH 1/3] pcm: add support to get PCM sample rate from name guneshwor.o.singh 2017-05-31 13:46 ` [PATCH 2/3] topology: Add max rates definition guneshwor.o.singh 2017-05-31 13:46 ` [PATCH 3/3] topology: Add parsing for rates from conf guneshwor.o.singh 2017-05-31 13:53 ` [PATCH 1/3] pcm: add support to get PCM sample rate from name Takashi Iwai 2017-06-01 4:09 ` Singh, Guneshwor 2017-06-01 5:55 ` Takashi Iwai 2017-06-01 5:59 ` Singh, Guneshwor
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.