Support audio effects
This commit is contained in:
parent
6549c2f907
commit
8ff441c6ff
2 changed files with 20 additions and 6 deletions
|
|
@ -5,4 +5,4 @@ file(GLOB_RECURSE PSEMEK_AUDIO_SOURCES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "s
|
||||||
|
|
||||||
add_library(psemek-audio ${PSEMEK_AUDIO_HEADERS} ${PSEMEK_AUDIO_SOURCES})
|
add_library(psemek-audio ${PSEMEK_AUDIO_HEADERS} ${PSEMEK_AUDIO_SOURCES})
|
||||||
target_include_directories(psemek-audio PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
|
target_include_directories(psemek-audio PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
|
||||||
target_link_libraries(psemek-audio PUBLIC psemek-sdl2 psemek-log psemek-util SDL2_mixer)
|
target_link_libraries(psemek-audio PUBLIC psemek-sdl2 psemek-log SDL2_mixer)
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
#include <psemek/audio/engine.hpp>
|
#include <psemek/audio/engine.hpp>
|
||||||
#include <psemek/sdl2/init.hpp>
|
#include <psemek/sdl2/init.hpp>
|
||||||
#include <psemek/log/log.hpp>
|
#include <psemek/log/log.hpp>
|
||||||
#include <psemek/util/not_implemented.hpp>
|
|
||||||
#include <psemek/util/unused.hpp>
|
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include <SDL2/SDL_mixer.h>
|
#include <SDL2/SDL_mixer.h>
|
||||||
|
|
@ -71,6 +69,8 @@ namespace psemek::audio
|
||||||
std::shared_ptr<sample_impl> sample;
|
std::shared_ptr<sample_impl> sample;
|
||||||
bool loop;
|
bool loop;
|
||||||
|
|
||||||
|
std::vector<std::shared_ptr<effect>> effects;
|
||||||
|
|
||||||
stream_impl(int channel, std::shared_ptr<sample_impl> sample, bool loop)
|
stream_impl(int channel, std::shared_ptr<sample_impl> sample, bool loop)
|
||||||
: channel(channel)
|
: channel(channel)
|
||||||
, sample(sample)
|
, sample(sample)
|
||||||
|
|
@ -85,13 +85,27 @@ namespace psemek::audio
|
||||||
|
|
||||||
void push_effect(std::shared_ptr<effect> e) override
|
void push_effect(std::shared_ptr<effect> e) override
|
||||||
{
|
{
|
||||||
unused(e);
|
effects.push_back(e);
|
||||||
util::not_implemented();
|
Mix_RegisterEffect(channel, &effect_func, nullptr, e.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear_effects() override
|
void clear_effects() override
|
||||||
{
|
{
|
||||||
util::not_implemented();
|
effects.clear();
|
||||||
|
Mix_UnregisterAllEffects(channel);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void effect_func(int, void * data, int len, void * udata)
|
||||||
|
{
|
||||||
|
auto e = reinterpret_cast<effect *>(udata);
|
||||||
|
|
||||||
|
if ((len % 2) != 0)
|
||||||
|
{
|
||||||
|
log::error() << "Cannot apply " << e->name() << " effect: number of bytes not even";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
(*e)(reinterpret_cast<std::int16_t *>(data), len / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void start() override
|
void start() override
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue