1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
|
/***************************************************************************
beep.c
This is used for computers/systems which can only output a constant tone.
This tone can be turned on and off.
e.g. PCW and PCW16 computer systems
KT - 25-Jun-2000
Sound handler
****************************************************************************/
#include "emu.h"
#include "sound/beep.h"
#define BEEP_RATE 48000
typedef struct _beep_state beep_state;
struct _beep_state
{
sound_stream *stream; /* stream number */
int enable; /* enable beep */
int frequency; /* set frequency - this can be changed using the appropiate function */
int incr; /* initial wave state */
INT16 signal; /* current signal */
};
INLINE beep_state *get_safe_token(device_t *device)
{
assert(device != NULL);
assert(device->type() == BEEP);
return (beep_state *)downcast<beep_device *>(device)->token();
}
/*************************************
*
* Stream updater
*
*************************************/
static STREAM_UPDATE( beep_sound_update )
{
beep_state *bs = (beep_state *) param;
stream_sample_t *buffer = outputs[0];
INT16 signal = bs->signal;
int clock = 0, rate = BEEP_RATE / 2;
/* get progress through wave */
int incr = bs->incr;
if (bs->frequency > 0)
clock = bs->frequency;
/* if we're not enabled, just fill with 0 */
if ( !bs->enable || clock == 0 )
{
memset( buffer, 0, samples * sizeof(*buffer) );
return;
}
/* fill in the sample */
while( samples-- > 0 )
{
*buffer++ = signal;
incr -= clock;
while( incr < 0 )
{
incr += rate;
signal = -signal;
}
}
/* store progress through wave */
bs->incr = incr;
bs->signal = signal;
}
/*************************************
*
* Sound handler start
*
*************************************/
static DEVICE_START( beep )
{
beep_state *pBeep = get_safe_token(device);
pBeep->stream = device->machine().sound().stream_alloc(*device, 0, 1, BEEP_RATE, pBeep, beep_sound_update );
pBeep->enable = 0;
pBeep->frequency = 3250;
pBeep->incr = 0;
pBeep->signal = 0x07fff;
}
/*************************************
*
* changing state to on from off will restart tone
*
*************************************/
void beep_set_state(device_t *device, int on)
{
beep_state *info = get_safe_token(device);
/* only update if new state is not the same as old state */
if (info->enable == on)
return;
info->stream->update();
info->enable = on;
/* restart wave from beginning */
info->incr = 0;
info->signal = 0x07fff;
}
/*************************************
*
* setting new frequency starts from beginning
*
*************************************/
void beep_set_frequency(device_t *device,int frequency)
{
beep_state *info = get_safe_token(device);
if (info->frequency == frequency)
return;
info->stream->update();
info->frequency = frequency;
info->signal = 0x07fff;
info->incr = 0;
}
/*************************************
*
* change a channel volume
*
*************************************/
void beep_set_volume(device_t *device, int volume)
{
beep_state *info = get_safe_token(device);
info->stream->update();
volume = 100 * volume / 7;
downcast<beep_device *>(device)->set_output_gain(0, volume);
}
/**************************************************************************
* Generic get_info
**************************************************************************/
DEVICE_GET_INFO( beep )
{
switch (state)
{
/* --- the following bits of info are returned as 64-bit signed integers --- */
case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(beep_state); break;
/* --- the following bits of info are returned as pointers to data or functions --- */
case DEVINFO_FCT_START: info->start = DEVICE_START_NAME( beep ); break;
/* --- the following bits of info are returned as NULL-terminated strings --- */
case DEVINFO_STR_NAME: strcpy(info->s, "Beep"); break;
case DEVINFO_STR_FAMILY: strcpy(info->s, "Beep"); break;
case DEVINFO_STR_VERSION: strcpy(info->s, "1.0"); break;
case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break;
case DEVINFO_STR_CREDITS: strcpy(info->s, "Copyright The MESS Team"); break;
}
}
const device_type BEEP = &device_creator<beep_device>;
beep_device::beep_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
: device_t(mconfig, BEEP, "Beep", tag, owner, clock),
device_sound_interface(mconfig, *this)
{
m_token = global_alloc_array_clear(UINT8, sizeof(beep_state));
}
//-------------------------------------------------
// device_config_complete - perform any
// operations now that the configuration is
// complete
//-------------------------------------------------
void beep_device::device_config_complete()
{
}
//-------------------------------------------------
// device_start - device-specific startup
//-------------------------------------------------
void beep_device::device_start()
{
DEVICE_START_NAME( beep )(this);
}
//-------------------------------------------------
// sound_stream_update - handle a stream update
//-------------------------------------------------
void beep_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
{
// should never get here
fatalerror("sound_stream_update called; not applicable to legacy sound devices\n");
}
|