X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Foutput%2Fwav.c;h=e9c7d6fd1a70bee549121c7ac1872619532e377d;hb=515ab0889ebde4b373d620044a1a98da37153056;hp=8aa787bd3f14e36f67fc7a58e870b20c98762fc2;hpb=364859ac732fadddada2d1622dfec7f2ba2fef76;p=libsigrok.git diff --git a/src/output/wav.c b/src/output/wav.c index 8aa787bd..e9c7d6fd 100644 --- a/src/output/wav.c +++ b/src/output/wav.c @@ -27,6 +27,7 @@ #define MIN_DATA_CHUNK_SAMPLES 10 struct out_context { + double scale; gboolean header_done; uint64_t samplerate; int num_channels; @@ -91,10 +92,9 @@ static int init(struct sr_output *o, GHashTable *options) struct sr_channel *ch; GSList *l; - (void)options; - outc = g_malloc0(sizeof(struct out_context)); o->priv = outc; + outc->scale = g_variant_get_double(g_hash_table_lookup(options, "scale")); for (l = o->sdi->channels; l; l = l->next) { ch = l->data; @@ -229,6 +229,7 @@ static int check_chanbuf_size(const struct sr_output *o) return size; } + static int receive(const struct sr_output *o, const struct sr_datafeed_packet *packet, GString **out) { @@ -238,6 +239,7 @@ static int receive(const struct sr_output *o, const struct sr_datafeed_packet *p const struct sr_config *src; struct sr_channel *ch; GSList *l; + float f; int num_channels, size, *chan_idx, idx, i, j; uint8_t *buf; @@ -289,7 +291,10 @@ 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; - float_to_le(buf, analog->data[i * num_channels + j]); + f = analog->data[i * num_channels + j]; + if (outc->scale != 0.0) + f /= outc->scale; + float_to_le(buf, f); } } g_free(chan_idx); @@ -329,12 +334,26 @@ static int cleanup(struct sr_output *o) 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", - .desc = "WAVE file format", + .desc = "Microsoft WAV file format", + .exts = (const char*[]){"wav", NULL}, + .options = get_options, .init = init, .receive = receive, .cleanup = cleanup, }; -