summaryrefslogtreecommitdiff
path: root/reference/C/CONTRIB/SNIP/sound.h
blob: fecaf6014a71dc945931dfa78927803b4f6aa565 (plain)
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
/*
**  SOUND.H
**
**  Original Copyright 1988-1991 by Bob Stout as part of
**  the MicroFirm Function Library (MFL)
**
**  This subset version is functionally identical to the
**  version originally published by the author in Tech Specialist
**  magazine and is hereby donated to the public domain.
*/

#if defined(__ZTC__)
 #include <int.h>
 #undef int_on
 #undef int_off
#elif defined(__TURBOC__)
 #define int_on         enable
 #define int_off        disable
 #ifndef inp
  #define inp           inportb
 #endif
 #ifndef outp
  #define outp          outportb
 #endif
#else /* assume MSC/QC */
 #include <conio.h>
 #define int_on         _enable
 #define int_off        _disable
 #define getvect        _dos_getvect
 #define setvect        _dos_setvect
#endif

/* defines for mktone() update parameter: */

#define ON 0          /* turn the speaker on */
#define UPDATE 1      /* sound is on, just change freq */
#define TOGGLE 2      /* for delay use, turn on, then off */

/* port equates */

#define SCNTRL 0x61   /* sound control port */
#define SOUNDON 0x03  /* bit mask to enable speaker */
#define SOUNDOFF 0xfc /* bit mask to disable speaker */
#define C8253 0x43    /* port address to control 8253 */
#define SETIMER 0xb6  /* tell 8253 to expect freq data next */
#define F8253 0x42    /* frequency address on 8253 */

/* frequency equates (muscical scale) */
/* digit in label is octave number, S indicates Sharp (#) */

#define C0      36489
#define CS0     34445
#define D0      32512
#define DS0     30673
#define E0      28961
#define F0      27329
#define FS0     25804
#define G0      24351
#define GS0     22981
#define A0      21694
#define AS0     20473
#define B0      19326

#define C1      18244
#define CS1     17218
#define D1      16251
#define DS1     15340
#define E1      14480
#define F1      13668
#define FS1     12899
#define G1      12175
#define GS1     11493
#define A1      10847
#define AS1     10238
#define B1      9663

#define C2      9121
#define CS2     8609
#define D2      8126
#define DS2     7670
#define E2      7239
#define F2      6833
#define FS2     6450
#define G2      6088
#define GS2     5746
#define A2      5424
#define AS2     5119
#define B2      4832

#define C3      4561
#define CS3     4305
#define D3      4063
#define DS3     3835
#define E3      3620
#define F3      3417
#define FS3     3225
#define G3      3044
#define GS3     2873
#define A3      2712
#define AS3     2560
#define B3      2416

#define C4      2280
#define CS4     2152
#define D4      2032
#define DS4     1917
#define E4      1810
#define F4      1708
#define FS4     1612
#define G4      1522
#define GS4     1437
#define A4      1356
#define AS4     1280
#define B4      1210

#define C5      1140
#define CS5     1076
#define D5      1016
#define DS5     959
#define E5      905
#define F5      854
#define FS5     806
#define G5      761
#define GS5     718
#define A5      678
#define AS5     640
#define B5      604

#define C6      570
#define CS6     538
#define D6      508
#define DS6     479
#define E6      449
#define F6      427
#define FS6     403
#define G6      380
#define GS6     359
#define A6      339
#define AS6     320
#define B6      302

#define C7      285
#define CS7     269
#define D7      254
#define DS7     240
#define E7      226
#define F7      214
#define FS7     202
#define G7      190
#define GS7     180
#define A7      169
#define AS7     160
#define B7      151

#define C8      143

#define REST    0

typedef struct
{
        unsigned int      freq;
        unsigned int      duration;
} NOTE;

#if __cplusplus
 extern "C" {
#endif

void  mktone(int, int, unsigned),
      dosound(int),
      soundon(void),
      soundoff(void),
      playb_close(void);

int   playb_note(unsigned, unsigned);

NOTE *playb_open(unsigned);

#if __cplusplus
 }
#endif