Add voice allocator master volume

This commit is contained in:
Jack Andersen 2016-07-13 20:16:40 -10:00
parent 85fa541f6a
commit f35ccbaad5
3 changed files with 25 additions and 3 deletions

View File

@ -44,6 +44,9 @@ struct IAudioVoiceEngine
/** Ensure backing platform buffer is filled as much as possible with mixed samples */
virtual void pumpAndMixVoices()=0;
/** Set total volume of engine */
virtual void setVolume(float vol)=0;
/** Get list of MIDI devices found on system */
virtual std::vector<std::pair<std::string, std::string>> enumerateMIDIDevices() const=0;

View File

@ -50,8 +50,12 @@ void BaseAudioVoiceEngine::_pumpAndMixVoices(size_t frames, int16_t* dataOut)
for (auto it = m_linearizedSubmixes.rbegin() ; it != m_linearizedSubmixes.rend() ; ++it)
(*it)->_pumpAndMix16(thisFrames);
size_t sampleCount = thisFrames * m_mixInfo.m_channelMap.m_channelCount;
for (size_t i=0 ; i<sampleCount ; ++i)
dataOut[i] *= m_totalVol;
remFrames -= thisFrames;
dataOut += thisFrames * m_mixInfo.m_channelMap.m_channelCount;
dataOut += sampleCount;
}
}
@ -93,8 +97,12 @@ void BaseAudioVoiceEngine::_pumpAndMixVoices(size_t frames, int32_t* dataOut)
for (auto it = m_linearizedSubmixes.rbegin() ; it != m_linearizedSubmixes.rend() ; ++it)
(*it)->_pumpAndMix32(thisFrames);
size_t sampleCount = thisFrames * m_mixInfo.m_channelMap.m_channelCount;
for (size_t i=0 ; i<sampleCount ; ++i)
dataOut[i] *= m_totalVol;
remFrames -= thisFrames;
dataOut += thisFrames * m_mixInfo.m_channelMap.m_channelCount;
dataOut += sampleCount;
}
}
@ -136,8 +144,12 @@ void BaseAudioVoiceEngine::_pumpAndMixVoices(size_t frames, float* dataOut)
for (auto it = m_linearizedSubmixes.rbegin() ; it != m_linearizedSubmixes.rend() ; ++it)
(*it)->_pumpAndMixFlt(thisFrames);
size_t sampleCount = thisFrames * m_mixInfo.m_channelMap.m_channelCount;
for (size_t i=0 ; i<sampleCount ; ++i)
dataOut[i] *= m_totalVol;
remFrames -= thisFrames;
dataOut += thisFrames * m_mixInfo.m_channelMap.m_channelCount;
dataOut += sampleCount;
}
}
@ -193,6 +205,11 @@ void BaseAudioVoiceEngine::register5MsCallback(std::function<void(double dt)>&&
m_5msCallback = std::move(callback);
}
void BaseAudioVoiceEngine::setVolume(float vol)
{
m_totalVol = vol;
}
const AudioVoiceEngineMixInfo& BaseAudioVoiceEngine::mixInfo() const
{
return m_mixInfo;

View File

@ -28,6 +28,7 @@ protected:
friend class AudioSubmix;
friend class AudioVoiceMono;
friend class AudioVoiceStereo;
float m_totalVol = 1.f;
AudioVoiceEngineMixInfo m_mixInfo;
std::list<AudioVoice*> m_activeVoices;
std::list<AudioSubmix*> m_activeSubmixes;
@ -69,6 +70,7 @@ public:
void register5MsCallback(std::function<void(double dt)>&& callback);
void setVolume(float vol);
const AudioVoiceEngineMixInfo& mixInfo() const;
AudioChannelSet getAvailableSet() {return m_mixInfo.m_channels;}
void pumpAndMixVoices() {}