asound.h: add SNDRV_PCM_FORMAT_{S, U}20
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH v3 1/4 asound.h: add SNDRV_PCM_FORMAT_{S, U}20
This patch adds definitions of 20-bit, 4-byte PCM formats SNDRV_PCM_FORMAT_{S,U}20, that were recently added to the kernel, to alsa-lib's own copy of asound.h.
--- include/sound/asound.h | 9 +++++++++ 1 file changed, 9 insertions(+)
include/sound/asound.h +9 -0
@@ -213,6 +213,11 @@ typedef int __bitwise snd_pcm_format_t;#define SNDRV_PCM_FORMAT_IMA_ADPCM ((__force snd_pcm_format_t) 22)#define SNDRV_PCM_FORMAT_MPEG ((__force snd_pcm_format_t) 23)#define SNDRV_PCM_FORMAT_GSM ((__force snd_pcm_format_t) 24) +#define SNDRV_PCM_FORMAT_S20_LE ((__force snd_pcm_format_t) 25)/* in four bytes, LSB justified */ +#define SNDRV_PCM_FORMAT_S20_BE ((__force snd_pcm_format_t) 26)/* in four bytes, LSB justified */ +#define SNDRV_PCM_FORMAT_U20_LE ((__force snd_pcm_format_t) 27)/* in four bytes, LSB justified */ +#define SNDRV_PCM_FORMAT_U20_BE ((__force snd_pcm_format_t) 28)/* in four bytes, LSB justified */ +/* gap in the numbering for a future standard linear format */ #define SNDRV_PCM_FORMAT_SPECIAL ((__force snd_pcm_format_t) 31)#define SNDRV_PCM_FORMAT_S24_3LE ((__force snd_pcm_format_t) 32)/* in three bytes */ #define SNDRV_PCM_FORMAT_S24_3BE ((__force snd_pcm_format_t) 33)/* in three bytes */
@@ -247,6 +252,8 @@ typedef int __bitwise snd_pcm_format_t;#define SNDRV_PCM_FORMAT_FLOAT SNDRV_PCM_FORMAT_FLOAT_LE#define SNDRV_PCM_FORMAT_FLOAT64 SNDRV_PCM_FORMAT_FLOAT64_LE#define SNDRV_PCM_FORMAT_IEC958_SUBFRAME SNDRV_PCM_FORMAT_IEC958_SUBFRAME_LE +#define SNDRV_PCM_FORMAT_S20 SNDRV_PCM_FORMAT_S20_LE +#define SNDRV_PCM_FORMAT_U20 SNDRV_PCM_FORMAT_U20_LE#endif #ifdef SNDRV_BIG_ENDIAN #define SNDRV_PCM_FORMAT_S16 SNDRV_PCM_FORMAT_S16_BE
@@ -258,6 +265,8 @@ typedef int __bitwise snd_pcm_format_t;#define SNDRV_PCM_FORMAT_FLOAT SNDRV_PCM_FORMAT_FLOAT_BE#define SNDRV_PCM_FORMAT_FLOAT64 SNDRV_PCM_FORMAT_FLOAT64_BE#define SNDRV_PCM_FORMAT_IEC958_SUBFRAME SNDRV_PCM_FORMAT_IEC958_SUBFRAME_BE +#define SNDRV_PCM_FORMAT_S20 SNDRV_PCM_FORMAT_S20_BE +#define SNDRV_PCM_FORMAT_U20 SNDRV_PCM_FORMAT_U20_BE#endif typedef int __bitwise snd_pcm_subformat_t ;
PATCH v3 2/4 pcm: add and describe SND_PCM_FORMAT_{S, U}20
In reply to a message not in the archiveThis patch adds and describes in various functions that query format properties SND_PCM_FORMAT_{S,U}20 formats that were recently added to the kernel as SNDRV_PCM_FORMAT_{S,U}20.
These formats are similar to existing 20-bit PCM formats SND_PCM_FORMAT_{S,U}20_3, however they occupy 4 bytes instead of 3.
--- include/pcm.h | 20 ++++++++++++++++++-- src/pcm/pcm.c | 10 ++++++++++ src/pcm/pcm_local.h | 4 ++++ src/pcm/pcm_misc.c | 41 ++++++++++++++++++++++++++++++++++++++--- 4 files changed, 70 insertions(+), 5 deletions(-)
include/pcm.h +18 -2
@@ -175,6 +175,14 @@ typedef enum _snd_pcm_format {SND_PCM_FORMAT_MPEG ,/** GSM */ SND_PCM_FORMAT_GSM , +/** Signed 20bit Little Endian in 4bytes format, LSB justified */ +SND_PCM_FORMAT_S20_LE , +/** Signed 20bit Big Endian in 4bytes format, LSB justified */ +SND_PCM_FORMAT_S20_BE , +/** Unsigned 20bit Little Endian in 4bytes format, LSB justified */ +SND_PCM_FORMAT_U20_LE , +/** Unsigned 20bit Big Endian in 4bytes format, LSB justified */ +SND_PCM_FORMAT_U20_BE ,/** Special */ SND_PCM_FORMAT_SPECIAL = 31,/** Signed 24bit Little Endian in 3bytes format */
@@ -239,7 +247,11 @@ typedef enum _snd_pcm_format {/** Float 64 bit CPU endian */ SND_PCM_FORMAT_FLOAT64 =SND_PCM_FORMAT_FLOAT64_LE ,/** IEC-958 CPU Endian */ - SND_PCM_FORMAT_IEC958_SUBFRAME = SND_PCM_FORMAT_IEC958_SUBFRAME_LE +SND_PCM_FORMAT_IEC958_SUBFRAME =SND_PCM_FORMAT_IEC958_SUBFRAME_LE , +/** Signed 20bit in 4bytes format, LSB justified, CPU Endian */ +SND_PCM_FORMAT_S20 =SND_PCM_FORMAT_S20_LE , +/** Unsigned 20bit in 4bytes format, LSB justified, CPU Endian */ +SND_PCM_FORMAT_U20 =SND_PCM_FORMAT_U20_LE , #elif __BYTE_ORDER == __BIG_ENDIAN /** Signed 16 bit CPU endian */ SND_PCM_FORMAT_S16 = SND_PCM_FORMAT_S16_BE,
@@ -258,7 +270,11 @@ typedef enum _snd_pcm_format {/** Float 64 bit CPU endian */ SND_PCM_FORMAT_FLOAT64 =SND_PCM_FORMAT_FLOAT64_BE ,/** IEC-958 CPU Endian */ - SND_PCM_FORMAT_IEC958_SUBFRAME = SND_PCM_FORMAT_IEC958_SUBFRAME_BE +SND_PCM_FORMAT_IEC958_SUBFRAME =SND_PCM_FORMAT_IEC958_SUBFRAME_BE , +/** Signed 20bit in 4bytes format, LSB justified, CPU Endian */ +SND_PCM_FORMAT_S20 =SND_PCM_FORMAT_S20_BE , +/** Unsigned 20bit in 4bytes format, LSB justified, CPU Endian */ +SND_PCM_FORMAT_U20 =SND_PCM_FORMAT_U20_BE , #else #error "Unknown endian"#endif
src/pcm/pcm.c +10 -0
@@ -1780,6 +1780,10 @@ static const char *const snd_pcm_format_names[] = {FORMAT (IMA_ADPCM ),FORMAT (MPEG ),FORMAT (GSM ), +FORMAT (S20_LE ), +FORMAT (S20_BE ), +FORMAT (U20_LE ), +FORMAT (U20_BE ),FORMAT (SPECIAL ),FORMAT (S24_3LE ), FORMAT(S24_3BE),
@@ -1814,6 +1818,8 @@ static const char *const snd_pcm_format_aliases[SND_PCM_FORMAT_LAST+1] = {FORMAT (FLOAT ),FORMAT (FLOAT64 ),FORMAT (IEC958_SUBFRAME ), +FORMAT (S20 ), + FORMAT(U20), };static const char *const snd_pcm_format_descriptions[] = {
@@ -1842,6 +1848,10 @@ static const char *const snd_pcm_format_descriptions[] = {FORMATD (IMA_ADPCM ,"Ima-ADPCM" ),FORMATD (MPEG ,"MPEG" ),FORMATD (GSM ,"GSM" ), +FORMATD (S20_LE ,"Signed 20 bit Little Endian in 4 bytes, LSB justified" ), +FORMATD (S20_BE ,"Signed 20 bit Big Endian in 4 bytes, LSB justified" ), +FORMATD (U20_LE ,"Unsigned 20 bit Little Endian in 4 bytes, LSB justified" ), +FORMATD (U20_BE ,"Unsigned 20 bit Big Endian in 4 bytes, LSB justified" ),FORMATD (SPECIAL ,"Special" ),FORMATD (S24_3LE ,"Signed 24 bit Little Endian in 3bytes" ), FORMATD(S24_3BE, "Signed 24 bit Big Endian in 3bytes"),
src/pcm/pcm_local.h +4 -0
@@ -984,6 +984,10 @@ const snd_config_t *snd_pcm_rate_get_default_converter(snd_config_t *root); (1U <<SND_PCM_FORMAT_S16_BE ) | \ (1U <<SND_PCM_FORMAT_U16_LE ) | \ (1U <<SND_PCM_FORMAT_U16_BE ) | \ + (1U <<SND_PCM_FORMAT_S20_LE ) | \ + (1U <<SND_PCM_FORMAT_S20_BE ) | \ + (1U <<SND_PCM_FORMAT_U20_LE ) | \ + (1U <<SND_PCM_FORMAT_U20_BE ) | \ (1U <<SND_PCM_FORMAT_S24_LE ) | \ (1U <<SND_PCM_FORMAT_S24_BE ) | \ (1U << SND_PCM_FORMAT_U24_LE) | \
src/pcm/pcm_misc.c +38 -3
133 lines not on this page · raw message
PATCH v3 3/4 pcm: linear, route: handle linear formats with 20-bit sample on 4 bytes
In reply to a message not in the archiveThe previous patch has added 20-bit PCM formats SND_PCM_FORMAT_{S,U}20 to alsa-lib.
We need to extend the linear format conversion code with handling of these sample formats so they can also be utilized by applications that only recognize the more typical ones like SND_PCM_FORMAT_S16.
Since the conversion arrays are indexed by a format bit width divided by 8 the easiest way to handle these formats is to treat them like they were 40-bit wide (the next free integer multiple of 8 bits).
This doesn't create a collision risk with a future format since there can't really be a 40-bit sample format that occupies 4 bytes.
Make sure we use the getput conversion method for these formats since a direct conversion from / to them is not supported.
--- src/pcm/pcm_linear.c | 14 +++++++++++--- src/pcm/pcm_route.c | 6 ++++-- src/pcm/plugin_ops.h | 50 ++++++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 61 insertions(+), 9 deletions(-)
src/pcm/pcm_linear.c +11 -3
@@ -100,8 +100,11 @@ int snd_pcm_linear_get_index(snd_pcm_format_t src_format, snd_pcm_format_t dst_fdefault : width =2 ;break ; } -return width *4 + endian *2 + sign +16 ; +return width *4 + endian *2 + sign +20 ; }else { +if (width ==20 ) + width =40 ; + width = width /8 -1 ;return width *4 + endian *2 + sign; }
@@ -131,8 +134,11 @@ int snd_pcm_linear_put_index(snd_pcm_format_t src_format, snd_pcm_format_t dst_fdefault : width =2 ;break ; } -return width *4 + endian *2 + sign +16 ; +return width *4 + endian *2 + sign +20 ; }else { +if (width ==20 ) + width =40 ; + width = width /8 -1 ;return width *4 + endian *2 + sign; }
@@ -303,7 +309,9 @@ static int snd_pcm_linear_hw_params(snd_pcm_t *pcm, snd_pcm_hw_params_t *params)if (err <0 )return err; linear->use_getput = (snd_pcm_format_physical_width (format) ==24 || -snd_pcm_format_physical_width (linear->sformat) ==24 ); +snd_pcm_format_physical_width (linear->sformat) ==24 || +snd_pcm_format_width (format) ==20 || +snd_pcm_format_width (linear->sformat) ==20 );if (linear->use_getput) {if (pcm->stream ==SND_PCM_STREAM_PLAYBACK ) { linear->get_idx =snd_pcm_linear_get_index (format,SND_PCM_FORMAT_S32 );
src/pcm/pcm_route.c +4 -2
@@ -565,10 +565,12 @@ static int snd_pcm_route_hw_params(snd_pcm_t *pcm, snd_pcm_hw_params_t * params) }if (err <0 )return err; -/* 3 bytes formats? */ +/* 3 bytes or 20-bit formats? */ route->params.use_getput = (snd_pcm_format_physical_width (src_format) +7 ) /8 ==3 || - (snd_pcm_format_physical_width (dst_format) +7 ) /8 ==3 ; + (snd_pcm_format_physical_width (dst_format) +7 ) /8 ==3 || +snd_pcm_format_width (src_format) ==20 || +snd_pcm_format_width (dst_format) ==20 ; route->params.get_idx =snd_pcm_linear_get_index (src_format,SND_PCM_FORMAT_S32 ); route->params.put_idx =snd_pcm_linear_put_index (SND_PCM_FORMAT_S32 , dst_format); route->params.conv_idx =snd_pcm_linear_convert_index (src_format, dst_format);
src/pcm/plugin_ops.h +46 -4
152 lines not on this page · raw message
PATCH v3 4/4 pcm: plug: add SND_PCM_FORMAT_{S, U}20 to linear_preferred_formats
In reply to a message not in the archiveThis commit adds the recently added formats SND_PCM_FORMAT_{S,U}20 to the linear_preferred_formats array in pcm_plug.
Let's give them lower priority than more standard S24 formats but a higher priority than less typical 3-byte versions.
--- src/pcm/pcm_plug.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
src/pcm/pcm_plug.c +11 -0
@@ -138,6 +138,17 @@ static const snd_pcm_format_t linear_preferred_formats[] = { SND_PCM_FORMAT_S24_LE, SND_PCM_FORMAT_U24_LE,#endif +#ifdef SND_LITTLE_ENDIAN +SND_PCM_FORMAT_S20_LE , +SND_PCM_FORMAT_U20_LE , +SND_PCM_FORMAT_S20_BE , +SND_PCM_FORMAT_U20_BE , +#else +SND_PCM_FORMAT_S20_BE , +SND_PCM_FORMAT_U20_BE , +SND_PCM_FORMAT_S20_LE , +SND_PCM_FORMAT_U20_LE , +#endif #ifdef SND_LITTLE_ENDIANSND_PCM_FORMAT_S24_3LE , SND_PCM_FORMAT_U24_3LE,