]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - check_wav.c
Merge topic branch t/sf_float into pu
[paraslash.git] / check_wav.c
index 074ad8fe74fbfe4b383a98d2d69ecf48c175f443..48a204bb598c1f9ebc873b10d64704eb256cc2de 100644 (file)
@@ -47,14 +47,14 @@ struct check_wav_context {
  * If no data is available and the buffer tree node is not in error state, the
  * function does nothing.
  */
-void check_wav_pre_select(struct sched *s, struct check_wav_context *cwc)
+void check_wav_pre_monitor(struct sched *s, struct check_wav_context *cwc)
 {
        int ret = btr_node_status(cwc->btrn, cwc->min_iqs, BTR_NT_INTERNAL);
        if (ret != 0)
                sched_min_delay(s);
 }
 
-static int check_wav_exec(struct btr_node *btrn, const char *cmd, char **result)
+static int check_wav_exec(const struct btr_node *btrn, const char *cmd, char **result)
 {
        struct check_wav_context *cwc = btr_context(btrn);
        int val, header_val, given, arg;
@@ -121,13 +121,13 @@ out:
  *
  * \return Standard.
  */
-int check_wav_post_select(struct check_wav_context *cwc)
+int check_wav_post_monitor(struct check_wav_context *cwc)
 {
        struct btr_node *btrn = cwc->btrn;
        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_select(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_select(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]);
@@ -198,8 +212,8 @@ out:
  * children of this node can figure out channel count, sample rate, etc.
  *
  * \return The (opaque) handle of the newly created check_wav instance. It is
- * supposed to be passed to \ref check_wav_pre_select() and \ref
- * check_wav_post_select().
+ * supposed to be passed to \ref check_wav_pre_monitor() and \ref
+ * check_wav_post_monitor().
  *
  * \sa \ref btr_new_node.
  */
@@ -207,7 +221,7 @@ struct check_wav_context *check_wav_init(struct btr_node *parent,
                struct btr_node *child, struct wav_params *params,
                struct btr_node **cw_btrn)
 {
-       struct check_wav_context *cwc = para_calloc(sizeof(*cwc));
+       struct check_wav_context *cwc = zalloc(sizeof(*cwc));
 
        cwc->state = CWS_NEED_HEADER;
        cwc->min_iqs = WAV_HEADER_LEN;
@@ -225,7 +239,7 @@ struct check_wav_context *check_wav_init(struct btr_node *parent,
  *
  * \param cwc Determines the instance to shut down.
  *
- * This function may only be called after check_wav_post_select() has returned
+ * This function may only be called after check_wav_post_monitor() has returned
  * negative.
  */
 void check_wav_shutdown(struct check_wav_context *cwc)