#ifndef BOO_AUDIOVOICEENGINE_HPP #define BOO_AUDIOVOICEENGINE_HPP #include "boo/audiodev/IAudioVoiceEngine.hpp" #include "AudioVoice.hpp" #include "AudioSubmix.hpp" #include namespace boo { /** Pertinent information from audio backend about optimal mixed-audio representation */ struct AudioVoiceEngineMixInfo { double m_sampleRate; soxr_datatype_t m_sampleFormat; unsigned m_bitsPerSample; AudioChannelSet m_channels; ChannelMap m_channelMap; size_t m_periodFrames; }; /** Base class for managing mixing and sample-rate-conversion amongst active voices */ class BaseAudioVoiceEngine : public IAudioVoiceEngine { protected: friend class AudioVoice; friend class AudioSubmix; friend class AudioVoiceMono; friend class AudioVoiceStereo; float m_totalVol = 1.f; AudioVoiceEngineMixInfo m_mixInfo; std::list m_activeVoices; std::list m_activeSubmixes; size_t m_5msFrames = 0; IAudioVoiceEngineCallback* m_engineCallback = nullptr; /* Shared scratch buffers for accumulating audio data for resampling */ std::vector m_scratchIn; std::vector m_scratch16Pre; std::vector m_scratch32Pre; std::vector m_scratchFltPre; std::vector m_scratch16Post; std::vector m_scratch32Post; std::vector m_scratchFltPost; AudioSubmix m_mainSubmix; std::list m_linearizedSubmixes; bool m_submixesDirty = true; 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: BaseAudioVoiceEngine() : m_mainSubmix(*this, nullptr, -1, false) {} ~BaseAudioVoiceEngine(); 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(bool mainOut, IAudioSubmixCallback* cb, int busId); void setCallbackInterface(IAudioVoiceEngineCallback* cb); void setVolume(float vol); const AudioVoiceEngineMixInfo& mixInfo() const; AudioChannelSet getAvailableSet() {return m_mixInfo.m_channels;} void pumpAndMixVoices() {} size_t get5MsFrames() const {return m_5msFrames;} }; } #endif // BOO_AUDIOVOICEENGINE_HPP