summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/sound/beep.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/devices/sound/beep.cpp')
-rw-r--r--src/devices/sound/beep.cpp65
1 files changed, 25 insertions, 40 deletions
diff --git a/src/devices/sound/beep.cpp b/src/devices/sound/beep.cpp
index 14fadcf6b7d..9a341a7a2d3 100644
--- a/src/devices/sound/beep.cpp
+++ b/src/devices/sound/beep.cpp
@@ -7,14 +7,11 @@
This is used for computers/systems which can only output a constant tone.
This tone can be turned on and off.
e.g. PCW and PCW16 computer systems
- KT - 25-Jun-2000
****************************************************************************/
#include "emu.h"
-#include "sound/beep.h"
-
-#define BEEP_RATE (384000)
+#include "beep.h"
// device type definition
@@ -24,7 +21,7 @@ beep_device::beep_device(const machine_config &mconfig, const char *tag, device_
: device_t(mconfig, BEEP, tag, owner, clock)
, device_sound_interface(mconfig, *this)
, m_stream(nullptr)
- , m_enable(0)
+ , m_enable(false)
, m_frequency(clock)
{
}
@@ -36,8 +33,11 @@ beep_device::beep_device(const machine_config &mconfig, const char *tag, device_
void beep_device::device_start()
{
- m_stream = stream_alloc(0, 1, BEEP_RATE);
- m_enable = 0;
+ // large stream buffer to favour emu/sound.cpp resample quality
+ m_stream = stream_alloc(0, 1, 48000 * 32);
+
+ m_enable = false;
+ m_incr = 0;
m_signal = 1.0;
// register for savestates
@@ -52,40 +52,24 @@ void beep_device::device_start()
// sound_stream_update - handle a stream update
//-------------------------------------------------
-void beep_device::sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs)
+void beep_device::sound_stream_update(sound_stream &stream)
{
- auto &buffer = outputs[0];
- int16_t signal = m_signal;
- int clock = 0, rate = BEEP_RATE / 2;
-
- /* get progress through wave */
- int incr = m_incr;
-
- if (m_frequency > 0)
- clock = m_frequency;
-
- /* if we're not enabled, just fill with 0 */
- if (!m_enable || clock == 0)
- {
- buffer.fill(0);
+ // if we're not enabled, just leave cleared
+ if (!m_enable || m_frequency == 0)
return;
- }
- /* fill in the sample */
- for (int sampindex = 0; sampindex < buffer.samples(); sampindex++)
+ // fill in the sample
+ for (int sampindex = 0; sampindex < stream.samples(); sampindex++)
{
- buffer.put(sampindex, signal);
- incr -= clock;
- while( incr < 0 )
+ m_incr -= m_frequency;
+ while (m_incr < 0)
{
- incr += rate;
- signal = -signal;
+ m_incr += stream.sample_rate() / 2;
+ m_signal = -m_signal;
}
- }
- /* store progress through wave */
- m_incr = incr;
- m_signal = signal;
+ stream.put(0, sampindex, m_signal);
+ }
}
@@ -95,15 +79,14 @@ void beep_device::sound_stream_update(sound_stream &stream, std::vector<read_str
void beep_device::set_state(int state)
{
- /* only update if new state is not the same as old state */
- int on = (state) ? 1 : 0;
- if (m_enable == on)
+ // only update if new state is not the same as old state
+ if (m_enable == bool(state))
return;
m_stream->update();
- m_enable = on;
+ m_enable = bool(state);
- /* restart wave from beginning */
+ // restart wave from beginning
m_incr = 0;
m_signal = 1.0;
}
@@ -120,6 +103,8 @@ void beep_device::set_clock(uint32_t frequency)
m_stream->update();
m_frequency = frequency;
- m_signal = 1.0;
+
+ // restart wave from beginning
m_incr = 0;
+ m_signal = 1.0;
}