2016-03-23 07:01:25 +00:00
|
|
|
#ifndef BOO_AUDIOVOICE_HPP
|
|
|
|
#define BOO_AUDIOVOICE_HPP
|
|
|
|
|
|
|
|
#include <soxr.h>
|
2016-03-24 00:01:57 +00:00
|
|
|
#include <list>
|
|
|
|
#include "boo/audiodev/IAudioVoice.hpp"
|
|
|
|
#include "AudioMatrix.hpp"
|
2016-03-23 07:01:25 +00:00
|
|
|
|
|
|
|
namespace boo
|
|
|
|
{
|
2016-03-24 00:01:57 +00:00
|
|
|
class BaseAudioVoiceEngine;
|
|
|
|
struct AudioVoiceEngineMixInfo;
|
2016-05-07 22:11:45 +00:00
|
|
|
class IAudioMix;
|
2016-03-23 07:01:25 +00:00
|
|
|
|
2016-03-24 00:01:57 +00:00
|
|
|
class AudioVoice : public IAudioVoice
|
2016-03-23 07:01:25 +00:00
|
|
|
{
|
2016-03-24 00:01:57 +00:00
|
|
|
friend class BaseAudioVoiceEngine;
|
2016-05-07 04:28:32 +00:00
|
|
|
friend class AudioSubmix;
|
2016-03-24 00:01:57 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
/* Mixer-engine relationships */
|
2016-05-07 22:11:45 +00:00
|
|
|
BaseAudioVoiceEngine& m_root;
|
|
|
|
IAudioMix& m_parent;
|
2016-03-24 00:01:57 +00:00
|
|
|
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-03-24 00:01:57 +00:00
|
|
|
bool m_dynamicRate;
|
|
|
|
|
|
|
|
/* Running bool */
|
|
|
|
bool m_running = false;
|
|
|
|
|
2016-05-11 21:29:11 +00:00
|
|
|
/* 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;
|
|
|
|
void _setPitchRatio(double ratio);
|
|
|
|
|
|
|
|
/* Mid-pump update */
|
|
|
|
void _midUpdate();
|
|
|
|
|
2016-03-24 00:01:57 +00:00
|
|
|
virtual size_t pumpAndMix(const AudioVoiceEngineMixInfo& mixInfo, size_t frames, int16_t* buf)=0;
|
|
|
|
virtual size_t pumpAndMix(const AudioVoiceEngineMixInfo& mixInfo, size_t frames, int32_t* buf)=0;
|
|
|
|
virtual size_t pumpAndMix(const AudioVoiceEngineMixInfo& mixInfo, size_t frames, float* buf)=0;
|
2016-05-07 22:11:45 +00:00
|
|
|
AudioVoice(BaseAudioVoiceEngine& root, IAudioMix& parent, IAudioVoiceCallback* cb, bool dynamicRate);
|
2016-03-24 00:01:57 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
~AudioVoice();
|
2016-05-11 21:29:11 +00:00
|
|
|
void resetSampleRate(double sampleRate);
|
2016-03-24 00:01:57 +00:00
|
|
|
void setPitchRatio(double ratio);
|
|
|
|
void start();
|
|
|
|
void stop();
|
|
|
|
void unbindVoice();
|
|
|
|
};
|
|
|
|
|
|
|
|
class AudioVoiceMono : public AudioVoice
|
|
|
|
{
|
|
|
|
AudioMatrixMono m_matrix;
|
2016-05-11 21:29:11 +00:00
|
|
|
void _resetSampleRate(double sampleRate);
|
2016-03-24 00:01:57 +00:00
|
|
|
|
|
|
|
static size_t SRCCallback(AudioVoiceMono* ctx,
|
|
|
|
int16_t** data, size_t requestedLen);
|
|
|
|
|
|
|
|
size_t pumpAndMix(const AudioVoiceEngineMixInfo& mixInfo, size_t frames, int16_t* buf);
|
|
|
|
size_t pumpAndMix(const AudioVoiceEngineMixInfo& mixInfo, size_t frames, int32_t* buf);
|
|
|
|
size_t pumpAndMix(const AudioVoiceEngineMixInfo& mixInfo, size_t frames, float* buf);
|
|
|
|
|
|
|
|
public:
|
2016-05-07 22:11:45 +00:00
|
|
|
AudioVoiceMono(BaseAudioVoiceEngine& root, IAudioMix& parent, IAudioVoiceCallback* cb,
|
2016-03-24 00:01:57 +00:00
|
|
|
double sampleRate, bool dynamicRate);
|
|
|
|
void setDefaultMatrixCoefficients();
|
|
|
|
void setMonoMatrixCoefficients(const float coefs[8]);
|
|
|
|
void setStereoMatrixCoefficients(const float coefs[8][2]);
|
|
|
|
};
|
|
|
|
|
|
|
|
class AudioVoiceStereo : public AudioVoice
|
|
|
|
{
|
|
|
|
AudioMatrixStereo m_matrix;
|
2016-05-11 21:29:11 +00:00
|
|
|
void _resetSampleRate(double sampleRate);
|
2016-03-24 00:01:57 +00:00
|
|
|
|
|
|
|
static size_t SRCCallback(AudioVoiceStereo* ctx,
|
|
|
|
int16_t** data, size_t requestedLen);
|
|
|
|
|
|
|
|
size_t pumpAndMix(const AudioVoiceEngineMixInfo& mixInfo, size_t frames, int16_t* buf);
|
|
|
|
size_t pumpAndMix(const AudioVoiceEngineMixInfo& mixInfo, size_t frames, int32_t* buf);
|
|
|
|
size_t pumpAndMix(const AudioVoiceEngineMixInfo& mixInfo, size_t frames, float* buf);
|
|
|
|
|
|
|
|
public:
|
2016-05-07 22:11:45 +00:00
|
|
|
AudioVoiceStereo(BaseAudioVoiceEngine& root, IAudioMix& parent, IAudioVoiceCallback* cb,
|
2016-03-24 00:01:57 +00:00
|
|
|
double sampleRate, bool dynamicRate);
|
|
|
|
void setDefaultMatrixCoefficients();
|
|
|
|
void setMonoMatrixCoefficients(const float coefs[8]);
|
|
|
|
void setStereoMatrixCoefficients(const float coefs[8][2]);
|
2016-03-23 07:01:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // BOO_AUDIOVOICE_HPP
|