mirror of
https://github.com/holub/mame
synced 2025-07-05 18:08:04 +03:00
sound: Fix wrapping bug when using fill/copy/bulk-add on write_stream_views
This commit is contained in:
parent
b4d73d64b1
commit
20fceccf39
@ -371,13 +371,9 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// safely write a sample to the buffer
|
// 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());
|
m_buffer->put(index_to_buffer_index(start), sample);
|
||||||
index += m_start;
|
|
||||||
if (index >= m_buffer->size())
|
|
||||||
index -= m_buffer->size();
|
|
||||||
m_buffer->put(index, sample);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// write a sample to the buffer, clamping to +/- the clamp value
|
// write a sample to the buffer, clamping to +/- the clamp value
|
||||||
@ -401,12 +397,9 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// safely add a sample to the buffer
|
// 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());
|
u32 index = index_to_buffer_index(start);
|
||||||
index += m_start;
|
|
||||||
if (index >= m_buffer->size())
|
|
||||||
index -= m_buffer->size();
|
|
||||||
m_buffer->put(index, m_buffer->get(index) + sample);
|
m_buffer->put(index, m_buffer->get(index) + sample);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -421,7 +414,7 @@ public:
|
|||||||
{
|
{
|
||||||
if (start + count > samples())
|
if (start + count > samples())
|
||||||
count = samples() - start;
|
count = samples() - start;
|
||||||
u32 index = start + m_start;
|
u32 index = index_to_buffer_index(start);
|
||||||
for (s32 sampindex = 0; sampindex < count; sampindex++)
|
for (s32 sampindex = 0; sampindex < count; sampindex++)
|
||||||
{
|
{
|
||||||
m_buffer->put(index, value);
|
m_buffer->put(index, value);
|
||||||
@ -436,7 +429,7 @@ public:
|
|||||||
{
|
{
|
||||||
if (start + count > samples())
|
if (start + count > samples())
|
||||||
count = samples() - start;
|
count = samples() - start;
|
||||||
u32 index = start + m_start;
|
u32 index = index_to_buffer_index(start);
|
||||||
for (s32 sampindex = 0; sampindex < count; sampindex++)
|
for (s32 sampindex = 0; sampindex < count; sampindex++)
|
||||||
{
|
{
|
||||||
m_buffer->put(index, src.get(start + sampindex));
|
m_buffer->put(index, src.get(start + sampindex));
|
||||||
@ -451,7 +444,7 @@ public:
|
|||||||
{
|
{
|
||||||
if (start + count > samples())
|
if (start + count > samples())
|
||||||
count = samples() - start;
|
count = samples() - start;
|
||||||
u32 index = start + m_start;
|
u32 index = index_to_buffer_index(start);
|
||||||
for (s32 sampindex = 0; sampindex < count; sampindex++)
|
for (s32 sampindex = 0; sampindex < count; sampindex++)
|
||||||
{
|
{
|
||||||
m_buffer->put(index, m_buffer->get(index) + src.get(start + 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, s32 start) { add(src, start, samples() - start); }
|
||||||
void add(read_stream_view const &src) { add(src, 0, samples()); }
|
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;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user