boo/lib/audiodev/AudioMatrix.cpp

81 lines
2.5 KiB
C++
Raw Normal View History

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:
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:
m_coefs[int(AudioChannel::FrontCenter)] = 1.0;
2016-01-28 23:53:51 +00:00
break;
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)
for (unsigned c=0 ; c<chmap.m_channelCount ; ++c)
{
AudioChannel ch = chmap.m_channels[c];
if (ch == AudioChannel::Unknown)
m_interleaveBuf.push_back(0);
else
m_interleaveBuf.push_back(data[0] * m_coefs[int(ch)]);
}
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:
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:
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;
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)
for (unsigned c=0 ; c<chmap.m_channelCount ; ++c)
{
AudioChannel ch = chmap.m_channels[c];
if (ch == AudioChannel::Unknown)
m_interleaveBuf.push_back(0);
else
m_interleaveBuf.push_back(data[0] * m_coefs[int(ch)][0] +
data[1] * m_coefs[int(ch)][1]);
}
2016-01-28 23:53:51 +00:00
voice.bufferSampleData(m_interleaveBuf.data(), frames);
}
}