#ifndef BOO_AUDIOSUBMIX_HPP #define BOO_AUDIOSUBMIX_HPP #include "boo/audiodev/IAudioSubmix.hpp" #include "IAudioMix.hpp" #include #include namespace boo { class BaseAudioVoiceEngine; class AudioVoice; class AudioSubmix : public IAudioSubmix, public IAudioMix { friend class BaseAudioVoiceEngine; /* Mixer-engine relationships */ BaseAudioVoiceEngine& m_root; IAudioMix& m_parent; std::list::iterator m_parentIt; bool m_bound = false; void bindSubmix(std::list::iterator pIt) { m_bound = true; m_parentIt = pIt; } /* Callback (effect source, optional) */ IAudioSubmixCallback* m_cb; /* Audio sources */ std::list m_activeVoices; std::list m_activeSubmixes; /* Output gains for each channel */ float m_gains[8]; /* Temporary scratch buffers for accumulating submix audio */ std::vector m_scratch16; std::vector m_scratch32; std::vector m_scratchFlt; void _pumpAndMixVoices(size_t frames, int16_t* dataOut); void _pumpAndMixVoices(size_t frames, int32_t* dataOut); void _pumpAndMixVoices(size_t frames, float* dataOut); void _unbindFrom(std::list::iterator it); void _unbindFrom(std::list::iterator it); public: ~AudioSubmix(); AudioSubmix(BaseAudioVoiceEngine& root, IAudioMix& parent, IAudioSubmixCallback* cb); std::unique_ptr allocateNewMonoVoice(double sampleRate, IAudioVoiceCallback* cb, bool dynamicPitch=false); std::unique_ptr allocateNewStereoVoice(double sampleRate, IAudioVoiceCallback* cb, bool dynamicPitch=false); std::unique_ptr allocateNewSubmix(IAudioSubmixCallback* cb=nullptr); void setChannelGains(const float gains[8]); void unbindSubmix(); const AudioVoiceEngineMixInfo& mixInfo() const; }; } #endif // BOO_AUDIOSUBMIX_HPP