From: Joel Holdsworth Date: Sat, 16 Mar 2013 15:03:48 +0000 (+0000) Subject: Implemented AnalogSnapshot::get_envelope_section X-Git-Tag: pulseview-0.1.0~73 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=9320072da54c5f1614779512d8c8d3bac6743419;p=pulseview.git Implemented AnalogSnapshot::get_envelope_section --- diff --git a/pv/data/analogsnapshot.cpp b/pv/data/analogsnapshot.cpp index c052782e..bec65065 100644 --- a/pv/data/analogsnapshot.cpp +++ b/pv/data/analogsnapshot.cpp @@ -85,6 +85,30 @@ const float* AnalogSnapshot::get_samples( return data; } +void AnalogSnapshot::get_envelope_section(EnvelopeSection &s, + uint64_t start, uint64_t end, float min_length) const +{ + assert(end <= get_sample_count()); + assert(start <= end); + assert(min_length > 0); + + lock_guard lock(_mutex); + + const unsigned int min_level = max((int)floorf(logf(min_length) / + LogEnvelopeScaleFactor) - 1, 0); + const unsigned int scale_power = (min_level + 1) * + EnvelopeScalePower; + start >>= scale_power; + end >>= scale_power; + + s.start = start << scale_power; + s.scale = 1 << scale_power; + s.length = end - start; + s.samples = new EnvelopeSample[s.length]; + memcpy(s.samples, _envelope_levels[min_level].samples + start, + s.length * sizeof(EnvelopeSample)); +} + void AnalogSnapshot::reallocate_envelope(Envelope &e) { const uint64_t new_data_length = ((e.length + EnvelopeDataUnit - 1) / diff --git a/pv/data/analogsnapshot.h b/pv/data/analogsnapshot.h index 59c43187..74d26763 100644 --- a/pv/data/analogsnapshot.h +++ b/pv/data/analogsnapshot.h @@ -35,13 +35,22 @@ namespace data { class AnalogSnapshot : public Snapshot { -private: +public: struct EnvelopeSample { float min; float max; }; + struct EnvelopeSection + { + uint64_t start; + unsigned int scale; + uint64_t length; + EnvelopeSample *samples; + }; + +private: struct Envelope { uint64_t length; @@ -66,6 +75,9 @@ public: const float* get_samples(int64_t start_sample, int64_t end_sample) const; + void get_envelope_section(EnvelopeSection &s, + uint64_t start, uint64_t end, float min_length) const; + private: void reallocate_envelope(Envelope &l);