Update audio example
This commit is contained in:
parent
8048496535
commit
cb69759cce
1 changed files with 19 additions and 1 deletions
|
|
@ -9,6 +9,8 @@
|
|||
#include <psemek/audio/effect/fade_out.hpp>
|
||||
#include <psemek/audio/effect/compressor.hpp>
|
||||
#include <psemek/audio/effect/pause.hpp>
|
||||
#include <psemek/audio/effect/loop.hpp>
|
||||
#include <psemek/audio/effect/pitch.hpp>
|
||||
#include <psemek/audio/duplicate.hpp>
|
||||
#include <psemek/audio/stereo.hpp>
|
||||
#include <psemek/audio/mixer.hpp>
|
||||
|
|
@ -20,6 +22,7 @@
|
|||
#include <psemek/geom/constants.hpp>
|
||||
#include <psemek/geom/camera.hpp>
|
||||
#include <psemek/prof/profiler.hpp>
|
||||
#include <psemek/io/file_stream.hpp>
|
||||
|
||||
#include <map>
|
||||
|
||||
|
|
@ -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<audio::volume_control_stereo> volume_control_;
|
||||
std::shared_ptr<audio::pitch_control> pitch_control_;
|
||||
std::shared_ptr<audio::pause_control> pause_control_;
|
||||
std::map<SDL_Keycode, audio::channel_ptr> channels_;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue