Using Linux Mint 17.1 and ALSA. I have two wav files producing identical sound: one using pcm_s16le and the other using pcm_s24le. Each is played correctly by Totem/videos. My code to set hardware parameters and to playback using pcm_s16le works fine. However, when I attempt to adjust these parameters to accommodate pcm_s24le as follows:
snd_pcm_hw_params_set_format(audioHandle, audioParams, SND_PCM_FORMAT_S24_LE);
[I have simply substituted 'SND_PCM_FORMAT_S24LE' for 'SND_PCM_FORMAT_S16_LE']. The call to snd_pcm_writei is
snd_pcm_writei(m_audioHandle, *m_pAudioFrameData, *m_pAudioFrameSize / (m_nChannels * m_bitsPerSample / 8);
I get mostly garbage sound (hissing, choppiness) with a hint of the correct sound.
Essentially my question is, how do I convert code that works for SND_PCM_FORMAT_S16_LE to work for SND_PCM_FORMAT_S24_LE?
There are three possible ways of storing 24-bit samples in memory:
LSB MSB
1st byte 2nd byte 3rd byte 4th byte alignment
S32_LE: 00000000 xxxxxxxx xxxxxxxx xxxxxxxx 32 bits
S24_LE: xxxxxxxx xxxxxxxx xxxxxxxx 00000000 32 bits
S24_3LE: xxxxxxxx xxxxxxxx xxxxxxxx 24 bits
Most hardware uses S32_LE, except for USB, which uses S24_3LE. There is no hardware that uses S24_LE.
ALSA can automatically convert the sample format, but you have to describe your own sample format correctly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With