Skip to content

Commit

Permalink
Updated for DirectX Tool Kit November 2021 release
Browse files Browse the repository at this point in the history
  • Loading branch information
walbourn committed Nov 8, 2021
1 parent c55980d commit 0095b8a
Show file tree
Hide file tree
Showing 197 changed files with 9,327 additions and 3,945 deletions.
108 changes: 49 additions & 59 deletions Kits/DirectXTK/Audio/AudioEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -578,10 +578,10 @@ HRESULT AudioEngine::Impl::Reset(const WAVEFORMATEX* wfx, const wchar_t* deviceI
//
// Inform any notify objects we are ready to go again
//
for (auto it = mNotifyObjects.begin(); it != mNotifyObjects.end(); ++it)
for (auto it : mNotifyObjects)
{
assert(*it != nullptr);
(*it)->OnReset();
assert(it != nullptr);
it->OnReset();
}

return S_OK;
Expand All @@ -590,23 +590,23 @@ HRESULT AudioEngine::Impl::Reset(const WAVEFORMATEX* wfx, const wchar_t* deviceI

void AudioEngine::Impl::SetSilentMode()
{
for (auto it = mNotifyObjects.begin(); it != mNotifyObjects.end(); ++it)
for (auto it : mNotifyObjects)
{
assert(*it != nullptr);
(*it)->OnCriticalError();
assert(it != nullptr);
it->OnCriticalError();
}

for (auto it = mOneShots.begin(); it != mOneShots.end(); ++it)
for (auto& it : mOneShots)
{
assert(it->second != nullptr);
it->second->DestroyVoice();
assert(it.second != nullptr);
it.second->DestroyVoice();
}
mOneShots.clear();

for (auto it = mVoicePool.begin(); it != mVoicePool.end(); ++it)
for (auto& it : mVoicePool)
{
assert(it->second != nullptr);
it->second->DestroyVoice();
assert(it.second != nullptr);
it.second->DestroyVoice();
}
mVoicePool.clear();

Expand All @@ -623,10 +623,10 @@ void AudioEngine::Impl::SetSilentMode()

void AudioEngine::Impl::Shutdown() noexcept
{
for (auto it = mNotifyObjects.begin(); it != mNotifyObjects.end(); ++it)
for (auto it : mNotifyObjects)
{
assert(*it != nullptr);
(*it)->OnDestroyEngine();
assert(it != nullptr);
it->OnDestroyEngine();
}

if (xaudio2)
Expand All @@ -635,17 +635,17 @@ void AudioEngine::Impl::Shutdown() noexcept

xaudio2->StopEngine();

for (auto it = mOneShots.begin(); it != mOneShots.end(); ++it)
for (auto& it : mOneShots)
{
assert(it->second != nullptr);
it->second->DestroyVoice();
assert(it.second != nullptr);
it.second->DestroyVoice();
}
mOneShots.clear();

for (auto it = mVoicePool.begin(); it != mVoicePool.end(); ++it)
for (auto& it : mVoicePool)
{
assert(it->second != nullptr);
it->second->DestroyVoice();
assert(it.second != nullptr);
it.second->DestroyVoice();
}
mVoicePool.clear();

Expand Down Expand Up @@ -697,7 +697,7 @@ bool AudioEngine::Impl::Update()

if (!xstate.BuffersQueued)
{
(void)it->second->Stop(0);
std::ignore = it->second->Stop(0);
if (it->first)
{
// Put voice back into voice pool for reuse since it has a non-zero voiceKey
Expand Down Expand Up @@ -729,10 +729,10 @@ bool AudioEngine::Impl::Update()
//
// Inform any notify objects of updates
//
for (auto it = mNotifyUpdates.begin(); it != mNotifyUpdates.end(); ++it)
for (auto it : mNotifyUpdates)
{
assert(*it != nullptr);
(*it)->OnUpdate();
assert(it != nullptr);
it->OnUpdate();
}

return true;
Expand All @@ -750,15 +750,15 @@ void AudioEngine::Impl::SetReverb(const XAUDIO2FX_REVERB_PARAMETERS* native) noe
if (!mReverbEnabled)
{
mReverbEnabled = true;
(void)mReverbVoice->EnableEffect(0);
std::ignore = mReverbVoice->EnableEffect(0);
}

(void)mReverbVoice->SetEffectParameters(0, native, sizeof(XAUDIO2FX_REVERB_PARAMETERS));
std::ignore = mReverbVoice->SetEffectParameters(0, native, sizeof(XAUDIO2FX_REVERB_PARAMETERS));
}
else if (mReverbEnabled)
{
mReverbEnabled = false;
(void)mReverbVoice->DisableEffect(0);
std::ignore = mReverbVoice->DisableEffect(0);
}
}

Expand Down Expand Up @@ -790,10 +790,10 @@ AudioStatistics AudioEngine::Impl::GetStatistics() const
stats.allocatedVoices = stats.allocatedVoicesOneShot = mOneShots.size() + mVoicePool.size();
stats.allocatedVoicesIdle = mVoicePool.size();

for (auto it = mNotifyObjects.begin(); it != mNotifyObjects.end(); ++it)
for (const auto it : mNotifyObjects)
{
assert(*it != nullptr);
(*it)->GatherStatistics(stats);
assert(it != nullptr);
it->GatherStatistics(stats);
}

assert(stats.allocatedVoices == (mOneShots.size() + mVoicePool.size() + mVoiceInstances));
Expand All @@ -804,16 +804,16 @@ AudioStatistics AudioEngine::Impl::GetStatistics() const

void AudioEngine::Impl::TrimVoicePool()
{
for (auto it = mNotifyObjects.begin(); it != mNotifyObjects.end(); ++it)
for (auto it : mNotifyObjects)
{
assert(*it != nullptr);
(*it)->OnTrim();
assert(it != nullptr);
it->OnTrim();
}

for (auto it = mVoicePool.begin(); it != mVoicePool.end(); ++it)
for (auto& it : mVoicePool)
{
assert(it->second != nullptr);
it->second->DestroyVoice();
assert(it.second != nullptr);
it.second->DestroyVoice();
}
mVoicePool.clear();
}
Expand Down Expand Up @@ -1034,18 +1034,18 @@ void AudioEngine::Impl::DestroyVoice(_In_ IXAudio2SourceVoice* voice) noexcept
return;

#ifndef NDEBUG
for (auto it = mOneShots.cbegin(); it != mOneShots.cend(); ++it)
for (const auto& it : mOneShots)
{
if (it->second == voice)
if (it.second == voice)
{
DebugTrace("ERROR: DestroyVoice should not be called for a one-shot voice\n");
return;
}
}

for (auto it = mVoicePool.cbegin(); it != mVoicePool.cend(); ++it)
for (const auto& it : mVoicePool)
{
if (it->second == voice)
if (it.second == voice)
{
DebugTrace("ERROR: DestroyVoice should not be called for a one-shot voice; see TrimVoicePool\n");
return;
Expand Down Expand Up @@ -1081,17 +1081,17 @@ void AudioEngine::Impl::UnregisterNotify(_In_ IVoiceNotify* notify, bool usesOne
{
bool setevent = false;

for (auto it = mOneShots.begin(); it != mOneShots.end(); ++it)
for (auto& it : mOneShots)
{
assert(it->second != nullptr);
assert(it.second != nullptr);

XAUDIO2_VOICE_STATE state;
it->second->GetState(&state, XAUDIO2_VOICE_NOSAMPLESPLAYED);
it.second->GetState(&state, XAUDIO2_VOICE_NOSAMPLESPLAYED);

if (state.pCurrentBufferContext == notify)
{
(void)it->second->Stop(0);
(void)it->second->FlushSourceBuffers();
std::ignore = it.second->Stop(0);
std::ignore = it.second->FlushSourceBuffers();
setevent = true;
}
}
Expand Down Expand Up @@ -1149,19 +1149,9 @@ AudioEngine::AudioEngine(
}


// Move constructor.
AudioEngine::AudioEngine(AudioEngine&& moveFrom) noexcept
: pImpl(std::move(moveFrom.pImpl))
{
}


// Move assignment.
AudioEngine& AudioEngine::operator= (AudioEngine&& moveFrom) noexcept
{
pImpl = std::move(moveFrom.pImpl);
return *this;
}
// Move ctor/operator.
AudioEngine::AudioEngine(AudioEngine&&) noexcept = default;
AudioEngine& AudioEngine::operator= (AudioEngine&&) noexcept = default;


// Public destructor.
Expand Down
24 changes: 4 additions & 20 deletions Kits/DirectXTK/Audio/DynamicSoundEffectInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ void DynamicSoundEffectInstance::Impl::Play()
mBase.AllocateVoice(&mWaveFormat);
}

(void)mBase.Play();
std::ignore = mBase.Play();

if (mBase.voice && (mBase.state == PLAYING) && (mBase.GetPendingBufferCount() <= 2))
{
Expand Down Expand Up @@ -252,25 +252,9 @@ DynamicSoundEffectInstance::DynamicSoundEffectInstance(
}


// Move constructor.
DynamicSoundEffectInstance::DynamicSoundEffectInstance(DynamicSoundEffectInstance&& moveFrom) noexcept
: pImpl(std::move(moveFrom.pImpl))
{
}


// Move assignment.
DynamicSoundEffectInstance& DynamicSoundEffectInstance::operator= (DynamicSoundEffectInstance&& moveFrom) noexcept
{
pImpl = std::move(moveFrom.pImpl);
return *this;
}


// Public destructor.
DynamicSoundEffectInstance::~DynamicSoundEffectInstance()
{
}
DynamicSoundEffectInstance::DynamicSoundEffectInstance(DynamicSoundEffectInstance&&) noexcept = default;
DynamicSoundEffectInstance& DynamicSoundEffectInstance::operator= (DynamicSoundEffectInstance&&) noexcept = default;
DynamicSoundEffectInstance::~DynamicSoundEffectInstance() = default;


// Public methods.
Expand Down
10 changes: 5 additions & 5 deletions Kits/DirectXTK/Audio/SoundCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -790,32 +790,32 @@ void SoundEffectInstanceBase::Apply3D(const X3DAUDIO_LISTENER& listener, const X

mDSPSettings.pMatrixCoefficients = nullptr;

(void)voice->SetFrequencyRatio(mFreqRatio * mDSPSettings.DopplerFactor);
std::ignore = voice->SetFrequencyRatio(mFreqRatio * mDSPSettings.DopplerFactor);

auto direct = mDirectVoice;
assert(direct != nullptr);
(void)voice->SetOutputMatrix(direct, mDSPSettings.SrcChannelCount, mDSPSettings.DstChannelCount, matrix);
std::ignore = voice->SetOutputMatrix(direct, mDSPSettings.SrcChannelCount, mDSPSettings.DstChannelCount, matrix);

if (reverb)
{
for (size_t j = 0; (j < mDSPSettings.SrcChannelCount) && (j < XAUDIO2_MAX_AUDIO_CHANNELS); ++j)
{
matrix[j] = mDSPSettings.ReverbLevel;
}
(void)voice->SetOutputMatrix(reverb, mDSPSettings.SrcChannelCount, 1, matrix);
std::ignore = voice->SetOutputMatrix(reverb, mDSPSettings.SrcChannelCount, 1, matrix);
}

if (mFlags & SoundEffectInstance_ReverbUseFilters)
{
XAUDIO2_FILTER_PARAMETERS filterDirect = { LowPassFilter, 2.0f * sinf(X3DAUDIO_PI / 6.0f * mDSPSettings.LPFDirectCoefficient), 1.0f };
// see XAudio2CutoffFrequencyToRadians() in XAudio2.h for more information on the formula used here
(void)voice->SetOutputFilterParameters(direct, &filterDirect);
std::ignore = voice->SetOutputFilterParameters(direct, &filterDirect);

if (reverb)
{
XAUDIO2_FILTER_PARAMETERS filterReverb = { LowPassFilter, 2.0f * sinf(X3DAUDIO_PI / 6.0f * mDSPSettings.LPFReverbCoefficient), 1.0f };
// see XAudio2CutoffFrequencyToRadians() in XAudio2.h for more information on the formula used here
(void)voice->SetOutputFilterParameters(reverb, &filterReverb);
std::ignore = voice->SetOutputFilterParameters(reverb, &filterReverb);
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions Kits/DirectXTK/Audio/SoundCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,17 +199,17 @@ namespace DirectX
if (immediate)
{
state = STOPPED;
(void)voice->Stop(0);
(void)voice->FlushSourceBuffers();
std::ignore = voice->Stop(0);
std::ignore = voice->FlushSourceBuffers();
}
else if (looped)
{
looped = false;
(void)voice->ExitLoop();
std::ignore = voice->ExitLoop();
}
else
{
(void)voice->Stop(XAUDIO2_PLAY_TAILS);
std::ignore = voice->Stop(XAUDIO2_PLAY_TAILS);
}
}

Expand All @@ -219,7 +219,7 @@ namespace DirectX
{
state = PAUSED;

(void)voice->Stop(0);
std::ignore = voice->Stop(0);
}
}

Expand Down Expand Up @@ -281,7 +281,7 @@ namespace DirectX
if (!xstate.BuffersQueued)
{
// Automatic stop if the buffer has finished playing
(void)voice->Stop();
std::ignore = voice->Stop();
state = STOPPED;
}
}
Expand Down Expand Up @@ -334,8 +334,8 @@ namespace DirectX
{
if (voice)
{
(void)voice->Stop(0);
(void)voice->FlushSourceBuffers();
std::ignore = voice->Stop(0);
std::ignore = voice->FlushSourceBuffers();
voice->DestroyVoice();
voice = nullptr;
}
Expand Down
Loading

0 comments on commit 0095b8a

Please sign in to comment.