From: Joel Holdsworth Date: Sun, 30 Nov 2014 10:29:54 +0000 (+0000) Subject: SignalData: Moved samplerate into Snapshot X-Git-Tag: pulseview-0.3.0~394 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=ff008de665c7990d5f3408f918ff090d8e6c60b2;p=pulseview.git SignalData: Moved samplerate into Snapshot --- diff --git a/pv/data/analogsnapshot.cpp b/pv/data/analogsnapshot.cpp index 589b1aa4..5e995158 100644 --- a/pv/data/analogsnapshot.cpp +++ b/pv/data/analogsnapshot.cpp @@ -45,8 +45,9 @@ const float AnalogSnapshot::LogEnvelopeScaleFactor = 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); diff --git a/pv/data/analogsnapshot.hpp b/pv/data/analogsnapshot.hpp index 3c6f99c2..69c28a2a 100644 --- a/pv/data/analogsnapshot.hpp +++ b/pv/data/analogsnapshot.hpp @@ -66,7 +66,7 @@ private: 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(); diff --git a/pv/data/decoderstack.cpp b/pv/data/decoderstack.cpp index e5a75877..a764e452 100644 --- a/pv/data/decoderstack.cpp +++ b/pv/data/decoderstack.cpp @@ -264,7 +264,7 @@ void DecoderStack::begin_decode() // Get the samplerate and start time start_time_ = snapshot_->start_time(); - samplerate_ = data->samplerate(); + samplerate_ = snapshot_->samplerate(); if (samplerate_ == 0.0) samplerate_ = 1.0; diff --git a/pv/data/logicsnapshot.cpp b/pv/data/logicsnapshot.cpp index 82d90074..a89c8f93 100644 --- a/pv/data/logicsnapshot.cpp +++ b/pv/data/logicsnapshot.cpp @@ -46,9 +46,9 @@ const int LogicSnapshot::MipMapScaleFactor = 1 << MipMapScalePower; const float LogicSnapshot::LogMipMapScaleFactor = logf(MipMapScaleFactor); const uint64_t LogicSnapshot::MipMapDataUnit = 64*1024; // bytes -LogicSnapshot::LogicSnapshot(shared_ptr logic, +LogicSnapshot::LogicSnapshot(shared_ptr 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); diff --git a/pv/data/logicsnapshot.hpp b/pv/data/logicsnapshot.hpp index 619048d8..8b1481ab 100644 --- a/pv/data/logicsnapshot.hpp +++ b/pv/data/logicsnapshot.hpp @@ -63,7 +63,7 @@ public: public: LogicSnapshot(std::shared_ptr logic, - uint64_t expected_num_samples = 0); + uint64_t samplerate, uint64_t expected_num_samples = 0); virtual ~LogicSnapshot(); diff --git a/pv/data/signaldata.cpp b/pv/data/signaldata.cpp index ceeef0b4..6a4c6d92 100644 --- a/pv/data/signaldata.cpp +++ b/pv/data/signaldata.cpp @@ -23,21 +23,9 @@ 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 diff --git a/pv/data/signaldata.hpp b/pv/data/signaldata.hpp index 7d67add1..51589771 100644 --- a/pv/data/signaldata.hpp +++ b/pv/data/signaldata.hpp @@ -37,17 +37,11 @@ public: virtual ~SignalData() {} public: - double samplerate() const; - void set_samplerate(double samplerate); - virtual std::vector< std::shared_ptr > snapshots() const = 0; virtual void clear() = 0; virtual uint64_t get_max_sample_count() const = 0; - -protected: - double samplerate_; }; } // namespace data diff --git a/pv/data/snapshot.cpp b/pv/data/snapshot.cpp index 6e1235d2..39fdc011 100644 --- a/pv/data/snapshot.cpp +++ b/pv/data/snapshot.cpp @@ -30,9 +30,10 @@ using std::recursive_mutex; 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) { @@ -56,6 +57,16 @@ double Snapshot::start_time() const 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_; diff --git a/pv/data/snapshot.hpp b/pv/data/snapshot.hpp index b9dacc7e..6015de9e 100644 --- a/pv/data/snapshot.hpp +++ b/pv/data/snapshot.hpp @@ -31,7 +31,7 @@ namespace data { class Snapshot { public: - Snapshot(unsigned int unit_size); + Snapshot(uint64_t samplerate, unsigned int unit_size); virtual ~Snapshot(); @@ -39,6 +39,9 @@ public: double start_time() const; + double samplerate() const; + void set_samplerate(double samplerate); + unsigned int unit_size() const; /** @@ -76,6 +79,7 @@ protected: std::vector data_; uint64_t sample_count_; double start_time_; + double samplerate_; uint64_t capacity_; unsigned int unit_size_; }; diff --git a/pv/session.cpp b/pv/session.cpp index 5e3b492c..46af90cc 100644 --- a/pv/session.cpp +++ b/pv/session.cpp @@ -85,7 +85,8 @@ namespace pv { 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(); } @@ -431,17 +432,10 @@ void Session::read_sample_rate(shared_ptr 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>( device->config_get(ConfigKey::SAMPLERATE)).get() : 0; - - // Set the sample rate of all data - const set< shared_ptr > data_set = get_data(); - for (shared_ptr data : data_set) { - assert(data); - data->set_samplerate(sample_rate); - } } void Session::sample_thread_proc(shared_ptr device, @@ -530,7 +524,8 @@ void Session::feed_in_logic(shared_ptr logic) // Create a new data snapshot cur_logic_snapshot_ = shared_ptr( - 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 @@ -585,7 +580,8 @@ void Session::feed_in_analog(shared_ptr analog) // Create a snapshot, keep it in the maps of channels snapshot = shared_ptr( - 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 diff --git a/pv/session.hpp b/pv/session.hpp index c6a317de..556f54e5 100644 --- a/pv/session.hpp +++ b/pv/session.hpp @@ -166,6 +166,7 @@ private: mutable std::mutex data_mutex_; std::shared_ptr logic_data_; + uint64_t cur_samplerate_; std::shared_ptr cur_logic_snapshot_; std::map< std::shared_ptr, std::shared_ptr > cur_analog_snapshots_; diff --git a/pv/storesession.cpp b/pv/storesession.cpp index 46dddcd6..af599db0 100644 --- a/pv/storesession.cpp +++ b/pv/storesession.cpp @@ -127,8 +127,8 @@ bool StoreSession::start() {{"filename", Glib::Variant::create(file_name_)}}); auto meta = context->create_meta_packet( - {{ConfigKey::SAMPLERATE, - Glib::Variant::create(data->samplerate())}}); + {{ConfigKey::SAMPLERATE, Glib::Variant::create( + snapshot->samplerate())}}); output_->receive(meta); } catch (Error error) { error_ = tr("Error while saving."); diff --git a/pv/view/analogsignal.cpp b/pv/view/analogsignal.cpp index 382d1e35..e559a4a4 100644 --- a/pv/view/analogsignal.cpp +++ b/pv/view/analogsignal.cpp @@ -112,7 +112,7 @@ void AnalogSignal::paint_mid(QPainter &p, const RowItemPaintParams &pp) 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(); diff --git a/pv/view/logicsignal.cpp b/pv/view/logicsignal.cpp index 48316f8b..b1aaae8f 100644 --- a/pv/view/logicsignal.cpp +++ b/pv/view/logicsignal.cpp @@ -177,7 +177,7 @@ void LogicSignal::paint_mid(QPainter &p, const RowItemPaintParams &pp) const shared_ptr &snapshot = snapshots.front(); - double samplerate = data_->samplerate(); + double samplerate = snapshot->samplerate(); // Show sample rate as 1Hz when it is unknown if (samplerate == 0.0) diff --git a/pv/view/view.cpp b/pv/view/view.cpp index aac6333a..e0c49c20 100644 --- a/pv/view/view.cpp +++ b/pv/view/view.cpp @@ -263,7 +263,10 @@ void View::zoom_one_to_one() double samplerate = 0.0; for (const shared_ptr d : visible_data) { assert(d); - samplerate = max(samplerate, d->samplerate()); + const vector< shared_ptr > snapshots = + d->snapshots(); + for (const shared_ptr &s : snapshots) + samplerate = max(samplerate, s->samplerate()); } if (samplerate == 0.0) @@ -311,12 +314,12 @@ pair View::get_time_extents() const const set< shared_ptr > visible_data = get_visible_data(); for (const shared_ptr d : visible_data) { - double samplerate = d->samplerate(); - samplerate = (samplerate <= 0.0) ? 1.0 : samplerate; - const vector< shared_ptr > snapshots = d->snapshots(); for (const shared_ptr &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 +