summaryrefslogtreecommitdiff
path: root/Source/Core/AudioCommon/Mixer.cpp
diff options
context:
space:
mode:
authorPokechu22 <Pokechu022@gmail.com>2022-08-24 17:22:39 -0700
committerPokechu22 <Pokechu022@gmail.com>2022-09-08 12:10:10 -0700
commit72de74d4fc81bf5cc2ed0b3a9a3c6c43856c0c5e (patch)
tree371115dbd4fdf3de842908c7649128d929adb04c /Source/Core/AudioCommon/Mixer.cpp
parentabb59a781aebf89cb3d808826ffc146e0a5d34ea (diff)
Mixer: Add assertions regarding num_samples versus buffer length
Diffstat (limited to 'Source/Core/AudioCommon/Mixer.cpp')
-rw-r--r--Source/Core/AudioCommon/Mixer.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/Source/Core/AudioCommon/Mixer.cpp b/Source/Core/AudioCommon/Mixer.cpp
index 2609ff89a5..ccec2db5c9 100644
--- a/Source/Core/AudioCommon/Mixer.cpp
+++ b/Source/Core/AudioCommon/Mixer.cpp
@@ -167,6 +167,11 @@ unsigned int Mixer::Mix(short* samples, unsigned int num_samples)
unsigned int available_samples =
std::min(m_dma_mixer.AvailableSamples(), m_streaming_mixer.AvailableSamples());
+ ASSERT_MSG(AUDIO, available_samples <= MAX_SAMPLES,
+ "Audio stretching would overflow m_scratch_buffer: min({}, {}) -> {} > {} ({})",
+ m_dma_mixer.AvailableSamples(), m_streaming_mixer.AvailableSamples(),
+ available_samples, MAX_SAMPLES, num_samples);
+
m_scratch_buffer.fill(0);
m_dma_mixer.Mix(m_scratch_buffer.data(), available_samples, false, emulation_speed,
@@ -213,10 +218,15 @@ unsigned int Mixer::MixSurround(float* samples, unsigned int num_samples)
// Mix() may also use m_scratch_buffer internally, but is safe because it alternates reads
// and writes.
+ ASSERT_MSG(AUDIO, needed_frames <= MAX_SAMPLES,
+ "needed_frames would overflow m_scratch_buffer: {} -> {} > {}", num_samples,
+ needed_frames, MAX_SAMPLES);
size_t available_frames = Mix(m_scratch_buffer.data(), static_cast<u32>(needed_frames));
if (available_frames != needed_frames)
{
- ERROR_LOG_FMT(AUDIO, "Error decoding surround frames.");
+ ERROR_LOG_FMT(AUDIO,
+ "Error decoding surround frames: needed {} frames for {} samples but got {}",
+ needed_frames, num_samples, available_frames);
return 0;
}
@@ -286,6 +296,9 @@ void Mixer::PushWiimoteSpeakerSamples(const short* samples, unsigned int num_sam
static constexpr u32 MAX_SPEAKER_SAMPLES = 20 * 2;
std::array<short, MAX_SPEAKER_SAMPLES * 2> samples_stereo;
+ ASSERT_MSG(AUDIO, num_samples <= MAX_SPEAKER_SAMPLES,
+ "num_samples would overflow samples_stereo: {} > {}", num_samples,
+ MAX_SPEAKER_SAMPLES);
if (num_samples <= MAX_SPEAKER_SAMPLES)
{
m_wiimote_speaker_mixer.SetInputSampleRateDivisor(sample_rate_divisor);