2016-01-28 23:53:51 +00:00
|
|
|
#include "boo/audiodev/AudioMatrix.hpp"
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
namespace boo
|
|
|
|
{
|
|
|
|
|
|
|
|
void AudioMatrixMono::setDefaultMatrixCoefficients()
|
|
|
|
{
|
|
|
|
memset(m_coefs, 0, sizeof(m_coefs));
|
|
|
|
switch (m_setOut)
|
|
|
|
{
|
|
|
|
case AudioChannelSet::Stereo:
|
|
|
|
case AudioChannelSet::Quad:
|
2016-03-08 07:09:58 +00:00
|
|
|
m_coefs[int(AudioChannel::FrontLeft)] = 1.0;
|
|
|
|
m_coefs[int(AudioChannel::FrontRight)] = 1.0;
|
2016-01-28 23:53:51 +00:00
|
|
|
break;
|
|
|
|
case AudioChannelSet::Surround51:
|
|
|
|
case AudioChannelSet::Surround71:
|
2016-03-08 07:09:58 +00:00
|
|
|
m_coefs[int(AudioChannel::FrontCenter)] = 1.0;
|
2016-01-28 23:53:51 +00:00
|
|
|
break;
|
2016-03-08 07:09:58 +00:00
|
|
|
default: break;
|
2016-01-28 23:53:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioMatrixMono::bufferMonoSampleData(IAudioVoice& voice, const int16_t* data, size_t samples)
|
|
|
|
{
|
|
|
|
const ChannelMap& chmap = voice.channelMap();
|
|
|
|
m_interleaveBuf.clear();
|
|
|
|
m_interleaveBuf.reserve(samples * chmap.m_channelCount);
|
|
|
|
for (size_t s=0 ; s<samples ; ++s, ++data)
|
2016-03-08 20:28:44 +00:00
|
|
|
for (unsigned c=0 ; c<chmap.m_channelCount ; ++c)
|
2016-01-29 01:17:19 +00:00
|
|
|
{
|
|
|
|
AudioChannel ch = chmap.m_channels[c];
|
|
|
|
if (ch == AudioChannel::Unknown)
|
|
|
|
m_interleaveBuf.push_back(0);
|
|
|
|
else
|
2016-03-08 07:09:58 +00:00
|
|
|
m_interleaveBuf.push_back(data[0] * m_coefs[int(ch)]);
|
2016-01-29 01:17:19 +00:00
|
|
|
}
|
2016-01-28 23:53:51 +00:00
|
|
|
voice.bufferSampleData(m_interleaveBuf.data(), samples);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioMatrixStereo::setDefaultMatrixCoefficients()
|
|
|
|
{
|
|
|
|
memset(m_coefs, 0, sizeof(m_coefs));
|
|
|
|
switch (m_setOut)
|
|
|
|
{
|
|
|
|
case AudioChannelSet::Stereo:
|
|
|
|
case AudioChannelSet::Quad:
|
2016-03-08 07:09:58 +00:00
|
|
|
m_coefs[int(AudioChannel::FrontLeft)][0] = 1.0;
|
|
|
|
m_coefs[int(AudioChannel::FrontRight)][1] = 1.0;
|
2016-01-28 23:53:51 +00:00
|
|
|
break;
|
|
|
|
case AudioChannelSet::Surround51:
|
|
|
|
case AudioChannelSet::Surround71:
|
2016-03-08 07:09:58 +00:00
|
|
|
m_coefs[int(AudioChannel::FrontLeft)][0] = 1.0;
|
|
|
|
m_coefs[int(AudioChannel::FrontRight)][1] = 1.0;
|
2016-01-28 23:53:51 +00:00
|
|
|
break;
|
2016-03-08 07:09:58 +00:00
|
|
|
default: break;
|
2016-01-28 23:53:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioMatrixStereo::bufferStereoSampleData(IAudioVoice& voice, const int16_t* data, size_t frames)
|
|
|
|
{
|
|
|
|
const ChannelMap& chmap = voice.channelMap();
|
|
|
|
m_interleaveBuf.clear();
|
|
|
|
m_interleaveBuf.reserve(frames * chmap.m_channelCount);
|
|
|
|
for (size_t f=0 ; f<frames ; ++f, data += 2)
|
2016-03-08 20:28:44 +00:00
|
|
|
for (unsigned c=0 ; c<chmap.m_channelCount ; ++c)
|
2016-01-29 01:17:19 +00:00
|
|
|
{
|
|
|
|
AudioChannel ch = chmap.m_channels[c];
|
|
|
|
if (ch == AudioChannel::Unknown)
|
|
|
|
m_interleaveBuf.push_back(0);
|
|
|
|
else
|
2016-03-08 07:09:58 +00:00
|
|
|
m_interleaveBuf.push_back(data[0] * m_coefs[int(ch)][0] +
|
|
|
|
data[1] * m_coefs[int(ch)][1]);
|
2016-01-29 01:17:19 +00:00
|
|
|
}
|
2016-01-28 23:53:51 +00:00
|
|
|
voice.bufferSampleData(m_interleaveBuf.data(), frames);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|