From: Soeren Apel Date: Mon, 13 Feb 2017 23:07:55 +0000 (+0100) Subject: AnalogSegment: Calculate min/max also for small sample sizes X-Git-Tag: pulseview-0.4.0~189 X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=commitdiff_plain;h=67b0df270f20c47f58bbc13b93f780d619c7d780 AnalogSegment: Calculate min/max also for small sample sizes --- diff --git a/pv/data/analogsegment.cpp b/pv/data/analogsegment.cpp index cfc0f2bb..38db0f12 100644 --- a/pv/data/analogsegment.cpp +++ b/pv/data/analogsegment.cpp @@ -167,6 +167,18 @@ void AnalogSegment::append_payload_to_envelope_levels() prev_length = e0.length; e0.length = sample_count_ / EnvelopeScaleFactor; + // Calculate min/max values in case we have too few samples for an envelope + if (sample_count_ < EnvelopeScaleFactor) { + it = begin_raw_sample_iteration(0); + for (uint64_t i = 0; i < sample_count_; i++) { + const float sample = *((float*)it->value); + if (sample < min_value_) min_value_ = sample; + if (sample > max_value_) max_value_ = sample; + continue_raw_sample_iteration(it, 1); + } + end_raw_sample_iteration(it); + } + // Break off if there are no new samples to compute if (e0.length == prev_length) return;