Skip to content

Commit e78583a

Browse files
committed
aplay: reorganize format handling in begin_wave()
Use strictly snd_pcm_format_physical_width/snd_pcm_format_width functions to determine the sample bit width. Signed-off-by: Jaroslav Kysela <[email protected]>
1 parent e5316c1 commit e78583a

File tree

1 file changed

+12
-20
lines changed

1 file changed

+12
-20
lines changed

aplay/aplay.c

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2710,31 +2710,29 @@ static void begin_wave(int fd, size_t cnt)
27102710
WaveHeader h;
27112711
WaveFmtBody f;
27122712
WaveChunkHeader cf, cd;
2713-
int bits;
2713+
int width, physical_width;
27142714
uint32_t tmp;
27152715
uint16_t tmp2;
27162716

27172717
/* WAVE cannot handle greater than 32bit (signed?) int */
27182718
if (cnt == (size_t)-2)
27192719
cnt = 0x7fffff00;
27202720

2721-
bits = 8;
2721+
width = snd_pcm_format_physical_width(hwparams.format);
2722+
physical_width = snd_pcm_format_width(hwparams.format);
2723+
2724+
if (width < 0 || physical_width < 0)
2725+
goto _format;
2726+
27222727
switch ((unsigned long) hwparams.format) {
27232728
case SND_PCM_FORMAT_U8:
2724-
bits = 8;
2725-
break;
27262729
case SND_PCM_FORMAT_S16_LE:
2727-
bits = 16;
2728-
break;
2730+
case SND_PCM_FORMAT_S24_LE: /* S24_LE is 24 bits stored in 32 bit width with 8 bit padding */
27292731
case SND_PCM_FORMAT_S32_LE:
2730-
case SND_PCM_FORMAT_FLOAT_LE:
2731-
bits = 32;
2732-
break;
2733-
case SND_PCM_FORMAT_S24_LE:
2732+
case SND_PCM_FORMAT_FLOAT_LE:
27342733
case SND_PCM_FORMAT_S24_3LE:
2735-
bits = 24;
2736-
break;
27372734
default:
2735+
_format:
27382736
error(_("Wave doesn't support %s format..."), snd_pcm_format_name(hwparams.format));
27392737
prg_exit(EXIT_FAILURE);
27402738
}
@@ -2752,17 +2750,11 @@ static void begin_wave(int fd, size_t cnt)
27522750
f.format = LE_SHORT(WAV_FMT_PCM);
27532751
f.channels = LE_SHORT(hwparams.channels);
27542752
f.sample_fq = LE_INT(hwparams.rate);
2755-
#if 0
2756-
tmp2 = (samplesize == 8) ? 1 : 2;
2757-
f.byte_p_spl = LE_SHORT(tmp2);
2758-
tmp = dsp_speed * hwparams.channels * (uint32_t) tmp2;
2759-
#else
2760-
tmp2 = hwparams.channels * snd_pcm_format_physical_width(hwparams.format) / 8;
2753+
tmp2 = hwparams.channels * physical_width / 8;
27612754
f.byte_p_spl = LE_SHORT(tmp2);
27622755
tmp = (uint32_t) tmp2 * hwparams.rate;
2763-
#endif
27642756
f.byte_p_sec = LE_INT(tmp);
2765-
f.bit_p_spl = LE_SHORT(bits);
2757+
f.bit_p_spl = LE_SHORT(width);
27662758

27672759
cd.type = WAV_DATA;
27682760
cd.length = LE_INT(cnt);

0 commit comments

Comments
 (0)