2016-03-24 00:01:57 +00:00
|
|
|
#ifndef BOO_AUDIOMATRIX_HPP
|
|
|
|
#define BOO_AUDIOMATRIX_HPP
|
|
|
|
|
|
|
|
#include "boo/audiodev/IAudioVoice.hpp"
|
|
|
|
#include <vector>
|
|
|
|
#include <stdint.h>
|
2016-05-07 04:28:32 +00:00
|
|
|
#include <limits.h>
|
2016-03-24 00:01:57 +00:00
|
|
|
|
|
|
|
namespace boo
|
|
|
|
{
|
|
|
|
struct AudioVoiceEngineMixInfo;
|
|
|
|
|
2016-05-07 04:28:32 +00:00
|
|
|
static inline int16_t Clamp16(float in)
|
|
|
|
{
|
|
|
|
if (in < SHRT_MIN)
|
|
|
|
return SHRT_MIN;
|
|
|
|
else if (in > SHRT_MAX)
|
|
|
|
return SHRT_MAX;
|
|
|
|
return in;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int32_t Clamp32(float in)
|
|
|
|
{
|
|
|
|
if (in < INT_MIN)
|
|
|
|
return INT_MIN;
|
|
|
|
else if (in > INT_MAX)
|
|
|
|
return INT_MAX;
|
|
|
|
return in;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline float ClampFlt(float in)
|
|
|
|
{
|
|
|
|
if (in < -1.f)
|
|
|
|
return -1.f;
|
|
|
|
else if (in > 1.f)
|
|
|
|
return 1.f;
|
|
|
|
return in;
|
|
|
|
}
|
|
|
|
|
2016-03-24 00:01:57 +00:00
|
|
|
class AudioMatrixMono
|
|
|
|
{
|
2016-05-21 21:45:55 +00:00
|
|
|
float m_coefs[8] = {};
|
|
|
|
float m_oldCoefs[8] = {};
|
|
|
|
size_t m_slewFrames = 0;
|
|
|
|
size_t m_curSlewFrame = 0;
|
2016-03-24 00:01:57 +00:00
|
|
|
public:
|
|
|
|
AudioMatrixMono() {setDefaultMatrixCoefficients(AudioChannelSet::Stereo);}
|
|
|
|
|
|
|
|
void setDefaultMatrixCoefficients(AudioChannelSet acSet);
|
2016-05-21 21:45:55 +00:00
|
|
|
void setMatrixCoefficients(const float coefs[8], size_t slewFrames=0)
|
2016-03-24 00:01:57 +00:00
|
|
|
{
|
2016-05-21 21:45:55 +00:00
|
|
|
m_slewFrames = slewFrames;
|
|
|
|
m_curSlewFrame = 0;
|
2016-03-24 00:01:57 +00:00
|
|
|
for (int i=0 ; i<8 ; ++i)
|
2016-05-21 21:45:55 +00:00
|
|
|
{
|
2016-05-21 22:18:15 +00:00
|
|
|
m_oldCoefs[i] = m_coefs[i];
|
2016-03-24 00:01:57 +00:00
|
|
|
m_coefs[i] = coefs[i];
|
2016-05-21 21:45:55 +00:00
|
|
|
}
|
2016-03-24 00:01:57 +00:00
|
|
|
}
|
|
|
|
|
2016-05-16 20:21:20 +00:00
|
|
|
int16_t* mixMonoSampleData(const AudioVoiceEngineMixInfo& info,
|
2016-05-21 21:45:55 +00:00
|
|
|
const int16_t* dataIn, int16_t* dataOut, size_t samples);
|
2016-05-16 20:21:20 +00:00
|
|
|
int32_t* mixMonoSampleData(const AudioVoiceEngineMixInfo& info,
|
2016-05-21 21:45:55 +00:00
|
|
|
const int32_t* dataIn, int32_t* dataOut, size_t samples);
|
2016-05-16 20:21:20 +00:00
|
|
|
float* mixMonoSampleData(const AudioVoiceEngineMixInfo& info,
|
2016-05-21 21:45:55 +00:00
|
|
|
const float* dataIn, float* dataOut, size_t samples);
|
2016-03-24 00:01:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class AudioMatrixStereo
|
|
|
|
{
|
2016-05-21 21:45:55 +00:00
|
|
|
float m_coefs[8][2] = {};
|
|
|
|
float m_oldCoefs[8][2] = {};
|
|
|
|
size_t m_slewFrames = 0;
|
|
|
|
size_t m_curSlewFrame = 0;
|
2016-03-24 00:01:57 +00:00
|
|
|
public:
|
|
|
|
AudioMatrixStereo() {setDefaultMatrixCoefficients(AudioChannelSet::Stereo);}
|
|
|
|
|
|
|
|
void setDefaultMatrixCoefficients(AudioChannelSet acSet);
|
2016-05-21 21:45:55 +00:00
|
|
|
void setMatrixCoefficients(const float coefs[8][2], size_t slewFrames=0)
|
2016-03-24 00:01:57 +00:00
|
|
|
{
|
2016-05-21 21:45:55 +00:00
|
|
|
m_slewFrames = slewFrames;
|
|
|
|
m_curSlewFrame = 0;
|
2016-03-24 00:01:57 +00:00
|
|
|
for (int i=0 ; i<8 ; ++i)
|
|
|
|
{
|
2016-05-21 22:18:15 +00:00
|
|
|
m_oldCoefs[i][0] = m_coefs[i][0];
|
|
|
|
m_oldCoefs[i][1] = m_coefs[i][1];
|
2016-03-24 00:01:57 +00:00
|
|
|
m_coefs[i][0] = coefs[i][0];
|
|
|
|
m_coefs[i][1] = coefs[i][1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-16 20:21:20 +00:00
|
|
|
int16_t* mixStereoSampleData(const AudioVoiceEngineMixInfo& info,
|
2016-05-21 21:45:55 +00:00
|
|
|
const int16_t* dataIn, int16_t* dataOut, size_t frames);
|
2016-05-16 20:21:20 +00:00
|
|
|
int32_t* mixStereoSampleData(const AudioVoiceEngineMixInfo& info,
|
2016-05-21 21:45:55 +00:00
|
|
|
const int32_t* dataIn, int32_t* dataOut, size_t frames);
|
2016-05-16 20:21:20 +00:00
|
|
|
float* mixStereoSampleData(const AudioVoiceEngineMixInfo& info,
|
2016-05-21 21:45:55 +00:00
|
|
|
const float* dataIn, float* dataOut, size_t frames);
|
2016-03-24 00:01:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // BOO_AUDIOMATRIX_HPP
|