2018-10-07 03:36:44 +00:00
|
|
|
#pragma once
|
2016-03-24 00:01:57 +00:00
|
|
|
|
|
|
|
#include "boo/audiodev/IAudioVoiceEngine.hpp"
|
2017-09-28 03:11:40 +00:00
|
|
|
#include "LtRtProcessing.hpp"
|
|
|
|
#include "Common.hpp"
|
2016-03-24 00:01:57 +00:00
|
|
|
#include "AudioVoice.hpp"
|
2016-05-07 04:28:32 +00:00
|
|
|
#include "AudioSubmix.hpp"
|
2016-05-19 10:14:21 +00:00
|
|
|
#include <functional>
|
2017-12-03 06:05:16 +00:00
|
|
|
#include <mutex>
|
2016-03-24 00:01:57 +00:00
|
|
|
|
|
|
|
namespace boo
|
|
|
|
{
|
|
|
|
|
|
|
|
/** Base class for managing mixing and sample-rate-conversion amongst active voices */
|
2016-07-13 03:03:52 +00:00
|
|
|
class BaseAudioVoiceEngine : public IAudioVoiceEngine
|
2016-03-24 00:01:57 +00:00
|
|
|
{
|
|
|
|
protected:
|
|
|
|
friend class AudioVoice;
|
2016-05-07 04:28:32 +00:00
|
|
|
friend class AudioSubmix;
|
2016-05-07 22:11:45 +00:00
|
|
|
friend class AudioVoiceMono;
|
|
|
|
friend class AudioVoiceStereo;
|
2016-07-14 06:16:40 +00:00
|
|
|
float m_totalVol = 1.f;
|
2016-03-24 00:01:57 +00:00
|
|
|
AudioVoiceEngineMixInfo m_mixInfo;
|
2017-12-03 06:05:16 +00:00
|
|
|
std::recursive_mutex m_dataMutex;
|
|
|
|
AudioVoice* m_voiceHead = nullptr;
|
|
|
|
AudioSubmix* m_submixHead = nullptr;
|
2016-05-19 10:14:21 +00:00
|
|
|
size_t m_5msFrames = 0;
|
2017-02-15 06:00:10 +00:00
|
|
|
IAudioVoiceEngineCallback* m_engineCallback = nullptr;
|
2016-03-24 00:01:57 +00:00
|
|
|
|
2016-05-07 22:11:45 +00:00
|
|
|
/* Shared scratch buffers for accumulating audio data for resampling */
|
|
|
|
std::vector<int16_t> m_scratchIn;
|
2016-07-14 04:59:41 +00:00
|
|
|
std::vector<int16_t> m_scratch16Pre;
|
|
|
|
std::vector<int32_t> m_scratch32Pre;
|
|
|
|
std::vector<float> m_scratchFltPre;
|
2017-12-03 06:05:16 +00:00
|
|
|
template <typename T> std::vector<T>& _getScratchPre();
|
2016-07-14 04:59:41 +00:00
|
|
|
std::vector<int16_t> m_scratch16Post;
|
|
|
|
std::vector<int32_t> m_scratch32Post;
|
|
|
|
std::vector<float> m_scratchFltPost;
|
2017-12-03 06:05:16 +00:00
|
|
|
template <typename T> std::vector<T>& _getScratchPost();
|
2016-05-07 22:11:45 +00:00
|
|
|
|
2017-09-28 03:11:40 +00:00
|
|
|
/* LtRt processing if enabled */
|
|
|
|
std::unique_ptr<LtRtProcessing> m_ltRtProcessing;
|
|
|
|
std::vector<int16_t> m_ltRtIn16;
|
|
|
|
std::vector<int32_t> m_ltRtIn32;
|
|
|
|
std::vector<float> m_ltRtInFlt;
|
2017-12-03 06:05:16 +00:00
|
|
|
template <typename T> std::vector<T>& _getLtRtIn();
|
2017-09-28 03:11:40 +00:00
|
|
|
|
2017-12-03 06:05:16 +00:00
|
|
|
std::unique_ptr<AudioSubmix> m_mainSubmix;
|
2016-07-13 03:03:52 +00:00
|
|
|
std::list<AudioSubmix*> m_linearizedSubmixes;
|
|
|
|
bool m_submixesDirty = true;
|
|
|
|
|
2017-12-03 06:05:16 +00:00
|
|
|
template <typename T>
|
|
|
|
void _pumpAndMixVoices(size_t frames, T* dataOut);
|
2016-05-07 04:28:32 +00:00
|
|
|
|
2018-08-18 22:08:58 +00:00
|
|
|
void _resetSampleRate();
|
|
|
|
|
2016-03-24 00:01:57 +00:00
|
|
|
public:
|
2017-12-03 06:05:16 +00:00
|
|
|
BaseAudioVoiceEngine() : m_mainSubmix(std::make_unique<AudioSubmix>(*this, nullptr, -1, false)) {}
|
2016-05-16 22:14:07 +00:00
|
|
|
~BaseAudioVoiceEngine();
|
2017-12-04 02:50:33 +00:00
|
|
|
ObjToken<IAudioVoice> allocateNewMonoVoice(double sampleRate,
|
|
|
|
IAudioVoiceCallback* cb,
|
|
|
|
bool dynamicPitch=false);
|
2016-03-24 00:01:57 +00:00
|
|
|
|
2017-12-04 02:50:33 +00:00
|
|
|
ObjToken<IAudioVoice> allocateNewStereoVoice(double sampleRate,
|
|
|
|
IAudioVoiceCallback* cb,
|
|
|
|
bool dynamicPitch=false);
|
2016-03-24 00:01:57 +00:00
|
|
|
|
2017-12-04 02:50:33 +00:00
|
|
|
ObjToken<IAudioSubmix> allocateNewSubmix(bool mainOut, IAudioSubmixCallback* cb, int busId);
|
2016-05-07 04:28:32 +00:00
|
|
|
|
2017-02-15 06:00:10 +00:00
|
|
|
void setCallbackInterface(IAudioVoiceEngineCallback* cb);
|
2016-05-19 10:14:21 +00:00
|
|
|
|
2016-07-14 06:16:40 +00:00
|
|
|
void setVolume(float vol);
|
2017-09-28 03:11:40 +00:00
|
|
|
bool enableLtRt(bool enable);
|
2016-05-07 04:28:32 +00:00
|
|
|
const AudioVoiceEngineMixInfo& mixInfo() const;
|
2017-09-28 03:11:40 +00:00
|
|
|
const AudioVoiceEngineMixInfo& clientMixInfo() const;
|
|
|
|
AudioChannelSet getAvailableSet() {return clientMixInfo().m_channels;}
|
2016-03-24 00:01:57 +00:00
|
|
|
void pumpAndMixVoices() {}
|
2016-07-06 21:29:06 +00:00
|
|
|
size_t get5MsFrames() const {return m_5msFrames;}
|
2016-03-24 00:01:57 +00:00
|
|
|
};
|
|
|
|
|
2017-12-03 06:05:16 +00:00
|
|
|
template <> inline std::vector<int16_t>& BaseAudioVoiceEngine::_getScratchPre<int16_t>() { return m_scratch16Pre; }
|
|
|
|
template <> inline std::vector<int32_t>& BaseAudioVoiceEngine::_getScratchPre<int32_t>() { return m_scratch32Pre; }
|
|
|
|
template <> inline std::vector<float>& BaseAudioVoiceEngine::_getScratchPre<float>() { return m_scratchFltPre; }
|
|
|
|
|
|
|
|
template <> inline std::vector<int16_t>& BaseAudioVoiceEngine::_getScratchPost<int16_t>() { return m_scratch16Post; }
|
|
|
|
template <> inline std::vector<int32_t>& BaseAudioVoiceEngine::_getScratchPost<int32_t>() { return m_scratch32Post; }
|
|
|
|
template <> inline std::vector<float>& BaseAudioVoiceEngine::_getScratchPost<float>() { return m_scratchFltPost; }
|
|
|
|
|
|
|
|
template <> inline std::vector<int16_t>& BaseAudioVoiceEngine::_getLtRtIn<int16_t>() { return m_ltRtIn16; }
|
|
|
|
template <> inline std::vector<int32_t>& BaseAudioVoiceEngine::_getLtRtIn<int32_t>() { return m_ltRtIn32; }
|
|
|
|
template <> inline std::vector<float>& BaseAudioVoiceEngine::_getLtRtIn<float>() { return m_ltRtInFlt; }
|
|
|
|
|
2016-03-24 00:01:57 +00:00
|
|
|
}
|
|
|
|
|