| 1 |
// license:BSD-3-Clause |
| 2 |
// copyright-holders:Nicola Salmoria,Aaron Giles |
| 3 |
/*************************************************************************** |
| 4 |
|
| 5 |
NAMCO sound driver. |
| 6 |
|
| 7 |
This driver handles the four known types of NAMCO wavetable sounds: |
| 8 |
|
| 9 |
- 3-voice mono (PROM-based design: Pac-Man, Pengo, Dig Dug, etc) |
| 10 |
- 8-voice quadrophonic (Pole Position 1, Pole Position 2) |
| 11 |
- 8-voice mono (custom 15XX: Mappy, Dig Dug 2, etc) |
| 12 |
- 8-voice stereo (System 1) |
| 13 |
|
| 14 |
The 15XX custom does not have a DAC of its own; instead, it streams |
| 15 |
the 4-bit PROM data directly into the 99XX custom DAC. Most pre-99XX |
| 16 |
(and pre-15XX) Namco games use a LS273 latch (cleared when sound is |
| 17 |
disabled), a 4.7K/2.2K/1K/470 resistor-weighted DAC, and a 4066 and |
| 18 |
second group of resistors (10K/22K/47K/100K) for volume control. |
| 19 |
Pole Position does more complicated sound mixing: a 4051 multiplexes |
| 20 |
wavetable sound with four signals derived from the 52XX and 54XX, the |
| 21 |
selected signal is distributed to four volume control sections, and |
| 22 |
finally the engine noise is mixed into all four channels. The later |
| 23 |
CUS30 also uses the 99XX DAC, or two 99XX in the optional 16-channel |
| 24 |
stereo configuration, but it uses no PROM and delivers its own samples. |
| 25 |
|
| 26 |
The CUS30 has been decapped and verified to be a ULA. |
| 27 |
|
| 28 |
***************************************************************************/ |
| 29 |
|
| 30 |
// additional modifications by tildearrow for furnace |
| 31 |
|
| 32 |
#include "namco.h" |
| 33 |
#include <string.h> |
| 34 |
|
| 35 |
/* quality parameter: internal sample rate is 192 KHz, output is 48 KHz */ |
| 36 |
#define INTERNAL_RATE 192000 |
| 37 |
|
| 38 |
/* 16 bits: sample bits of the stream buffer */ |
| 39 |
/* 4 bits: volume */ |
| 40 |
/* 4 bits: prom sample bits */ |
| 41 |
#define MIXLEVEL (1 << (16 - 4 - 4)) |
| 42 |
|
| 43 |
/* stream output level */ |
| 44 |
#define OUTPUT_LEVEL(n) ((n) * MIXLEVEL / m_voices) |
| 45 |
|
| 46 |
/* a position of waveform sample */ |
| 47 |
#define WAVEFORM_POSITION(n) (((n) >> m_f_fracbits) & 0x1f) |
| 48 |
|
| 49 |
namco_audio_device::namco_audio_device(uint32_t clock) |
| 50 |
: m_wave_ptr(NULL) |
| 51 |
, m_last_channel(nullptr) |
| 52 |
, m_wavedata(nullptr) |
| 53 |
, m_wave_size(0) |
| 54 |
, m_sound_enable(false) |
| 55 |
, m_namco_clock(0) |
| 56 |
, m_sample_rate(0) |
| 57 |
, m_f_fracbits(0) |
| 58 |
, m_voices(0) |
| 59 |
, m_stereo(false) |
| 60 |
{ |
| 61 |
} |
| 62 |
|
| 63 |
namco_device::namco_device(uint32_t clock) |
| 64 |
: namco_audio_device(clock) |
| 65 |
{ |
| 66 |
} |
| 67 |
|
| 68 |
namco_15xx_device::namco_15xx_device(uint32_t clock) |
| 69 |
:namco_audio_device(clock) |
| 70 |
{ |
| 71 |
} |
| 72 |
|
| 73 |
namco_cus30_device::namco_cus30_device(uint32_t clock) |
| 74 |
: namco_audio_device(clock) |
| 75 |
{ |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
//------------------------------------------------- |
| 80 |
// device_start - device-specific startup |
| 81 |
//------------------------------------------------- |
| 82 |
|
| 83 |
void namco_audio_device::device_start(unsigned char* wavePtr) |
| 84 |
{ |
| 85 |
/* extract globals from the interface */ |
| 86 |
m_last_channel = m_channel_list + m_voices; |
| 87 |
|
| 88 |
m_wave_ptr = wavePtr; |
| 89 |
|
| 90 |
memset(m_waveram_alloc,0,1024); |
| 91 |
|
| 92 |
/* build the waveform table */ |
| 93 |
build_decoded_waveform(m_wave_ptr); |
| 94 |
|
| 95 |
/* start with sound enabled, many games don't have a sound enable register */ |
| 96 |
m_sound_enable = true; |
| 97 |
|
| 98 |
/* reset all the voices */ |
| 99 |
for (sound_channel *voice = m_channel_list; voice < m_last_channel; voice++) |
| 100 |
{ |
| 101 |
voice->frequency = 0; |
| 102 |
voice->volume[0] = voice->volume[1] = 0; |
| 103 |
voice->waveform_select = 0; |
| 104 |
voice->counter = 0; |
| 105 |
voice->noise_sw = 0; |
| 106 |
voice->noise_state = 0; |
| 107 |
voice->noise_seed = 1; |
| 108 |
voice->noise_counter = 0; |
| 109 |
voice->noise_hold = 0; |
| 110 |
} |
| 111 |
} |
| 112 |
|
| 113 |
void namco_audio_device::device_clock_changed(int clk) |
| 114 |
{ |
| 115 |
int clock_multiple; |
| 116 |
|
| 117 |
// adjust internal clock |
| 118 |
m_namco_clock = clk; |
| 119 |
for (clock_multiple = 0; m_namco_clock < INTERNAL_RATE; clock_multiple++) |
| 120 |
m_namco_clock *= 2; |
| 121 |
|
| 122 |
m_f_fracbits = clock_multiple + 15; |
| 123 |
|
| 124 |
// adjust output clock |
| 125 |
m_sample_rate = m_namco_clock; |
| 126 |
|
| 127 |
//logerror("Namco: freq fractional bits = %d: internal freq = %d, output freq = %d\n", m_f_fracbits, m_namco_clock, m_sample_rate); |
| 128 |
} |
| 129 |
|
| 130 |
|
| 131 |
/* update the decoded waveform data */ |
| 132 |
void namco_audio_device::update_namco_waveform(int offset, uint8_t data) |
| 133 |
{ |
| 134 |
if (m_wave_size == 1) |
| 135 |
{ |
| 136 |
int16_t wdata; |
| 137 |
int v; |
| 138 |
|
| 139 |
/* use full byte, first 4 high bits, then low 4 bits */ |
| 140 |
for (v = 0; v < (int)MAX_VOLUME; v++) |
| 141 |
{ |
| 142 |
wdata = ((data >> 4) & 0x0f) - 8; |
| 143 |
m_waveform[v][offset * 2] = OUTPUT_LEVEL(wdata * v); |
| 144 |
wdata = (data & 0x0f) - 8; |
| 145 |
m_waveform[v][offset * 2 + 1] = OUTPUT_LEVEL(wdata * v); |
| 146 |
} |
| 147 |
} |
| 148 |
else |
| 149 |
{ |
| 150 |
int v; |
| 151 |
|
| 152 |
/* use only low 4 bits */ |
| 153 |
for (v = 0; v < (int)MAX_VOLUME; v++) |
| 154 |
m_waveform[v][offset] = OUTPUT_LEVEL(((data & 0x0f) - 8) * v); |
| 155 |
} |
| 156 |
} |
| 157 |
|
| 158 |
|
| 159 |
/* build the decoded waveform table */ |
| 160 |
void namco_audio_device::build_decoded_waveform(uint8_t *rgnbase) |
| 161 |
{ |
| 162 |
if (rgnbase != nullptr) |
| 163 |
m_wavedata = rgnbase; |
| 164 |
else |
| 165 |
{ |
| 166 |
m_wavedata = m_waveram_alloc; |
| 167 |
} |
| 168 |
|
| 169 |
for (int offset = 0; offset < 256; offset++) |
| 170 |
update_namco_waveform(offset, m_wavedata[offset]); |
| 171 |
} |
| 172 |
|
| 173 |
|
| 174 |
/* generate sound by oversampling */ |
| 175 |
uint32_t namco_audio_device::namco_update_one(short* buffer, int size, const int16_t *wave, uint32_t counter, uint32_t freq, int16_t& last_out) |
| 176 |
{ |
| 177 |
for (int sampindex = 0; sampindex < size; sampindex++) |
| 178 |
{ |
| 179 |
last_out=wave[WAVEFORM_POSITION(counter)]; |
| 180 |
buffer[sampindex]+=wave[WAVEFORM_POSITION(counter)]; |
| 181 |
counter += freq; |
| 182 |
} |
| 183 |
|
| 184 |
return counter; |
| 185 |
} |
| 186 |
|
| 187 |
|
| 188 |
void namco_audio_device::sound_enable_w(int state) |
| 189 |
{ |
| 190 |
m_sound_enable = state; |
| 191 |
} |
| 192 |
|
| 193 |
void namco_device::device_start(unsigned char* wavePtr) { |
| 194 |
memset(m_soundregs,0,1024); |
| 195 |
namco_audio_device::device_start(wavePtr); |
| 196 |
} |
| 197 |
|
| 198 |
void namco_15xx_device::device_start(unsigned char* wavePtr) { |
| 199 |
memset(m_soundregs,0,1024); |
| 200 |
namco_audio_device::device_start(wavePtr); |
| 201 |
} |
| 202 |
|
| 203 |
void namco_cus30_device::device_start(unsigned char* wavePtr) { |
| 204 |
namco_audio_device::device_start(wavePtr); |
| 205 |
} |
| 206 |
|
| 207 |
|
| 208 |
/********************************************************************************/ |
| 209 |
|
| 210 |
/* pacman register map |
| 211 |
0x05: ch 0 waveform select |
| 212 |
0x0a: ch 1 waveform select |
| 213 |
0x0f: ch 2 waveform select |
| 214 |
|
| 215 |
0x10: ch 0 the first voice has extra frequency bits |
| 216 |
0x11-0x14: ch 0 frequency |
| 217 |
0x15: ch 0 volume |
| 218 |
|
| 219 |
0x16-0x19: ch 1 frequency |
| 220 |
0x1a: ch 1 volume |
| 221 |
|
| 222 |
0x1b-0x1e: ch 2 frequency |
| 223 |
0x1f: ch 2 volume |
| 224 |
*/ |
| 225 |
|
| 226 |
void namco_device::pacman_sound_w(int offset, uint8_t data) |
| 227 |
{ |
| 228 |
sound_channel *voice; |
| 229 |
int ch; |
| 230 |
|
| 231 |
data &= 0x0f; |
| 232 |
if (m_soundregs[offset] == data) |
| 233 |
return; |
| 234 |
|
| 235 |
/* set the register */ |
| 236 |
m_soundregs[offset] = data; |
| 237 |
|
| 238 |
if (offset < 0x10) |
| 239 |
ch = (offset - 5) / 5; |
| 240 |
else if (offset == 0x10) |
| 241 |
ch = 0; |
| 242 |
else |
| 243 |
ch = (offset - 0x11) / 5; |
| 244 |
|
| 245 |
if (ch >= m_voices) |
| 246 |
return; |
| 247 |
|
| 248 |
/* recompute the voice parameters */ |
| 249 |
voice = m_channel_list + ch; |
| 250 |
switch (offset - ch * 5) |
| 251 |
{ |
| 252 |
case 0x05: |
| 253 |
voice->waveform_select = data & 7; |
| 254 |
break; |
| 255 |
|
| 256 |
case 0x10: |
| 257 |
case 0x11: |
| 258 |
case 0x12: |
| 259 |
case 0x13: |
| 260 |
case 0x14: |
| 261 |
/* the frequency has 20 bits */ |
| 262 |
/* the first voice has extra frequency bits */ |
| 263 |
voice->frequency = (ch == 0) ? m_soundregs[0x10] : 0; |
| 264 |
voice->frequency += (m_soundregs[ch * 5 + 0x11] << 4); |
| 265 |
voice->frequency += (m_soundregs[ch * 5 + 0x12] << 8); |
| 266 |
voice->frequency += (m_soundregs[ch * 5 + 0x13] << 12); |
| 267 |
voice->frequency += (m_soundregs[ch * 5 + 0x14] << 16); /* always 0 */ |
| 268 |
break; |
| 269 |
|
| 270 |
case 0x15: |
| 271 |
voice->volume[0] = data; |
| 272 |
break; |
| 273 |
} |
| 274 |
} |
| 275 |
|
| 276 |
void namco_cus30_device::pacman_sound_w(int offset, uint8_t data) |
| 277 |
{ |
| 278 |
sound_channel *voice; |
| 279 |
int ch; |
| 280 |
|
| 281 |
uint8_t *soundregs = &m_wavedata[0x100]; |
| 282 |
|
| 283 |
data &= 0x0f; |
| 284 |
if (soundregs[offset] == data) |
| 285 |
return; |
| 286 |
|
| 287 |
/* set the register */ |
| 288 |
soundregs[offset] = data; |
| 289 |
|
| 290 |
if (offset < 0x10) |
| 291 |
ch = (offset - 5) / 5; |
| 292 |
else if (offset == 0x10) |
| 293 |
ch = 0; |
| 294 |
else |
| 295 |
ch = (offset - 0x11) / 5; |
| 296 |
|
| 297 |
if (ch >= m_voices) |
| 298 |
return; |
| 299 |
|
| 300 |
/* recompute the voice parameters */ |
| 301 |
voice = m_channel_list + ch; |
| 302 |
switch (offset - ch * 5) |
| 303 |
{ |
| 304 |
case 0x05: |
| 305 |
voice->waveform_select = data & 7; |
| 306 |
break; |
| 307 |
|
| 308 |
case 0x10: |
| 309 |
case 0x11: |
| 310 |
case 0x12: |
| 311 |
case 0x13: |
| 312 |
case 0x14: |
| 313 |
/* the frequency has 20 bits */ |
| 314 |
/* the first voice has extra frequency bits */ |
| 315 |
voice->frequency = (ch == 0) ? soundregs[0x10] : 0; |
| 316 |
voice->frequency += (soundregs[ch * 5 + 0x11] << 4); |
| 317 |
voice->frequency += (soundregs[ch * 5 + 0x12] << 8); |
| 318 |
voice->frequency += (soundregs[ch * 5 + 0x13] << 12); |
| 319 |
voice->frequency += (soundregs[ch * 5 + 0x14] << 16); /* always 0 */ |
| 320 |
break; |
| 321 |
|
| 322 |
case 0x15: |
| 323 |
voice->volume[0] = data; |
| 324 |
break; |
| 325 |
} |
| 326 |
} |
| 327 |
|
| 328 |
/********************************************************************************/ |
| 329 |
|
| 330 |
/* polepos register map |
| 331 |
Note: even if there are 8 voices, the game doesn't use the first 2 because |
| 332 |
it select the 54XX/52XX outputs on those channels |
| 333 |
|
| 334 |
0x00-0x01 ch 0 frequency |
| 335 |
0x02 ch 0 xxxx---- GAIN 2 volume |
| 336 |
0x03 ch 0 xxxx---- GAIN 3 volume |
| 337 |
----xxxx GAIN 4 volume |
| 338 |
|
| 339 |
0x04-0x07 ch 1 |
| 340 |
|
| 341 |
. |
| 342 |
. |
| 343 |
. |
| 344 |
|
| 345 |
0x1c-0x1f ch 7 |
| 346 |
|
| 347 |
0x23 ch 0 xxxx---- GAIN 1 volume |
| 348 |
-----xxx waveform select |
| 349 |
----x-xx channel output select |
| 350 |
0-7 (all the same, shared with waveform select) = wave |
| 351 |
8 = CHANL1 (54XX pins 17-20) |
| 352 |
9 = CHANL2 (54XX pins 8-11) |
| 353 |
A = CHANL3 (54XX pins 4-7) |
| 354 |
B = CHANL4 (52XX) |
| 355 |
0x27 ch 1 |
| 356 |
0x2b ch 2 |
| 357 |
0x2f ch 3 |
| 358 |
0x33 ch 4 |
| 359 |
0x37 ch 5 |
| 360 |
0x3b ch 6 |
| 361 |
0x3f ch 7 |
| 362 |
*/ |
| 363 |
|
| 364 |
uint8_t namco_device::polepos_sound_r(int offset) |
| 365 |
{ |
| 366 |
return m_soundregs[offset]; |
| 367 |
} |
| 368 |
|
| 369 |
void namco_device::polepos_sound_w(int offset, uint8_t data) |
| 370 |
{ |
| 371 |
sound_channel *voice; |
| 372 |
int ch; |
| 373 |
|
| 374 |
if (m_soundregs[offset] == data) |
| 375 |
return; |
| 376 |
|
| 377 |
/* set the register */ |
| 378 |
m_soundregs[offset] = data; |
| 379 |
|
| 380 |
ch = (offset & 0x1f) / 4; |
| 381 |
|
| 382 |
/* recompute the voice parameters */ |
| 383 |
voice = m_channel_list + ch; |
| 384 |
switch (offset & 0x23) |
| 385 |
{ |
| 386 |
case 0x00: |
| 387 |
case 0x01: |
| 388 |
/* the frequency has 16 bits */ |
| 389 |
voice->frequency = m_soundregs[ch * 4 + 0x00]; |
| 390 |
voice->frequency += m_soundregs[ch * 4 + 0x01] << 8; |
| 391 |
break; |
| 392 |
|
| 393 |
case 0x23: |
| 394 |
voice->waveform_select = data & 7; |
| 395 |
// https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wimplicit-fallthrough |
| 396 |
// fall through |
| 397 |
case 0x02: |
| 398 |
case 0x03: |
| 399 |
voice->volume[0] = voice->volume[1] = 0; |
| 400 |
// front speakers ? |
| 401 |
voice->volume[0] += m_soundregs[ch * 4 + 0x03] >> 4; |
| 402 |
voice->volume[1] += m_soundregs[ch * 4 + 0x03] & 0x0f; |
| 403 |
// rear speakers ? |
| 404 |
voice->volume[0] += m_soundregs[ch * 4 + 0x23] >> 4; |
| 405 |
voice->volume[1] += m_soundregs[ch * 4 + 0x02] >> 4; |
| 406 |
|
| 407 |
voice->volume[0] /= 2; |
| 408 |
voice->volume[1] /= 2; |
| 409 |
|
| 410 |
/* if 54XX or 52XX selected, silence this voice */ |
| 411 |
if (m_soundregs[ch * 4 + 0x23] & 8) |
| 412 |
voice->volume[0] = voice->volume[1] = 0; |
| 413 |
break; |
| 414 |
} |
| 415 |
} |
| 416 |
|
| 417 |
|
| 418 |
/********************************************************************************/ |
| 419 |
|
| 420 |
/* 15XX register map |
| 421 |
0x03 ch 0 volume |
| 422 |
0x04-0x05 ch 0 frequency |
| 423 |
0x06 ch 0 waveform select & frequency |
| 424 |
|
| 425 |
0x0b ch 1 volume |
| 426 |
0x0c-0x0d ch 1 frequency |
| 427 |
0x0e ch 1 waveform select & frequency |
| 428 |
|
| 429 |
. |
| 430 |
. |
| 431 |
. |
| 432 |
|
| 433 |
0x3b ch 7 volume |
| 434 |
0x3c-0x3d ch 7 frequency |
| 435 |
0x3e ch 7 waveform select & frequency |
| 436 |
|
| 437 |
Grobda also stuffs values into register offset 0x02 with a frequency of zero |
| 438 |
to make 15XX channels act like a 4-bit DAC instead of waveform voices. This |
| 439 |
has been emulated by allowing writes to set the upper counter bits directly. |
| 440 |
Possibly offsets 0x00 and 0x01 can be used to set the fractional bits. |
| 441 |
*/ |
| 442 |
|
| 443 |
template <typename T, typename U> constexpr T make_bitmask(U n) |
| 444 |
{ |
| 445 |
return T((n < (int)(8 * sizeof(T)) ? (std::make_unsigned_t<T>(1) << n) : std::make_unsigned_t<T>(0)) - 1); |
| 446 |
} |
| 447 |
|
| 448 |
void namco_15xx_device::namco_15xx_w(int offset, uint8_t data) |
| 449 |
{ |
| 450 |
sound_channel *voice; |
| 451 |
int ch; |
| 452 |
|
| 453 |
if (m_soundregs[offset] == data) |
| 454 |
return; |
| 455 |
|
| 456 |
/* set the register */ |
| 457 |
m_soundregs[offset] = data; |
| 458 |
|
| 459 |
ch = offset / 8; |
| 460 |
if (ch >= m_voices) |
| 461 |
return; |
| 462 |
|
| 463 |
/* recompute the voice parameters */ |
| 464 |
voice = m_channel_list + ch; |
| 465 |
switch (offset - ch * 8) |
| 466 |
{ |
| 467 |
case 0x02: |
| 468 |
voice->counter &= make_bitmask<uint32_t>(m_f_fracbits); |
| 469 |
voice->counter |= uint32_t(data & 0x1f) << m_f_fracbits; |
| 470 |
break; |
| 471 |
|
| 472 |
case 0x03: |
| 473 |
voice->volume[0] = data & 0x0f; |
| 474 |
break; |
| 475 |
|
| 476 |
case 0x06: |
| 477 |
voice->waveform_select = (data >> 4) & 7; |
| 478 |
// https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wimplicit-fallthrough |
| 479 |
// fall through |
| 480 |
case 0x04: |
| 481 |
case 0x05: |
| 482 |
/* the frequency has 20 bits */ |
| 483 |
voice->frequency = m_soundregs[ch * 8 + 0x04]; |
| 484 |
voice->frequency += m_soundregs[ch * 8 + 0x05] << 8; |
| 485 |
voice->frequency += (m_soundregs[ch * 8 + 0x06] & 15) << 16; /* high bits are from here */ |
| 486 |
break; |
| 487 |
} |
| 488 |
} |
| 489 |
|
| 490 |
|
| 491 |
/********************************************************************************/ |
| 492 |
|
| 493 |
/* namcos1 register map |
| 494 |
0x00 ch 0 left volume |
| 495 |
0x01 ch 0 waveform select & frequency |
| 496 |
0x02-0x03 ch 0 frequency |
| 497 |
0x04 ch 0 right volume AND |
| 498 |
0x04 ch 1 noise sw |
| 499 |
|
| 500 |
0x08 ch 1 left volume |
| 501 |
0x09 ch 1 waveform select & frequency |
| 502 |
0x0a-0x0b ch 1 frequency |
| 503 |
0x0c ch 1 right volume AND |
| 504 |
0x0c ch 2 noise sw |
| 505 |
|
| 506 |
. |
| 507 |
. |
| 508 |
. |
| 509 |
|
| 510 |
0x38 ch 7 left volume |
| 511 |
0x39 ch 7 waveform select & frequency |
| 512 |
0x3a-0x3b ch 7 frequency |
| 513 |
0x3c ch 7 right volume AND |
| 514 |
0x3c ch 0 noise sw |
| 515 |
*/ |
| 516 |
|
| 517 |
void namco_cus30_device::namcos1_sound_w(int offset, uint8_t data) |
| 518 |
{ |
| 519 |
sound_channel *voice; |
| 520 |
int ch; |
| 521 |
int nssw; |
| 522 |
|
| 523 |
|
| 524 |
/* verify the offset */ |
| 525 |
if (offset > 63) |
| 526 |
{ |
| 527 |
//logerror("NAMCOS1 sound: Attempting to write past the 64 registers segment\n"); |
| 528 |
return; |
| 529 |
} |
| 530 |
|
| 531 |
uint8_t *soundregs = &m_wavedata[0x100]; |
| 532 |
|
| 533 |
if (soundregs[offset] == data) |
| 534 |
return; |
| 535 |
|
| 536 |
/* set the register */ |
| 537 |
soundregs[offset] = data; |
| 538 |
|
| 539 |
ch = offset / 8; |
| 540 |
if (ch >= m_voices) |
| 541 |
return; |
| 542 |
|
| 543 |
/* recompute the voice parameters */ |
| 544 |
voice = m_channel_list + ch; |
| 545 |
switch (offset - ch * 8) |
| 546 |
{ |
| 547 |
case 0x00: |
| 548 |
voice->volume[0] = data & 0x0f; |
| 549 |
break; |
| 550 |
|
| 551 |
case 0x01: |
| 552 |
voice->waveform_select = (data >> 4) & 15; |
| 553 |
// https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wimplicit-fallthrough |
| 554 |
// fall through |
| 555 |
case 0x02: |
| 556 |
case 0x03: |
| 557 |
/* the frequency has 20 bits */ |
| 558 |
voice->frequency = (soundregs[ch * 8 + 0x01] & 15) << 16; /* high bits are from here */ |
| 559 |
voice->frequency += soundregs[ch * 8 + 0x02] << 8; |
| 560 |
voice->frequency += soundregs[ch * 8 + 0x03]; |
| 561 |
break; |
| 562 |
|
| 563 |
case 0x04: |
| 564 |
voice->volume[1] = data & 0x0f; |
| 565 |
|
| 566 |
nssw = ((data & 0x80) >> 7); |
| 567 |
if (++voice == m_last_channel) |
| 568 |
voice = m_channel_list; |
| 569 |
voice->noise_sw = nssw; |
| 570 |
break; |
| 571 |
} |
| 572 |
} |
| 573 |
|
| 574 |
void namco_cus30_device::namcos1_cus30_w(int offset, uint8_t data) |
| 575 |
{ |
| 576 |
if (offset < 0x100) |
| 577 |
{ |
| 578 |
if (m_wavedata[offset] != data) |
| 579 |
{ |
| 580 |
|
| 581 |
m_wavedata[offset] = data; |
| 582 |
|
| 583 |
/* update the decoded waveform table */ |
| 584 |
update_namco_waveform(offset, data); |
| 585 |
} |
| 586 |
} |
| 587 |
else if (offset < 0x140) { |
| 588 |
namcos1_sound_w(offset - 0x100,data); |
| 589 |
} |
| 590 |
else |
| 591 |
m_wavedata[offset] = data; |
| 592 |
} |
| 593 |
|
| 594 |
uint8_t namco_cus30_device::namcos1_cus30_r(int offset) |
| 595 |
{ |
| 596 |
return m_wavedata[offset]; |
| 597 |
} |
| 598 |
|
| 599 |
uint8_t namco_15xx_device::sharedram_r(int offset) |
| 600 |
{ |
| 601 |
return m_soundregs[offset]; |
| 602 |
} |
| 603 |
|
| 604 |
void namco_15xx_device::sharedram_w(int offset, uint8_t data) |
| 605 |
{ |
| 606 |
if (offset < 0x40) |
| 607 |
namco_15xx_w(offset, data); |
| 608 |
else |
| 609 |
{ |
| 610 |
m_soundregs[offset] = data; |
| 611 |
} |
| 612 |
} |
| 613 |
|
| 614 |
//------------------------------------------------- |
| 615 |
// sound_stream_update - handle a stream update |
| 616 |
//------------------------------------------------- |
| 617 |
|
| 618 |
void namco_audio_device::sound_stream_update(short** outputs, int len) |
| 619 |
{ |
| 620 |
if (m_stereo) |
| 621 |
{ |
| 622 |
/* zap the contents of the buffers */ |
| 623 |
memset(outputs[0],0,len*sizeof(short)); |
| 624 |
memset(outputs[1],0,len*sizeof(short)); |
| 625 |
|
| 626 |
/* if no sound, we're done */ |
| 627 |
if (!m_sound_enable) |
| 628 |
return; |
| 629 |
|
| 630 |
/* loop over each voice and add its contribution */ |
| 631 |
for (sound_channel *voice = m_channel_list; voice < m_last_channel; voice++) |
| 632 |
{ |
| 633 |
short* lmix = outputs[0]; |
| 634 |
short* rmix = outputs[1]; |
| 635 |
int lv = voice->volume[0]; |
| 636 |
int rv = voice->volume[1]; |
| 637 |
|
| 638 |
if (voice->noise_sw) |
| 639 |
{ |
| 640 |
int f = voice->frequency & 0xff; |
| 641 |
|
| 642 |
/* only update if we have non-zero volume */ |
| 643 |
if (lv || rv) |
| 644 |
{ |
| 645 |
int hold_time = 1 << (m_f_fracbits - 16); |
| 646 |
int hold = voice->noise_hold; |
| 647 |
uint32_t delta = f << 4; |
| 648 |
uint32_t c = voice->noise_counter; |
| 649 |
int16_t l_noise_data = OUTPUT_LEVEL(0x07 * (lv >> 1)); |
| 650 |
int16_t r_noise_data = OUTPUT_LEVEL(0x07 * (rv >> 1)); |
| 651 |
int i; |
| 652 |
|
| 653 |
/* add our contribution */ |
| 654 |
for (i = 0; i < len; i++) |
| 655 |
{ |
| 656 |
int cnt; |
| 657 |
|
| 658 |
if (voice->noise_state) |
| 659 |
{ |
| 660 |
lmix[i]+=l_noise_data; |
| 661 |
rmix[i]+=r_noise_data; |
| 662 |
voice->last_out=(l_noise_data+r_noise_data)>>1; |
| 663 |
} |
| 664 |
else |
| 665 |
{ |
| 666 |
lmix[i]+=-l_noise_data; |
| 667 |
rmix[i]+=-r_noise_data; |
| 668 |
voice->last_out=-((l_noise_data+r_noise_data)>>1); |
| 669 |
} |
| 670 |
|
| 671 |
if (hold) |
| 672 |
{ |
| 673 |
hold--; |
| 674 |
continue; |
| 675 |
} |
| 676 |
|
| 677 |
hold = hold_time; |
| 678 |
|
| 679 |
c += delta; |
| 680 |
cnt = (c >> 12); |
| 681 |
c &= (1 << 12) - 1; |
| 682 |
for( ;cnt > 0; cnt--) |
| 683 |
{ |
| 684 |
if ((voice->noise_seed + 1) & 2) voice->noise_state ^= 1; |
| 685 |
if (voice->noise_seed & 1) voice->noise_seed ^= 0x28000; |
| 686 |
voice->noise_seed >>= 1; |
| 687 |
} |
| 688 |
} |
| 689 |
|
| 690 |
/* update the counter and hold time for this voice */ |
| 691 |
voice->noise_counter = c; |
| 692 |
voice->noise_hold = hold; |
| 693 |
} |
| 694 |
} |
| 695 |
else |
| 696 |
{ |
| 697 |
/* save the counter for this voice */ |
| 698 |
uint32_t c = voice->counter; |
| 699 |
|
| 700 |
/* only update if we have non-zero left volume */ |
| 701 |
if (lv) |
| 702 |
{ |
| 703 |
const int16_t *lw = &m_waveform[lv][voice->waveform_select * 32]; |
| 704 |
|
| 705 |
/* generate sound into the buffer */ |
| 706 |
c = namco_update_one(lmix, len, lw, voice->counter, voice->frequency, voice->last_out); |
| 707 |
} |
| 708 |
|
| 709 |
/* only update if we have non-zero right volume */ |
| 710 |
if (rv) |
| 711 |
{ |
| 712 |
const int16_t *rw = &m_waveform[rv][voice->waveform_select * 32]; |
| 713 |
|
| 714 |
/* generate sound into the buffer */ |
| 715 |
c = namco_update_one(rmix, len, rw, voice->counter, voice->frequency, voice->last_out); |
| 716 |
} |
| 717 |
|
| 718 |
/* update the counter for this voice */ |
| 719 |
voice->counter = c; |
| 720 |
} |
| 721 |
} |
| 722 |
} |
| 723 |
else |
| 724 |
{ |
| 725 |
sound_channel *voice; |
| 726 |
|
| 727 |
short* buffer = outputs[0]; |
| 728 |
/* zap the contents of the buffer */ |
| 729 |
memset(buffer,0,len*sizeof(short)); |
| 730 |
|
| 731 |
/* if no sound, we're done */ |
| 732 |
if (!m_sound_enable) |
| 733 |
return; |
| 734 |
|
| 735 |
/* loop over each voice and add its contribution */ |
| 736 |
for (voice = m_channel_list; voice < m_last_channel; voice++) |
| 737 |
{ |
| 738 |
int v = voice->volume[0]; |
| 739 |
if (voice->noise_sw) |
| 740 |
{ |
| 741 |
int f = voice->frequency & 0xff; |
| 742 |
|
| 743 |
/* only update if we have non-zero volume */ |
| 744 |
if (v) |
| 745 |
{ |
| 746 |
int hold_time = 1 << (m_f_fracbits - 16); |
| 747 |
int hold = voice->noise_hold; |
| 748 |
uint32_t delta = f << 4; |
| 749 |
uint32_t c = voice->noise_counter; |
| 750 |
int16_t noise_data = OUTPUT_LEVEL(0x07 * (v >> 1)); |
| 751 |
int i; |
| 752 |
|
| 753 |
/* add our contribution */ |
| 754 |
for (i = 0; i < len; i++) |
| 755 |
{ |
| 756 |
int cnt; |
| 757 |
|
| 758 |
if (voice->noise_state) |
| 759 |
{ |
| 760 |
buffer[i]+=noise_data; |
| 761 |
voice->last_out=noise_data; |
| 762 |
} |
| 763 |
else { |
| 764 |
buffer[i]+=-noise_data; |
| 765 |
voice->last_out=-noise_data; |
| 766 |
|
| 767 |
} |
| 768 |
|
| 769 |
if (hold) |
| 770 |
{ |
| 771 |
hold--; |
| 772 |
continue; |
| 773 |
} |
| 774 |
|
| 775 |
hold = hold_time; |
| 776 |
|
| 777 |
c += delta; |
| 778 |
cnt = (c >> 12); |
| 779 |
c &= (1 << 12) - 1; |
| 780 |
for( ;cnt > 0; cnt--) |
| 781 |
{ |
| 782 |
if ((voice->noise_seed + 1) & 2) voice->noise_state ^= 1; |
| 783 |
if (voice->noise_seed & 1) voice->noise_seed ^= 0x28000; |
| 784 |
voice->noise_seed >>= 1; |
| 785 |
} |
| 786 |
} |
| 787 |
|
| 788 |
/* update the counter and hold time for this voice */ |
| 789 |
voice->noise_counter = c; |
| 790 |
voice->noise_hold = hold; |
| 791 |
} |
| 792 |
} |
| 793 |
else |
| 794 |
{ |
| 795 |
/* only update if we have non-zero volume */ |
| 796 |
if (v) |
| 797 |
{ |
| 798 |
const int16_t *w = &m_waveform[v][voice->waveform_select * 32]; |
| 799 |
|
| 800 |
/* generate sound into buffer and update the counter for this voice */ |
| 801 |
voice->counter = namco_update_one(buffer, len, w, voice->counter, voice->frequency, voice->last_out); |
| 802 |
} |
| 803 |
} |
| 804 |
} |
| 805 |
} |
| 806 |
} |