boo/lib/audiodev/AudioVoice.hpp

128 lines
3.6 KiB
C++
Raw Normal View History

2016-03-23 07:01:25 +00:00
#ifndef BOO_AUDIOVOICE_HPP
#define BOO_AUDIOVOICE_HPP
#include <soxr.h>
#include <list>
#include <unordered_map>
#include "boo/audiodev/IAudioVoice.hpp"
#include "AudioMatrix.hpp"
2016-03-23 07:01:25 +00:00
2016-06-08 04:37:21 +00:00
struct AudioUnitVoiceEngine;
struct VSTVoiceEngine;
struct WAVOutVoiceEngine;
2016-06-08 04:37:21 +00:00
2016-03-23 07:01:25 +00:00
namespace boo
{
class BaseAudioVoiceEngine;
struct AudioVoiceEngineMixInfo;
struct IAudioSubmix;
2016-03-23 07:01:25 +00:00
class AudioVoice : public IAudioVoice
2016-03-23 07:01:25 +00:00
{
friend class BaseAudioVoiceEngine;
2016-05-07 04:28:32 +00:00
friend class AudioSubmix;
friend struct WASAPIAudioVoiceEngine;
2016-06-08 04:37:21 +00:00
friend struct ::AudioUnitVoiceEngine;
friend struct ::VSTVoiceEngine;
friend struct ::WAVOutVoiceEngine;
protected:
/* Mixer-engine relationships */
2016-05-07 22:11:45 +00:00
BaseAudioVoiceEngine& m_root;
std::list<AudioVoice*>::iterator m_parentIt;
bool m_bound = false;
void bindVoice(std::list<AudioVoice*>::iterator pIt)
{
m_bound = true;
m_parentIt = pIt;
}
/* Callback (audio source) */
IAudioVoiceCallback* m_cb;
/* Sample-rate converter */
2016-05-11 04:50:26 +00:00
soxr_t m_src = nullptr;
2016-05-16 02:41:11 +00:00
double m_sampleRateIn;
double m_sampleRateOut;
bool m_dynamicRate;
/* Running bool */
bool m_running = false;
/* Deferred sample-rate reset */
bool m_resetSampleRate = false;
double m_deferredSampleRate;
virtual void _resetSampleRate(double sampleRate)=0;
/* Deferred pitch ratio set */
bool m_setPitchRatio = false;
double m_pitchRatio = 1.0;
bool m_slew = false;
void _setPitchRatio(double ratio, bool slew);
/* Mid-pump update */
void _midUpdate();
virtual size_t pumpAndMix16(size_t frames)=0;
virtual size_t pumpAndMix32(size_t frames)=0;
virtual size_t pumpAndMixFlt(size_t frames)=0;
AudioVoice(BaseAudioVoiceEngine& root, IAudioVoiceCallback* cb, bool dynamicRate);
public:
~AudioVoice();
void resetSampleRate(double sampleRate);
void setPitchRatio(double ratio, bool slew);
void start();
void stop();
void unbindVoice();
2016-06-08 04:37:21 +00:00
double getSampleRateIn() const {return m_sampleRateIn;}
double getSampleRateOut() const {return m_sampleRateOut;}
};
class AudioVoiceMono : public AudioVoice
{
std::unordered_map<IAudioSubmix*, AudioMatrixMono> m_sendMatrices;
bool m_silentOut = false;
void _resetSampleRate(double sampleRate);
static size_t SRCCallback(AudioVoiceMono* ctx,
int16_t** data, size_t requestedLen);
size_t pumpAndMix16(size_t frames);
size_t pumpAndMix32(size_t frames);
size_t pumpAndMixFlt(size_t frames);
public:
AudioVoiceMono(BaseAudioVoiceEngine& root, IAudioVoiceCallback* cb,
double sampleRate, bool dynamicRate);
void resetChannelLevels();
void setMonoChannelLevels(IAudioSubmix* submix, const float coefs[8], bool slew);
void setStereoChannelLevels(IAudioSubmix* submix, const float coefs[8][2], bool slew);
};
class AudioVoiceStereo : public AudioVoice
{
std::unordered_map<IAudioSubmix*, AudioMatrixStereo> m_sendMatrices;
bool m_silentOut = false;
void _resetSampleRate(double sampleRate);
static size_t SRCCallback(AudioVoiceStereo* ctx,
int16_t** data, size_t requestedLen);
size_t pumpAndMix16(size_t frames);
size_t pumpAndMix32(size_t frames);
size_t pumpAndMixFlt(size_t frames);
public:
AudioVoiceStereo(BaseAudioVoiceEngine& root, IAudioVoiceCallback* cb,
double sampleRate, bool dynamicRate);
void resetChannelLevels();
void setMonoChannelLevels(IAudioSubmix* submix, const float coefs[8], bool slew);
void setStereoChannelLevels(IAudioSubmix* submix, const float coefs[8][2], bool slew);
2016-03-23 07:01:25 +00:00
};
}
#endif // BOO_AUDIOVOICE_HPP