X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Foutput%2Fwav.c;h=6984c03d29b5185c61c41cc34325772d964249c2;hb=176d785d33a28a1bb24f2ee483595ec54f7b52b6;hp=14ef36df185c3b862529be98767dedb214943cd5;hpb=da3d141f04e9a17bd41c5adfb5c83369fe3759df;p=libsigrok.git diff --git a/src/output/wav.c b/src/output/wav.c index 14ef36df..6984c03d 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) @@ -45,7 +46,7 @@ static int realloc_chanbufs(const struct sr_output *o, int size) outc = o->priv; for (i = 0; i < outc->num_channels; i++) { - if (!(outc->chanbuf[i] = g_try_realloc(outc->chanbuf[i], sizeof(float) * size))) { + if (!(outc->chanbuf[i] = g_try_realloc(outc->chanbuf[i], sizeof(float) * size))) { sr_err("Unable to allocate enough output buffer memory."); return SR_ERR; } @@ -236,7 +237,6 @@ 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_config *src; struct sr_channel *ch; @@ -261,7 +261,6 @@ 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: if (!outc->header_done) { *out = gen_header(o); @@ -269,23 +268,16 @@ static int receive(const struct sr_output *o, const struct sr_datafeed_packet *p } else *out = g_string_sized_new(512); - analog_old = packet->payload; analog = packet->payload; - - 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 = analog->num_samples; - channels = analog->meaning->channels; - num_channels = g_slist_length(analog->meaning->channels); - data = g_malloc(sizeof(float) * num_samples * num_channels); - ret = sr_analog_to_float(analog, data); - if (ret != SR_OK) - return ret; - } + 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; if (num_samples == 0) return SR_OK; @@ -297,7 +289,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_old->num_samples) != SR_OK) + if (realloc_chanbufs(o, analog->num_samples) != SR_OK) return SR_ERR_MALLOC; } @@ -312,7 +304,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); @@ -363,6 +355,7 @@ static int cleanup(struct sr_output *o) g_free(outc->chanbuf[i]); g_free(outc->chanbuf_used); g_free(outc->chanbuf); + g_free(outc->fdata); g_free(outc); o->priv = NULL;