Previous 15994 Revisions Next

r14349 Sunday 5th February, 2012 at 08:57:14 UTC by Miodrag Milanović
Commit of upd1771 by request (nw)
[src/mess/audio]upd1771.c

src/mess/audio/upd1771.c
r14348r14349
5353
5454    All NC pins are unknown, maybe some are  "test" pins.
5555
56    All non PCM writes are made through address 0x3600 on the upD7801
56    All writes are made through address 0x3600 on the upD7801
5757    Instead of using register=value, this chip require sending multiple
5858    bytes for each command, one after the other.
5959
r14348r14349
6767
6868#define MAX_PACKET_SIZE 0x8000
6969
70
7170/*
7271  Each of the 8 waveforms have been sampled at 192Khz using period 0xFF,
7372  filtered, and each of the 32 levels have been calculated with averages on around 10 samples
r14348r14349
8786{ -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}
8887};
8988
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
90116#define STATE_SILENCE 0
91117#define STATE_NOISE   1
92118#define STATE_TONE    2
119#define STATE_ADPCM   3
93120
94121typedef struct _upd1771_state upd1771_state;
95122struct _upd1771_state
r14348r14349
113140    UINT8    t_tpos;//timber pos
114141    UINT16   t_ppos;//period pos
115142
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
117149
150    //noise pulse components
118151    UINT8    n_value[3];  //[0;1]
119152    UINT16   n_volume[3]; //[0; 31]
120153    UINT32   n_period[3];
121154    UINT32   n_ppos[3];   //period pos
122
123155};
124156
125157
r14348r14349
159191   of bit cropping/rounding.
160192*/
161193
194/*
195*************NOISE*****************
196Noise consists on 4 different components
197A weird Wavetable LFSR (for lack of a better term),
198and three independent (but equal) low frequency
19950/50 pulse wavs.
162200
201The 4 components are mixed in a mysterious way,
202a weird ORing with volume having a huge effect.
163203
204Byte0: 0x01
205
206Byte1: 0bTTTOOOOO
207  MSB 3 bits of LFSR Timbre (8 wavetables)
208  LSB 5 bits ?????????
209
210Byte2: 0bPPPPPPPP
211  8bits of clock divider/period
212
213Byte3: 0b???VVVVV
214   MSB 3 bits unknown
215   LSB 5 bits of "Volume"
216
217
218Byte4: 0bPPPPPPPP  Low Freq0 period(if not 0 this peridically resets the  Wavetable LFSR)
219Byte5: 0bPPPPPPPP  Low Freq1 period(if not 0 this peridically resets the  Wavetable LFSR)
220Byte6: 0bPPPPPPPP  Low Freq2 period(if not 0 this peridically resets the  Wavetable LFSR)
221
222Byte7: 0b???VVVVV  Low Freq0 volume
223Byte8: 0b???VVVVV  Low Freq1 volume
224Byte9: 0b???VVVVV  Low Freq2 volume
225*/
226
164227WRITE8_DEVICE_HANDLER( upd1771_w )
165228{
166229    upd1771_state *state = get_safe_token( device );
r14348r14349
192255                state->state = STATE_NOISE;
193256                state->index = 0;
194257
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
195262                //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;
199266
200267                state->n_volume[0] = state->packet[7]& 0x1f;
201268                state->n_volume[1] = state->packet[8]& 0x1f;
r14348r14349
237304                //TODO play capture!
238305            state->index = 0;
239306            state->packet[0]=0;
307                state->state = STATE_ADPCM;
240308         }
241309         else
242310            state->timer->adjust( attotime::from_ticks( 512, device->clock() ) );
r14348r14349
245313
246314        //garbage: wipe stack
247315        default:
316            state->state = STATE_SILENCE;
248317         state->index = 0;
249318        break;
250319    }
r14348r14349
298367            while (--samples >= 0 ){
299368
300369                *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
302382                //mix in each of the noise's 3 pulse components
303383                char res[3];
304384                for (size_t i=0;i<3;++i){
305385
306                      res[i] = state->n_value[i];
386                    res[i] = state->n_value[i]* 127;
307387                    state->n_ppos[i]++;
308388                    if (state->n_ppos[i] >= state->n_period[i]){
309389                        state->n_ppos[i] = 0;
r14348r14349
311391                    }
312392                }
313393                //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                           ) ;
315400
316401                buffer++;
317402            }
r14348r14349
396481}
397482
398483DEFINE_LEGACY_SOUND_DEVICE(UPD1771C, upd1771c);
484

Previous 15994 Revisions Next


© 1998-2018 The MESS Team