Best viewed in 1024x768

Sound

Sound on the calculator is simulated by rapidly turning on and off the linkport from 'High' to 'Low'. This is a similar technique they used to simulate digital audio onto a PC speaker, it was simply the rapid ON and OFF action of the speaker thousands of times per second.

Sound Demo v1.0

This simple program uses the link port to output sound. This is the jack located on the bottom of the calculator, the same jack used to transfer programs from the computer to your calculator. You will need a 2.5mm <--> 3.5mm adapter. This can be purchased at Radio Shack.

Instructions for hooking up the calculator to headphones or a speaker are located at: http://cccsrv.trevano.ch/~blutz/TIGen/TIElectronics.html

Simply run the program, plug in the headphones, and enjoy. The source code can be found on my web page


Brief Overview

Sound are Sine Waves. We can simulate sound waves with square waves, which can be produced by rapidly turning on and shutting off the speakers.


You turn on the speaker by turning on the link port wires, wait a delay, and shut them off. Then you wait another delay, and shut it off. Make sure the delays are equal. You have sound!



Problems

One problem I didn't bother solving is the frequency <-> speed problem. Basically when you make a sound with twice the frequency, it takes only half the speed. Since the program uses two inner loops (one when the speaker is on, the other when off) to create the full square wave, when the inner loop is halved, the frequency is doubled. This is what we want, that is great. But also it takes only half the time to complete the full square wave. So when one sound at 500 hz takes 1 second, then a sound at 1000 hz takes only half a second

Another problem is that it disables interrupts. You can re-enable them, it might not sound as good, but should still work. Disabling interrupts may cause some shells not to work, so...

Also the PlayTone function doesnt use a standard frequency measurement. C is used as the frequency, but not in hertz. It's delay is the delay it takes the Z80 processor to loop C number of times, using the djnz instruction. It uses all the speed toward the sound. Also, HL is not in seconds, really just any 'ol number - see the source code.



Other Notes

Using Interrupts

Interrupts are impossible. Interrupts execute at 200 hz per second, making it (therotically), only possible to have 100 hz sounds. (one interrupt turns the wire on, the other off) sounds. This sound is tooo low and not good for any purpose.

Sound Library

86wav already came out. I was thinking about a midi thing, but the midi format is too complicated for me.

Achieving Real Time Sound

To integrate sound in a game, you will need a constant slow down or a really small sound. To use a constant slowdown, have the sound routine check a flag byte that you make up. When a bit is set on this flag byte, play the sound, and reset the flag. If no bits are set, then do a bunch of nops to keep the speed constant whether a flag is set or not.

Or you can have a really small sounds during gameplay, or sounds that only play on the titlescreen and "Game Over". You get the idea.