Phone Tone simulates DTMF (dual-tone multi-frequency) telephone dialing by generating two simultaneous tones for each digit entered. The program accepts a phone number as a string and loops through each character, mapping it to a pair of frequency values (variables `a` and `b`) that correspond to the standard DTMF tone matrix rows and columns. The SOUND command is used with multiple channel parameters to produce the two-tone combinations, covering all twelve standard telephone keypad symbols: digits 0–9, asterisk (*), and hash (#). After each tone, a brief silence is inserted via a second SOUND call that resets the channels before advancing to the next digit.
Program Structure
The program is compact and linear. Line 10 prompts the user to enter a phone number using INPUT ... LINE, which captures the entire entry (including symbols like * and #) as a string n$. Lines 20–230 loop over each character with a FOR/NEXT construct, and line 240 sends execution back to 10 for another number.
DTMF Frequency Mapping
DTMF encodes each keypad symbol as a pair of audio frequencies — one from a low group (rows) and one from a high group (columns). The program approximates this with two hardware pitch values, a (low group) and b (high group):
| Key | a (row) | b (column) |
|---|---|---|
| 1 | 156 | 90 |
| 2 | 156 | 81 |
| 3 | 156 | 74 |
| 4 | 142 | 90 |
| 5 | 142 | 81 |
| 6 | 142 | 74 |
| 7 | 128 | 90 |
| 8 | 128 | 81 |
| 9 | 128 | 74 |
| * | 116 | 90 |
| 0 | 116 | 81 |
| # | 116 | 74 |
The row values (156, 142, 128, 116) decrease as you go down the keypad, and the column values (90, 81, 74) decrease left to right, reflecting the inverse relationship between the hardware pitch register values and actual audio frequency — higher register values correspond to lower pitches on this sound hardware.
SOUND Channel Usage
Line 205 issues a multi-parameter SOUND command: SOUND 0,b;1,0;2,a;3,0;7,60;8,15;9,15. Channels 0 and 2 carry the two tone pitches (b and a respectively), while channels 1 and 3 set their fine-tune registers to zero. Register 7 (the mixer control, set to 60) enables tone output on both channels. Registers 8 and 9 set the amplitude of channels A and B to 15 (maximum), producing audible output on both simultaneously. This is the key mechanism that generates the characteristic DTMF two-tone character.
Line 220 silences all channels with SOUND 0,0;1,0;2,0;3,0;7,63;8,0;9,0, setting amplitudes to zero and disabling all outputs via mixer register 63. A PAUSE 1 follows to create a brief inter-digit gap before the loop advances.
Key BASIC Idioms
INPUT ... LINEis used instead of plainINPUTso that characters like*and#are accepted without triggering syntax errors.- Substring indexing via
n$(n)extracts a single character at positionnwithin the loop. - The tone duration is controlled by
PAUSE 5(approximately 250 ms at 50 Hz), giving a reasonable approximation of a real dial tone burst.
Anomalies and Limitations
- There is no default case for unrecognized characters: if the user enters a letter or other symbol, variables
aandbretain their values from the previous digit, causing that prior tone pair to replay unintentionally. - The
RESETtoken appears in the line5REM comment only, and has no effect on program execution. - The twelve IF statements (lines
100–200) are evaluated sequentially for every character, with no early exit on a match, making this slightly less efficient than a branching structure would be — though at these program sizes the impact is negligible.
Content
Image Gallery
Source Code
5 REM © 1984 by James Palumbo
10 INPUT "Enter # -->"; LINE n$
20 FOR n=1 TO LEN n$
100 IF n$(n)="1" THEN LET a=156:LET b=90
110 IF n$(n)="2" THEN LET a=156:LET b=81
120 IF n$(n)="3" THEN LET a=156:LET b=74
130 IF n$(n)="4" THEN LET a=142:LET b=90
140 IF n$(n)="5" THEN LET a=142:LET b=81
150 IF n$(n)="6" THEN LET a=142:LET b=74
160 IF n$(n)="7" THEN LET a=128:LET b=90
170 IF n$(n)="8" THEN LET a=128:LET b=81
180 IF n$(n)="9" THEN LET a=128:LET b=74
190 IF n$(n)="*" THEN LET a=116:LET b=90
195 IF n$(n)="0" THEN LET a=116:LET b=81
200 IF n$(n)="#" THEN LET a=116:LET b=74
205 SOUND 0,b;1,0;2,a;3,0;7,60;8,15;9,15
210 PAUSE 5
220 SOUND 0,0;1,0;2,0;3,0;7,63;8,0;9,0:PAUSE 1
230 NEXT n
240 GO TO 10
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.