]> sigrok.org Git - pulseview.git/commitdiff
Implement single sample value getters
authorSoeren Apel <redacted>
Sun, 16 Aug 2020 19:09:11 +0000 (21:09 +0200)
committerSoeren Apel <redacted>
Sat, 22 Aug 2020 22:16:19 +0000 (00:16 +0200)
pv/data/analogsegment.cpp
pv/data/analogsegment.hpp
pv/data/segment.cpp
pv/data/segment.hpp
pv/data/signalbase.cpp

index e6f9626c8c07bdaf0cd0382c674ac50b4771e2b2..579013097a713d3792da81aea0bebf09d45fb95e 100644 (file)
@@ -96,6 +96,16 @@ void AnalogSegment::append_interleaved_samples(const float *data,
                        prev_sample_count + 1, prev_sample_count + 1);
 }
 
+float AnalogSegment::get_sample(int64_t sample_num) const
+{
+       assert(sample_num >= 0);
+       assert(sample_num <= (int64_t)sample_count_);
+
+       lock_guard<recursive_mutex> lock(mutex_);  // Because of free_unused_memory()
+
+       return *((const float*)get_raw_sample(sample_num));
+}
+
 void AnalogSegment::get_samples(int64_t start_sample, int64_t end_sample,
        float* dest) const
 {
index 846837ce75f47c2df2afedeaae64f9159d3bd53b..633170439b8b0b0cc40372b1c538e4ec38b7501e 100644 (file)
@@ -81,6 +81,7 @@ public:
        void append_interleaved_samples(const float *data,
                size_t sample_count, size_t stride);
 
+       float get_sample(int64_t sample_num) const;
        void get_samples(int64_t start_sample, int64_t end_sample, float* dest) const;
 
        const pair<float, float> get_min_max() const;
index 2bac00621a0eb2de8dfd15c65f1cdfa5b9f22e4c..1dfdefd46704d030a2b950cfc9d0c2a219968d13 100644 (file)
@@ -211,6 +211,20 @@ void Segment::append_samples(void* data, uint64_t samples)
        sample_count_ += samples;
 }
 
+const uint8_t* Segment::get_raw_sample(uint64_t sample_num) const
+{
+       assert(sample_num <= sample_count_);
+
+       uint64_t chunk_num = (sample_num * unit_size_) / chunk_size_;
+       uint64_t chunk_offs = (sample_num * unit_size_) % chunk_size_;
+
+       lock_guard<recursive_mutex> lock(mutex_);  // Because of free_unused_memory()
+
+       const uint8_t* chunk = data_chunks_[chunk_num];
+
+       return chunk + chunk_offs;
+}
+
 void Segment::get_raw_samples(uint64_t start, uint64_t count,
        uint8_t* dest) const
 {
@@ -219,13 +233,13 @@ void Segment::get_raw_samples(uint64_t start, uint64_t count,
        assert(count > 0);
        assert(dest != nullptr);
 
-       lock_guard<recursive_mutex> lock(mutex_);
-
        uint8_t* dest_ptr = dest;
 
        uint64_t chunk_num = (start * unit_size_) / chunk_size_;
        uint64_t chunk_offs = (start * unit_size_) % chunk_size_;
 
+       lock_guard<recursive_mutex> lock(mutex_);  // Because of free_unused_memory()
+
        while (count > 0) {
                const uint8_t* chunk = data_chunks_[chunk_num];
 
index 8465949c3a13e444846b9596e2aa413592092f5c..9bdc17dd6f1c54fa854fd823eb12685e40763c7e 100644 (file)
 
 #include <mutex>
 #include <thread>
-#include <vector>
+#include <deque>
 
 #include <QObject>
 
 using std::recursive_mutex;
-using std::vector;
+using std::deque;
 
 namespace SegmentTest {
 struct SmallSize8Single;
@@ -84,6 +84,7 @@ public:
 protected:
        void append_single_sample(void *data);
        void append_samples(void *data, uint64_t samples);
+       const uint8_t* get_raw_sample(uint64_t sample_num) const;
        void get_raw_samples(uint64_t start, uint64_t count, uint8_t *dest) const;
 
        SegmentDataIterator* begin_sample_iteration(uint64_t start);
@@ -94,7 +95,7 @@ protected:
 
        uint32_t segment_id_;
        mutable recursive_mutex mutex_;
-       vector<uint8_t*> data_chunks_;
+       deque<uint8_t*> data_chunks_;
        uint8_t* current_chunk_;
        uint64_t used_samples_, unused_samples_;
        uint64_t sample_count_;
index 7d420ac7017902e8cffa80aee9be976f1fa75e67..fb68724401c4f979acb79d66191192653a8d0a72 100644 (file)
@@ -574,7 +574,9 @@ void SignalBase::convert_single_segment_range(AnalogSegment *asegment,
 
                // Create sigrok::Analog instance
                float *asamples = new float[ConversionBlockSize];
+               assert(asamples);
                uint8_t *lsamples = new uint8_t[ConversionBlockSize];
+               assert(lsamples);
 
                vector<shared_ptr<sigrok::Channel> > channels;
                if (channel_)