FREQOUT

 
Library


#include <FREQOUT.bas>

This library has some initialization code that can either be copied into your program or the code can be run inline as in the following-

initFREQOUT:
#include <FREQOUT.bas>
return

...

main:
    gosub initFREQOUT
 

 
C
F

S

Interface

 #define SIN(x)   sin_tbl(x)
 #define COS(x)   sin_tbl(x-64)

' duration is in milliseconds
' freq1 and freq2 in Hz
SUB FREQOUT(pin, duration, freq1, freq2)

Internals

     ARMbasic uses integers, but there may be a need for certain functions that normally use floating point calculations.  One of these is the cosine function, which normally operates on degrees or radians.  But for simplicity and the binary world, these values and the result value have been normalized to fit in a byte value. but in this case it is expressed as -127 to +127 or the cos() multiplied by 127.

   These SIN and COS functions are identical to the PBASIC versions and are used by FREQOUT.  Rather than degrees or radians there are 256 divisions (360/256 degrees) which returns a value of -127 to +127 which correspond to -1 to 1 for normal sine and cosine function.

   The SIN function is implemented using string, and accessed a byte at a time to generate the 256 values.  COS is the SIN function shifted 90 degrees or 64 places

 
Example

#include <FREQOUT.bas>
...


'Generate a soothing dual frequency tone on pin 4 for 8 seconds
'using frequncies 2500 and 6000

FREQOUT (4, 8000, 2500, 6000)