]> sigrok.org Git - pulseview.git/commitdiff
SignalData: Moved samplerate into Snapshot
authorJoel Holdsworth <redacted>
Sun, 30 Nov 2014 10:29:54 +0000 (10:29 +0000)
committerJoel Holdsworth <redacted>
Tue, 9 Dec 2014 18:24:59 +0000 (18:24 +0000)
15 files changed:
pv/data/analogsnapshot.cpp
pv/data/analogsnapshot.hpp
pv/data/decoderstack.cpp
pv/data/logicsnapshot.cpp
pv/data/logicsnapshot.hpp
pv/data/signaldata.cpp
pv/data/signaldata.hpp
pv/data/snapshot.cpp
pv/data/snapshot.hpp
pv/session.cpp
pv/session.hpp
pv/storesession.cpp
pv/view/analogsignal.cpp
pv/view/logicsignal.cpp
pv/view/view.cpp

index 589b1aa4b628e5f0e3ae8a7376651e09bbdec45d..5e995158ee1dd672163c741538768d767599749a 100644 (file)
@@ -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);
 
index 3c6f99c2c873dad8bb2956eb43672968aef2771c..69c28a2a60b793e13a790cb360172aae61236eac 100644 (file)
@@ -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();
 
index e5a758773b17d0a886b424492fbd50dad59fb6e7..a764e452d3d82bc203f88e83cac34bf231fbb699 100644 (file)
@@ -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;
 
index 82d900749c027cc1bdbbb159e826310285889618..a89c8f93e36261862c5f4bad70696b80e50e5aba 100644 (file)
@@ -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> 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);
index 619048d8ae18b82244d51731b259165a164625b0..8b1481abfe3b4da576f863056ed526641dcb2093 100644 (file)
@@ -63,7 +63,7 @@ public:
 
 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();
 
index ceeef0b424fbc5c5edbd2415563a2353a195851a..6a4c6d926bf6e3d071d03b24515aaf63ed916c65 100644 (file)
 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
index 7d67add14d9caf1027c9da05c06dbb49be16c781..515897711524bcbf4aa43ec8b4b9dc69eead2865 100644 (file)
@@ -37,17 +37,11 @@ public:
        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
index 6e1235d24218fafce46f95c8c99a93c759d87109..39fdc011f1602e2686721b79bf6d9377a5e1cb40 100644 (file)
@@ -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_;
index b9dacc7eb6beb85323747854ccecd4ddd7b027c3..6015de9e65a9a367f7f29e52af84b274f83316fe 100644 (file)
@@ -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<uint8_t> data_;
        uint64_t sample_count_;
        double start_time_;
+       double samplerate_;
        uint64_t capacity_;
        unsigned int unit_size_;
 };
index 5e3b492c1ae018c1fe390d7f1f010eb104209203..46af90cc0fa68141e1fe48782d56dc9a2a8a6771 100644 (file)
@@ -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> 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,
@@ -530,7 +524,8 @@ void Session::feed_in_logic(shared_ptr<Logic> logic)
 
                // 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
@@ -585,7 +580,8 @@ void Session::feed_in_analog(shared_ptr<Analog> analog)
 
                        // 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
index c6a317def7b61b5f1b61a6bef5ffa65847372fc4..556f54e5d5c938454a49486a7aac011bf561c26a 100644 (file)
@@ -166,6 +166,7 @@ private:
 
        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_;
index 46dddcd64411fb85ac998c19d6b493977c52df5d..af599db00e769c6d17687116281b400b56420f05 100644 (file)
@@ -127,8 +127,8 @@ bool StoreSession::start()
                        {{"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.");
index 382d1e35ad75f6fdf22f9d16aeea3b34835cc0cc..e559a4a45c50da008bc8ab234c5f693e417c6f20 100644 (file)
@@ -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();
index 48316f8b56340c6ae22c10dccccdedceaac38999..b1aaae8f2ddbdf26e2724c1b99787d87d7fd8b0d 100644 (file)
@@ -177,7 +177,7 @@ void LogicSignal::paint_mid(QPainter &p, const RowItemPaintParams &pp)
        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)
index aac6333addd032c0adb85886c60f2fdf9b48a248..e0c49c20ad4b2f60b4e9ea1b16c69420318321ba 100644 (file)
@@ -263,7 +263,10 @@ void View::zoom_one_to_one()
        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)
@@ -311,12 +314,12 @@ pair<double, double> View::get_time_extents() const
        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 +