Hi folks,
I haven't done any Sound development for Classic Mac OS, but I thought that writing a simple DTMF (UK DTMF) player would be fun.

This is my minimally functional version that works on a Mac Plus under system 7 down to a Mac 128kB on System 1 (If you Run DtmfSys1. You can type digits, ‘*’ and ‘#’ or type ‘-‘ to end a sound. You can click on the keypad to make a DTMF sound too (it stops when you let go). In System 7 it plays with periodic clicks, but under System 6 it's smooth. It's about 6kB on the disk and needs about 18kB in System 6 to run, but by default I've allocated 32kB for System 7 (haven't checked the minimum it'll run in).
It uses the Sound Driver in FourTone mode. Because DTMF tone frequencies aren't obvious multiples of each other, this approach makes far more sense than e.g. trying to create DTMF sound resources. Instead, I created a 256 sample Sine wave in Signed 0:15 fixed-point arithmetic (does everyone understand that?) by matrix multiplication. Conventionally that can be calculated as:
x'=x * Cos a - y * Sin a;
y'=x * Sin a + y * Cos a;
e.g. if we pick a=90º, then Cos a=0, Sin a=1; so [1,0] => [0,1] and [0,1] => [-1,0] which is correct.
In practice we need to pick 360º/256=1.40625º. So Sin a=0.02454, Cos a=0.9996988. In Signed 0:15 fixed-point that's 804 and 32758. As a side note, the fastest calculations can be done by calculating only 64 of the samples, and for each one you just reflect or negate to get the remaining quadrants (64 x 4 multiplies x 7µs each = 1.8ms).
At first I tried to follow the Inside Macintosh guide for using the Sound Driver, but in fact, it didn't seem to work at all! So, then I looked up all the MacTech articles on generating sound and found this one:
http://preserve.mactech.com/articles/mactech/Vol.02/02.02/SoundMadeSimple/index.html
Basically the article explains StartSound doesn't work properly at all as described in Inside Macintosh, but if you go straight to the underlying Sound Drive Parameter Block based API it does work. It's important to go for the early articles so that the APIs you use are likely to work with early Macs and OS versions. There's a whole bunch of Sound articles in MacTech. Perhaps I'll explore more of them in the future, because I might need a better sound payback to avoid glitches under System 7.
It looks like I used a bunch of custom buttons for the keypad buttons, but I didn't. I wanted to be able to figure out which keypad button was hit in one go, straight from the keypad grid & mouse coordinates. I used a pair of SICNs for pressed and released and invalidated only the button I wanted redrawn. The keypad digits are added to each button using DrawChar.
There’s space at the top for a full phone number and I’ll add a text box for that next. In theory, if you do audio out from a Mac to a UK landline and press digits it should phone the number, because they’re sine waves for UK DTMF at the right frequencies on a real Mac. (which might be the same as international DTMF, but I haven't checked). It runs in 32kB (it’s a 6kB program, doesn’t run in 16kB, but might run in 24kB). Running it in colour or on a PowerPC Mac might need a bit more.
Anyway, here’s the project and two versions of the app, one that uses WaitNextEvent for System versions that don't support GetNextEvent. I still haven't followed @David Cook 's guide on checking for that. There's also a few bugs: if the window is partially covered and re-exposed not all the buttons get properly redrawn. Also if you hold the mouse on one button, move it and let go on another, then the first keypad button remains highlighted.
I haven't done any Sound development for Classic Mac OS, but I thought that writing a simple DTMF (UK DTMF) player would be fun.

This is my minimally functional version that works on a Mac Plus under system 7 down to a Mac 128kB on System 1 (If you Run DtmfSys1. You can type digits, ‘*’ and ‘#’ or type ‘-‘ to end a sound. You can click on the keypad to make a DTMF sound too (it stops when you let go). In System 7 it plays with periodic clicks, but under System 6 it's smooth. It's about 6kB on the disk and needs about 18kB in System 6 to run, but by default I've allocated 32kB for System 7 (haven't checked the minimum it'll run in).
It uses the Sound Driver in FourTone mode. Because DTMF tone frequencies aren't obvious multiples of each other, this approach makes far more sense than e.g. trying to create DTMF sound resources. Instead, I created a 256 sample Sine wave in Signed 0:15 fixed-point arithmetic (does everyone understand that?) by matrix multiplication. Conventionally that can be calculated as:
x'=x * Cos a - y * Sin a;
y'=x * Sin a + y * Cos a;
e.g. if we pick a=90º, then Cos a=0, Sin a=1; so [1,0] => [0,1] and [0,1] => [-1,0] which is correct.
In practice we need to pick 360º/256=1.40625º. So Sin a=0.02454, Cos a=0.9996988. In Signed 0:15 fixed-point that's 804 and 32758. As a side note, the fastest calculations can be done by calculating only 64 of the samples, and for each one you just reflect or negate to get the remaining quadrants (64 x 4 multiplies x 7µs each = 1.8ms).
At first I tried to follow the Inside Macintosh guide for using the Sound Driver, but in fact, it didn't seem to work at all! So, then I looked up all the MacTech articles on generating sound and found this one:
http://preserve.mactech.com/articles/mactech/Vol.02/02.02/SoundMadeSimple/index.html
Basically the article explains StartSound doesn't work properly at all as described in Inside Macintosh, but if you go straight to the underlying Sound Drive Parameter Block based API it does work. It's important to go for the early articles so that the APIs you use are likely to work with early Macs and OS versions. There's a whole bunch of Sound articles in MacTech. Perhaps I'll explore more of them in the future, because I might need a better sound payback to avoid glitches under System 7.
It looks like I used a bunch of custom buttons for the keypad buttons, but I didn't. I wanted to be able to figure out which keypad button was hit in one go, straight from the keypad grid & mouse coordinates. I used a pair of SICNs for pressed and released and invalidated only the button I wanted redrawn. The keypad digits are added to each button using DrawChar.
There’s space at the top for a full phone number and I’ll add a text box for that next. In theory, if you do audio out from a Mac to a UK landline and press digits it should phone the number, because they’re sine waves for UK DTMF at the right frequencies on a real Mac. (which might be the same as international DTMF, but I haven't checked). It runs in 32kB (it’s a 6kB program, doesn’t run in 16kB, but might run in 24kB). Running it in colour or on a PowerPC Mac might need a bit more.
Anyway, here’s the project and two versions of the app, one that uses WaitNextEvent for System versions that don't support GetNextEvent. I still haven't followed @David Cook 's guide on checking for that. There's also a few bugs: if the window is partially covered and re-exposed not all the buttons get properly redrawn. Also if you hold the mouse on one button, move it and let go on another, then the first keypad button remains highlighted.



