summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/sound
diff options
context:
space:
mode:
author Vas Crabb <vas@vastheman.com>2020-09-27 01:24:38 +1000
committer Vas Crabb <vas@vastheman.com>2020-09-27 01:24:38 +1000
commitb38ffb6bff20044d368fcde3f3bfdd00ae905f22 (patch)
treec7c07a82a61264806ec69cc514fff0d71e90e2aa /src/devices/sound
parent59ae905ee3597650bbcd01cff85a1f5cefa783c2 (diff)
Changed some sound devices back to using std::unique_ptr<T []> for
things that don't need to change size. Using a std::vector has additional overhead for keeping the size and allocated size, and it means you can inadvertently resize it. Also, if you register one for save state then cause it to reallocate, very bad things happen. Fixed some mixed tab/space indents in sound/mm5837.h Changed namco_163.cpp to have registers as an array in the device, since there aren't many of them, and also restored zeroing them on start.
Diffstat (limited to 'src/devices/sound')
-rw-r--r--src/devices/sound/k005289.cpp5
-rw-r--r--src/devices/sound/k005289.h2
-rw-r--r--src/devices/sound/k054539.cpp5
-rw-r--r--src/devices/sound/k054539.h2
-rw-r--r--src/devices/sound/mm5837.h42
-rw-r--r--src/devices/sound/mos6560.cpp15
-rw-r--r--src/devices/sound/mos6560.h4
-rw-r--r--src/devices/sound/namco_163.cpp5
-rw-r--r--src/devices/sound/namco_163.h2
9 files changed, 41 insertions, 41 deletions
diff --git a/src/devices/sound/k005289.cpp b/src/devices/sound/k005289.cpp
index b80f77839d7..00fe18e2c2f 100644
--- a/src/devices/sound/k005289.cpp
+++ b/src/devices/sound/k005289.cpp
@@ -171,17 +171,16 @@ void k005289_device::sound_stream_update(sound_stream &stream, std::vector<read_
void k005289_device::make_mixer_table(int voices)
{
int count = voices * 128;
- int i;
int gain = 16;
/* allocate memory */
- m_mixer_table.resize(256 * voices);
+ m_mixer_table = std::make_unique<stream_buffer::sample_t []>(256 * voices);
/* find the middle of the table */
m_mixer_lookup = &m_mixer_table[128 * voices];
/* fill in the table - 16 bit case */
- for (i = 0; i < count; i++)
+ for (int i = 0; i < count; i++)
{
int val = i * gain * 16 / voices;
if (val > 32767) val = 32767;
diff --git a/src/devices/sound/k005289.h b/src/devices/sound/k005289.h
index 656dccbcb7f..989ab15ae6d 100644
--- a/src/devices/sound/k005289.h
+++ b/src/devices/sound/k005289.h
@@ -36,7 +36,7 @@ private:
int m_rate;
/* mixer tables and internal buffers */
- std::vector<stream_buffer::sample_t> m_mixer_table;
+ std::unique_ptr<stream_buffer::sample_t []> m_mixer_table;
stream_buffer::sample_t *m_mixer_lookup;
std::vector<short> m_mixer_buffer;
diff --git a/src/devices/sound/k054539.cpp b/src/devices/sound/k054539.cpp
index 8d1b368e9ad..cba942e002f 100644
--- a/src/devices/sound/k054539.cpp
+++ b/src/devices/sound/k054539.cpp
@@ -23,7 +23,6 @@ k054539_device::k054539_device(const machine_config &mconfig, const char *tag, d
, device_sound_interface(mconfig, *this)
, device_rom_interface(mconfig, *this)
, flags(0)
- , ram(0x4000)
, reverb_pos(0)
, cur_ptr(0)
, cur_limit(0)
@@ -320,6 +319,8 @@ void k054539_device::init_chip()
memset(posreg_latch, 0, sizeof(posreg_latch)); //*
flags |= UPDATE_AT_KEYON; //* make it default until proven otherwise
+ ram = std::make_unique<uint8_t []>(0x4000);
+
reverb_pos = 0;
cur_ptr = 0;
memset(&ram[0], 0, 0x4000);
@@ -333,7 +334,7 @@ void k054539_device::init_chip()
save_item(NAME(flags));
save_item(NAME(regs));
- save_item(NAME(ram));
+ save_pointer(NAME(ram), 0x4000);
save_item(NAME(reverb_pos));
save_item(NAME(cur_ptr));
save_item(NAME(cur_limit));
diff --git a/src/devices/sound/k054539.h b/src/devices/sound/k054539.h
index ec019ba990e..6c79ac6d0be 100644
--- a/src/devices/sound/k054539.h
+++ b/src/devices/sound/k054539.h
@@ -88,7 +88,7 @@ private:
int flags;
unsigned char regs[0x230];
- std::vector<uint8_t> ram;
+ std::unique_ptr<uint8_t []> ram;
int reverb_pos;
int32_t cur_ptr;
diff --git a/src/devices/sound/mm5837.h b/src/devices/sound/mm5837.h
index abe1a2a2ec2..49374537b9c 100644
--- a/src/devices/sound/mm5837.h
+++ b/src/devices/sound/mm5837.h
@@ -128,22 +128,22 @@ public:
static u32 frequency(double vdd)
{
// Vdd should be negative -6.2..-15V
- if (vdd > -6.2 || vdd < -15)
- throw emu_fatalerror("mm5837 frequency should be -6.2V .. -15V");
-
- // curve fitting done in excel from this table:
- // { 0, 0, 0, 0, 0, 0, 1, 2267, 8731, 16382, 23531, 32564, 38347, 40010, 37800, 33173 }
- double result = 191.98*vdd*vdd*vdd + 5448.4*vdd*vdd + 43388*vdd + 105347;
-
- // datasheet claims frequency range 24-56kHz at Vdd=-14V, but also lists
- // maximum cycle times as ranging from 1.1-2.4s; since the 17-bit shift
- // register cycles after 131072 clocks, we would expect the actual cycle
- // times to be 2.34-5.46s at the 24-56kHz frequency range, so I'm presuming
- // that it ticks 2x per "clock", effectively running at 2x the frequency
- result *= 2;
-
- // make sure the result isn't TOO crazy
- result = std::max(result, 100.0);
+ if (vdd > -6.2 || vdd < -15)
+ throw emu_fatalerror("mm5837 frequency should be -6.2V .. -15V");
+
+ // curve fitting done in excel from this table:
+ // { 0, 0, 0, 0, 0, 0, 1, 2267, 8731, 16382, 23531, 32564, 38347, 40010, 37800, 33173 }
+ double result = 191.98*vdd*vdd*vdd + 5448.4*vdd*vdd + 43388*vdd + 105347;
+
+ // datasheet claims frequency range 24-56kHz at Vdd=-14V, but also lists
+ // maximum cycle times as ranging from 1.1-2.4s; since the 17-bit shift
+ // register cycles after 131072 clocks, we would expect the actual cycle
+ // times to be 2.34-5.46s at the 24-56kHz frequency range, so I'm presuming
+ // that it ticks 2x per "clock", effectively running at 2x the frequency
+ result *= 2;
+
+ // make sure the result isn't TOO crazy
+ result = std::max(result, 100.0);
return u32(result);
}
@@ -171,10 +171,10 @@ protected:
virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override;
private:
- // internal state
+ // internal state
devcb_write_line m_output_cb; // output callback
- emu_timer *m_timer; // output timer
- double m_vdd; // configured voltage
+ emu_timer *m_timer; // output timer
+ double m_vdd; // configured voltage
mm5837_source m_source; // noise source
};
@@ -199,8 +199,8 @@ protected:
private:
sound_stream *m_stream; // sound stream
- double m_vdd; // configured voltage
- mm5837_source m_source; // noise source
+ double m_vdd; // configured voltage
+ mm5837_source m_source; // noise source
};
diff --git a/src/devices/sound/mos6560.cpp b/src/devices/sound/mos6560.cpp
index e3f94ef6aa6..e551df0a93d 100644
--- a/src/devices/sound/mos6560.cpp
+++ b/src/devices/sound/mos6560.cpp
@@ -620,20 +620,17 @@ void mos6560_device::soundport_w( int offset, int data )
void mos6560_device::sound_start()
{
- int i;
-
m_channel = stream_alloc(0, 1, machine().sample_rate());
/* buffer for fastest played sample for 5 second so we have enough data for min 5 second */
m_noisesize = NOISE_FREQUENCY_MAX * NOISE_BUFFER_SIZE_SEC;
- m_noise.resize(m_noisesize);
+ m_noise = std::make_unique<int8_t []>(m_noisesize);
{
int noiseshift = 0x7ffff8;
- char data;
- for (i = 0; i < m_noisesize; i++)
+ for (int i = 0; i < m_noisesize; i++)
{
- data = 0;
+ char data = 0;
if (noiseshift & 0x400000)
data |= 0x80;
if (noiseshift & 0x100000)
@@ -661,11 +658,11 @@ void mos6560_device::sound_start()
if (m_tonesize > 0)
{
- m_tone.resize(m_tonesize);
+ m_tone = std::make_unique<int16_t []>(m_tonesize);
- for (i = 0; i < m_tonesize; i++)
+ for (int i = 0; i < m_tonesize; i++)
{
- m_tone[i] = (int16_t)(sin (2 * M_PI * i / m_tonesize) * 127 + 0.5);
+ m_tone[i] = int16_t(sin (2 * M_PI * i / m_tonesize) * 127 + 0.5);
}
}
}
diff --git a/src/devices/sound/mos6560.h b/src/devices/sound/mos6560.h
index 6937fdf4eac..182cba47dba 100644
--- a/src/devices/sound/mos6560.h
+++ b/src/devices/sound/mos6560.h
@@ -176,8 +176,8 @@ protected:
m_noisesamples; /* count of samples to give out per tone */
sound_stream *m_channel;
- std::vector<int16_t> m_tone;
- std::vector<int8_t> m_noise;
+ std::unique_ptr<int16_t []> m_tone;
+ std::unique_ptr<int8_t []> m_noise;
emu_timer *m_line_timer;
};
diff --git a/src/devices/sound/namco_163.cpp b/src/devices/sound/namco_163.cpp
index 87cd82a03eb..08daf720d17 100644
--- a/src/devices/sound/namco_163.cpp
+++ b/src/devices/sound/namco_163.cpp
@@ -11,13 +11,14 @@
#include "emu.h"
#include "namco_163.h"
+#include <algorithm>
+
DEFINE_DEVICE_TYPE(NAMCO_163, namco_163_sound_device, "namco_163_sound", "Namco 163 (Sound)")
namco_163_sound_device::namco_163_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock)
: device_t(mconfig, NAMCO_163, tag, owner, clock)
, device_sound_interface(mconfig, *this)
- , m_ram(0x80)
, m_reg_addr(0x78)
, m_addr(0)
, m_inc(false)
@@ -33,6 +34,8 @@ namco_163_sound_device::namco_163_sound_device(const machine_config &mconfig, co
void namco_163_sound_device::device_start()
{
+ std::fill(std::begin(m_ram), std::end(m_ram), 0);
+
m_stream = stream_alloc(0, 1, clock() / 15);
save_item(NAME(m_ram));
diff --git a/src/devices/sound/namco_163.h b/src/devices/sound/namco_163.h
index a4e205b6177..f3a7428300d 100644
--- a/src/devices/sound/namco_163.h
+++ b/src/devices/sound/namco_163.h
@@ -24,7 +24,7 @@ protected:
virtual void device_clock_changed() override;
// global sound parameters
- std::vector<u8> m_ram;
+ u8 m_ram[0x80];
u8 m_reg_addr;
u8 m_addr;
bool m_inc;