1 // license:BSD-3-Clause
2 // copyright-holders:K.Wilkins
3 /***************************************************************************
4 
5     Lunar Lander Specific Sound Code
6 
7 ***************************************************************************/
8 
9 #include "emu.h"
10 #include "includes/asteroid.h"
11 #include "sound/discrete.h"
12 #include "speaker.h"
13 
14 /************************************************************************/
15 /* Lunar Lander Sound System Analog emulation by K.Wilkins Nov 2000     */
16 /* Questions/Suggestions to mame@esplexo.co.uk                          */
17 /************************************************************************/
18 #define LLANDER_TONE3K_EN   NODE_01
19 #define LLANDER_TONE6K_EN   NODE_02
20 #define LLANDER_THRUST_DATA NODE_03
21 #define LLANDER_EXPLOD_EN   NODE_04
22 #define LLANDER_NOISE_RESET NODE_05
23 
24 #define LLANDER_NOISE               NODE_10
25 #define LLANDER_TONE_3K_SND         NODE_11
26 #define LLANDER_TONE_6K_SND         NODE_12
27 #define LLANDER_THRUST_EXPLOD_SND   NODE_13
28 
29 static const discrete_lfsr_desc llander_lfsr =
30 {
31 	DISC_CLK_IS_FREQ,
32 	16,         /* Bit Length */
33 	0,          /* Reset Value */
34 	6,          /* Use Bit 6 as XOR input 0 */
35 	14,         /* Use Bit 14 as XOR input 1 */
36 	DISC_LFSR_XNOR,     /* Feedback stage1 is inverted XOR */
37 	DISC_LFSR_IN0,      /* Feedback stage2 is just stage 1 output external feed not used */
38 	DISC_LFSR_REPLACE,  /* Feedback stage3 replaces the shifted register contents */
39 	0x000001,       /* Everything is shifted into the first bit only */
40 	0,          /* Output not inverted */
41 	14          /* Output bit */
42 };
43 
44 static DISCRETE_SOUND_START(llander_discrete)
45 	/************************************************/
46 	/* llander Effects Relataive Gain Table         */
47 	/*                                              */
48 	/* Effect       V-ampIn   Gain ratio  Relative  */
49 	/* Tone3k        4        10/390          9.2   */
50 	/* Tone6k        4        10/390          9.2   */
51 	/* Explode       3.8      10/6.8*2     1000.0   */
52 	/* Thrust        3.8      10/6.8*2      600.0   */
53 	/*  NOTE: Thrust gain has to be tweaked, due to */
54 	/*        the filter stage.                     */
55 	/************************************************/
56 
57 	/*                        NODE             GAIN      OFFSET  INIT */
58 	DISCRETE_INPUTX_DATA(LLANDER_THRUST_DATA,  600.0/7*7.6,   0,      0)
DISCRETE_INPUT_LOGIC(LLANDER_TONE3K_EN)59 	DISCRETE_INPUT_LOGIC(LLANDER_TONE3K_EN)
60 	DISCRETE_INPUT_LOGIC(LLANDER_TONE6K_EN)
61 	DISCRETE_INPUT_LOGIC(LLANDER_EXPLOD_EN)
62 	DISCRETE_INPUT_PULSE(LLANDER_NOISE_RESET, 1)
63 
64 	DISCRETE_LFSR_NOISE(NODE_20, 1, LLANDER_NOISE_RESET, 12000, 1, 0, 0, &llander_lfsr) // 12KHz Noise source for thrust
65 	DISCRETE_RCFILTER(LLANDER_NOISE, NODE_20, 2247, 1e-6)
66 
67 	DISCRETE_SQUAREWFIX(LLANDER_TONE_3K_SND, LLANDER_TONE3K_EN, 3000, 9.2, 50, 0, 0)    // 3KHz
68 
69 	DISCRETE_SQUAREWFIX(LLANDER_TONE_6K_SND, LLANDER_TONE6K_EN, 6000, 9.2, 50, 0, 0)    // 6KHz
70 
71 	DISCRETE_MULTIPLY(NODE_30, LLANDER_NOISE, LLANDER_THRUST_DATA)  // Mix in 12KHz Noise source for thrust
72 	/* TBD - replace this line with a Sallen-Key Bandpass macro */
73 	DISCRETE_FILTER2(NODE_31, 1, NODE_30, 89.5, (1.0 / 7.6), DISC_FILTER_BANDPASS)
74 	DISCRETE_MULTIPLY(NODE_32, NODE_30, 1000.0/600.0)   // Explode adds original noise source onto filtered source
75 	DISCRETE_ONOFF(NODE_33, LLANDER_EXPLOD_EN, NODE_32)
76 	DISCRETE_ADDER2(NODE_34, 1, NODE_31, NODE_33)
77 	/* TBD - replace this line with a Active Lowpass macro */
78 	DISCRETE_FILTER1(LLANDER_THRUST_EXPLOD_SND, 1, NODE_34, 560, DISC_FILTER_LOWPASS)
79 
80 	DISCRETE_ADDER3(NODE_90, 1, LLANDER_TONE_3K_SND, LLANDER_TONE_6K_SND, LLANDER_THRUST_EXPLOD_SND)    // Mix all four sound sources
81 	DISCRETE_GAIN(NODE_91, NODE_90, 65534.0/(9.2+9.2+600+1000))
82 
83 	DISCRETE_OUTPUT(NODE_90, 65534.0/(9.2+9.2+600+1000))        // Take the output from the mixer
84 DISCRETE_SOUND_END
85 
86 void asteroid_state::llander_snd_reset_w(uint8_t data)
87 {
88 	/* Resets the LFSR that is used for the white noise generator       */
89 	m_discrete->write(LLANDER_NOISE_RESET, 0);                /* Reset */
90 }
91 
llander_sounds_w(uint8_t data)92 void asteroid_state::llander_sounds_w(uint8_t data)
93 {
94 	m_discrete->write(LLANDER_THRUST_DATA, data & 0x07);      /* Thrust volume */
95 	m_discrete->write(LLANDER_TONE3K_EN, data & 0x10);        /* Tone 3KHz enable */
96 	m_discrete->write(LLANDER_TONE6K_EN, data & 0x20);        /* Tone 6KHz enable */
97 	m_discrete->write(LLANDER_EXPLOD_EN, data & 0x08);        /* Explosion */
98 }
99 
100 
llander_sound(machine_config & config)101 void asteroid_state::llander_sound(machine_config &config)
102 {
103 	SPEAKER(config, "mono").front_center();
104 
105 	DISCRETE(config, m_discrete, llander_discrete).add_route(ALL_OUTPUTS, "mono", 1.0);
106 }
107