30 #include <libsigrokcxx/libsigrokcxx.hpp>
32 using std::lock_guard;
33 using std::recursive_mutex;
37 using std::shared_ptr;
50 const uint64_t expected_num_samples) :
51 Segment(samplerate, logic->unit_size()),
52 last_append_sample_(0)
56 lock_guard<recursive_mutex> lock(
mutex_);
63 lock_guard<recursive_mutex> lock(
mutex_);
70 #ifdef HAVE_UNALIGNED_LITTLE_ENDIAN_ACCESS
71 return *(uint64_t*)ptr;
76 value |= ((uint64_t)ptr[7]) << 56;
79 value |= ((uint64_t)ptr[6]) << 48;
82 value |= ((uint64_t)ptr[5]) << 40;
85 value |= ((uint64_t)ptr[4]) << 32;
88 value |= ((uint32_t)ptr[3]) << 24;
91 value |= ((uint32_t)ptr[2]) << 16;
108 #ifdef HAVE_UNALIGNED_LITTLE_ENDIAN_ACCESS
109 *(uint64_t*)ptr = value;
113 ptr[7] = value >> 56;
116 ptr[6] = value >> 48;
119 ptr[5] = value >> 40;
122 ptr[4] = value >> 32;
125 ptr[3] = value >> 24;
128 ptr[2] = value >> 16;
145 assert((logic->data_length() %
unit_size_) == 0);
147 lock_guard<recursive_mutex> lock(
mutex_);
157 int64_t start_sample, int64_t end_sample)
const
160 assert(start_sample >= 0);
162 assert(end_sample >= 0);
163 assert(end_sample <= (int64_t)sample_count_);
164 assert(start_sample <= end_sample);
166 lock_guard<recursive_mutex> lock(
mutex_);
168 const size_t size = (end_sample - start_sample) *
unit_size_;
169 memcpy(data, (
const uint8_t*)
data_.data() + start_sample *
unit_size_, size);
188 uint64_t prev_length;
189 const uint8_t *src_ptr;
191 uint64_t accumulator;
192 unsigned int diff_counter;
199 if (m0.
length == prev_length)
207 const uint8_t *
const end_src_ptr = (uint8_t*)
data_.data() +
209 for (src_ptr = (uint8_t*)
data_.data() +
211 src_ptr < end_src_ptr;) {
215 while (diff_counter-- > 0) {
236 if (m.
length == prev_length)
242 src_ptr = (uint8_t*)ml.
data +
244 const uint8_t *
const end_dest_ptr =
246 for (dest_ptr = (uint8_t*)m.
data +
248 dest_ptr < end_dest_ptr;
252 while (diff_counter-- > 0) {
270 std::vector<EdgePair> &edges,
271 uint64_t start, uint64_t end,
272 float min_length,
int sig_index)
274 uint64_t index = start;
280 assert(start <= end);
281 assert(min_length > 0);
282 assert(sig_index >= 0);
283 assert(sig_index < 64);
285 lock_guard<recursive_mutex> lock(
mutex_);
287 const uint64_t block_length = (uint64_t)max(min_length, 1.0f);
288 const unsigned int min_level = max((
int)floorf(logf(min_length) /
290 const uint64_t sig_mask = 1ULL << sig_index;
293 last_sample = (
get_sample(start) & sig_mask) != 0;
294 edges.push_back(pair<int64_t, bool>(index++, last_sample));
296 while (index + block_length <= end) {
307 const uint64_t final_index = min(end,
310 for (; index < final_index &&
317 if (sample != last_sample) {
318 fast_forward =
false;
326 const int min_level_scale_power =
328 index =
pow2_ceil(index, min_level_scale_power);
335 if (last_sample != sample)
336 fast_forward =
false;
349 const int level_scale_power =
351 const uint64_t offset =
352 index >> level_scale_power;
356 if (offset >=
mip_map_[level].length ||
383 const int level_scale_power =
385 const uint64_t offset =
386 index >> level_scale_power;
390 if (offset >=
mip_map_[level].length ||
395 if (level == min_level)
411 for (; index < end; index++) {
414 if (sample != last_sample)
423 const int64_t final_index = index + block_length;
424 if (index + block_length > end)
428 const bool final_sample =
429 (
get_sample(final_index - 1) & sig_mask) != 0;
430 edges.push_back(pair<int64_t, bool>(index, final_sample));
433 last_sample = final_sample;
437 const bool end_sample =
get_sample(end) & sig_mask;
438 if (last_sample != end_sample)
439 edges.push_back(pair<int64_t, bool>(end, end_sample));
440 edges.push_back(pair<int64_t, bool>(end + 1, end_sample));
453 const uint64_t p = 1 << power;
454 return (x + p - 1) / p * p;
void reallocate_mipmap_level(MipMapLevel &m)
uint64_t get_sample(uint64_t index) const
static const float LogMipMapScaleFactor
static const uint64_t MipMapDataUnit
static const int MipMapScalePower
void set_capacity(uint64_t new_capacity)
Increase the capacity of the segment.
std::vector< uint8_t > data_
void get_subsampled_edges(std::vector< EdgePair > &edges, uint64_t start, uint64_t end, float min_length, int sig_index)
void append_data(void *data, uint64_t samples)
uint64_t get_subsample(int level, uint64_t offset) const
LogicSegment(std::shared_ptr< sigrok::Logic > logic, uint64_t samplerate, uint64_t expected_num_samples=0)
uint64_t get_sample_count() const
static const int MipMapScaleFactor
void append_payload_to_mipmap()
static uint64_t pow2_ceil(uint64_t x, unsigned int power)
struct MipMapLevel mip_map_[ScaleStepCount]
std::recursive_mutex mutex_
void get_samples(uint8_t *const data, int64_t start_sample, int64_t end_sample) const
void pack_sample(uint8_t *ptr, uint64_t value)
uint64_t last_append_sample_
static const unsigned int ScaleStepCount
void append_payload(std::shared_ptr< sigrok::Logic > logic)
uint64_t unpack_sample(const uint8_t *ptr) const