# Amuse: include/amuse/Submix.hpp Source File

Submix.hpp
#ifndef __AMUSE_SUBMIX_HPP__
#define __AMUSE_SUBMIX_HPP__
#include <memory>
#include "SoundMacroState.hpp"
#include "IBackendSubmix.hpp"
#include "IBackendVoice.hpp"
#include "EffectBase.hpp"
#include "EffectChorus.hpp"
#include "EffectDelay.hpp"
#include "EffectReverb.hpp"
#include <unordered_set>
namespace amuse
{
class IBackendSubmix;
class Sequencer;
class Submix
{
friend class Engine;
friend class Voice;
friend class Sequencer;
Engine& m_root;
Submix* m_submix = nullptr;
std::list<Submix>::iterator m_engineIt;
std::unique_ptr<IBackendSubmix> m_backendSubmix;
std::vector<std::unique_ptr<EffectBaseTypeless>> m_effectStack;
bool m_destroyed = false;
void _destroy();
public:
Submix(Engine& engine, Submix* smx);
~Submix()
{
#ifndef NDEBUG
/* Ensure proper destruction procedure followed */
assert(m_destroyed);
#endif
}
Submix* getParentSubmix() {return m_submix;}
template <class T, class ...Args>
T& makeEffect(Args... args)
{
switch (m_backendSubmix->getSampleFormat())
{
case SubmixFormat::Int16:
{
using ImpType = typename T::template ImpType<int16_t>;
m_effectStack.emplace_back(new ImpType(args..., m_backendSubmix->getSampleRate()));
return static_cast<ImpType&>(*m_effectStack.back());
}
case SubmixFormat::Int32:
{
using ImpType = typename T::template ImpType<int32_t>;
m_effectStack.emplace_back(new ImpType(args..., m_backendSubmix->getSampleRate()));
return static_cast<ImpType&>(*m_effectStack.back());
}
case SubmixFormat::Float:
{
using ImpType = typename T::template ImpType<float>;
m_effectStack.emplace_back(new ImpType(args..., m_backendSubmix->getSampleRate()));
return static_cast<ImpType&>(*m_effectStack.back());
}
}
}
EffectChorus& makeChorus(uint32_t baseDelay, uint32_t variation, uint32_t period);
EffectDelay& makeDelay(uint32_t initDelay, uint32_t initFeedback, uint32_t initOutput);
EffectReverbStd& makeReverbStd(float coloration, float mix, float time,
float damping, float preDelay);
EffectReverbHi& makeReverbHi(float coloration, float mix, float time,
float damping, float preDelay, float crosstalk);
void clearEffects() {m_effectStack.clear();}
bool canApplyEffect() const {return m_effectStack.size() != 0;}
void applyEffect(int16_t* audio, size_t frameCount, const ChannelMap& chanMap) const;
void applyEffect(int32_t* audio, size_t frameCount, const ChannelMap& chanMap) const;
void applyEffect(float* audio, size_t frameCount, const ChannelMap& chanMap) const;
Engine& getEngine() {return m_root;}
};
}
#endif // __AMUSE_SUBMIX_HPP__
amuse::Submix::applyEffect
void applyEffect(int16_t *audio, size_t frameCount, const ChannelMap &chanMap) const
amuse::EffectReverbStd
Definition: EffectReverb.hpp:31
amuse::Submix::clearEffects
void clearEffects()
Definition: Submix.hpp:88
amuse::Submix::makeReverbStd
EffectReverbStd & makeReverbStd(float coloration, float mix, float time, float damping, float preDelay)
amuse::EffectReverbHi
Definition: EffectReverb.hpp:83
amuse::Submix::makeChorus
EffectChorus & makeChorus(uint32_t baseDelay, uint32_t variation, uint32_t period)
amuse::EffectDelay
Definition: EffectDelay.hpp:15
amuse
Definition: AudioGroup.hpp:8
amuse::Voice
Definition: Voice.hpp:30
amuse::Submix
Definition: Submix.hpp:20
amuse::EffectChorus
Definition: EffectChorus.hpp:16
amuse::Submix::makeReverbHi
EffectReverbHi & makeReverbHi(float coloration, float mix, float time, float damping, float preDelay, float crosstalk)
amuse::Engine
Definition: Engine.hpp:23
amuse::ChannelMap
Definition: IBackendVoice.hpp:22
amuse::Submix::getParentSubmix
Submix * getParentSubmix()
Definition: Submix.hpp:44
amuse::Submix::canApplyEffect
bool canApplyEffect() const
Definition: Submix.hpp:91
amuse::Submix::makeEffect
T & makeEffect(Args...args)
Definition: Submix.hpp:48
amuse::Submix::makeDelay
EffectDelay & makeDelay(uint32_t initDelay, uint32_t initFeedback, uint32_t initOutput)
amuse::Sequencer
Definition: Sequencer.hpp:27