diff mbox series

speaker-test: add support for S24_LE and S24_BE

Message ID 20210312170316.63231-1-pierre-louis.bossart@linux.intel.com
State New
Headers show
Series speaker-test: add support for S24_LE and S24_BE | expand

Commit Message

Pierre-Louis Bossart March 12, 2021, 5:03 p.m. UTC
These formats are sometimes advertised by drivers, e.g. SOF.
The format is 3 bytes packed in 32-bit container, with the MSB zeroed
out.

sample: 0x00123456

S24_LE format:
b0 56
b1 34
b2 12
b3 00

S24_BE format:
b0 00
b1 12
b2 34
b3 56

I only tested the S24_LE format with the SOF driver, S24_BE was added
for symmetry only.

Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
---
 speaker-test/speaker-test.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

Comments

Takashi Iwai March 14, 2021, 8:34 a.m. UTC | #1
On Fri, 12 Mar 2021 18:03:16 +0100,
Pierre-Louis Bossart wrote:
> 
> These formats are sometimes advertised by drivers, e.g. SOF.
> The format is 3 bytes packed in 32-bit container, with the MSB zeroed
> out.
> 
> sample: 0x00123456
> 
> S24_LE format:
> b0 56
> b1 34
> b2 12
> b3 00
> 
> S24_BE format:
> b0 00
> b1 12
> b2 34
> b3 56
> 
> I only tested the S24_LE format with the SOF driver, S24_BE was added
> for symmetry only.
> 
> Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>

Thanks, applied now.


Takashi
diff mbox series

Patch

diff --git a/speaker-test/speaker-test.c b/speaker-test/speaker-test.c
index 773af0a..fd13d88 100644
--- a/speaker-test/speaker-test.c
+++ b/speaker-test/speaker-test.c
@@ -285,6 +285,8 @@  static const int	supported_formats[] = {
   SND_PCM_FORMAT_FLOAT_LE,
   SND_PCM_FORMAT_S24_3LE,
   SND_PCM_FORMAT_S24_3BE,
+  SND_PCM_FORMAT_S24_LE,
+  SND_PCM_FORMAT_S24_BE,
   SND_PCM_FORMAT_S32_LE,
   SND_PCM_FORMAT_S32_BE,
   -1
@@ -338,6 +340,20 @@  static void do_generate(uint8_t *frames, int channel, int count,
         *samp8++ = BE_INT(res.i) >> 8;
         *samp8++ = BE_INT(res.i) >> 16;
         break;
+      case SND_PCM_FORMAT_S24_LE:
+        res.i >>= 8;
+        *samp8++ = LE_INT(res.i);
+        *samp8++ = LE_INT(res.i) >> 8;
+        *samp8++ = LE_INT(res.i) >> 16;
+        *samp8++ = 0;
+        break;
+      case SND_PCM_FORMAT_S24_BE:
+        res.i >>= 8;
+        *samp8++ = 0;
+        *samp8++ = BE_INT(res.i);
+        *samp8++ = BE_INT(res.i) >> 8;
+        *samp8++ = BE_INT(res.i) >> 16;
+        break;
       case SND_PCM_FORMAT_S32_LE:
 	*samp32++ = LE_INT(res.i);
         break;