From cb69759ccec14f2403024f8702665e16efcb8001 Mon Sep 17 00:00:00 2001 From: lisyarus Date: Sat, 8 Oct 2022 19:14:12 +0300 Subject: [PATCH] Update audio example --- examples/audio.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/examples/audio.cpp b/examples/audio.cpp index 057f57f8..1de90e36 100644 --- a/examples/audio.cpp +++ b/examples/audio.cpp @@ -9,6 +9,8 @@ #include #include #include +#include +#include #include #include #include @@ -20,6 +22,7 @@ #include #include #include +#include #include @@ -69,8 +72,10 @@ struct audio_app : app::app("Audio example") { mixer_ = audio::make_mixer(); + volume_control_ = audio::volume_stereo(mixer_, 0.5f, 0.5f, 0.1f); - auto compressor = audio::compressor(volume_control_, audio::from_db(-2.f), 0.95f, 0.002f, 1.f, audio::from_db(1.f)); + pitch_control_ = audio::pitch(volume_control_, 1.f, 0.1f); + auto compressor = audio::compressor(pitch_control_, audio::from_db(-2.f), 0.95f, 0.002f, 1.f, audio::from_db(1.f)); pause_control_ = audio::pause(compressor, false, 0.01f); engine_.output()->stream(pause_control_); } @@ -90,6 +95,12 @@ struct audio_app { pause_control_->paused(!pause_control_->paused()); } + + if (key == SDLK_KP_PLUS) + pitch_control_->pitch(std::pow(2.f, 1.f / 12.f)); + + if (key == SDLK_KP_MINUS) + pitch_control_->pitch(std::pow(2.f, - 1.f / 12.f)); } void on_key_up(SDL_Keycode key) override @@ -103,6 +114,12 @@ struct audio_app ch->stream(audio::fade_out(s, 0.01f)); channels_.erase(key); } + + if (key == SDLK_KP_PLUS) + pitch_control_->pitch(1.f); + + if (key == SDLK_KP_MINUS) + pitch_control_->pitch(1.f); } void update() override @@ -139,6 +156,7 @@ private: audio::engine engine_; audio::mixer_ptr mixer_; std::shared_ptr volume_control_; + std::shared_ptr pitch_control_; std::shared_ptr pause_control_; std::map channels_;