src/mess/audio/upd1771.c
| r14348 | r14349 | |
| 53 | 53 | |
| 54 | 54 | All NC pins are unknown, maybe some are "test" pins. |
| 55 | 55 | |
| 56 | | All non PCM writes are made through address 0x3600 on the upD7801 |
| 56 | All writes are made through address 0x3600 on the upD7801 |
| 57 | 57 | Instead of using register=value, this chip require sending multiple |
| 58 | 58 | bytes for each command, one after the other. |
| 59 | 59 | |
| r14348 | r14349 | |
| 67 | 67 | |
| 68 | 68 | #define MAX_PACKET_SIZE 0x8000 |
| 69 | 69 | |
| 70 | | |
| 71 | 70 | /* |
| 72 | 71 | Each of the 8 waveforms have been sampled at 192Khz using period 0xFF, |
| 73 | 72 | filtered, and each of the 32 levels have been calculated with averages on around 10 samples |
| r14348 | r14349 | |
| 87 | 86 | { -84,-121,-128,-105, -51, 7, 38, 66, 93, 97, 93, 88, 89, 96, 102, 111, 116, 118, 118, 119, 118, 118, 117, 117, 118, 118, 117, 117, 117, 115, 85, -14} |
| 88 | 87 | }; |
| 89 | 88 | |
| 89 | |
| 90 | |
| 91 | #define NOISE_SIZE 255 |
| 92 | |
| 93 | |
| 94 | static unsigned char noise_tbl[]= |
| 95 | { |
| 96 | 0x1c,0x86,0x8a,0x8f,0x98,0xa1,0xad,0xbe,0xd9,0x8a,0x66,0x4d,0x40,0x33,0x2b,0x23, |
| 97 | 0x1e,0x8a,0x90,0x97,0xa4,0xae,0xb8,0xd6,0xec,0xe9,0x69,0x4a,0x3e,0x34,0x2d,0x27, |
| 98 | 0x24,0x24,0x89,0x8e,0x93,0x9c,0xa5,0xb0,0xc1,0xdd,0x40,0x36,0x30,0x29,0x27,0x24, |
| 99 | 0x8b,0x90,0x96,0x9e,0xa7,0xb3,0xc4,0xe1,0x25,0x21,0x8a,0x8f,0x93,0x9d,0xa5,0xb2, |
| 100 | 0xc2,0xdd,0xdd,0x98,0xa2,0xaf,0xbf,0xd8,0xfd,0x65,0x4a,0x3c,0x31,0x2b,0x24,0x22, |
| 101 | 0x1e,0x87,0x8c,0x91,0x9a,0xa3,0xaf,0xc0,0xdb,0xbe,0xd9,0x8c,0x66,0x4d,0x40,0x34, |
| 102 | 0x2c,0x24,0x1f,0x88,0x90,0x9a,0xa4,0xb2,0xc2,0xda,0xff,0x67,0x4d,0x3d,0x34,0x2d, |
| 103 | 0x26,0x24,0x20,0x89,0x8e,0x93,0x9c,0xa5,0xb1,0xc2,0xde,0xc1,0xda,0xff,0x67,0x4d, |
| 104 | 0x3d,0x33,0x2d,0x26,0x24,0x20,0x89,0x8e,0x93,0x9c,0xa5,0xb1,0xc2,0xdd,0xa3,0xb0, |
| 105 | 0xc0,0xd9,0xfe,0x66,0x4b,0x3c,0x32,0x2b,0x24,0x23,0x1e,0x88,0x8d,0x92,0x9b,0xa4, |
| 106 | 0xb0,0xc1,0xdc,0xad,0xbe,0xda,0x22,0x20,0x1c,0x85,0x8a,0x8f,0x98,0xa1,0xad,0xbe, |
| 107 | 0xda,0x20,0x1b,0x85,0x8d,0x97,0xa1,0xaf,0xbf,0xd8,0xfd,0x64,0x49,0x3a,0x30,0x2a, |
| 108 | 0x23,0x21,0x1d,0x86,0x8b,0x91,0x9a,0xa2,0xae,0xc0,0xdb,0x33,0x2b,0x24,0x1f,0x88, |
| 109 | 0x90,0x9a,0xa4,0xb2,0xc2,0xda,0xff,0x67,0x4c,0x3e,0x33,0x2d,0x25,0x24,0x1f,0x89, |
| 110 | 0x8e,0x93,0x9c,0xa5,0xb1,0xc2,0xde,0x85,0x8e,0x98,0xa2,0xb0,0xc0,0xd9,0xfe,0x64, |
| 111 | 0x4b,0x3b,0x31,0x2a,0x23,0x22,0x1e,0x88,0x8c,0x91,0x9b,0xa3,0xaf,0xc1,0xdc,0xdc |
| 112 | }; |
| 113 | |
| 114 | |
| 115 | |
| 90 | 116 | #define STATE_SILENCE 0 |
| 91 | 117 | #define STATE_NOISE 1 |
| 92 | 118 | #define STATE_TONE 2 |
| 119 | #define STATE_ADPCM 3 |
| 93 | 120 | |
| 94 | 121 | typedef struct _upd1771_state upd1771_state; |
| 95 | 122 | struct _upd1771_state |
| r14348 | r14349 | |
| 113 | 140 | UINT8 t_tpos;//timber pos |
| 114 | 141 | UINT16 t_ppos;//period pos |
| 115 | 142 | |
| 116 | | //TODO noise wavetable LFSR |
| 143 | //noise wavetable LFSR |
| 144 | UINT8 nw_timbre; //[0; 7] |
| 145 | UINT8 nw_volume; //[0; 31] |
| 146 | UINT32 nw_period; |
| 147 | UINT32 nw_tpos; //timber pos |
| 148 | UINT32 nw_ppos; //period pos |
| 117 | 149 | |
| 150 | //noise pulse components |
| 118 | 151 | UINT8 n_value[3]; //[0;1] |
| 119 | 152 | UINT16 n_volume[3]; //[0; 31] |
| 120 | 153 | UINT32 n_period[3]; |
| 121 | 154 | UINT32 n_ppos[3]; //period pos |
| 122 | | |
| 123 | 155 | }; |
| 124 | 156 | |
| 125 | 157 | |
| r14348 | r14349 | |
| 159 | 191 | of bit cropping/rounding. |
| 160 | 192 | */ |
| 161 | 193 | |
| 194 | /* |
| 195 | *************NOISE***************** |
| 196 | Noise consists on 4 different components |
| 197 | A weird Wavetable LFSR (for lack of a better term), |
| 198 | and three independent (but equal) low frequency |
| 199 | 50/50 pulse wavs. |
| 162 | 200 | |
| 201 | The 4 components are mixed in a mysterious way, |
| 202 | a weird ORing with volume having a huge effect. |
| 163 | 203 | |
| 204 | Byte0: 0x01 |
| 205 | |
| 206 | Byte1: 0bTTTOOOOO |
| 207 | MSB 3 bits of LFSR Timbre (8 wavetables) |
| 208 | LSB 5 bits ????????? |
| 209 | |
| 210 | Byte2: 0bPPPPPPPP |
| 211 | 8bits of clock divider/period |
| 212 | |
| 213 | Byte3: 0b???VVVVV |
| 214 | MSB 3 bits unknown |
| 215 | LSB 5 bits of "Volume" |
| 216 | |
| 217 | |
| 218 | Byte4: 0bPPPPPPPP Low Freq0 period(if not 0 this peridically resets the Wavetable LFSR) |
| 219 | Byte5: 0bPPPPPPPP Low Freq1 period(if not 0 this peridically resets the Wavetable LFSR) |
| 220 | Byte6: 0bPPPPPPPP Low Freq2 period(if not 0 this peridically resets the Wavetable LFSR) |
| 221 | |
| 222 | Byte7: 0b???VVVVV Low Freq0 volume |
| 223 | Byte8: 0b???VVVVV Low Freq1 volume |
| 224 | Byte9: 0b???VVVVV Low Freq2 volume |
| 225 | */ |
| 226 | |
| 164 | 227 | WRITE8_DEVICE_HANDLER( upd1771_w ) |
| 165 | 228 | { |
| 166 | 229 | upd1771_state *state = get_safe_token( device ); |
| r14348 | r14349 | |
| 192 | 255 | state->state = STATE_NOISE; |
| 193 | 256 | state->index = 0; |
| 194 | 257 | |
| 258 | state->nw_timbre = (state->packet[1] & 0xE0) >> 5; |
| 259 | state->nw_period = ((UINT32)state->packet[2]+1)<<7; |
| 260 | state->nw_volume = state->packet[3] & 0x1f; |
| 261 | |
| 195 | 262 | //very long clocked periods.. used for engine drones |
| 196 | | state->n_period[0] = (((UINT32)state->packet[4])+1)*128; |
| 197 | | state->n_period[1] = (((UINT32)state->packet[5])+1)*128; |
| 198 | | state->n_period[2] = (((UINT32)state->packet[6])+1)*128; |
| 263 | state->n_period[0] = (((UINT32)state->packet[4])+1)<<7; |
| 264 | state->n_period[1] = (((UINT32)state->packet[5])+1)<<7; |
| 265 | state->n_period[2] = (((UINT32)state->packet[6])+1)<<7; |
| 199 | 266 | |
| 200 | 267 | state->n_volume[0] = state->packet[7]& 0x1f; |
| 201 | 268 | state->n_volume[1] = state->packet[8]& 0x1f; |
| r14348 | r14349 | |
| 237 | 304 | //TODO play capture! |
| 238 | 305 | state->index = 0; |
| 239 | 306 | state->packet[0]=0; |
| 307 | state->state = STATE_ADPCM; |
| 240 | 308 | } |
| 241 | 309 | else |
| 242 | 310 | state->timer->adjust( attotime::from_ticks( 512, device->clock() ) ); |
| r14348 | r14349 | |
| 245 | 313 | |
| 246 | 314 | //garbage: wipe stack |
| 247 | 315 | default: |
| 316 | state->state = STATE_SILENCE; |
| 248 | 317 | state->index = 0; |
| 249 | 318 | break; |
| 250 | 319 | } |
| r14348 | r14349 | |
| 298 | 367 | while (--samples >= 0 ){ |
| 299 | 368 | |
| 300 | 369 | *buffer = 0; |
| 301 | | //TODO implement "wavetable-LFSR" component |
| 370 | |
| 371 | //"wavetable-LFSR" component |
| 372 | int wlfsr_val = ((int)noise_tbl[state->nw_tpos])-127;//data too wide |
| 373 | |
| 374 | state->nw_ppos++; |
| 375 | if (state->nw_ppos >= state->nw_period){ |
| 376 | state->nw_tpos++; |
| 377 | if (state->nw_tpos == NOISE_SIZE) |
| 378 | state->nw_tpos = 0; |
| 379 | state->nw_ppos = 0; |
| 380 | } |
| 381 | |
| 302 | 382 | //mix in each of the noise's 3 pulse components |
| 303 | 383 | char res[3]; |
| 304 | 384 | for (size_t i=0;i<3;++i){ |
| 305 | 385 | |
| 306 | | res[i] = state->n_value[i]; |
| 386 | res[i] = state->n_value[i]* 127; |
| 307 | 387 | state->n_ppos[i]++; |
| 308 | 388 | if (state->n_ppos[i] >= state->n_period[i]){ |
| 309 | 389 | state->n_ppos[i] = 0; |
| r14348 | r14349 | |
| 311 | 391 | } |
| 312 | 392 | } |
| 313 | 393 | //not quite, but close. |
| 314 | | *buffer+= ((res[0]*state->n_volume[0]) | (res[1]*state->n_volume[1]) | (res[2]*state->n_volume[2])) * 127; |
| 394 | *buffer+= ( |
| 395 | (wlfsr_val*state->nw_volume) | |
| 396 | (res[0]*state->n_volume[0]) | |
| 397 | (res[1]*state->n_volume[1]) | |
| 398 | (res[2]*state->n_volume[2]) |
| 399 | ) ; |
| 315 | 400 | |
| 316 | 401 | buffer++; |
| 317 | 402 | } |
| r14348 | r14349 | |
| 396 | 481 | } |
| 397 | 482 | |
| 398 | 483 | DEFINE_LEGACY_SOUND_DEVICE(UPD1771C, upd1771c); |
| 484 | |