diff mbox

speaker-test: Support S24_3LE sample format

Message ID 20180302143104.22859-1-julian@jusst.de (mailing list archive)
State New, archived
Headers show

Commit Message

Julian Scheel March 2, 2018, 2:31 p.m. UTC
Implement support signed 24 bit samples, packed in 3 bytes.

Signed-off-by: Julian Scheel <julian@jusst.de>
---
 speaker-test/speaker-test.c | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

Comments

Takashi Iwai March 5, 2018, 3:15 p.m. UTC | #1
On Fri, 02 Mar 2018 15:31:04 +0100,
Julian Scheel wrote:
> 
> Implement support signed 24 bit samples, packed in 3 bytes.
> 
> Signed-off-by: Julian Scheel <julian@jusst.de>

Thanks for the patch.  The change itself is OK, but now I noticed that
there are way too many open-codes for the same stuff.  Let's kick them
out and then apply the support for a new format.

I cleaned up the code now in git tree.  Could you rebase your patch?
Also, it'd be better to have both *_LE and *_BE formats.  It shouldn't
be hard.


thanks,

Takashi
diff mbox

Patch

diff --git a/speaker-test/speaker-test.c b/speaker-test/speaker-test.c
index 46b0589..dbee63f 100644
--- a/speaker-test/speaker-test.c
+++ b/speaker-test/speaker-test.c
@@ -284,6 +284,7 @@  static const int	supported_formats[] = {
   SND_PCM_FORMAT_S16_LE,
   SND_PCM_FORMAT_S16_BE,
   SND_PCM_FORMAT_FLOAT_LE,
+  SND_PCM_FORMAT_S24_3LE,
   SND_PCM_FORMAT_S32_LE,
   SND_PCM_FORMAT_S32_BE,
   -1
@@ -341,6 +342,19 @@  static void generate_sine(uint8_t *frames, int channel, int count, double *_phas
 	  *samp_f++ = 0.0;
         }
         break;
+      case SND_PCM_FORMAT_S24_3LE:
+        if (chn==channel) {
+          res = (sin((phase * 2 * M_PI) / max_phase - M_PI)) * generator_scale * 0x7fffff;
+          ires = res;
+          *samp8++ = LE_INT(ires);
+          *samp8++ = LE_INT(ires) >> 8;
+          *samp8++ = LE_INT(ires) >> 16;
+        } else {
+          *samp8++ = 0;
+          *samp8++ = 0;
+          *samp8++ = 0;
+        }
+        break;
       case SND_PCM_FORMAT_S32_LE:
         if (chn==channel) {
           res = (sin((phase * 2 * M_PI) / max_phase - M_PI)) * generator_scale * 0x7fffffff;
@@ -415,6 +429,19 @@  static void generate_pink_noise( uint8_t *frames, int channel, int count) {
           *samp16++ = 0;
         }
         break;
+      case SND_PCM_FORMAT_S24_3LE:
+        if (chn==channel) {
+          res = generate_pink_noise_sample(&pink) * generator_scale * 0x07fffff;
+          ires = res;
+          *samp8++ = LE_INT(ires);
+          *samp8++ = LE_INT(ires) >> 8;
+          *samp8++ = LE_INT(ires) >> 16;
+        } else {
+          *samp8++ = 0;
+          *samp8++ = 0;
+          *samp8++ = 0;
+        }
+        break;
       case SND_PCM_FORMAT_S32_LE:
         if (chn==channel) {
           res = generate_pink_noise_sample(&pink) * generator_scale * 0x07fffffff;
@@ -482,6 +509,17 @@  static void generate_pattern(uint8_t *frames, int channel, int count, int *_patt
 	  *samp_f++ = 0.0;
         }
         break;
+      case SND_PCM_FORMAT_S24_3LE:
+        if (chn==channel) {
+          *samp8++ = LE_INT(pattern);
+          *samp8++ = LE_INT(pattern) >> 8;
+          *samp8++ = LE_INT(pattern) >> 16;
+        } else {
+          *samp8++ = 0;
+          *samp8++ = 0;
+          *samp8++ = 0;
+        }
+        break;
       case SND_PCM_FORMAT_S32_LE:
         if (chn==channel) {
           *samp32++ = LE_INT(pattern);