summaryrefslogtreecommitdiff
path: root/Source/Core/AudioCommon/Mixer.cpp
diff options
context:
space:
mode:
authorJMC47 <JMC4789@gmail.com>2025-08-05 20:02:58 -0400
committerGitHub <noreply@github.com>2025-08-05 20:02:58 -0400
commit3111a785a106e4d184d9c3037e1df9a35ce06d31 (patch)
tree1a681778186604d46e2e8ef95b3b5a08e7fcc0c3 /Source/Core/AudioCommon/Mixer.cpp
parent804cf465fcc6fbe879a8a927988052eca761fa25 (diff)
parentd7f45c7b9616ab547feb9b3ec3d8cbfa5b08f0b3 (diff)
Merge pull request #13725 from Sam-Belliveau/more-consistent-looping
Fade audio after an entire loop
Diffstat (limited to 'Source/Core/AudioCommon/Mixer.cpp')
-rw-r--r--Source/Core/AudioCommon/Mixer.cpp19
1 files changed, 14 insertions, 5 deletions
diff --git a/Source/Core/AudioCommon/Mixer.cpp b/Source/Core/AudioCommon/Mixer.cpp
index 1e074cbfce..eab73fb17c 100644
--- a/Source/Core/AudioCommon/Mixer.cpp
+++ b/Source/Core/AudioCommon/Mixer.cpp
@@ -93,6 +93,8 @@ void Mixer::MixerFifo::Mix(s16* samples, std::size_t num_samples)
std::clamp((buffer_size_samples) / (GRANULE_SIZE >> 1), static_cast<std::size_t>(4),
static_cast<std::size_t>(MAX_GRANULE_QUEUE_SIZE));
+ bool fade_audio = m_queue_fading.load(std::memory_order_relaxed);
+
m_granule_queue_size.store(buffer_size_granules, std::memory_order_relaxed);
while (num_samples-- > 0)
@@ -106,9 +108,9 @@ void Mixer::MixerFifo::Mix(s16* samples, std::size_t num_samples)
// If either index is less than the index jump, that means we reached
// the end of the of the buffer and need to load the next granule.
if (front_index < index_jump)
- Dequeue(&m_front);
+ fade_audio = Dequeue(&m_front);
else if (back_index < index_jump)
- Dequeue(&m_back);
+ fade_audio = Dequeue(&m_back);
// The Granules are pre-windowed, so we can just add them together
const std::size_t ft = front_index >> GRANULE_FRAC_BITS;
@@ -137,7 +139,7 @@ void Mixer::MixerFifo::Mix(s16* samples, std::size_t num_samples)
s5 * StereoPair{(+0.0f + 0.0f * t1 + 1.0f * t2 - 1.0f * t3) / 12.0f});
// Apply Fade In / Fade Out depending on if we are looping
- if (m_queue_looping.load(std::memory_order_relaxed))
+ if (fade_audio)
m_fade_volume += fade_out_mul * (0.0f - m_fade_volume);
else
m_fade_volume += fade_in_mul * (1.0f - m_fade_volume);
@@ -533,10 +535,11 @@ void Mixer::MixerFifo::Enqueue()
m_queue[head][i] = m_next_buffer[(i + start_index) & GRANULE_MASK] * GRANULE_WINDOW[i];
m_queue_head.store(next_head, std::memory_order_release);
+ m_queue_fading.store(false, std::memory_order_relaxed);
m_queue_looping.store(false, std::memory_order_relaxed);
}
-void Mixer::MixerFifo::Dequeue(Granule* granule)
+bool Mixer::MixerFifo::Dequeue(Granule* granule)
{
const std::size_t granule_queue_size = m_granule_queue_size.load(std::memory_order_relaxed);
const std::size_t head = m_queue_head.load(std::memory_order_acquire);
@@ -562,16 +565,22 @@ void Mixer::MixerFifo::Dequeue(Granule* granule)
// This provides smoother audio playback than suddenly stopping.
const std::size_t gap = std::max<std::size_t>(2, granule_queue_size >> 1) - 1;
next_tail = (head - gap) & GRANULE_QUEUE_MASK;
+
+ bool looping = m_queue_looping.load(std::memory_order_relaxed);
+ m_queue_fading.store(looping, std::memory_order_relaxed);
m_queue_looping.store(true, std::memory_order_relaxed);
}
else
{
std::fill(granule->begin(), granule->end(), StereoPair{0.0f, 0.0f});
+ m_queue_fading.store(false, std::memory_order_relaxed);
m_queue_looping.store(false, std::memory_order_relaxed);
- return;
+ return false;
}
}
*granule = m_queue[tail];
m_queue_tail.store(next_tail, std::memory_order_release);
+
+ return m_queue_fading.load(std::memory_order_relaxed);
}