X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=pv%2Fdata%2Fanalogsegment.cpp;h=b3f310a144c5cd7ce2e18fb83ed242bd10526b6c;hb=c70e34649be658e7a443d5e68abe16dd55d53bf2;hp=cfc0f2bb60a9498d9561f10c27b5e22ae84ee896;hpb=7db61e770abd2d1c7eb326a09e35cd4266664c1d;p=pulseview.git diff --git a/pv/data/analogsegment.cpp b/pv/data/analogsegment.cpp index cfc0f2b..b3f310a 100644 --- a/pv/data/analogsegment.cpp +++ b/pv/data/analogsegment.cpp @@ -106,17 +106,17 @@ const std::pair AnalogSegment::get_min_max() const return std::make_pair(min_value_, max_value_); } -SegmentAnalogDataIterator* AnalogSegment::begin_sample_iteration(uint64_t start) const +SegmentAnalogDataIterator* AnalogSegment::begin_sample_iteration(uint64_t start) { return (SegmentAnalogDataIterator*)begin_raw_sample_iteration(start); } -void AnalogSegment::continue_sample_iteration(SegmentAnalogDataIterator* it, uint64_t increase) const +void AnalogSegment::continue_sample_iteration(SegmentAnalogDataIterator* it, uint64_t increase) { Segment::continue_raw_sample_iteration((SegmentRawDataIterator*)it, increase); } -void AnalogSegment::end_sample_iteration(SegmentAnalogDataIterator* it) const +void AnalogSegment::end_sample_iteration(SegmentAnalogDataIterator* it) { Segment::end_raw_sample_iteration((SegmentRawDataIterator*)it); } @@ -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;