summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author Aaron Giles <aaron@aarongiles.com>2021-04-21 22:48:24 -0700
committer Aaron Giles <aaron@aarongiles.com>2021-04-21 22:48:47 -0700
commit20fceccf3950ff74f5cbcd7deb502a17cd50039c (patch)
tree74625b88d1a1d760984a0c17aa66b8d3da67c3b4
parentb4d73d64b14217e207d7a68e11c73e6fddf14125 (diff)
sound: Fix wrapping bug when using fill/copy/bulk-add on write_stream_views
-rw-r--r--src/emu/sound.h32
1 files changed, 18 insertions, 14 deletions
diff --git a/src/emu/sound.h b/src/emu/sound.h
index 3aefc4bef3f..84c304dab68 100644
--- a/src/emu/sound.h
+++ b/src/emu/sound.h
@@ -371,13 +371,9 @@ public:
}
// safely write a sample to the buffer
- void put(s32 index, sample_t sample)
+ void put(s32 start, sample_t sample)
{
- sound_assert(u32(index) < samples());
- index += m_start;
- if (index >= m_buffer->size())
- index -= m_buffer->size();
- m_buffer->put(index, sample);
+ m_buffer->put(index_to_buffer_index(start), sample);
}
// write a sample to the buffer, clamping to +/- the clamp value
@@ -401,12 +397,9 @@ public:
}
// safely add a sample to the buffer
- void add(s32 index, sample_t sample)
+ void add(s32 start, sample_t sample)
{
- sound_assert(u32(index) < samples());
- index += m_start;
- if (index >= m_buffer->size())
- index -= m_buffer->size();
+ u32 index = index_to_buffer_index(start);
m_buffer->put(index, m_buffer->get(index) + sample);
}
@@ -421,7 +414,7 @@ public:
{
if (start + count > samples())
count = samples() - start;
- u32 index = start + m_start;
+ u32 index = index_to_buffer_index(start);
for (s32 sampindex = 0; sampindex < count; sampindex++)
{
m_buffer->put(index, value);
@@ -436,7 +429,7 @@ public:
{
if (start + count > samples())
count = samples() - start;
- u32 index = start + m_start;
+ u32 index = index_to_buffer_index(start);
for (s32 sampindex = 0; sampindex < count; sampindex++)
{
m_buffer->put(index, src.get(start + sampindex));
@@ -451,7 +444,7 @@ public:
{
if (start + count > samples())
count = samples() - start;
- u32 index = start + m_start;
+ u32 index = index_to_buffer_index(start);
for (s32 sampindex = 0; sampindex < count; sampindex++)
{
m_buffer->put(index, m_buffer->get(index) + src.get(start + sampindex));
@@ -460,6 +453,17 @@ public:
}
void add(read_stream_view const &src, s32 start) { add(src, start, samples() - start); }
void add(read_stream_view const &src) { add(src, 0, samples()); }
+
+private:
+ // given a stream starting offset, return the buffer index
+ u32 index_to_buffer_index(s32 start) const
+ {
+ sound_assert(u32(start) < samples());
+ u32 index = start + m_start;
+ if (index >= m_buffer->size())
+ index -= m_buffer->size();
+ return index;
+ }
};