]> sigrok.org Git - libsigrok.git/blobdiff - src/output/wav.c
Introduce standard implementation of the dev_list() callback
[libsigrok.git] / src / output / wav.c
index 507e0e77b53700ad2e9ac71cac01b3730a008e34..f991cbfdc68526d9fea8754ad200565b712076a9 100644 (file)
@@ -36,6 +36,7 @@ struct out_context {
        int chanbuf_size;
        int *chanbuf_used;
        uint8_t **chanbuf;
+       float *fdata;
 };
 
 static int realloc_chanbufs(const struct sr_output *o, int size)
@@ -281,7 +282,9 @@ static int receive(const struct sr_output *o, const struct sr_datafeed_packet *p
                        num_samples = analog->num_samples;
                        channels = analog->meaning->channels;
                        num_channels = g_slist_length(analog->meaning->channels);
-                       data = g_malloc(sizeof(float) * num_samples * num_channels);
+                       if (!(data = g_try_realloc(outc->fdata, sizeof(float) * num_samples * num_channels)))
+                               return SR_ERR_MALLOC;
+                       outc->fdata = data;
                        ret = sr_analog_to_float(analog, data);
                        if (ret != SR_OK)
                                return ret;
@@ -312,7 +315,7 @@ static int receive(const struct sr_output *o, const struct sr_datafeed_packet *p
                        for (j = 0; j < num_channels; j++) {
                                idx = chan_idx[j];
                                buf = outc->chanbuf[idx] + outc->chanbuf_used[idx]++ * 4;
-                               f = analog_old->data[i * num_channels + j];
+                               f = data[i * num_channels + j];
                                if (outc->scale != 0.0)
                                        f /= outc->scale;
                                float_to_le(buf, f);
@@ -338,6 +341,19 @@ static int receive(const struct sr_output *o, const struct sr_datafeed_packet *p
        return SR_OK;
 }
 
+static struct sr_option options[] = {
+       { "scale", "Scale", "Scale values by factor", NULL, NULL },
+       ALL_ZERO
+};
+
+static const struct sr_option *get_options(void)
+{
+       if (!options[0].def)
+               options[0].def = g_variant_ref_sink(g_variant_new_double(0.0));
+
+       return options;
+}
+
 static int cleanup(struct sr_output *o)
 {
        struct out_context *outc;
@@ -345,29 +361,18 @@ static int cleanup(struct sr_output *o)
 
        outc = o->priv;
        g_slist_free(outc->channels);
+       g_variant_unref(options[0].def);
        for (i = 0; i < outc->num_channels; i++)
                g_free(outc->chanbuf[i]);
        g_free(outc->chanbuf_used);
        g_free(outc->chanbuf);
+       g_free(outc->fdata);
        g_free(outc);
        o->priv = NULL;
 
        return SR_OK;
 }
 
-static struct sr_option options[] = {
-       { "scale", "Scale", "Scale values by factor", NULL, NULL },
-       ALL_ZERO
-};
-
-static const struct sr_option *get_options(void)
-{
-       if (!options[0].def)
-               options[0].def = g_variant_ref_sink(g_variant_new_double(0.0));
-
-       return options;
-}
-
 SR_PRIV struct sr_output_module output_wav = {
        .id = "wav",
        .name = "WAV",