[comp.sys.ibm.pc] Turbo Pascal

arunc@uxe.cso.uiuc.edu (07/13/88)

I am writing a program in Turbo Pascal 4.0 to drill musicians
in their recognition of sequences of intervals.  TP4 has a 
built-in Sound(Frequency) function, where "Frequency" is an integer
value.

However, I need frequencies which are real-number values.  (For example,
middle C (C4) is 261.6 Hz.)   I have completed writing the program using
only integers, but the resulting pitch-intervals are, understandably,
"out of tune".

How can frequencies be gotten out of the speaker that are real-number
values?  Can this be done using Turbo Pascal?  Are there other languages
which allow for this degree of control?

Thanks for any help,

	Arun Chandra
	arunc@uiucuxc.CSO.UIUC.EDU

dixon@control.steinmetz (walt dixon) (07/16/88)

I'm not familiar with the TP library and the Sound routine in
particular,  but I have messed around with the sound generation
hardware.  The common way to generate sounds is to use one
channel of an 8253 counter/timer chip in mode3.  This causes
the square wave output of the chip to go to the speaker through
a low pass filter.  The counter clocks at 1,193,180Hz.  You
load a counter with a divisor to get specific frequencies.
For example, the 440Hz a above middle c requires a counter
of 1193180/440.  This tone is faithfully reproduced.  The
accuracy of the resulting note is limited by roundoff/truncation
in the division.  I don't know how the TP sound function
works.

I have written a device driver which takes character strings
similar to the BASICA sound statement. (My driver also supports
key signatures,  double sharps/flags, and naturals). To my untrained
(more like tone deaf),  I was able to get reasonable accurate
reproduction in the 3rd octave and above.  The most difficult
problem I had to deal with was getting accurate note timings.
I eventually sped up the system clock to increase timer resolution.
 
This driver is published in chapter 11 of the MS-DOS Papers 
(Howard Sams,  1988). Take a look at this chapter if you need 
more information.  [I don't get any royalties from book sales -- 
just citing what I belive to be a good reference.]  

I hope this helps.

Walt Dixon		{ARPA:		Dixon@ge-crd.arpa		}
			{US Mail:	GE CRD				}
			{		PO Box 8			}
			{		Schenectady,  NY 12345		}
			{Phone:		518-387-5798			}