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
{
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;
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
{
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];
#include <mutex>
#include <thread>
-#include <vector>
+#include <deque>
#include <QObject>
using std::recursive_mutex;
-using std::vector;
+using std::deque;
namespace SegmentTest {
struct SmallSize8Single;
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);
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_;
// 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_)