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);
}
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;