boo/lib/audiodev/AudioSubmix.hpp

82 lines
2.5 KiB
C++
Raw Normal View History

2016-05-07 04:28:32 +00:00
#ifndef BOO_AUDIOSUBMIX_HPP
#define BOO_AUDIOSUBMIX_HPP
#include "boo/audiodev/IAudioSubmix.hpp"
2016-05-07 22:11:45 +00:00
#include "IAudioMix.hpp"
2016-05-07 04:28:32 +00:00
#include <list>
2016-05-07 22:11:45 +00:00
#include <vector>
2016-05-07 04:28:32 +00:00
2016-06-08 04:37:21 +00:00
struct AudioUnitVoiceEngine;
struct VSTVoiceEngine;
2016-06-08 04:37:21 +00:00
2016-05-07 04:28:32 +00:00
namespace boo
{
class BaseAudioVoiceEngine;
class AudioVoice;
2016-05-07 22:11:45 +00:00
class AudioSubmix : public IAudioSubmix, public IAudioMix
2016-05-07 04:28:32 +00:00
{
friend class BaseAudioVoiceEngine;
friend struct WASAPIAudioVoiceEngine;
2016-06-08 04:37:21 +00:00
friend struct ::AudioUnitVoiceEngine;
friend struct ::VSTVoiceEngine;
2016-05-07 04:28:32 +00:00
/* Mixer-engine relationships */
2016-05-07 22:11:45 +00:00
BaseAudioVoiceEngine& m_root;
IAudioMix& m_parent;
2016-05-07 04:28:32 +00:00
std::list<AudioSubmix*>::iterator m_parentIt;
bool m_bound = false;
void bindSubmix(std::list<AudioSubmix*>::iterator pIt)
{
m_bound = true;
m_parentIt = pIt;
}
/* Callback (effect source, optional) */
IAudioSubmixCallback* m_cb;
/* Audio sources */
std::list<AudioVoice*> m_activeVoices;
std::list<AudioSubmix*> m_activeSubmixes;
/* Output gains for each channel */
float m_gains[8];
2016-05-07 22:11:45 +00:00
/* Temporary scratch buffers for accumulating submix audio */
std::vector<int16_t> m_scratch16;
std::vector<int32_t> m_scratch32;
std::vector<float> m_scratchFlt;
2016-05-31 05:16:29 +00:00
void _pumpAndMixVoices(size_t frames, int16_t* dataOut, int16_t* mainOut);
void _pumpAndMixVoices(size_t frames, int32_t* dataOut, int32_t* mainOut);
void _pumpAndMixVoices(size_t frames, float* dataOut, float* mainOut);
2016-05-07 04:28:32 +00:00
void _unbindFrom(std::list<AudioVoice*>::iterator it);
void _unbindFrom(std::list<AudioSubmix*>::iterator it);
void _resetOutputSampleRate();
2016-05-07 04:28:32 +00:00
public:
~AudioSubmix();
2016-05-07 22:11:45 +00:00
AudioSubmix(BaseAudioVoiceEngine& root, IAudioMix& parent, IAudioSubmixCallback* cb);
2016-05-07 04:28:32 +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 22:11:45 +00:00
std::unique_ptr<IAudioSubmix> allocateNewSubmix(IAudioSubmixCallback* cb=nullptr);
void setChannelGains(const float gains[8]);
2016-05-07 04:28:32 +00:00
void unbindSubmix();
const AudioVoiceEngineMixInfo& mixInfo() const;
double getSampleRate() const;
SubmixFormat getSampleFormat() const;
2016-05-07 04:28:32 +00:00
};
}
#endif // BOO_AUDIOSUBMIX_HPP