diff options
author | 2019-12-11 07:29:38 -0500 | |
---|---|---|
committer | 2019-12-11 07:30:55 -0500 | |
commit | aedd969c5362d8c44d94d820b8f58bf77d9f62b3 (patch) | |
tree | 730ab03ca259ba9d84fbc23d081b8b45cc7fa9bf /src | |
parent | 669066220f53c8dcfa18c04a7e814edd4fd10f60 (diff) |
saa1099: Use narrower types for members; clean up code slightly (nw)
Diffstat (limited to 'src')
-rw-r--r-- | src/devices/sound/saa1099.cpp | 68 | ||||
-rw-r--r-- | src/devices/sound/saa1099.h | 47 |
2 files changed, 51 insertions, 64 deletions
diff --git a/src/devices/sound/saa1099.cpp b/src/devices/sound/saa1099.cpp index a0f7dbac075..9c41ca7a939 100644 --- a/src/devices/sound/saa1099.cpp +++ b/src/devices/sound/saa1099.cpp @@ -73,14 +73,14 @@ #define LEFT 0x00 #define RIGHT 0x01 -static constexpr int amplitude_lookup[16] = { +static constexpr u16 amplitude_lookup[16] = { 0*32767/16, 1*32767/16, 2*32767/16, 3*32767/16, 4*32767/16, 5*32767/16, 6*32767/16, 7*32767/16, 8*32767/16, 9*32767/16, 10*32767/16, 11*32767/16, 12*32767/16, 13*32767/16, 14*32767/16, 15*32767/16 }; -static constexpr uint8_t envelope[8][64] = { +static constexpr u8 envelope[8][64] = { /* zero amplitude */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -135,19 +135,19 @@ DEFINE_DEVICE_TYPE(SAA1099, saa1099_device, "saa1099", "Philips SAA1099") // saa1099_device - constructor //------------------------------------------------- -saa1099_device::saa1099_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) +saa1099_device::saa1099_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) : device_t(mconfig, SAA1099, tag, owner, clock) , device_sound_interface(mconfig, *this) , m_stream(nullptr) , m_noise_params{ 0, 0 } - , m_env_enable{ 0, 0 } - , m_env_reverse_right{ 0, 0 } + , m_env_enable{ false, false } + , m_env_reverse_right{ false, false } , m_env_mode{ 0, 0 } - , m_env_bits{ 0, 0 } - , m_env_clock{ 0, 0 } + , m_env_bits{ false, false } + , m_env_clock{ false, false } , m_env_step{ 0, 0 } - , m_all_ch_enable(0) - , m_sync_state(0) + , m_all_ch_enable(false) + , m_sync_state(false) , m_selected_reg(0) , m_sample_rate(0.0) { @@ -161,7 +161,6 @@ saa1099_device::saa1099_device(const machine_config &mconfig, const char *tag, d void saa1099_device::device_start() { /* copy global parameters */ - m_master_clock = clock(); m_sample_rate = clock() / 256; /* for each chip allocate one stream */ @@ -200,7 +199,6 @@ void saa1099_device::device_start() void saa1099_device::device_clock_changed() { - m_master_clock = clock(); m_sample_rate = clock() / 256; m_stream->set_sample_rate(m_sample_rate); @@ -227,10 +225,10 @@ void saa1099_device::sound_stream_update(sound_stream &stream, stream_sample_t * { switch (m_noise_params[ch]) { - case 0: m_noise[ch].freq = m_master_clock/256.0 * 2; break; - case 1: m_noise[ch].freq = m_master_clock/512.0 * 2; break; - case 2: m_noise[ch].freq = m_master_clock/1024.0 * 2; break; - case 3: m_noise[ch].freq = m_channels[ch * 3].freq; break; // todo: this case will be m_master_clock/[ch*3's octave divisor, 0 is = 256*2, higher numbers are higher] * 2 if the tone generator phase reset bit (0x1c bit 1) is set. + case 0: m_noise[ch].freq = clock()/256.0 * 2; break; + case 1: m_noise[ch].freq = clock()/512.0 * 2; break; + case 2: m_noise[ch].freq = clock()/1024.0 * 2; break; + case 3: m_noise[ch].freq = m_channels[ch * 3].freq; break; // todo: this case will be clock()/[ch*3's octave divisor, 0 is = 256*2, higher numbers are higher] * 2 if the tone generator phase reset bit (0x1c bit 1) is set. } } @@ -243,7 +241,7 @@ void saa1099_device::sound_stream_update(sound_stream &stream, stream_sample_t * for (ch = 0; ch < 6; ch++) { if (m_channels[ch].freq == 0.0) - m_channels[ch].freq = (double)((2 * m_master_clock / 512) << m_channels[ch].octave) / + m_channels[ch].freq = (double)((2 * clock() / 512) << m_channels[ch].octave) / (511.0 - (double)m_channels[ch].frequency); /* check the actual position in the square wave */ @@ -251,7 +249,7 @@ void saa1099_device::sound_stream_update(sound_stream &stream, stream_sample_t * while (m_channels[ch].counter < 0) { /* calculate new frequency now after the half wave is updated */ - m_channels[ch].freq = (double)((2 * m_master_clock / 512) << m_channels[ch].octave) / + m_channels[ch].freq = (double)((2 * clock() / 512) << m_channels[ch].octave) / (511.0 - (double)m_channels[ch].frequency); m_channels[ch].counter += m_sample_rate; @@ -326,7 +324,7 @@ void saa1099_device::envelope_w(int ch) m_channels[ch*3+0].envelope[ LEFT] = m_channels[ch*3+1].envelope[ LEFT] = m_channels[ch*3+2].envelope[ LEFT] = envelope[mode][step] & mask; - if (m_env_reverse_right[ch] & 0x01) + if (m_env_reverse_right[ch]) { m_channels[ch*3+0].envelope[RIGHT] = m_channels[ch*3+1].envelope[RIGHT] = @@ -401,21 +399,13 @@ void saa1099_device::data_w(u8 data) break; /* channel i frequency enable */ case 0x14: - m_channels[0].freq_enable = data & 0x01; - m_channels[1].freq_enable = data & 0x02; - m_channels[2].freq_enable = data & 0x04; - m_channels[3].freq_enable = data & 0x08; - m_channels[4].freq_enable = data & 0x10; - m_channels[5].freq_enable = data & 0x20; + for (ch = 0; ch < 6; ch++) + m_channels[ch].freq_enable = BIT(data, ch); break; /* channel i noise enable */ case 0x15: - m_channels[0].noise_enable = data & 0x01; - m_channels[1].noise_enable = data & 0x02; - m_channels[2].noise_enable = data & 0x04; - m_channels[3].noise_enable = data & 0x08; - m_channels[4].noise_enable = data & 0x10; - m_channels[5].noise_enable = data & 0x20; + for (ch = 0; ch < 6; ch++) + m_channels[ch].noise_enable = BIT(data, ch); break; /* noise generators parameters */ case 0x16: @@ -425,25 +415,23 @@ void saa1099_device::data_w(u8 data) /* envelope generators parameters */ case 0x18: case 0x19: ch = reg - 0x18; - m_env_reverse_right[ch] = data & 0x01; + m_env_reverse_right[ch] = BIT(data, 0); m_env_mode[ch] = (data >> 1) & 0x07; - m_env_bits[ch] = data & 0x10; - m_env_clock[ch] = data & 0x20; - m_env_enable[ch] = data & 0x80; + m_env_bits[ch] = BIT(data, 4); + m_env_clock[ch] = BIT(data, 5); + m_env_enable[ch] = BIT(data, 7); /* reset the envelope */ m_env_step[ch] = 0; break; /* channels enable & reset generators */ case 0x1c: - m_all_ch_enable = data & 0x01; - m_sync_state = data & 0x02; - if (data & 0x02) + m_all_ch_enable = BIT(data, 0); + m_sync_state = BIT(data, 1); + if (BIT(data, 1)) { - int i; - /* Synch & Reset generators */ logerror("%s: -reg 0x1c- Chip reset\n", machine().describe_context()); - for (i = 0; i < 6; i++) + for (int i = 0; i < 6; i++) { m_channels[i].level = 0; m_channels[i].counter = 0.0; diff --git a/src/devices/sound/saa1099.h b/src/devices/sound/saa1099.h index a322b391b19..3ffb3e9d3d5 100644 --- a/src/devices/sound/saa1099.h +++ b/src/devices/sound/saa1099.h @@ -19,7 +19,7 @@ class saa1099_device : public device_t, public device_sound_interface { public: - saa1099_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); + saa1099_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock); void control_w(u8 data); void data_w(u8 data); @@ -39,17 +39,17 @@ private: { saa1099_channel() : amplitude{ 0, 0 }, envelope{ 0, 0 } { } - int frequency = 0; /* frequency (0x00..0xff) */ - int freq_enable = 0; /* frequency enable */ - int noise_enable = 0; /* noise enable */ - int octave = 0; /* octave (0x00..0x07) */ - int amplitude[2]; /* amplitude (0x00..0x0f) */ - int envelope[2]; /* envelope (0x00..0x0f or 0x10 == off) */ + u8 frequency = 0; // frequency (0x00..0xff) + bool freq_enable = false; // frequency enable + bool noise_enable = false; // noise enable + u8 octave = 0; // octave (0x00..0x07) + u16 amplitude[2]; // amplitude + u8 envelope[2]; // envelope (0x00..0x0f or 0x10 == off) /* vars to simulate the square wave */ double counter = 0.0; double freq = 0.0; - int level = 0; + u8 level = 0; }; struct saa1099_noise @@ -58,27 +58,26 @@ private: /* vars to simulate the noise generator output */ double counter = 0.0; - double freq = 0.0; - uint32_t level = 0xFFFFFFFF; /* noise polynomial shifter */ + double freq = 0.0; + u32 level = 0xffffffffU; // noise polynomial shifter }; void envelope_w(int ch); - sound_stream *m_stream; /* our stream */ - int m_noise_params[2]; /* noise generators parameters */ - int m_env_enable[2]; /* envelope generators enable */ - int m_env_reverse_right[2]; /* envelope reversed for right channel */ - int m_env_mode[2]; /* envelope generators mode */ - int m_env_bits[2]; /* non zero = 3 bits resolution */ - int m_env_clock[2]; /* envelope clock mode (non-zero external) */ - int m_env_step[2]; /* current envelope step */ - int m_all_ch_enable; /* all channels enable */ - int m_sync_state; /* sync all channels */ - int m_selected_reg; /* selected register */ - saa1099_channel m_channels[6]; /* channels */ - saa1099_noise m_noise[2]; /* noise generators */ + sound_stream *m_stream; // our stream + u8 m_noise_params[2]; // noise generators parameters + bool m_env_enable[2]; // envelope generators enable + bool m_env_reverse_right[2]; // envelope reversed for right channel + u8 m_env_mode[2]; // envelope generators mode + bool m_env_bits[2]; // true = 3 bits resolution + bool m_env_clock[2]; // envelope clock mode (true external) + u8 m_env_step[2]; // current envelope step + bool m_all_ch_enable; // all channels enable + bool m_sync_state; // sync all channels + u8 m_selected_reg; // selected register + saa1099_channel m_channels[6]; // channels + saa1099_noise m_noise[2]; // noise generators double m_sample_rate; - int m_master_clock; }; DECLARE_DEVICE_TYPE(SAA1099, saa1099_device) |