2016-03-24 00:01:57 +00:00
|
|
|
#ifndef BOO_AUDIOVOICEENGINE_HPP
|
|
|
|
#define BOO_AUDIOVOICEENGINE_HPP
|
|
|
|
|
|
|
|
#include "boo/audiodev/IAudioVoiceEngine.hpp"
|
|
|
|
#include "AudioVoice.hpp"
|
2016-05-07 04:28:32 +00:00
|
|
|
#include "AudioSubmix.hpp"
|
2016-05-07 22:11:45 +00:00
|
|
|
#include "IAudioMix.hpp"
|
2016-03-24 00:01:57 +00:00
|
|
|
|
|
|
|
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 */
|
2016-05-07 22:11:45 +00:00
|
|
|
class BaseAudioVoiceEngine : public IAudioVoiceEngine, public IAudioMix
|
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-03-24 00:01:57 +00:00
|
|
|
AudioVoiceEngineMixInfo m_mixInfo;
|
|
|
|
std::list<AudioVoice*> m_activeVoices;
|
2016-05-07 04:28:32 +00:00
|
|
|
std::list<AudioSubmix*> m_activeSubmixes;
|
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;
|
|
|
|
std::vector<int16_t> m_scratch16;
|
|
|
|
std::vector<int32_t> m_scratch32;
|
|
|
|
std::vector<float> m_scratchFlt;
|
|
|
|
|
2016-03-24 00:01:57 +00:00
|
|
|
void _pumpAndMixVoices(size_t frames, int16_t* dataOut);
|
|
|
|
void _pumpAndMixVoices(size_t frames, int32_t* dataOut);
|
|
|
|
void _pumpAndMixVoices(size_t frames, float* dataOut);
|
|
|
|
|
2016-05-07 04:28:32 +00:00
|
|
|
void _unbindFrom(std::list<AudioVoice*>::iterator it);
|
|
|
|
void _unbindFrom(std::list<AudioSubmix*>::iterator it);
|
|
|
|
|
2016-03-24 00:01:57 +00:00
|
|
|
public:
|
2016-05-16 22:14:07 +00:00
|
|
|
~BaseAudioVoiceEngine();
|
2016-03-24 00:01:57 +00:00
|
|
|
std::unique_ptr<IAudioVoice> allocateNewMonoVoice(double sampleRate,
|
|
|
|
IAudioVoiceCallback* cb,
|
|
|
|
bool dynamicPitch=false);
|
|
|
|
|
|
|
|
std::unique_ptr<IAudioVoice> allocateNewStereoVoice(double sampleRate,
|
|
|
|
IAudioVoiceCallback* cb,
|
|
|
|
bool dynamicPitch=false);
|
|
|
|
|
2016-05-07 04:28:32 +00:00
|
|
|
std::unique_ptr<IAudioSubmix> allocateNewSubmix(IAudioSubmixCallback* cb);
|
|
|
|
|
|
|
|
const AudioVoiceEngineMixInfo& mixInfo() const;
|
2016-03-24 00:01:57 +00:00
|
|
|
AudioChannelSet getAvailableSet() {return m_mixInfo.m_channels;}
|
|
|
|
void pumpAndMixVoices() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // BOO_AUDIOVOICEENGINE_HPP
|