]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
Merge topic branch t/sf_float into pu pu
authorAndre Noll <maan@tuebingen.mpg.de>
Fri, 19 Apr 2024 18:45:36 +0000 (20:45 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Fri, 19 Apr 2024 18:45:36 +0000 (20:45 +0200)
A single patch which adds two new sample formats for 32 bit IEEE
float waveform data.

<!--

- The alsa writer also supports 32 bit float sample formats.

-->

* refs/heads/t/sf_float:
  New audio formats: 32 bit float (little and big endian).

alsa_write.c
ao_write.c
check_wav.c
m4/lls/include/sample-format.m4
para.h

index 53d7b1b454932c36b3e578d794d688cee6cf7270..7e71d4aef70396c4ee7599d9ca890f7ec9cc04d5 100644 (file)
@@ -61,6 +61,8 @@ static snd_pcm_format_t get_alsa_pcm_format(enum sample_format sf)
        case SF_S16_BE: return SND_PCM_FORMAT_S16_BE;
        case SF_U16_LE: return SND_PCM_FORMAT_U16_LE;
        case SF_U16_BE: return SND_PCM_FORMAT_U16_BE;
+       case SF_FLOAT_LE: return SND_PCM_FORMAT_FLOAT_LE;
+       case SF_FLOAT_BE: return SND_PCM_FORMAT_FLOAT_BE;
        default: return SND_PCM_FORMAT_S16_LE;
        }
 }
index 43a58dd6d5a364f2370659608302e6c7d9f24324..cc1a4f0facd58e738976600a653266a6066556f8 100644 (file)
@@ -87,6 +87,8 @@ static int aow_set_sample_format(unsigned sample_rate, unsigned channels,
                case SF_U8:
                case SF_U16_LE:
                case SF_U16_BE:
+               case SF_FLOAT_LE:
+               case SF_FLOAT_BE:
                        return -E_BAD_SAMPLE_FORMAT;
                case SF_S8:
                        /* no need to set byte_format */
index cb39eb540dafae31733623625bf31474c463a243..48a204bb598c1f9ebc873b10d64704eb256cc2de 100644 (file)
@@ -127,7 +127,7 @@ int check_wav_post_monitor(struct check_wav_context *cwc)
        unsigned char *a;
        size_t sz;
        int ret;
-       uint16_t bps; /* bits per sample */
+       uint16_t format_code, bps; /* bits per sample */
        const char *sample_formats[] = {SAMPLE_FORMATS};
 
        if (!btrn)
@@ -157,13 +157,24 @@ int check_wav_post_monitor(struct check_wav_context *cwc)
        cwc->state = CWS_HAVE_HEADER;
        /* Only set those values which have not already been set. */
        cwc->channels = a[22];
+       format_code = read_u16(a + 20);
+       if (format_code != 1 && format_code != 3) {
+               cwc->state = CWS_NO_HEADER;
+               goto out;
+       }
        cwc->sample_rate = read_u32(a + 24);
        bps = read_u16(a + 34);
-       if (bps != 8 && bps != 16) {
+       if (bps != 8 && bps != 16 && bps != 32) {
                PARA_WARNING_LOG("%u bps not supported, assuming 16\n",
                        bps);
                bps = 16;
        }
+       if ((bps < 32 && format_code != 1) || (bps == 32 && format_code != 3)) {
+               PARA_WARNING_LOG("invalid bps/format_code (%u/%u)\n",
+                       bps, format_code);
+               cwc->state = CWS_NO_HEADER;
+               goto out;
+       }
        /*
         * 8-bit samples are stored as unsigned bytes, ranging from 0
         * to 255.  16-bit samples are stored as 2's-complement signed
@@ -171,9 +182,12 @@ int check_wav_post_monitor(struct check_wav_context *cwc)
         */
        if (bps == 8)
                cwc->sample_format = SF_U8;
-       else
+       else if (bps == 16)
                cwc->sample_format = (a[3] == 'F')?
                        SF_S16_LE : SF_S16_BE;
+       else /* 32 bit */
+               cwc->sample_format = (a[3] == 'F')?
+                       SF_FLOAT_LE : SF_FLOAT_BE;
        PARA_NOTICE_LOG("%uHz, %s, %s\n", cwc->sample_rate,
                cwc->channels == 1? "mono" : "stereo",
                sample_formats[cwc->sample_format]);
index 0daad1929116c99f0a0502bf3dcc5815dad96ddf..030ab7d5d3ed85c394072ebd6c02774ce988c087 100644 (file)
@@ -11,7 +11,9 @@
                SAMPLE_FORMAT_S16_LE = "S16_LE",
                SAMPLE_FORMAT_S16_BE = "S16_BE",
                SAMPLE_FORMAT_U16_LE = "U16_LE",
-               SAMPLE_FORMAT_U16_BE = "U16_BE"
+               SAMPLE_FORMAT_U16_BE = "U16_BE",
+               SAMPLE_FORMAT_FLOAT_LE = "FLOAT_LE",
+               SAMPLE_FORMAT_FLOAT_BE = "FLOAT_BE"
        }
        default_val = S16_LE
        [help]
diff --git a/para.h b/para.h
index 280c282323db369e7d0e84173324016aa425a92d..6f1565aaaf65a6df871a4a9951d55a9c17653274 100644 (file)
--- a/para.h
+++ b/para.h
@@ -203,6 +203,8 @@ _static_inline_ bool iov_valid(const struct iovec *iov)
        SAMPLE_FORMAT(SF_S16_BE, "16 bit signed, big endian"), \
        SAMPLE_FORMAT(SF_U16_LE, "16 bit unsigned, little endian"), \
        SAMPLE_FORMAT(SF_U16_BE, "16 bit unsigned, big endian"), \
+       SAMPLE_FORMAT(SF_FLOAT_LE, "32 bit float, little endian"), \
+       SAMPLE_FORMAT(SF_FLOAT_BE, "32 bit float, big endian"), \
 
 /** \cond sample_format */
 #define SAMPLE_FORMAT(a, b) a