]> sigrok.org Git - pulseview.git/commitdiff
Implemented AnalogSnapshot::get_envelope_section
authorJoel Holdsworth <redacted>
Sat, 16 Mar 2013 15:03:48 +0000 (15:03 +0000)
committerJoel Holdsworth <redacted>
Thu, 21 Mar 2013 22:44:19 +0000 (22:44 +0000)
pv/data/analogsnapshot.cpp
pv/data/analogsnapshot.h

index c052782ed6cc6842f5029c80b6de3223ee76d50c..bec65065631aa19239a1f27f18f3b6287521f3a5 100644 (file)
@@ -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<recursive_mutex> 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) /
index 59c43187788e4c231dc85d652f0cb849ed5f7a91..74d26763825167a41c81390c08647ba0a3b03560 100644 (file)
@@ -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);