Skip to content

Commit 85df6b5

Browse files
perexgtiwai
authored andcommitted
ALSA: pcm: clarify and fix default msbits value for all formats
Return used most significant bits from sample bit-width rather than the whole physical sample word size. The starting bit offset is defined in the format itself. The behaviour is not changed for 32-bit formats like S32_LE. But with this change - msbits value 24 instead 32 is returned for 24-bit formats like S24_LE etc. Also, commit 2112aa0 ("ALSA: pcm: Introduce MSBITS subformat interface") compares sample bit-width not physical sample bit-width to reset MSBITS_MAX bit from the subformat bitmask. Probably no applications are using msbits value for other than S32_LE/U32_LE formats, because no drivers are reducing msbits value for other formats (with the msb offset) at the moment. For sanity, increase PCM protocol version, letting the user space to detect the changed behaviour. Signed-off-by: Jaroslav Kysela <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Takashi Iwai <[email protected]>
1 parent 67c3d77 commit 85df6b5

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

include/uapi/sound/asound.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ struct snd_hwdep_dsp_image {
142142
* *
143143
*****************************************************************************/
144144

145-
#define SNDRV_PCM_VERSION SNDRV_PROTOCOL_VERSION(2, 0, 16)
145+
#define SNDRV_PCM_VERSION SNDRV_PROTOCOL_VERSION(2, 0, 17)
146146

147147
typedef unsigned long snd_pcm_uframes_t;
148148
typedef signed long snd_pcm_sframes_t;
@@ -416,7 +416,7 @@ struct snd_pcm_hw_params {
416416
unsigned int rmask; /* W: requested masks */
417417
unsigned int cmask; /* R: changed masks */
418418
unsigned int info; /* R: Info flags for returned setup */
419-
unsigned int msbits; /* R: used most significant bits */
419+
unsigned int msbits; /* R: used most significant bits (in sample bit-width) */
420420
unsigned int rate_num; /* R: rate numerator */
421421
unsigned int rate_den; /* R: rate denominator */
422422
snd_pcm_uframes_t fifo_size; /* R: chip FIFO size in frames */

sound/core/pcm_native.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,11 @@ static int fixup_unreferenced_params(struct snd_pcm_substream *substream,
486486
i = hw_param_interval_c(params, SNDRV_PCM_HW_PARAM_SAMPLE_BITS);
487487
if (snd_interval_single(i))
488488
params->msbits = snd_interval_value(i);
489+
m = hw_param_mask_c(params, SNDRV_PCM_HW_PARAM_FORMAT);
490+
if (snd_mask_single(m)) {
491+
snd_pcm_format_t format = (__force snd_pcm_format_t)snd_mask_min(m);
492+
params->msbits = snd_pcm_format_width(format);
493+
}
489494
}
490495

491496
if (params->msbits) {

0 commit comments

Comments
 (0)