Working Studio implementation

This commit is contained in:
Jack Andersen
2016-07-13 18:54:46 -10:00
parent d3d5595422
commit 2dcb9dd1c7
68 changed files with 1981 additions and 2098 deletions

View File

@@ -6,74 +6,68 @@
namespace amuse
{
void BooBackendVoice::VoiceCallback::preSupplyAudio(boo::IAudioVoice&,
double dt)
void BooBackendVoice::VoiceCallback::preSupplyAudio(boo::IAudioVoice&, double dt)
{
m_parent.m_clientVox.preSupplyAudio(dt);
}
size_t BooBackendVoice::VoiceCallback::supplyAudio(boo::IAudioVoice&,
size_t frames, int16_t* data)
size_t BooBackendVoice::VoiceCallback::supplyAudio(boo::IAudioVoice&, size_t frames, int16_t* data)
{
return m_parent.m_clientVox.supplyAudio(frames, data);
}
BooBackendVoice::BooBackendVoice(boo::IAudioVoiceEngine& engine, Voice& clientVox,
double sampleRate, bool dynamicPitch)
: m_clientVox(clientVox), m_cb(*this),
m_booVoice(engine.allocateNewMonoVoice(sampleRate, &m_cb, dynamicPitch))
{}
void BooBackendVoice::resetSampleRate(double sampleRate)
void BooBackendVoice::VoiceCallback::routeAudio(size_t frames, double dt, int busId, int16_t* in, int16_t* out)
{
m_booVoice->resetSampleRate(sampleRate);
m_parent.m_clientVox.routeAudio(frames, dt, busId, in, out);
}
void BooBackendVoice::resetChannelLevels()
void BooBackendVoice::VoiceCallback::routeAudio(size_t frames, double dt, int busId, int32_t* in, int32_t* out)
{
m_booVoice->resetChannelLevels();
m_parent.m_clientVox.routeAudio(frames, dt, busId, in, out);
}
void BooBackendVoice::VoiceCallback::routeAudio(size_t frames, double dt, int busId, float* in, float* out)
{
m_parent.m_clientVox.routeAudio(frames, dt, busId, in, out);
}
BooBackendVoice::BooBackendVoice(boo::IAudioVoiceEngine& engine, Voice& clientVox, double sampleRate, bool dynamicPitch)
: m_clientVox(clientVox), m_cb(*this), m_booVoice(engine.allocateNewMonoVoice(sampleRate, &m_cb, dynamicPitch))
{
}
void BooBackendVoice::resetSampleRate(double sampleRate) { m_booVoice->resetSampleRate(sampleRate); }
void BooBackendVoice::resetChannelLevels() { m_booVoice->resetChannelLevels(); }
void BooBackendVoice::setChannelLevels(IBackendSubmix* submix, const float coefs[8], bool slew)
{
BooBackendSubmix& smx = *reinterpret_cast<BooBackendSubmix*>(submix);
m_booVoice->setMonoChannelLevels(smx.m_booSubmix.get(), coefs, slew);
}
void BooBackendVoice::setPitchRatio(double ratio, bool slew)
{
m_booVoice->setPitchRatio(ratio, slew);
}
void BooBackendVoice::setPitchRatio(double ratio, bool slew) { m_booVoice->setPitchRatio(ratio, slew); }
void BooBackendVoice::start()
{
m_booVoice->start();
}
void BooBackendVoice::start() { m_booVoice->start(); }
void BooBackendVoice::stop()
{
m_booVoice->stop();
}
void BooBackendVoice::stop() { m_booVoice->stop(); }
bool BooBackendSubmix::SubmixCallback::canApplyEffect() const
{
return m_parent.m_clientSmx.canApplyEffect();
}
bool BooBackendSubmix::SubmixCallback::canApplyEffect() const { return m_parent.m_clientSmx.canApplyEffect(); }
void BooBackendSubmix::SubmixCallback::applyEffect(int16_t* audio, size_t frameCount,
const boo::ChannelMap& chanMap, double) const
void BooBackendSubmix::SubmixCallback::applyEffect(int16_t* audio, size_t frameCount, const boo::ChannelMap& chanMap,
double) const
{
return m_parent.m_clientSmx.applyEffect(audio, frameCount, reinterpret_cast<const ChannelMap&>(chanMap));
}
void BooBackendSubmix::SubmixCallback::applyEffect(int32_t* audio, size_t frameCount,
const boo::ChannelMap& chanMap, double) const
void BooBackendSubmix::SubmixCallback::applyEffect(int32_t* audio, size_t frameCount, const boo::ChannelMap& chanMap,
double) const
{
return m_parent.m_clientSmx.applyEffect(audio, frameCount, reinterpret_cast<const ChannelMap&>(chanMap));
}
void BooBackendSubmix::SubmixCallback::applyEffect(float* audio, size_t frameCount,
const boo::ChannelMap& chanMap, double) const
void BooBackendSubmix::SubmixCallback::applyEffect(float* audio, size_t frameCount, const boo::ChannelMap& chanMap,
double) const
{
return m_parent.m_clientSmx.applyEffect(audio, frameCount, reinterpret_cast<const ChannelMap&>(chanMap));
}
@@ -83,9 +77,10 @@ void BooBackendSubmix::SubmixCallback::resetOutputSampleRate(double sampleRate)
m_parent.m_clientSmx.resetOutputSampleRate(sampleRate);
}
BooBackendSubmix::BooBackendSubmix(boo::IAudioVoiceEngine& engine, Submix& clientSmx, bool mainOut)
: m_clientSmx(clientSmx), m_cb(*this), m_booSubmix(engine.allocateNewSubmix(mainOut, &m_cb))
{}
BooBackendSubmix::BooBackendSubmix(boo::IAudioVoiceEngine& engine, Submix& clientSmx, bool mainOut, int busId)
: m_clientSmx(clientSmx), m_cb(*this), m_booSubmix(engine.allocateNewSubmix(mainOut, &m_cb, busId))
{
}
void BooBackendSubmix::setSendLevel(IBackendSubmix* submix, float level, bool slew)
{
@@ -93,21 +88,11 @@ void BooBackendSubmix::setSendLevel(IBackendSubmix* submix, float level, bool sl
m_booSubmix->setSendLevel(smx.m_booSubmix.get(), level, slew);
}
double BooBackendSubmix::getSampleRate() const
{
return m_booSubmix->getSampleRate();
}
double BooBackendSubmix::getSampleRate() const { return m_booSubmix->getSampleRate(); }
SubmixFormat BooBackendSubmix::getSampleFormat() const
{
return SubmixFormat(m_booSubmix->getSampleFormat());
}
SubmixFormat BooBackendSubmix::getSampleFormat() const { return SubmixFormat(m_booSubmix->getSampleFormat()); }
std::string BooBackendMIDIReader::description()
{
return m_midiIn->description();
}
std::string BooBackendMIDIReader::description() { return m_midiIn->description(); }
BooBackendMIDIReader::~BooBackendMIDIReader() {}
@@ -120,25 +105,25 @@ BooBackendMIDIReader::BooBackendMIDIReader(Engine& engine, const char* name, boo
auto devices = voxAlloc.m_booEngine.enumerateMIDIDevices();
for (const auto& dev : devices)
{
m_midiIn = voxAlloc.m_booEngine.newRealMIDIIn(dev.first.c_str(),
std::bind(&BooBackendMIDIReader::_MIDIReceive, this,
std::placeholders::_1, std::placeholders::_2));
m_midiIn = voxAlloc.m_booEngine.newRealMIDIIn(
dev.first.c_str(),
std::bind(&BooBackendMIDIReader::_MIDIReceive, this, std::placeholders::_1, std::placeholders::_2));
if (m_midiIn)
return;
}
m_midiIn = voxAlloc.m_booEngine.newVirtualMIDIIn(std::bind(&BooBackendMIDIReader::_MIDIReceive, this,
std::placeholders::_1, std::placeholders::_2));
m_midiIn = voxAlloc.m_booEngine.newVirtualMIDIIn(
std::bind(&BooBackendMIDIReader::_MIDIReceive, this, std::placeholders::_1, std::placeholders::_2));
}
else
m_midiIn = voxAlloc.m_booEngine.newRealMIDIIn(name,
std::bind(&BooBackendMIDIReader::_MIDIReceive, this,
std::placeholders::_1, std::placeholders::_2));
m_midiIn = voxAlloc.m_booEngine.newRealMIDIIn(
name, std::bind(&BooBackendMIDIReader::_MIDIReceive, this, std::placeholders::_1, std::placeholders::_2));
}
void BooBackendMIDIReader::_MIDIReceive(std::vector<uint8_t>&& bytes, double time)
{
std::unique_lock<std::mutex> lk(m_midiMutex, std::defer_lock_t{});
if (m_useLock) lk.lock();
if (m_useLock)
lk.lock();
m_queue.emplace_back(time, std::move(bytes));
#if 0
openlog("LogIt", (LOG_CONS|LOG_PERROR|LOG_PID), LOG_DAEMON);
@@ -152,14 +137,15 @@ void BooBackendMIDIReader::pumpReader(double dt)
dt += 0.001; /* Add 1ms to ensure consumer keeps up with producer */
std::unique_lock<std::mutex> lk(m_midiMutex, std::defer_lock_t{});
if (m_useLock) lk.lock();
if (m_useLock)
lk.lock();
if (m_queue.empty())
return;
/* Determine range of buffer updates within this period */
auto periodEnd = m_queue.cbegin();
double startPt = m_queue.front().first;
for (; periodEnd != m_queue.cend() ; ++periodEnd)
for (; periodEnd != m_queue.cend(); ++periodEnd)
{
double delta = periodEnd->first - startPt;
if (delta > dt)
@@ -170,7 +156,7 @@ void BooBackendMIDIReader::pumpReader(double dt)
return;
/* Dispatch buffers */
for (auto it = m_queue.begin() ; it != periodEnd ;)
for (auto it = m_queue.begin(); it != periodEnd;)
{
#if 0
char str[64];
@@ -208,9 +194,7 @@ void BooBackendMIDIReader::noteOn(uint8_t chan, uint8_t key, uint8_t velocity)
#endif
}
void BooBackendMIDIReader::notePressure(uint8_t /*chan*/, uint8_t /*key*/, uint8_t /*pressure*/)
{
}
void BooBackendMIDIReader::notePressure(uint8_t /*chan*/, uint8_t /*key*/, uint8_t /*pressure*/) {}
void BooBackendMIDIReader::controlChange(uint8_t chan, uint8_t control, uint8_t value)
{
@@ -224,9 +208,7 @@ void BooBackendMIDIReader::programChange(uint8_t chan, uint8_t program)
seq->setChanProgram(chan, program);
}
void BooBackendMIDIReader::channelPressure(uint8_t /*chan*/, uint8_t /*pressure*/)
{
}
void BooBackendMIDIReader::channelPressure(uint8_t /*chan*/, uint8_t /*pressure*/) {}
void BooBackendMIDIReader::pitchBend(uint8_t chan, int16_t pitch)
{
@@ -234,20 +216,15 @@ void BooBackendMIDIReader::pitchBend(uint8_t chan, int16_t pitch)
seq->setPitchWheel(chan, (pitch - 0x2000) / float(0x2000));
}
void BooBackendMIDIReader::allSoundOff(uint8_t chan)
{
for (std::shared_ptr<Sequencer>& seq : m_engine.getActiveSequencers())
seq->allOff(chan, true);
}
void BooBackendMIDIReader::resetAllControllers(uint8_t /*chan*/)
{
}
void BooBackendMIDIReader::resetAllControllers(uint8_t /*chan*/) {}
void BooBackendMIDIReader::localControl(uint8_t /*chan*/, bool /*on*/)
{
}
void BooBackendMIDIReader::localControl(uint8_t /*chan*/, bool /*on*/) {}
void BooBackendMIDIReader::allNotesOff(uint8_t chan)
{
@@ -255,67 +232,39 @@ void BooBackendMIDIReader::allNotesOff(uint8_t chan)
seq->allOff(chan, false);
}
void BooBackendMIDIReader::omniMode(uint8_t /*chan*/, bool /*on*/)
{
}
void BooBackendMIDIReader::omniMode(uint8_t /*chan*/, bool /*on*/) {}
void BooBackendMIDIReader::polyMode(uint8_t /*chan*/, bool /*on*/)
{
}
void BooBackendMIDIReader::polyMode(uint8_t /*chan*/, bool /*on*/) {}
void BooBackendMIDIReader::sysex(const void* /*data*/, size_t /*len*/) {}
void BooBackendMIDIReader::sysex(const void* /*data*/, size_t /*len*/)
{
}
void BooBackendMIDIReader::timeCodeQuarterFrame(uint8_t /*message*/, uint8_t /*value*/) {}
void BooBackendMIDIReader::timeCodeQuarterFrame(uint8_t /*message*/, uint8_t /*value*/)
{
}
void BooBackendMIDIReader::songPositionPointer(uint16_t /*pointer*/) {}
void BooBackendMIDIReader::songPositionPointer(uint16_t /*pointer*/)
{
}
void BooBackendMIDIReader::songSelect(uint8_t /*song*/) {}
void BooBackendMIDIReader::songSelect(uint8_t /*song*/)
{
}
void BooBackendMIDIReader::tuneRequest() {}
void BooBackendMIDIReader::tuneRequest()
{
}
void BooBackendMIDIReader::startSeq() {}
void BooBackendMIDIReader::continueSeq() {}
void BooBackendMIDIReader::startSeq()
{
}
void BooBackendMIDIReader::stopSeq() {}
void BooBackendMIDIReader::continueSeq()
{
}
void BooBackendMIDIReader::reset() {}
void BooBackendMIDIReader::stopSeq()
{
}
BooBackendVoiceAllocator::BooBackendVoiceAllocator(boo::IAudioVoiceEngine& booEngine) : m_booEngine(booEngine) {}
void BooBackendMIDIReader::reset()
{
}
BooBackendVoiceAllocator::BooBackendVoiceAllocator(boo::IAudioVoiceEngine& booEngine)
: m_booEngine(booEngine)
{}
std::unique_ptr<IBackendVoice>
BooBackendVoiceAllocator::allocateVoice(Voice& clientVox, double sampleRate, bool dynamicPitch)
std::unique_ptr<IBackendVoice> BooBackendVoiceAllocator::allocateVoice(Voice& clientVox, double sampleRate,
bool dynamicPitch)
{
return std::make_unique<BooBackendVoice>(m_booEngine, clientVox, sampleRate, dynamicPitch);
}
std::unique_ptr<IBackendSubmix> BooBackendVoiceAllocator::allocateSubmix(Submix& clientSmx, bool mainOut)
std::unique_ptr<IBackendSubmix> BooBackendVoiceAllocator::allocateSubmix(Submix& clientSmx, bool mainOut, int busId)
{
return std::make_unique<BooBackendSubmix>(m_booEngine, clientSmx, mainOut);
return std::make_unique<BooBackendSubmix>(m_booEngine, clientSmx, mainOut, busId);
}
std::vector<std::pair<std::string, std::string>> BooBackendVoiceAllocator::enumerateMIDIDevices()
@@ -336,14 +285,7 @@ void BooBackendVoiceAllocator::register5MsCallback(std::function<void(double)>&&
m_booEngine.register5MsCallback(std::move(callback));
}
AudioChannelSet BooBackendVoiceAllocator::getAvailableSet()
{
return AudioChannelSet(m_booEngine.getAvailableSet());
}
void BooBackendVoiceAllocator::pumpAndMixVoices()
{
m_booEngine.pumpAndMixVoices();
}
AudioChannelSet BooBackendVoiceAllocator::getAvailableSet() { return AudioChannelSet(m_booEngine.getAvailableSet()); }
void BooBackendVoiceAllocator::pumpAndMixVoices() { m_booEngine.pumpAndMixVoices(); }
}