diff --git a/example/audio/0-wrapping_unsafe_apis.cpp b/example/audio/0-wrapping_unsafe_apis.cpp index dbbfff6ff..590638b36 100644 --- a/example/audio/0-wrapping_unsafe_apis.cpp +++ b/example/audio/0-wrapping_unsafe_apis.cpp @@ -41,12 +41,12 @@ int main() // sample rate, but these APIs are not type safe using float or double values; e.g.: const auto unsafe_context = audio_third_party::get_musical_context(); - std::cout << MP_UNITS_STD_FMT::format("Musical context:\n\tTempo: {}\n\tSample Rate: {}\n\n", unsafe_context.tempo, - unsafe_context.sample_rate); + std::cout << MP_UNITS_STD_FMT::format("Musical context:\n\tTempo: {}\n\tSample Rate: {}\n\n", + unsafe_context.current_tempo, unsafe_context.current_sample_rate); // These unsafe APIs can be wrapped a new API returning type-safe quantities for tempo and sample rate; e.g.: const auto safe_context = audio::get_musical_context(); - std::cout << MP_UNITS_STD_FMT::format("Musical context:\n\tTempo: {}\n\tSample Rate: {}\n", safe_context.tempo, - safe_context.sample_rate); + std::cout << MP_UNITS_STD_FMT::format("Musical context:\n\tTempo: {}\n\tSample Rate: {}\n", + safe_context.current_tempo, safe_context.current_sample_rate); } diff --git a/example/audio/1-lfo.cpp b/example/audio/1-lfo.cpp index 1caec4fc2..6d357175c 100644 --- a/example/audio/1-lfo.cpp +++ b/example/audio/1-lfo.cpp @@ -51,7 +51,7 @@ class sine_wave_osc { { std::cout << MP_UNITS_STD_FMT::format( "Created oscillator with starting frequency {} ({}) for sample rate {} at tempo {}\n", freq, m_frequency, - context.sample_rate, context.tempo); + context.current_sample_rate, context.current_tempo); } quantity get_frequency() const { return m_frequency; } @@ -71,7 +71,7 @@ class sine_wave_osc { void set_period(QuantityOf auto period) { std::cout << MP_UNITS_STD_FMT::format("Setting period to {} -- ", period); - set_period(period / m_context.tempo); + set_period(period / m_context.current_tempo); } quantity operator()() @@ -86,7 +86,7 @@ class sine_wave_osc { private: using phase_t = quantity_point; - void update_step() { m_step = (m_frequency / m_context.sample_rate) * angular::revolution; } + void update_step() { m_step = (m_frequency / m_context.current_sample_rate) * angular::revolution; } audio::musical_context m_context; quantity m_frequency; @@ -121,8 +121,8 @@ int main() // duration equal to 2 measures of 4/4 music (i.e. 2 whole notes at // the current tempo): const auto beats = 2 * audio::whole_note; - const auto buffer_duration = value_cast(beats) / context.tempo; - const auto buffer_size = (buffer_duration * context.sample_rate).in(audio::sample); + const auto buffer_duration = value_cast(beats) / context.current_tempo; + const auto buffer_size = (buffer_duration * context.current_sample_rate).in(audio::sample); std::cout << MP_UNITS_STD_FMT::format("\nCreating buffer with size:\n\t{}\n\t{}\n\t{}\n\n", beats, buffer_duration, buffer_size); diff --git a/example/audio/third_party_audio_api.h b/example/audio/third_party_audio_api.h index c8376efc3..185db80b0 100644 --- a/example/audio/third_party_audio_api.h +++ b/example/audio/third_party_audio_api.h @@ -26,8 +26,8 @@ namespace audio_third_party { //! State of a playback engine for music host application. struct musical_context { - float sample_rate; //!< samples per second - float tempo; //!< beats per minute (quarter note == one beat) + float current_sample_rate; //!< samples per second + float current_tempo; //!< beats per minute (quarter note == one beat) }; //! API provided by music host application to provide global info @@ -35,6 +35,6 @@ struct musical_context { musical_context get_musical_context() { // Example data, this would be variable in a real-world context - return musical_context{.sample_rate = 8000.f, .tempo = 130.f}; + return musical_context{.current_sample_rate = 8000.f, .current_tempo = 130.f}; } } // namespace audio_third_party diff --git a/example/audio/wrapped_third_party_audio_api.h b/example/audio/wrapped_third_party_audio_api.h index 6dd028728..80bebdc38 100644 --- a/example/audio/wrapped_third_party_audio_api.h +++ b/example/audio/wrapped_third_party_audio_api.h @@ -29,16 +29,16 @@ namespace audio { //! Typesafe version of music application playback engine state struct musical_context { - mp_units::quantity sample_rate; - mp_units::quantity tempo; + mp_units::quantity current_sample_rate; + mp_units::quantity current_tempo; }; //! Typesafe wrapper around API for host application musical context musical_context get_musical_context() { auto context = audio_third_party::get_musical_context(); - return musical_context{.sample_rate = context.sample_rate * mp_units::si::hertz, - .tempo = context.tempo * beats_per_minute}; + return musical_context{.current_sample_rate = context.current_sample_rate * mp_units::si::hertz, + .current_tempo = context.current_tempo * beats_per_minute}; } } // namespace audio