2016-03-24 00:01:57 +00:00
|
|
|
#include "AudioVoice.hpp"
|
|
|
|
#include "AudioVoiceEngine.hpp"
|
|
|
|
#include "logvisor/logvisor.hpp"
|
|
|
|
|
|
|
|
namespace boo
|
|
|
|
{
|
|
|
|
static logvisor::Module Log("boo::AudioVoice");
|
|
|
|
|
2016-12-14 01:08:42 +00:00
|
|
|
static AudioMatrixMono DefaultMonoMtx;
|
|
|
|
static AudioMatrixStereo DefaultStereoMtx;
|
|
|
|
|
2016-07-13 03:03:52 +00:00
|
|
|
AudioVoice::AudioVoice(BaseAudioVoiceEngine& root,
|
2016-05-07 22:11:45 +00:00
|
|
|
IAudioVoiceCallback* cb, bool dynamicRate)
|
2016-07-13 03:03:52 +00:00
|
|
|
: m_root(root), m_cb(cb), m_dynamicRate(dynamicRate) {}
|
2016-03-24 00:01:57 +00:00
|
|
|
|
|
|
|
AudioVoice::~AudioVoice()
|
|
|
|
{
|
|
|
|
unbindVoice();
|
|
|
|
soxr_delete(m_src);
|
|
|
|
}
|
|
|
|
|
2016-05-17 03:46:03 +00:00
|
|
|
void AudioVoice::_setPitchRatio(double ratio, bool slew)
|
2016-03-24 00:01:57 +00:00
|
|
|
{
|
|
|
|
if (m_dynamicRate)
|
|
|
|
{
|
2016-05-19 10:14:21 +00:00
|
|
|
soxr_error_t err = soxr_set_io_ratio(m_src, ratio * m_sampleRateIn / m_sampleRateOut, slew ? m_root.m_5msFrames : 0);
|
2016-03-24 00:01:57 +00:00
|
|
|
if (err)
|
|
|
|
{
|
|
|
|
Log.report(logvisor::Fatal, "unable to set resampler rate: %s", soxr_strerror(err));
|
2016-05-11 21:29:11 +00:00
|
|
|
m_setPitchRatio = false;
|
2016-03-24 00:01:57 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2016-05-11 21:29:11 +00:00
|
|
|
m_setPitchRatio = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioVoice::_midUpdate()
|
|
|
|
{
|
|
|
|
if (m_resetSampleRate)
|
|
|
|
_resetSampleRate(m_deferredSampleRate);
|
|
|
|
if (m_setPitchRatio)
|
2016-05-17 03:46:03 +00:00
|
|
|
_setPitchRatio(m_pitchRatio, m_slew);
|
2016-05-11 21:29:11 +00:00
|
|
|
}
|
|
|
|
|
2016-05-17 03:46:03 +00:00
|
|
|
void AudioVoice::setPitchRatio(double ratio, bool slew)
|
2016-05-11 21:29:11 +00:00
|
|
|
{
|
|
|
|
m_setPitchRatio = true;
|
|
|
|
m_pitchRatio = ratio;
|
2016-05-17 03:46:03 +00:00
|
|
|
m_slew = slew;
|
2016-05-11 21:29:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AudioVoice::resetSampleRate(double sampleRate)
|
|
|
|
{
|
|
|
|
m_resetSampleRate = true;
|
|
|
|
m_deferredSampleRate = sampleRate;
|
2016-03-24 00:01:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AudioVoice::start()
|
|
|
|
{
|
|
|
|
m_running = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioVoice::stop()
|
|
|
|
{
|
|
|
|
m_running = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioVoice::unbindVoice()
|
|
|
|
{
|
|
|
|
if (m_bound)
|
|
|
|
{
|
2016-07-13 03:03:52 +00:00
|
|
|
m_root._unbindFrom(m_parentIt);
|
2016-03-24 00:01:57 +00:00
|
|
|
m_bound = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-13 03:03:52 +00:00
|
|
|
AudioVoiceMono::AudioVoiceMono(BaseAudioVoiceEngine& root, IAudioVoiceCallback* cb,
|
2016-03-24 00:01:57 +00:00
|
|
|
double sampleRate, bool dynamicRate)
|
2016-07-13 03:03:52 +00:00
|
|
|
: AudioVoice(root, cb, dynamicRate)
|
2016-03-24 00:01:57 +00:00
|
|
|
{
|
2016-05-11 21:29:11 +00:00
|
|
|
_resetSampleRate(sampleRate);
|
2016-05-11 04:50:26 +00:00
|
|
|
}
|
|
|
|
|
2016-05-11 21:29:11 +00:00
|
|
|
void AudioVoiceMono::_resetSampleRate(double sampleRate)
|
2016-05-11 04:50:26 +00:00
|
|
|
{
|
|
|
|
soxr_delete(m_src);
|
|
|
|
|
2016-07-13 03:03:52 +00:00
|
|
|
double rateOut = m_root.mixInfo().m_sampleRate;
|
|
|
|
soxr_datatype_t formatOut = m_root.mixInfo().m_sampleFormat;
|
2016-06-17 06:01:36 +00:00
|
|
|
soxr_io_spec_t ioSpec = soxr_io_spec(SOXR_INT16_I, formatOut);
|
2016-05-11 04:50:26 +00:00
|
|
|
soxr_quality_spec_t qSpec = soxr_quality_spec(SOXR_20_BITQ, m_dynamicRate ? SOXR_VR : 0);
|
2016-03-24 00:01:57 +00:00
|
|
|
|
|
|
|
soxr_error_t err;
|
2016-07-07 19:18:57 +00:00
|
|
|
m_src = soxr_create(sampleRate, rateOut, 1,
|
2016-03-24 00:01:57 +00:00
|
|
|
&err, &ioSpec, &qSpec, nullptr);
|
|
|
|
|
|
|
|
if (err)
|
|
|
|
{
|
|
|
|
Log.report(logvisor::Fatal, "unable to create soxr resampler: %s", soxr_strerror(err));
|
2016-05-11 21:29:11 +00:00
|
|
|
m_resetSampleRate = false;
|
2016-03-24 00:01:57 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-05-16 02:41:11 +00:00
|
|
|
m_sampleRateIn = sampleRate;
|
|
|
|
m_sampleRateOut = rateOut;
|
2016-03-24 00:01:57 +00:00
|
|
|
soxr_set_input_fn(m_src, soxr_input_fn_t(SRCCallback), this, 0);
|
2016-05-17 03:46:03 +00:00
|
|
|
_setPitchRatio(m_pitchRatio, false);
|
2016-05-11 21:29:11 +00:00
|
|
|
m_resetSampleRate = false;
|
2016-03-24 00:01:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t AudioVoiceMono::SRCCallback(AudioVoiceMono* ctx, int16_t** data, size_t frames)
|
|
|
|
{
|
2016-05-07 22:11:45 +00:00
|
|
|
std::vector<int16_t>& scratchIn = ctx->m_root.m_scratchIn;
|
2016-03-24 00:01:57 +00:00
|
|
|
if (scratchIn.size() < frames)
|
|
|
|
scratchIn.resize(frames);
|
|
|
|
*data = scratchIn.data();
|
2016-06-17 06:01:36 +00:00
|
|
|
if (ctx->m_silentOut)
|
|
|
|
{
|
|
|
|
memset(*data, 0, frames * 2);
|
|
|
|
return frames;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return ctx->m_cb->supplyAudio(*ctx, frames, scratchIn.data());
|
2016-03-24 00:01:57 +00:00
|
|
|
}
|
|
|
|
|
2016-07-13 03:03:52 +00:00
|
|
|
size_t AudioVoiceMono::pumpAndMix16(size_t frames)
|
2016-03-24 00:01:57 +00:00
|
|
|
{
|
2016-07-14 04:59:41 +00:00
|
|
|
std::vector<int16_t>& scratch16Pre = m_root.m_scratch16Pre;
|
|
|
|
if (scratch16Pre.size() < frames)
|
|
|
|
scratch16Pre.resize(frames);
|
2016-03-24 00:01:57 +00:00
|
|
|
|
2016-07-14 04:59:41 +00:00
|
|
|
std::vector<int16_t>& scratch16Post = m_root.m_scratch16Post;
|
|
|
|
if (scratch16Post.size() < frames)
|
|
|
|
scratch16Post.resize(frames);
|
|
|
|
|
|
|
|
double dt = frames / m_sampleRateOut;
|
|
|
|
m_cb->preSupplyAudio(*this, dt);
|
2016-05-19 10:14:21 +00:00
|
|
|
_midUpdate();
|
2016-07-14 04:59:41 +00:00
|
|
|
size_t oDone = soxr_output(m_src, scratch16Pre.data(), frames);
|
2016-03-24 00:01:57 +00:00
|
|
|
|
2016-05-19 10:14:21 +00:00
|
|
|
if (oDone)
|
2016-05-31 05:16:29 +00:00
|
|
|
{
|
2016-12-14 01:08:42 +00:00
|
|
|
if (m_sendMatrices.size())
|
|
|
|
{
|
|
|
|
for (auto& mtx : m_sendMatrices)
|
|
|
|
{
|
|
|
|
AudioSubmix& smx = *reinterpret_cast<AudioSubmix*>(mtx.first);
|
|
|
|
m_cb->routeAudio(oDone, 1, dt, smx.m_busId, scratch16Pre.data(), scratch16Post.data());
|
2017-09-28 03:11:40 +00:00
|
|
|
mtx.second.mixMonoSampleData(m_root.clientMixInfo(), scratch16Post.data(), smx._getMergeBuf16(oDone), oDone);
|
2016-12-14 01:08:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2016-07-13 03:03:52 +00:00
|
|
|
{
|
2016-12-14 01:08:42 +00:00
|
|
|
AudioSubmix& smx = reinterpret_cast<AudioSubmix&>(m_root.m_mainSubmix);
|
|
|
|
m_cb->routeAudio(oDone, 1, dt, m_root.m_mainSubmix.m_busId, scratch16Pre.data(), scratch16Post.data());
|
2017-09-28 03:11:40 +00:00
|
|
|
DefaultMonoMtx.mixMonoSampleData(m_root.clientMixInfo(), scratch16Post.data(), smx._getMergeBuf16(oDone), oDone);
|
2016-07-13 03:03:52 +00:00
|
|
|
}
|
2016-05-31 05:16:29 +00:00
|
|
|
}
|
2016-05-19 10:14:21 +00:00
|
|
|
|
|
|
|
return oDone;
|
2016-03-24 00:01:57 +00:00
|
|
|
}
|
|
|
|
|
2016-07-13 03:03:52 +00:00
|
|
|
size_t AudioVoiceMono::pumpAndMix32(size_t frames)
|
2016-03-24 00:01:57 +00:00
|
|
|
{
|
2016-07-14 04:59:41 +00:00
|
|
|
std::vector<int32_t>& scratch32Pre = m_root.m_scratch32Pre;
|
|
|
|
if (scratch32Pre.size() < frames)
|
|
|
|
scratch32Pre.resize(frames);
|
|
|
|
|
|
|
|
std::vector<int32_t>& scratch32Post = m_root.m_scratch32Post;
|
|
|
|
if (scratch32Post.size() < frames)
|
|
|
|
scratch32Post.resize(frames);
|
2016-03-24 00:01:57 +00:00
|
|
|
|
2016-07-14 04:59:41 +00:00
|
|
|
double dt = frames / m_sampleRateOut;
|
|
|
|
m_cb->preSupplyAudio(*this, dt);
|
2016-05-19 10:14:21 +00:00
|
|
|
_midUpdate();
|
2016-07-14 04:59:41 +00:00
|
|
|
size_t oDone = soxr_output(m_src, scratch32Pre.data(), frames);
|
2016-05-19 10:14:21 +00:00
|
|
|
|
|
|
|
if (oDone)
|
2016-05-31 05:16:29 +00:00
|
|
|
{
|
2016-12-14 01:08:42 +00:00
|
|
|
if (m_sendMatrices.size())
|
2016-07-13 03:03:52 +00:00
|
|
|
{
|
2016-12-14 01:08:42 +00:00
|
|
|
for (auto& mtx : m_sendMatrices)
|
|
|
|
{
|
|
|
|
AudioSubmix& smx = *reinterpret_cast<AudioSubmix*>(mtx.first);
|
|
|
|
m_cb->routeAudio(oDone, 1, dt, smx.m_busId, scratch32Pre.data(), scratch32Post.data());
|
2017-09-28 03:11:40 +00:00
|
|
|
mtx.second.mixMonoSampleData(m_root.clientMixInfo(), scratch32Post.data(), smx._getMergeBuf32(oDone), oDone);
|
2016-12-14 01:08:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
AudioSubmix& smx = reinterpret_cast<AudioSubmix&>(m_root.m_mainSubmix);
|
|
|
|
m_cb->routeAudio(oDone, 1, dt, m_root.m_mainSubmix.m_busId, scratch32Pre.data(), scratch32Post.data());
|
2017-09-28 03:11:40 +00:00
|
|
|
DefaultMonoMtx.mixMonoSampleData(m_root.clientMixInfo(), scratch32Post.data(), smx._getMergeBuf32(oDone), oDone);
|
2016-07-13 03:03:52 +00:00
|
|
|
}
|
2016-05-31 05:16:29 +00:00
|
|
|
}
|
2016-03-24 00:01:57 +00:00
|
|
|
|
2016-05-19 10:14:21 +00:00
|
|
|
return oDone;
|
2016-03-24 00:01:57 +00:00
|
|
|
}
|
|
|
|
|
2016-07-13 03:03:52 +00:00
|
|
|
size_t AudioVoiceMono::pumpAndMixFlt(size_t frames)
|
2016-03-24 00:01:57 +00:00
|
|
|
{
|
2016-07-14 04:59:41 +00:00
|
|
|
std::vector<float>& scratchFltPre = m_root.m_scratchFltPre;
|
|
|
|
if (scratchFltPre.size() < frames)
|
|
|
|
scratchFltPre.resize(frames + 2);
|
|
|
|
|
|
|
|
std::vector<float>& scratchFltPost = m_root.m_scratchFltPost;
|
|
|
|
if (scratchFltPost.size() < frames)
|
|
|
|
scratchFltPost.resize(frames + 2);
|
2016-03-24 00:01:57 +00:00
|
|
|
|
2016-07-14 04:59:41 +00:00
|
|
|
double dt = frames / m_sampleRateOut;
|
|
|
|
m_cb->preSupplyAudio(*this, dt);
|
2016-05-19 10:14:21 +00:00
|
|
|
_midUpdate();
|
2016-07-14 04:59:41 +00:00
|
|
|
size_t oDone = soxr_output(m_src, scratchFltPre.data(), frames);
|
2016-05-19 10:14:21 +00:00
|
|
|
|
|
|
|
if (oDone)
|
2016-05-31 05:16:29 +00:00
|
|
|
{
|
2016-12-14 01:08:42 +00:00
|
|
|
if (m_sendMatrices.size())
|
|
|
|
{
|
|
|
|
for (auto& mtx : m_sendMatrices)
|
|
|
|
{
|
|
|
|
AudioSubmix& smx = *reinterpret_cast<AudioSubmix*>(mtx.first);
|
|
|
|
m_cb->routeAudio(oDone, 1, dt, smx.m_busId, scratchFltPre.data(), scratchFltPost.data());
|
2017-09-28 03:11:40 +00:00
|
|
|
mtx.second.mixMonoSampleData(m_root.clientMixInfo(), scratchFltPost.data(), smx._getMergeBufFlt(oDone), oDone);
|
2016-12-14 01:08:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2016-07-13 03:03:52 +00:00
|
|
|
{
|
2016-12-14 01:08:42 +00:00
|
|
|
AudioSubmix& smx = reinterpret_cast<AudioSubmix&>(m_root.m_mainSubmix);
|
|
|
|
m_cb->routeAudio(oDone, 1, dt, m_root.m_mainSubmix.m_busId, scratchFltPre.data(), scratchFltPost.data());
|
2017-09-28 03:11:40 +00:00
|
|
|
DefaultMonoMtx.mixMonoSampleData(m_root.clientMixInfo(), scratchFltPost.data(), smx._getMergeBufFlt(oDone), oDone);
|
2016-07-13 03:03:52 +00:00
|
|
|
}
|
2016-05-31 05:16:29 +00:00
|
|
|
}
|
2016-03-24 00:01:57 +00:00
|
|
|
|
2016-05-19 10:14:21 +00:00
|
|
|
return oDone;
|
2016-03-24 00:01:57 +00:00
|
|
|
}
|
|
|
|
|
2016-07-13 03:03:52 +00:00
|
|
|
void AudioVoiceMono::resetChannelLevels()
|
2016-03-24 00:01:57 +00:00
|
|
|
{
|
2016-07-13 03:03:52 +00:00
|
|
|
m_root.m_submixesDirty = true;
|
|
|
|
m_sendMatrices.clear();
|
2016-03-24 00:01:57 +00:00
|
|
|
}
|
|
|
|
|
2016-07-13 03:03:52 +00:00
|
|
|
void AudioVoiceMono::setMonoChannelLevels(IAudioSubmix* submix, const float coefs[8], bool slew)
|
2016-03-24 00:01:57 +00:00
|
|
|
{
|
2017-01-16 08:39:56 +00:00
|
|
|
if (!submix)
|
|
|
|
submix = &m_root.m_mainSubmix;
|
|
|
|
|
2016-07-13 03:03:52 +00:00
|
|
|
auto search = m_sendMatrices.find(submix);
|
|
|
|
if (search == m_sendMatrices.cend())
|
|
|
|
search = m_sendMatrices.emplace(submix, AudioMatrixMono{}).first;
|
|
|
|
search->second.setMatrixCoefficients(coefs, slew ? m_root.m_5msFrames : 0);
|
2016-03-24 00:01:57 +00:00
|
|
|
}
|
|
|
|
|
2016-07-13 03:03:52 +00:00
|
|
|
void AudioVoiceMono::setStereoChannelLevels(IAudioSubmix* submix, const float coefs[8][2], bool slew)
|
2016-03-24 00:01:57 +00:00
|
|
|
{
|
|
|
|
float newCoefs[8] =
|
|
|
|
{
|
|
|
|
coefs[0][0],
|
|
|
|
coefs[1][0],
|
|
|
|
coefs[2][0],
|
|
|
|
coefs[3][0],
|
|
|
|
coefs[4][0],
|
|
|
|
coefs[5][0],
|
|
|
|
coefs[6][0],
|
|
|
|
coefs[7][0]
|
|
|
|
};
|
2016-05-31 05:16:29 +00:00
|
|
|
|
2017-01-16 08:39:56 +00:00
|
|
|
if (!submix)
|
|
|
|
submix = &m_root.m_mainSubmix;
|
|
|
|
|
2016-07-13 03:03:52 +00:00
|
|
|
auto search = m_sendMatrices.find(submix);
|
|
|
|
if (search == m_sendMatrices.cend())
|
|
|
|
search = m_sendMatrices.emplace(submix, AudioMatrixMono{}).first;
|
|
|
|
search->second.setMatrixCoefficients(newCoefs, slew ? m_root.m_5msFrames : 0);
|
2016-05-31 05:16:29 +00:00
|
|
|
}
|
|
|
|
|
2016-07-13 03:03:52 +00:00
|
|
|
AudioVoiceStereo::AudioVoiceStereo(BaseAudioVoiceEngine& root, IAudioVoiceCallback* cb,
|
2016-03-24 00:01:57 +00:00
|
|
|
double sampleRate, bool dynamicRate)
|
2016-07-13 03:03:52 +00:00
|
|
|
: AudioVoice(root, cb, dynamicRate)
|
2016-03-24 00:01:57 +00:00
|
|
|
{
|
2016-05-11 21:29:11 +00:00
|
|
|
_resetSampleRate(sampleRate);
|
2016-05-11 04:50:26 +00:00
|
|
|
}
|
|
|
|
|
2016-05-11 21:29:11 +00:00
|
|
|
void AudioVoiceStereo::_resetSampleRate(double sampleRate)
|
2016-05-11 04:50:26 +00:00
|
|
|
{
|
|
|
|
soxr_delete(m_src);
|
|
|
|
|
2016-07-13 03:03:52 +00:00
|
|
|
double rateOut = m_root.mixInfo().m_sampleRate;
|
|
|
|
soxr_datatype_t formatOut = m_root.mixInfo().m_sampleFormat;
|
2016-06-17 06:01:36 +00:00
|
|
|
soxr_io_spec_t ioSpec = soxr_io_spec(SOXR_INT16_I, formatOut);
|
2016-05-11 04:50:26 +00:00
|
|
|
soxr_quality_spec_t qSpec = soxr_quality_spec(SOXR_20_BITQ, m_dynamicRate ? SOXR_VR : 0);
|
2016-03-24 00:01:57 +00:00
|
|
|
|
|
|
|
soxr_error_t err;
|
2016-05-16 02:41:11 +00:00
|
|
|
m_src = soxr_create(sampleRate, rateOut, 2,
|
2016-03-24 00:01:57 +00:00
|
|
|
&err, &ioSpec, &qSpec, nullptr);
|
|
|
|
|
|
|
|
if (!m_src)
|
|
|
|
{
|
|
|
|
Log.report(logvisor::Fatal, "unable to create soxr resampler: %s", soxr_strerror(err));
|
2016-05-11 21:29:11 +00:00
|
|
|
m_resetSampleRate = false;
|
2016-03-24 00:01:57 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-05-16 02:41:11 +00:00
|
|
|
m_sampleRateIn = sampleRate;
|
|
|
|
m_sampleRateOut = rateOut;
|
2016-03-24 00:01:57 +00:00
|
|
|
soxr_set_input_fn(m_src, soxr_input_fn_t(SRCCallback), this, 0);
|
2016-05-17 03:46:03 +00:00
|
|
|
_setPitchRatio(m_pitchRatio, false);
|
2016-05-11 21:29:11 +00:00
|
|
|
m_resetSampleRate = false;
|
2016-03-24 00:01:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t AudioVoiceStereo::SRCCallback(AudioVoiceStereo* ctx, int16_t** data, size_t frames)
|
|
|
|
{
|
2016-05-07 22:11:45 +00:00
|
|
|
std::vector<int16_t>& scratchIn = ctx->m_root.m_scratchIn;
|
2016-03-24 00:01:57 +00:00
|
|
|
size_t samples = frames * 2;
|
|
|
|
if (scratchIn.size() < samples)
|
|
|
|
scratchIn.resize(samples);
|
|
|
|
*data = scratchIn.data();
|
2016-06-17 06:01:36 +00:00
|
|
|
if (ctx->m_silentOut)
|
|
|
|
{
|
|
|
|
memset(*data, 0, samples * 2);
|
|
|
|
return frames;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return ctx->m_cb->supplyAudio(*ctx, frames, scratchIn.data());
|
2016-03-24 00:01:57 +00:00
|
|
|
}
|
|
|
|
|
2016-07-13 03:03:52 +00:00
|
|
|
size_t AudioVoiceStereo::pumpAndMix16(size_t frames)
|
2016-03-24 00:01:57 +00:00
|
|
|
{
|
|
|
|
size_t samples = frames * 2;
|
|
|
|
|
2016-07-14 04:59:41 +00:00
|
|
|
std::vector<int16_t>& scratch16Pre = m_root.m_scratch16Pre;
|
|
|
|
if (scratch16Pre.size() < samples)
|
|
|
|
scratch16Pre.resize(samples);
|
|
|
|
|
|
|
|
std::vector<int16_t>& scratch16Post = m_root.m_scratch16Post;
|
|
|
|
if (scratch16Post.size() < samples)
|
|
|
|
scratch16Post.resize(samples);
|
|
|
|
|
|
|
|
double dt = frames / m_sampleRateOut;
|
|
|
|
m_cb->preSupplyAudio(*this, dt);
|
2016-05-19 10:14:21 +00:00
|
|
|
_midUpdate();
|
2016-07-14 04:59:41 +00:00
|
|
|
size_t oDone = soxr_output(m_src, scratch16Pre.data(), frames);
|
2016-03-24 00:01:57 +00:00
|
|
|
|
2016-05-19 10:14:21 +00:00
|
|
|
if (oDone)
|
2016-05-31 05:16:29 +00:00
|
|
|
{
|
2016-12-14 01:08:42 +00:00
|
|
|
if (m_sendMatrices.size())
|
2016-07-13 03:03:52 +00:00
|
|
|
{
|
2016-12-14 01:08:42 +00:00
|
|
|
for (auto& mtx : m_sendMatrices)
|
|
|
|
{
|
|
|
|
AudioSubmix& smx = *reinterpret_cast<AudioSubmix*>(mtx.first);
|
|
|
|
m_cb->routeAudio(oDone, 2, dt, smx.m_busId, scratch16Pre.data(), scratch16Post.data());
|
2017-09-28 03:11:40 +00:00
|
|
|
mtx.second.mixStereoSampleData(m_root.clientMixInfo(), scratch16Post.data(), smx._getMergeBuf16(oDone), oDone);
|
2016-12-14 01:08:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
AudioSubmix& smx = reinterpret_cast<AudioSubmix&>(m_root.m_mainSubmix);
|
|
|
|
m_cb->routeAudio(oDone, 2, dt, m_root.m_mainSubmix.m_busId, scratch16Pre.data(), scratch16Post.data());
|
2017-09-28 03:11:40 +00:00
|
|
|
DefaultStereoMtx.mixStereoSampleData(m_root.clientMixInfo(), scratch16Post.data(), smx._getMergeBuf16(oDone), oDone);
|
2016-07-13 03:03:52 +00:00
|
|
|
}
|
2016-05-31 05:16:29 +00:00
|
|
|
}
|
2016-05-19 10:14:21 +00:00
|
|
|
|
|
|
|
return oDone;
|
2016-03-24 00:01:57 +00:00
|
|
|
}
|
|
|
|
|
2016-07-13 03:03:52 +00:00
|
|
|
size_t AudioVoiceStereo::pumpAndMix32(size_t frames)
|
2016-03-24 00:01:57 +00:00
|
|
|
{
|
|
|
|
size_t samples = frames * 2;
|
|
|
|
|
2016-07-14 04:59:41 +00:00
|
|
|
std::vector<int32_t>& scratch32Pre = m_root.m_scratch32Pre;
|
|
|
|
if (scratch32Pre.size() < samples)
|
|
|
|
scratch32Pre.resize(samples);
|
|
|
|
|
|
|
|
std::vector<int32_t>& scratch32Post = m_root.m_scratch32Post;
|
|
|
|
if (scratch32Post.size() < samples)
|
|
|
|
scratch32Post.resize(samples);
|
|
|
|
|
|
|
|
double dt = frames / m_sampleRateOut;
|
|
|
|
m_cb->preSupplyAudio(*this, dt);
|
2016-05-19 10:14:21 +00:00
|
|
|
_midUpdate();
|
2016-07-14 04:59:41 +00:00
|
|
|
size_t oDone = soxr_output(m_src, scratch32Pre.data(), frames);
|
2016-05-19 10:14:21 +00:00
|
|
|
|
|
|
|
if (oDone)
|
2016-05-31 05:16:29 +00:00
|
|
|
{
|
2016-12-14 01:08:42 +00:00
|
|
|
if (m_sendMatrices.size())
|
|
|
|
{
|
|
|
|
for (auto& mtx : m_sendMatrices)
|
|
|
|
{
|
|
|
|
AudioSubmix& smx = *reinterpret_cast<AudioSubmix*>(mtx.first);
|
|
|
|
m_cb->routeAudio(oDone, 2, dt, smx.m_busId, scratch32Pre.data(), scratch32Post.data());
|
2017-09-28 03:11:40 +00:00
|
|
|
mtx.second.mixStereoSampleData(m_root.clientMixInfo(), scratch32Post.data(), smx._getMergeBuf32(oDone), oDone);
|
2016-12-14 01:08:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2016-07-13 03:03:52 +00:00
|
|
|
{
|
2016-12-14 01:08:42 +00:00
|
|
|
AudioSubmix& smx = reinterpret_cast<AudioSubmix&>(m_root.m_mainSubmix);
|
|
|
|
m_cb->routeAudio(oDone, 2, dt, m_root.m_mainSubmix.m_busId, scratch32Pre.data(), scratch32Post.data());
|
2017-09-28 03:11:40 +00:00
|
|
|
DefaultStereoMtx.mixStereoSampleData(m_root.clientMixInfo(), scratch32Post.data(), smx._getMergeBuf32(oDone), oDone);
|
2016-07-13 03:03:52 +00:00
|
|
|
}
|
2016-05-31 05:16:29 +00:00
|
|
|
}
|
2016-03-24 00:01:57 +00:00
|
|
|
|
2016-05-19 10:14:21 +00:00
|
|
|
return oDone;
|
2016-03-24 00:01:57 +00:00
|
|
|
}
|
|
|
|
|
2016-07-13 03:03:52 +00:00
|
|
|
size_t AudioVoiceStereo::pumpAndMixFlt(size_t frames)
|
2016-03-24 00:01:57 +00:00
|
|
|
{
|
|
|
|
size_t samples = frames * 2;
|
|
|
|
|
2016-07-14 04:59:41 +00:00
|
|
|
std::vector<float>& scratchFltPre = m_root.m_scratchFltPre;
|
|
|
|
if (scratchFltPre.size() < samples)
|
|
|
|
scratchFltPre.resize(samples + 4);
|
|
|
|
|
|
|
|
std::vector<float>& scratchFltPost = m_root.m_scratchFltPost;
|
|
|
|
if (scratchFltPost.size() < samples)
|
|
|
|
scratchFltPost.resize(samples + 4);
|
|
|
|
|
|
|
|
double dt = frames / m_sampleRateOut;
|
|
|
|
m_cb->preSupplyAudio(*this, dt);
|
2016-05-19 10:14:21 +00:00
|
|
|
_midUpdate();
|
2016-07-14 04:59:41 +00:00
|
|
|
size_t oDone = soxr_output(m_src, scratchFltPre.data(), frames);
|
2016-05-19 10:14:21 +00:00
|
|
|
|
|
|
|
if (oDone)
|
2016-05-31 05:16:29 +00:00
|
|
|
{
|
2016-12-14 01:08:42 +00:00
|
|
|
if (m_sendMatrices.size())
|
|
|
|
{
|
|
|
|
for (auto& mtx : m_sendMatrices)
|
|
|
|
{
|
|
|
|
AudioSubmix& smx = *reinterpret_cast<AudioSubmix*>(mtx.first);
|
|
|
|
m_cb->routeAudio(oDone, 2, dt, smx.m_busId, scratchFltPre.data(), scratchFltPost.data());
|
2017-09-28 03:11:40 +00:00
|
|
|
mtx.second.mixStereoSampleData(m_root.clientMixInfo(), scratchFltPost.data(), smx._getMergeBufFlt(oDone), oDone);
|
2016-12-14 01:08:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2016-07-13 03:03:52 +00:00
|
|
|
{
|
2016-12-14 01:08:42 +00:00
|
|
|
AudioSubmix& smx = reinterpret_cast<AudioSubmix&>(m_root.m_mainSubmix);
|
|
|
|
m_cb->routeAudio(oDone, 2, dt, m_root.m_mainSubmix.m_busId, scratchFltPre.data(), scratchFltPost.data());
|
2017-09-28 03:11:40 +00:00
|
|
|
DefaultStereoMtx.mixStereoSampleData(m_root.clientMixInfo(), scratchFltPost.data(), smx._getMergeBufFlt(oDone), oDone);
|
2016-07-13 03:03:52 +00:00
|
|
|
}
|
2016-05-31 05:16:29 +00:00
|
|
|
}
|
2016-03-24 00:01:57 +00:00
|
|
|
|
2016-05-19 10:14:21 +00:00
|
|
|
return oDone;
|
2016-03-24 00:01:57 +00:00
|
|
|
}
|
|
|
|
|
2016-07-13 03:03:52 +00:00
|
|
|
void AudioVoiceStereo::resetChannelLevels()
|
2016-03-24 00:01:57 +00:00
|
|
|
{
|
2016-07-13 03:03:52 +00:00
|
|
|
m_root.m_submixesDirty = true;
|
|
|
|
m_sendMatrices.clear();
|
2016-03-24 00:01:57 +00:00
|
|
|
}
|
|
|
|
|
2016-07-13 03:03:52 +00:00
|
|
|
void AudioVoiceStereo::setMonoChannelLevels(IAudioSubmix* submix, const float coefs[8], bool slew)
|
2016-03-24 00:01:57 +00:00
|
|
|
{
|
|
|
|
float newCoefs[8][2] =
|
|
|
|
{
|
|
|
|
{coefs[0], coefs[0]},
|
|
|
|
{coefs[1], coefs[1]},
|
|
|
|
{coefs[2], coefs[2]},
|
|
|
|
{coefs[3], coefs[3]},
|
|
|
|
{coefs[4], coefs[4]},
|
|
|
|
{coefs[5], coefs[5]},
|
|
|
|
{coefs[6], coefs[6]},
|
|
|
|
{coefs[7], coefs[7]}
|
|
|
|
};
|
|
|
|
|
2017-01-16 08:39:56 +00:00
|
|
|
if (!submix)
|
|
|
|
submix = &m_root.m_mainSubmix;
|
|
|
|
|
2016-07-13 03:03:52 +00:00
|
|
|
auto search = m_sendMatrices.find(submix);
|
|
|
|
if (search == m_sendMatrices.cend())
|
|
|
|
search = m_sendMatrices.emplace(submix, AudioMatrixStereo{}).first;
|
|
|
|
search->second.setMatrixCoefficients(newCoefs, slew ? m_root.m_5msFrames : 0);
|
2016-05-31 05:16:29 +00:00
|
|
|
}
|
|
|
|
|
2016-07-13 03:03:52 +00:00
|
|
|
void AudioVoiceStereo::setStereoChannelLevels(IAudioSubmix* submix, const float coefs[8][2], bool slew)
|
2016-05-31 05:16:29 +00:00
|
|
|
{
|
2017-01-16 08:39:56 +00:00
|
|
|
if (!submix)
|
|
|
|
submix = &m_root.m_mainSubmix;
|
|
|
|
|
2016-07-13 03:03:52 +00:00
|
|
|
auto search = m_sendMatrices.find(submix);
|
|
|
|
if (search == m_sendMatrices.cend())
|
|
|
|
search = m_sendMatrices.emplace(submix, AudioMatrixStereo{}).first;
|
|
|
|
search->second.setMatrixCoefficients(coefs, slew ? m_root.m_5msFrames : 0);
|
2016-05-31 05:16:29 +00:00
|
|
|
}
|
|
|
|
|
2016-03-24 00:01:57 +00:00
|
|
|
}
|