X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Foutput%2Fwav.c;h=f991cbfdc68526d9fea8754ad200565b712076a9;hb=4b1a9d5d8641080bf10e269aa12a3fc17460365f;hp=cd0694ab8b2f0c722d655870c58f42f8d78b334d;hpb=b73cac758e32a28c56b9f021405b04838face3e3;p=libsigrok.git diff --git a/src/output/wav.c b/src/output/wav.c index cd0694ab..f991cbfd 100644 --- a/src/output/wav.c +++ b/src/output/wav.c @@ -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) @@ -236,8 +237,8 @@ static int receive(const struct sr_output *o, const struct sr_datafeed_packet *p { struct out_context *outc; const struct sr_datafeed_meta *meta; + const struct sr_datafeed_analog_old *analog_old; const struct sr_datafeed_analog *analog; - const struct sr_datafeed_analog2 *analog2; const struct sr_config *src; struct sr_channel *ch; GSList *l; @@ -261,28 +262,30 @@ static int receive(const struct sr_output *o, const struct sr_datafeed_packet *p outc->samplerate = g_variant_get_uint64(src->data); } break; + case SR_DF_ANALOG_OLD: case SR_DF_ANALOG: - case SR_DF_ANALOG2: if (!outc->header_done) { *out = gen_header(o); outc->header_done = TRUE; } else *out = g_string_sized_new(512); + analog_old = packet->payload; analog = packet->payload; - analog2 = packet->payload; - if (packet->type == SR_DF_ANALOG) { - num_samples = analog->num_samples; - channels = analog->channels; - num_channels = g_slist_length(analog->channels); - data = analog->data; + if (packet->type == SR_DF_ANALOG_OLD) { + num_samples = analog_old->num_samples; + channels = analog_old->channels; + num_channels = g_slist_length(analog_old->channels); + data = analog_old->data; } else { - num_samples = analog2->num_samples; - channels = analog2->meaning->channels; - num_channels = g_slist_length(analog2->meaning->channels); - data = g_malloc(sizeof(float) * num_samples * num_channels); - ret = sr_analog_to_float(analog2, data); + num_samples = analog->num_samples; + channels = analog->meaning->channels; + num_channels = g_slist_length(analog->meaning->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; } @@ -297,7 +300,7 @@ static int receive(const struct sr_output *o, const struct sr_datafeed_packet *p } if (num_samples > outc->chanbuf_size) { - if (realloc_chanbufs(o, analog->num_samples) != SR_OK) + if (realloc_chanbufs(o, analog_old->num_samples) != SR_OK) return SR_ERR_MALLOC; } @@ -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->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",