]> git.alsa-project.org Git - alsa-lib.git/commitdiff
pcm: Introduce snd_pcm_subformat_value()
authorCezary Rojewski <cezary.rojewski@intel.com>
Fri, 4 Aug 2023 08:07:19 +0000 (10:07 +0200)
committerJaroslav Kysela <perex@perex.cz>
Fri, 8 Dec 2023 19:03:28 +0000 (20:03 +0100)
Allow userspace applications to select subformats easily just like in
snd_pcm_format_t case - by string conversion.

Closes: https://github.com/alsa-project/alsa-lib/pull/342
Signed-off-by: Cezary Rojewski <cezary.rojewski@intel.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
include/pcm.h
src/pcm/pcm.c

index e7853313106907fe7ba79d78d3e9d257b8669bf3..f18620bed63101db07f5698410ae33f70e4455fb 100644 (file)
@@ -282,6 +282,8 @@ typedef enum _snd_pcm_format {
 
 /** PCM sample subformat */
 typedef enum _snd_pcm_subformat {
+       /** Unknown */
+       SND_PCM_SUBFORMAT_UNKNOWN = -1,
        /** Standard */
        SND_PCM_SUBFORMAT_STD = 0,
        SND_PCM_SUBFORMAT_LAST = SND_PCM_SUBFORMAT_STD
@@ -1092,6 +1094,7 @@ const char *snd_pcm_format_name(const snd_pcm_format_t format);
 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_subformat_t snd_pcm_subformat_value(const char* name);
 snd_pcm_format_t snd_pcm_format_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);
index ad9e8956a3298cf7a29336eead02d5980196a0ca..8aae5afd525686118bb178ff99b6b8bc1261dd41 100644 (file)
@@ -2197,6 +2197,30 @@ const char *snd_pcm_subformat_description(const snd_pcm_subformat_t subformat)
        return snd_pcm_subformat_descriptions[subformat];
 }
 
+/**
+ * \brief get PCM sample subformat from name
+ * \param name PCM sample subformat name (case insensitive)
+ * \return PCM sample subformat
+ */
+snd_pcm_subformat_t snd_pcm_subformat_value(const char* name)
+{
+       snd_pcm_subformat_t subformat;
+
+       for (subformat = 0; subformat <= SND_PCM_SUBFORMAT_LAST; subformat++) {
+               if (snd_pcm_subformat_names[subformat] &&
+                   !strcasecmp(name, snd_pcm_subformat_names[subformat]))
+                       return subformat;
+       }
+
+       for (subformat = 0; subformat <= SND_PCM_SUBFORMAT_LAST; subformat++) {
+               if (snd_pcm_subformat_descriptions[subformat] &&
+                   !strcasecmp(name, snd_pcm_subformat_descriptions[subformat]))
+                       return subformat;
+       }
+
+       return SND_PCM_SUBFORMAT_UNKNOWN;
+}
+
 /**
  * \brief (DEPRECATED) get name of PCM start mode setting
  * \param mode PCM start mode