append_data(analog.data, analog.num_samples);
}
-const float* AnalogSnapshot::get_samples() const
+const float* AnalogSnapshot::get_samples(
+ int64_t start_sample, int64_t end_sample) const
{
- return (const float*)_data;
+ assert(start_sample >= 0);
+ assert(start_sample < (int64_t)_sample_count);
+ assert(end_sample >= 0);
+ assert(end_sample < (int64_t)_sample_count);
+ assert(start_sample <= end_sample);
+
+ lock_guard<recursive_mutex> lock(_mutex);
+
+ float *const data = new float[end_sample - start_sample];
+ memcpy(data, (float*)_data + start_sample, sizeof(float) *
+ (end_sample - start_sample));
+ return data;
}
} // namespace data
void append_payload(const sr_datafeed_analog &analog);
- const float* get_samples() const;
+ const float* get_samples(int64_t start_sample,
+ int64_t end_sample) const;
};
} // namespace data
(int64_t)0), last_sample);
const int64_t end_sample = min(max((int64_t)ceil(end),
(int64_t)0), last_sample);
+ const int64_t sample_count = end_sample - start_sample;
- const float* samples = snapshot->get_samples();
+ const float* samples = snapshot->get_samples(
+ start_sample, end_sample);
assert(samples);
- QPointF *points = new QPointF[end_sample - start_sample];
+ QPointF *points = new QPointF[sample_count];
QPointF *point = points;
for (int64_t sample = start_sample;
sample != end_sample; sample++) {
const float x = (sample / samples_per_pixel -
pixels_offset) + left;
- *point++ = QPointF(x, samples[sample] + y);
+ *point++ = QPointF(x,
+ samples[sample - start_sample] + y);
}
p.setPen(_colour);