logf(EnvelopeScaleFactor);
const uint64_t AnalogSnapshot::EnvelopeDataUnit = 64*1024; // bytes
-AnalogSnapshot::AnalogSnapshot(const uint64_t expected_num_samples) :
- Snapshot(sizeof(float))
+AnalogSnapshot::AnalogSnapshot(
+ uint64_t samplerate, const uint64_t expected_num_samples) :
+ Snapshot(samplerate, sizeof(float))
{
set_capacity(expected_num_samples);
static const uint64_t EnvelopeDataUnit;
public:
- AnalogSnapshot(uint64_t expected_num_samples = 0);
+ AnalogSnapshot(uint64_t samplerate, uint64_t expected_num_samples = 0);
virtual ~AnalogSnapshot();
// Get the samplerate and start time
start_time_ = snapshot_->start_time();
- samplerate_ = data->samplerate();
+ samplerate_ = snapshot_->samplerate();
if (samplerate_ == 0.0)
samplerate_ = 1.0;
const float LogicSnapshot::LogMipMapScaleFactor = logf(MipMapScaleFactor);
const uint64_t LogicSnapshot::MipMapDataUnit = 64*1024; // bytes
-LogicSnapshot::LogicSnapshot(shared_ptr<Logic> logic,
+LogicSnapshot::LogicSnapshot(shared_ptr<Logic> logic, uint64_t samplerate,
const uint64_t expected_num_samples) :
- Snapshot(logic->unit_size()),
+ Snapshot(samplerate, logic->unit_size()),
last_append_sample_(0)
{
set_capacity(expected_num_samples);
public:
LogicSnapshot(std::shared_ptr<sigrok::Logic> logic,
- uint64_t expected_num_samples = 0);
+ uint64_t samplerate, uint64_t expected_num_samples = 0);
virtual ~LogicSnapshot();
namespace pv {
namespace data {
-SignalData::SignalData() :
- samplerate_(0)
+SignalData::SignalData()
{
}
-double SignalData::samplerate() const
-{
- return samplerate_;
-}
-
-void SignalData::set_samplerate(double samplerate)
-{
- samplerate_ = samplerate;
- clear();
-}
-
} // namespace data
} // namespace pv
virtual ~SignalData() {}
public:
- double samplerate() const;
- void set_samplerate(double samplerate);
-
virtual std::vector< std::shared_ptr<Snapshot> > snapshots() const = 0;
virtual void clear() = 0;
virtual uint64_t get_max_sample_count() const = 0;
-
-protected:
- double samplerate_;
};
} // namespace data
namespace pv {
namespace data {
-Snapshot::Snapshot(unsigned int unit_size) :
+Snapshot::Snapshot(uint64_t samplerate, unsigned int unit_size) :
sample_count_(0),
start_time_(0),
+ samplerate_(samplerate),
capacity_(0),
unit_size_(unit_size)
{
return start_time_;
}
+double Snapshot::samplerate() const
+{
+ return samplerate_;
+}
+
+void Snapshot::set_samplerate(double samplerate)
+{
+ samplerate_ = samplerate;
+}
+
unsigned int Snapshot::unit_size() const
{
return unit_size_;
class Snapshot
{
public:
- Snapshot(unsigned int unit_size);
+ Snapshot(uint64_t samplerate, unsigned int unit_size);
virtual ~Snapshot();
double start_time() const;
+ double samplerate() const;
+ void set_samplerate(double samplerate);
+
unsigned int unit_size() const;
/**
std::vector<uint8_t> data_;
uint64_t sample_count_;
double start_time_;
+ double samplerate_;
uint64_t capacity_;
unsigned int unit_size_;
};
Session::Session(DeviceManager &device_manager) :
device_manager_(device_manager),
session_(device_manager.context()->create_session()),
- capture_state_(Stopped)
+ capture_state_(Stopped),
+ cur_samplerate_(0)
{
set_default_device();
}
{
const auto keys = device_->config_keys(ConfigKey::DEVICE_OPTIONS);
const auto iter = keys.find(ConfigKey::SAMPLERATE);
- const uint64_t sample_rate = (iter != keys.end() &&
+ cur_samplerate_ = (iter != keys.end() &&
(*iter).second.find(sigrok::GET) != (*iter).second.end()) ?
VariantBase::cast_dynamic<Variant<guint64>>(
device->config_get(ConfigKey::SAMPLERATE)).get() : 0;
-
- // Set the sample rate of all data
- const set< shared_ptr<data::SignalData> > data_set = get_data();
- for (shared_ptr<data::SignalData> data : data_set) {
- assert(data);
- data->set_samplerate(sample_rate);
- }
}
void Session::sample_thread_proc(shared_ptr<Device> device,
// Create a new data snapshot
cur_logic_snapshot_ = shared_ptr<data::LogicSnapshot>(
- new data::LogicSnapshot(logic, sample_limit));
+ new data::LogicSnapshot(
+ logic, cur_samplerate_, sample_limit));
logic_data_->push_snapshot(cur_logic_snapshot_);
// @todo Putting this here means that only listeners querying
// Create a snapshot, keep it in the maps of channels
snapshot = shared_ptr<data::AnalogSnapshot>(
- new data::AnalogSnapshot(sample_limit));
+ new data::AnalogSnapshot(
+ cur_samplerate_, sample_limit));
cur_analog_snapshots_[channel] = snapshot;
// Find the annalog data associated with the channel
mutable std::mutex data_mutex_;
std::shared_ptr<data::Logic> logic_data_;
+ uint64_t cur_samplerate_;
std::shared_ptr<data::LogicSnapshot> cur_logic_snapshot_;
std::map< std::shared_ptr<sigrok::Channel>, std::shared_ptr<data::AnalogSnapshot> >
cur_analog_snapshots_;
{{"filename",
Glib::Variant<Glib::ustring>::create(file_name_)}});
auto meta = context->create_meta_packet(
- {{ConfigKey::SAMPLERATE,
- Glib::Variant<guint64>::create(data->samplerate())}});
+ {{ConfigKey::SAMPLERATE, Glib::Variant<guint64>::create(
+ snapshot->samplerate())}});
output_->receive(meta);
} catch (Error error) {
error_ = tr("Error while saving.");
snapshots.front();
const double pixels_offset = pp.pixels_offset();
- const double samplerate = data_->samplerate();
+ const double samplerate = snapshot->samplerate();
const double start_time = snapshot->start_time();
const int64_t last_sample = snapshot->get_sample_count() - 1;
const double samples_per_pixel = samplerate * pp.scale();
const shared_ptr<pv::data::LogicSnapshot> &snapshot =
snapshots.front();
- double samplerate = data_->samplerate();
+ double samplerate = snapshot->samplerate();
// Show sample rate as 1Hz when it is unknown
if (samplerate == 0.0)
double samplerate = 0.0;
for (const shared_ptr<SignalData> d : visible_data) {
assert(d);
- samplerate = max(samplerate, d->samplerate());
+ const vector< shared_ptr<Snapshot> > snapshots =
+ d->snapshots();
+ for (const shared_ptr<Snapshot> &s : snapshots)
+ samplerate = max(samplerate, s->samplerate());
}
if (samplerate == 0.0)
const set< shared_ptr<SignalData> > visible_data = get_visible_data();
for (const shared_ptr<SignalData> d : visible_data)
{
- double samplerate = d->samplerate();
- samplerate = (samplerate <= 0.0) ? 1.0 : samplerate;
-
const vector< shared_ptr<Snapshot> > snapshots =
d->snapshots();
for (const shared_ptr<Snapshot> &s : snapshots) {
+ double samplerate = s->samplerate();
+ samplerate = (samplerate <= 0.0) ? 1.0 : samplerate;
+
const double start_time = s->start_time();
left_time = min(left_time, start_time);
right_time = max(right_time, start_time +