diff options
-rw-r--r-- | include/djinterop/track.hpp | 9 | ||||
-rw-r--r-- | src/djinterop/enginelibrary/el_track_impl.cpp | 39 | ||||
-rw-r--r-- | src/djinterop/enginelibrary/el_track_impl.hpp | 2 | ||||
-rw-r--r-- | src/djinterop/impl/track_impl.hpp | 2 | ||||
-rw-r--r-- | src/djinterop/track.cpp | 4 | ||||
-rw-r--r-- | test/enginelibrary/performance_data_test.cpp | 6 |
6 files changed, 30 insertions, 32 deletions
diff --git a/include/djinterop/track.hpp b/include/djinterop/track.hpp index 5ab8710..e317bfd 100644 --- a/include/djinterop/track.hpp +++ b/include/djinterop/track.hpp @@ -281,7 +281,14 @@ public: void set_publisher(stdx::optional<std::string> publisher) const; void set_publisher(std::string publisher) const; - int64_t recommended_waveform_size() const; + /// Get the required number of samples per waveform entry. + /// + /// The waveform for a track is provided merely as a set of waveform points, + /// and so the scale of it is only meaningful when a relationship between + /// the waveform and the samples it represents is known. This method + /// provides the required number of samples per waveform entry that should + /// be understood when constructing or reading waveforms. + int64_t required_waveform_samples_per_entry() const; /// Get the path to this track's file on disk, relative to the music /// database. diff --git a/src/djinterop/enginelibrary/el_track_impl.cpp b/src/djinterop/enginelibrary/el_track_impl.cpp index 3618c73..733258c 100644 --- a/src/djinterop/enginelibrary/el_track_impl.cpp +++ b/src/djinterop/enginelibrary/el_track_impl.cpp @@ -80,18 +80,6 @@ inline int64_t calculate_overview_waveform_samples_per_entry( return ((sample_count / qn) * qn) / 1024; } -/// Calculate the recommended number of entries in the high-resolution waveform. -/// -/// The recommended number of entries in any high-resolution end-point is -/// expected to be the ceiling division of number of samples by quantisation -/// number. -inline int64_t calculate_high_resolution_waveform_num_entries( - int64_t sample_rate, int64_t sample_count) -{ - auto qn = quantisation_number(sample_rate); - return sample_count / qn + (sample_count % qn != 0); -} - } // namespace el_track_impl::el_track_impl(std::shared_ptr<el_storage> storage, int64_t id) @@ -679,26 +667,22 @@ void el_track_impl::set_publisher(boost::optional<std::string> publisher) set_metadata_str(metadata_str_type::publisher, publisher); } -int64_t el_track_impl::recommended_waveform_size() +int64_t el_track_impl::required_waveform_samples_per_entry() { auto smp = sampling(); if (!smp) { return 0; } - if (smp->sample_count <= 0) - { - throw track_database_inconsistency{ - "Track has non-positive sample count", id()}; - } if (smp->sample_rate <= 0) { throw track_database_inconsistency{"Track has non-positive sample rate", id()}; } - return calculate_high_resolution_waveform_num_entries( - smp->sample_rate, smp->sample_count); + // In high-resolution waveforms, the samples-per-entry is the same as + // the quantisation number. + return quantisation_number(smp->sample_rate); } std::string el_track_impl::relative_path() @@ -765,13 +749,18 @@ void el_track_impl::set_sampling(boost::optional<sampling_info> sampling) if (!high_res_waveform_d.waveform.empty()) { - high_res_waveform_d.samples_per_entry = - sample_count / high_res_waveform_d.waveform.size(); + // The high-resolution waveform has a required number of samples per + // entry that is dependent on the sample rate. If the sample rate is + // genuinely changed using this method, note that the waveform is likely + // to need to be updated as well afterwards. + high_res_waveform_d.samples_per_entry = quantisation_number(sample_rate); set_high_res_waveform_data(std::move(high_res_waveform_d)); } if (!overview_waveform_d.waveform.empty()) { + // The overview waveform has a varying number of samples per entry, as + // the number of entries is always fixed. overview_waveform_d.samples_per_entry = calculate_overview_waveform_samples_per_entry( sample_rate, sample_count); @@ -832,9 +821,9 @@ void el_track_impl::set_waveform(std::vector<waveform_entry> waveform) overview_waveform_d.waveform.push_back(entry); } - // TODO (mr-smidge) resize waveform to be compatible with quantisation - // number, padding out with zeroes at end as necessary. - high_res_waveform_d.samples_per_entry = sample_count / waveform.size(); + // Make the assumption that the client has respected the required number + // of samples per entry when constructing the waveform. + high_res_waveform_d.samples_per_entry = quantisation_number(sample_rate); high_res_waveform_d.waveform = std::move(waveform); } diff --git a/src/djinterop/enginelibrary/el_track_impl.hpp b/src/djinterop/enginelibrary/el_track_impl.hpp index 3074f5f..bd934e1 100644 --- a/src/djinterop/enginelibrary/el_track_impl.hpp +++ b/src/djinterop/enginelibrary/el_track_impl.hpp @@ -263,7 +263,7 @@ public: std::vector<waveform_entry> overview_waveform() override; boost::optional<std::string> publisher() override; void set_publisher(boost::optional<std::string> publisher) override; - int64_t recommended_waveform_size() override; + int64_t required_waveform_samples_per_entry() override; std::string relative_path() override; void set_relative_path(std::string relative_path) override; boost::optional<sampling_info> sampling() override; diff --git a/src/djinterop/impl/track_impl.hpp b/src/djinterop/impl/track_impl.hpp index 2e68df0..d4f086a 100644 --- a/src/djinterop/impl/track_impl.hpp +++ b/src/djinterop/impl/track_impl.hpp @@ -106,7 +106,7 @@ public: virtual std::vector<waveform_entry> overview_waveform() = 0; virtual boost::optional<std::string> publisher() = 0; virtual void set_publisher(boost::optional<std::string> publisher) = 0; - virtual int64_t recommended_waveform_size() = 0; + virtual int64_t required_waveform_samples_per_entry() = 0; virtual std::string relative_path() = 0; virtual void set_relative_path(std::string relative_path) = 0; virtual boost::optional<sampling_info> sampling() = 0; diff --git a/src/djinterop/track.cpp b/src/djinterop/track.cpp index 777dcd8..eb15ba4 100644 --- a/src/djinterop/track.cpp +++ b/src/djinterop/track.cpp @@ -465,9 +465,9 @@ void track::set_publisher(std::string publisher) const set_publisher(stdx::make_optional(publisher)); } -int64_t track::recommended_waveform_size() const +int64_t track::required_waveform_samples_per_entry() const { - return pimpl_->recommended_waveform_size(); + return pimpl_->required_waveform_samples_per_entry(); } std::string track::relative_path() const diff --git a/test/enginelibrary/performance_data_test.cpp b/test/enginelibrary/performance_data_test.cpp index 9e2cb58..b1fb830 100644 --- a/test/enginelibrary/performance_data_test.cpp +++ b/test/enginelibrary/performance_data_test.cpp @@ -110,7 +110,8 @@ static void populate_track_1(djinterop::track& t) // High-resolution waveform data std::vector<djinterop::waveform_entry> waveform; - int64_t waveform_size = t.recommended_waveform_size(); + int64_t samples_per_entry = t.required_waveform_samples_per_entry(); + int64_t waveform_size = (t.sampling()->sample_count / samples_per_entry) + 1; waveform.reserve(waveform_size); for (int64_t i = 0; i < waveform_size; ++i) { @@ -261,7 +262,8 @@ static void populate_track_2(djinterop::track& t) 1, {"Loop 2", 2345600, 2345700, el::standard_pad_colors::pad_2}); // High-resolution waveform data - int64_t waveform_size = t.recommended_waveform_size(); + int64_t samples_per_entry = t.required_waveform_samples_per_entry(); + int64_t waveform_size = (t.sampling()->sample_count / samples_per_entry) + 1; std::vector<djinterop::waveform_entry> waveform; waveform.reserve(waveform_size); for (int64_t i = 0; i < waveform_size; ++i) |