projects
/
pulseview.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Implement A2L presets and custom threshold handling
[pulseview.git]
/
pv
/
data
/
analogsegment.cpp
diff --git
a/pv/data/analogsegment.cpp
b/pv/data/analogsegment.cpp
index 6719340c5e9e06eb58698de193c3dfd7927d238c..6dc2b915b30c4683f766bf97da4f662c44a9c07d 100644
(file)
--- a/
pv/data/analogsegment.cpp
+++ b/
pv/data/analogsegment.cpp
@@
-20,9
+20,10
@@
#include <extdef.h>
#include <cassert>
#include <extdef.h>
#include <cassert>
-#include <cstring>
-#include <cstdlib>
#include <cmath>
#include <cmath>
+#include <cstdlib>
+#include <cstring>
+#include <memory>
#include <algorithm>
#include <algorithm>
@@
-37,15
+38,15
@@
using std::max_element;
using std::min;
using std::min_element;
using std::pair;
using std::min;
using std::min_element;
using std::pair;
+using std::unique_ptr;
namespace pv {
namespace data {
const int AnalogSegment::EnvelopeScalePower = 4;
const int AnalogSegment::EnvelopeScaleFactor = 1 << EnvelopeScalePower;
namespace pv {
namespace data {
const int AnalogSegment::EnvelopeScalePower = 4;
const int AnalogSegment::EnvelopeScaleFactor = 1 << EnvelopeScalePower;
-const float AnalogSegment::LogEnvelopeScaleFactor =
- logf(EnvelopeScaleFactor);
-const uint64_t AnalogSegment::EnvelopeDataUnit = 64*1024; // bytes
+const float AnalogSegment::LogEnvelopeScaleFactor = logf(EnvelopeScaleFactor);
+const uint64_t AnalogSegment::EnvelopeDataUnit = 64 * 1024; // bytes
AnalogSegment::AnalogSegment(Analog& owner, uint64_t samplerate) :
Segment(samplerate, sizeof(float)),
AnalogSegment::AnalogSegment(Analog& owner, uint64_t samplerate) :
Segment(samplerate, sizeof(float)),
@@
-73,11
+74,17
@@
void AnalogSegment::append_interleaved_samples(const float *data,
uint64_t prev_sample_count = sample_count_;
uint64_t prev_sample_count = sample_count_;
- for (uint32_t i=0; i < sample_count; i++) {
- append_single_sample((void*)data);
+ // Deinterleave the samples and add them
+ unique_ptr<float> deint_data(new float[sample_count]);
+ float *deint_data_ptr = deint_data.get();
+ for (uint32_t i = 0; i < sample_count; i++) {
+ *deint_data_ptr = (float)(*data);
+ deint_data_ptr++;
data += stride;
}
data += stride;
}
+ append_samples(deint_data.get(), sample_count);
+
// Generate the first mip-map from the data
append_payload_to_envelope_levels();
// Generate the first mip-map from the data
append_payload_to_envelope_levels();
@@
-89,18
+96,19
@@
void AnalogSegment::append_interleaved_samples(const float *data,
prev_sample_count + 1);
}
prev_sample_count + 1);
}
-const float* AnalogSegment::get_samples(
-
int64_t start_sample, int64_t end_sample
) const
+void AnalogSegment::get_samples(int64_t start_sample, int64_t end_sample,
+
float* dest
) const
{
assert(start_sample >= 0);
assert(start_sample < (int64_t)sample_count_);
assert(end_sample >= 0);
{
assert(start_sample >= 0);
assert(start_sample < (int64_t)sample_count_);
assert(end_sample >= 0);
- assert(end_sample < (int64_t)sample_count_);
+ assert(end_sample <
=
(int64_t)sample_count_);
assert(start_sample <= end_sample);
assert(start_sample <= end_sample);
+ assert(dest != nullptr);
lock_guard<recursive_mutex> lock(mutex_);
lock_guard<recursive_mutex> lock(mutex_);
-
return (float*)get_raw_samples(start_sample, (end_sample - start_sample)
);
+
get_raw_samples(start_sample, (end_sample - start_sample), (uint8_t*)dest
);
}
const pair<float, float> AnalogSegment::get_min_max() const
}
const pair<float, float> AnalogSegment::get_min_max() const
@@
-174,8
+182,10
@@
void AnalogSegment::append_payload_to_envelope_levels()
it = begin_raw_sample_iteration(0);
for (uint64_t i = 0; i < sample_count_; i++) {
const float sample = *((float*)it->value);
it = begin_raw_sample_iteration(0);
for (uint64_t i = 0; i < sample_count_; i++) {
const float sample = *((float*)it->value);
- if (sample < min_value_) min_value_ = sample;
- if (sample > max_value_) max_value_ = sample;
+ if (sample < min_value_)
+ min_value_ = sample;
+ if (sample > max_value_)
+ max_value_ = sample;
continue_raw_sample_iteration(it, 1);
}
end_raw_sample_iteration(it);
continue_raw_sample_iteration(it, 1);
}
end_raw_sample_iteration(it);
@@
-191,7
+201,7
@@
void AnalogSegment::append_payload_to_envelope_levels()
// Iterate through the samples to populate the first level mipmap
uint64_t start_sample = prev_length * EnvelopeScaleFactor;
// Iterate through the samples to populate the first level mipmap
uint64_t start_sample = prev_length * EnvelopeScaleFactor;
- uint64_t end_sample
= e0.length * EnvelopeScaleFactor;
+ uint64_t end_sample = e0.length * EnvelopeScaleFactor;
it = begin_raw_sample_iteration(start_sample);
for (uint64_t i = start_sample; i < end_sample; i += EnvelopeScaleFactor) {
it = begin_raw_sample_iteration(start_sample);
for (uint64_t i = start_sample; i < end_sample; i += EnvelopeScaleFactor) {
@@
-202,8
+212,10
@@
void AnalogSegment::append_payload_to_envelope_levels()
*max_element(samples, samples + EnvelopeScaleFactor),
};
*max_element(samples, samples + EnvelopeScaleFactor),
};
- if (sub_sample.min < min_value_) min_value_ = sub_sample.min;
- if (sub_sample.max > max_value_) max_value_ = sub_sample.max;
+ if (sub_sample.min < min_value_)
+ min_value_ = sub_sample.min;
+ if (sub_sample.max > max_value_)
+ max_value_ = sub_sample.max;
continue_raw_sample_iteration(it, EnvelopeScaleFactor);
*dest_ptr++ = sub_sample;
continue_raw_sample_iteration(it, EnvelopeScaleFactor);
*dest_ptr++ = sub_sample;
@@
-213,7
+225,7
@@
void AnalogSegment::append_payload_to_envelope_levels()
// Compute higher level mipmaps
for (unsigned int level = 1; level < ScaleStepCount; level++) {
Envelope &e = envelope_levels_[level];
// Compute higher level mipmaps
for (unsigned int level = 1; level < ScaleStepCount; level++) {
Envelope &e = envelope_levels_[level];
- const Envelope &el = envelope_levels_[level
-
1];
+ const Envelope &el = envelope_levels_[level
-
1];
// Expand the data buffer to fit the new samples
prev_length = e.length;
// Expand the data buffer to fit the new samples
prev_length = e.length;