summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu
diff options
context:
space:
mode:
author Aaron Giles <aaron@aarongiles.com>2020-09-17 01:24:17 -0700
committer Aaron Giles <aaron@aarongiles.com>2020-09-17 01:24:17 -0700
commit8d7d01caef380b119fbd8653fa5ad23e0d592564 (patch)
tree69ad747e9a42081425070a010fff86688bf67b54 /src/emu
parentdc0ede3c90717ed25de0695c555b861f06344f18 (diff)
Revert "sound: Improved view interfaces to match usage patterns"
This reverts commit dc0ede3c90717ed25de0695c555b861f06344f18.
Diffstat (limited to 'src/emu')
-rw-r--r--src/emu/disound.cpp6
-rw-r--r--src/emu/sound.cpp41
-rw-r--r--src/emu/sound.h70
-rw-r--r--src/emu/speaker.cpp11
4 files changed, 49 insertions, 79 deletions
diff --git a/src/emu/disound.cpp b/src/emu/disound.cpp
index 1e7be43b32f..29d8b4e13b5 100644
--- a/src/emu/disound.cpp
+++ b/src/emu/disound.cpp
@@ -512,9 +512,9 @@ void device_mixer_interface::sound_stream_update(sound_stream &stream, std::vect
int outputnum = m_outputmap[inputnum];
auto &output = outputs[outputnum];
if (!m_output_clear[outputnum])
- output.copy_indexed(0, input);
+ output.copy(input);
else
- output.add_indexed(0, input);
+ output.add(input);
m_output_clear[outputnum] = true;
}
@@ -522,5 +522,5 @@ void device_mixer_interface::sound_stream_update(sound_stream &stream, std::vect
// clear anything unused
for (int outputnum = 0; outputnum < m_outputs; outputnum++)
if (!m_output_clear[outputnum])
- outputs[outputnum].fill_indexed(0, 0);
+ outputs[outputnum].fill(0);
}
diff --git a/src/emu/sound.cpp b/src/emu/sound.cpp
index d2c968ca370..a00546f7af3 100644
--- a/src/emu/sound.cpp
+++ b/src/emu/sound.cpp
@@ -208,7 +208,7 @@ void stream_buffer::flush_wav()
// convert and fill
for (int sampindex = 0; sampindex < cursamples; sampindex++)
- buffer[sampindex] = s16(view.get_indexed(samplebase + sampindex) * 32768.0);
+ buffer[sampindex] = s16(view.get(samplebase + sampindex) * 32768.0);
// write to the WAV
wav_add_data_16(m_wav_file, buffer, cursamples);
@@ -743,7 +743,7 @@ read_stream_view sound_stream::update_view(attotime start, attotime end, u32 out
#if (SOUND_DEBUG)
// clear each output view to NANs before we call the callback
for (unsigned int outindex = 0; outindex < m_output.size(); outindex++)
- m_output_view[outindex].fill_indexed(0, NAN);
+ m_output_view[outindex].fill(NAN);
#endif
// if we have an extended callback, that's all we need
@@ -753,7 +753,7 @@ read_stream_view sound_stream::update_view(attotime start, attotime end, u32 out
// make sure everything was overwritten
for (unsigned int outindex = 0; outindex < m_output.size(); outindex++)
for (int sampindex = 0; sampindex < m_output_view[outindex].samples(); sampindex++)
- m_output_view[outindex].get_indexed(sampindex);
+ m_output_view[outindex].get(sampindex);
for (unsigned int outindex = 0; outindex < m_output.size(); outindex++)
m_output[outindex].m_buffer.flush_wav();
@@ -934,7 +934,7 @@ void sound_stream::stream_update_legacy(sound_stream &stream, std::vector<read_s
{
stream_sample_t *dest = inputptr[inputnum];
for (int index = 0; index < cursamples; index++)
- dest[index] = stream_sample_t(inputs[inputnum].get_indexed(baseindex + index) * stream_buffer::sample_t(32768.0));
+ dest[index] = stream_sample_t(inputs[inputnum].get(baseindex + index) * stream_buffer::sample_t(32768.0));
}
// run the callback
@@ -945,7 +945,7 @@ void sound_stream::stream_update_legacy(sound_stream &stream, std::vector<read_s
{
stream_sample_t *src = outputptr[outputnum];
for (int index = 0; index < cursamples; index++)
- outputs[outputnum].put_indexed(baseindex + index, stream_buffer::sample_t(src[index]) * stream_buffer::sample_t(1.0 / 32768.0));
+ outputs[outputnum].put(baseindex + index, stream_buffer::sample_t(src[index]) * stream_buffer::sample_t(1.0 / 32768.0));
}
}
}
@@ -1012,6 +1012,7 @@ void default_resampler_stream::resampler_sound_update(sound_stream &stream, std:
}
// if we have equal sample rates, we just need to copy
+ auto numsamples = output.samples();
if (input.sample_rate() == output.sample_rate())
{
output.copy(input);
@@ -1033,13 +1034,14 @@ void default_resampler_stream::resampler_sound_update(sound_stream &stream, std:
attotime latency = latency_samples * input.sample_period();
// clamp the latency to the start (only relevant at the beginning)
+ s32 dstindex = 0;
attotime output_start = output.start_time();
- while (latency > output_start && !output.done())
+ while (latency > output_start && dstindex < numsamples)
{
- output.put(0);
+ output.put(dstindex++, 0);
output_start += output.sample_period();
}
- if (output.done())
+ if (dstindex >= numsamples)
return;
// create a rebased input buffer around the adjusted start time
@@ -1053,14 +1055,15 @@ void default_resampler_stream::resampler_sound_update(sound_stream &stream, std:
sound_assert(srcpos <= 1.0f);
// input is undersampled: point sample except where our sample period covers a boundary
+ s32 srcindex = 0;
if (step < 1.0)
{
- stream_buffer::sample_t cursample = rebased.get();
- while (!output.done())
+ stream_buffer::sample_t cursample = rebased.get(srcindex++);
+ for ( ; dstindex < numsamples; dstindex++)
{
// if still within the current sample, just replicate
if (srcpos <= 1.0)
- output.put(cursample);
+ output.put(dstindex, cursample);
// if crossing a sample boundary, blend with the neighbor
else
@@ -1068,18 +1071,19 @@ void default_resampler_stream::resampler_sound_update(sound_stream &stream, std:
srcpos -= 1.0;
sound_assert(srcpos <= step + 1e-5);
stream_buffer::sample_t prevsample = cursample;
- cursample = rebased.get();
- output.put(stepinv * (prevsample * (step - srcpos) + srcpos * cursample));
+ cursample = rebased.get(srcindex++);
+ output.put(dstindex, stepinv * (prevsample * (step - srcpos) + srcpos * cursample));
}
srcpos += step;
}
+ sound_assert(srcindex <= rebased.samples());
}
// input is oversampled: sum the energy
else
{
- float cursample = rebased.get();
- while (!output.done())
+ float cursample = rebased.get(srcindex++);
+ for ( ; dstindex < numsamples; dstindex++)
{
// compute the partial first sample and advance
stream_buffer::sample_t scale = 1.0 - srcpos;
@@ -1089,17 +1093,18 @@ void default_resampler_stream::resampler_sound_update(sound_stream &stream, std:
stream_buffer::sample_t remaining = step - scale;
while (remaining >= 1.0)
{
- sample += rebased.get();
+ sample += rebased.get(srcindex++);
remaining -= 1.0;
}
// add in the final partial sample
- cursample = rebased.get();
+ cursample = rebased.get(srcindex++);
sample += cursample * remaining;
- output.put(sample * stepinv);
+ output.put(dstindex, sample * stepinv);
// our position is now the remainder
srcpos = remaining;
+ sound_assert(srcindex <= rebased.samples());
}
}
}
diff --git a/src/emu/sound.h b/src/emu/sound.h
index d7a833c749d..5ccc78c015b 100644
--- a/src/emu/sound.h
+++ b/src/emu/sound.h
@@ -239,7 +239,6 @@ public:
m_buffer(buffer),
m_end(end),
m_start(start),
- m_offset(0),
m_gain(gain)
{
normalize_start_end();
@@ -276,7 +275,6 @@ public:
m_start = rhs.m_start;
m_end = rhs.m_end;
m_gain = rhs.m_gain;
- m_offset = 0;
normalize_start_end();
return *this;
}
@@ -294,18 +292,6 @@ public:
// return the number of samples represented by the buffer
u32 samples() const { return m_end - m_start; }
- // return the current offset within the buffer
- s32 offset() const { return m_offset; }
-
- // return the number of samples remaining from the current offset
- s32 remaining() const { return samples() - m_offset; }
-
- // (re)set the current offset within the buffer
- read_stream_view const &reset(s32 offset = 0) const { m_offset = offset; return *this; }
-
- // return true if we've consumed all the samples in the view
- bool done() const { return m_offset >= samples(); }
-
// return the starting or ending time of the buffer
attotime start_time() const { return m_buffer->index_time(m_start); }
attotime end_time() const { return m_buffer->index_time(m_end); }
@@ -317,7 +303,7 @@ public:
read_stream_view &apply_gain(float gain) { m_gain *= gain; return *this; }
// safely fetch a gain-scaled sample from the buffer
- sample_t get_indexed(s32 index) const
+ sample_t get(s32 index) const
{
sound_assert(u32(index) < samples());
index += m_start;
@@ -328,7 +314,7 @@ public:
// safely fetch a raw sample from the buffer; if you use this, you need to
// apply the gain yourself for correctness
- sample_t getraw_indexed(s32 index) const
+ sample_t getraw(s32 index) const
{
sound_assert(u32(index) < samples());
index += m_start;
@@ -337,10 +323,6 @@ public:
return m_buffer->get(index);
}
- // non-indexed versions of the above that use the implied offset
- sample_t get() const { sound_assert(m_offset < samples()); return get_indexed(m_offset++); }
- sample_t getraw() const { sound_assert(m_offset < samples()); return getraw_indexed(m_offset++); }
-
protected:
// normalize start/end
void normalize_start_end()
@@ -356,7 +338,6 @@ protected:
stream_buffer *m_buffer; // pointer to the stream buffer we're viewing
s32 m_end; // ending sample index (always >= start)
s32 m_start; // starting sample index
- mutable s32 m_offset; // current read/write offset
sample_t m_gain; // overall gain factor
};
@@ -383,11 +364,8 @@ public:
{
}
- // (re)set the current offset within the buffer
- write_stream_view &reset(s32 offset = 0) { m_offset = offset; return *this; }
-
// safely write a gain-applied sample to the buffer
- void put_indexed(s32 index, sample_t sample)
+ void put(s32 index, sample_t sample)
{
sound_assert(u32(index) < samples());
index += m_start;
@@ -397,7 +375,7 @@ public:
}
// safely add a gain-applied sample to the buffer
- void add_indexed(s32 index, sample_t sample)
+ void add(s32 index, sample_t sample)
{
sound_assert(u32(index) < samples());
index += m_start;
@@ -407,9 +385,9 @@ public:
}
// fill part of the view with the given value
- s32 fill_indexed(s32 start, sample_t value, s32 count = -1)
+ void fill(sample_t value, s32 start, s32 count)
{
- if (count < 0 || start + count > samples())
+ if (start + count > samples())
count = samples() - start;
u32 index = start + m_start;
for (s32 sampindex = 0; sampindex < count; sampindex++)
@@ -417,51 +395,39 @@ public:
m_buffer->put(index, value);
index = m_buffer->next_index(index);
}
- return count;
}
+ void fill(sample_t value, s32 start) { fill(value, start, samples() - start); }
+ void fill(sample_t value) { fill(value, 0, samples()); }
// copy data from another view
- s32 copy_indexed(s32 start, read_stream_view const &src, s32 srcstart = -1, s32 count = -1)
+ void copy(read_stream_view const &src, s32 start, s32 count)
{
- if (count < 0 || start + count > samples())
+ if (start + count > samples())
count = samples() - start;
- if (srcstart < 0)
- srcstart = start;
- if (srcstart + count > src.samples())
- count = src.samples() - srcstart;
u32 index = start + m_start;
for (s32 sampindex = 0; sampindex < count; sampindex++)
{
- m_buffer->put(index, src.get_indexed(srcstart + sampindex));
+ m_buffer->put(index, src.get(start + sampindex));
index = m_buffer->next_index(index);
}
- return count;
}
+ void copy(read_stream_view const &src, s32 start) { copy(src, start, samples() - start); }
+ void copy(read_stream_view const &src) { copy(src, 0, samples()); }
// add data from another view to our current values
- s32 add_indexed(s32 start, read_stream_view const &src, s32 srcstart = -1, s32 count = -1)
+ void add(read_stream_view const &src, s32 start, s32 count)
{
- if (count < 0 || start + count > samples())
+ if (start + count > samples())
count = samples() - start;
- if (srcstart < 0)
- srcstart = start;
- if (srcstart + count > src.samples())
- count = src.samples() - srcstart;
u32 index = start + m_start;
for (s32 sampindex = 0; sampindex < count; sampindex++)
{
- m_buffer->put(index, m_buffer->get(index) + src.get_indexed(start + sampindex));
+ m_buffer->put(index, m_buffer->get(index) + src.get(start + sampindex));
index = m_buffer->next_index(index);
}
- return count;
}
-
- // non-indexed versions of the above that use the implied offset
- void put(sample_t sample) { sound_assert(m_offset < samples()); put_indexed(m_offset++, sample); }
- void add(sample_t sample) { sound_assert(m_offset < samples()); add_indexed(m_offset++, sample); }
- s32 fill(sample_t value, s32 count = -1) { m_offset += count = fill_indexed(m_offset, value, count); return count; }
- s32 copy(read_stream_view const &src, s32 count = -1) { count = copy_indexed(m_offset, src, m_offset, count); m_offset += count; src.reset(src.offset() + count); return count; }
- s32 add(read_stream_view const &src, s32 count = -1) { count = add_indexed(m_offset, src, m_offset, count); m_offset += count; src.reset(src.offset() + count); return count; }
+ 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()); }
};
diff --git a/src/emu/speaker.cpp b/src/emu/speaker.cpp
index b487b5d8aea..3cbb14355a4 100644
--- a/src/emu/speaker.cpp
+++ b/src/emu/speaker.cpp
@@ -74,9 +74,9 @@ void speaker_device::mix(stream_buffer::sample_t *leftmix, stream_buffer::sample
if (machine().options().speaker_report() != 0)
{
u32 samples_per_bucket = m_mixer_stream->sample_rate() / BUCKETS_PER_SECOND;
- while (!view.done())
+ for (int sample = 0; sample < expected_samples; sample++)
{
- m_current_max = std::max(m_current_max, fabsf(view.get()));
+ m_current_max = std::max(m_current_max, fabsf(view.get(sample)));
if (++m_samples_this_bucket >= samples_per_bucket)
{
m_max_sample.push_back(m_current_max);
@@ -84,7 +84,6 @@ void speaker_device::mix(stream_buffer::sample_t *leftmix, stream_buffer::sample
m_samples_this_bucket = 0;
}
}
- view.reset();
}
// mix if sound is enabled
@@ -94,7 +93,7 @@ void speaker_device::mix(stream_buffer::sample_t *leftmix, stream_buffer::sample
if (m_x == 0)
for (int sample = 0; sample < expected_samples; sample++)
{
- stream_buffer::sample_t cursample = view.get();
+ stream_buffer::sample_t cursample = view.get(sample);
leftmix[sample] += cursample;
rightmix[sample] += cursample;
}
@@ -102,12 +101,12 @@ void speaker_device::mix(stream_buffer::sample_t *leftmix, stream_buffer::sample
// if the speaker is to the left, send only to the left
else if (m_x < 0)
for (int sample = 0; sample < expected_samples; sample++)
- leftmix[sample] += view.get();
+ leftmix[sample] += view.get(sample);
// if the speaker is to the right, send only to the right
else
for (int sample = 0; sample < expected_samples; sample++)
- rightmix[sample] += view.get();
+ rightmix[sample] += view.get(sample);
}
}