This is what I use to make multi-frequency sounds. It works great. It can make complex sounds, but as has been pointed out it won't sound like a guitar without alot of help. It will make a chord if you use three frequencies in the signal array. You have to set the frequency, and delta. Delta is the frequency of the signal divided by the number of samples. Also you must set the volume.
+ Code Snippettype SINUSOIDAL_WAVE
fundamental as float rem Frequency
theta as float rem Instantaneous angle
delta as float rem Incremental rotation
amplitude as float rem Peak amplitude
endtype
dim signal() as SINUSOIDAL_WAVE
function GenerateSignal16(ptr as dword, numsamples as integer)
local integrator as integer = 0
local i as integer
local j as integer
local wtemp as word
for i = 0 to numsamples - 1
integrator = 0
for j = 0 to array count(signal())
inc integrator, int(sin(wrapvalue(signal(j).theta)) * ...
signal(j).amplitude)
inc signal(j).theta, signal(j).delta
next j
wtemp = integrator
*ptr = wtemp
inc ptr, 2
next i
endfunction
function WritePCMWaveFile(filename as string, wavedata_blk as integer, ...
size as integer)
local i as integer
local j as integer
local k as integer
local s2 as integer
local ptr as dword
ptr = get memblock ptr(wavedata_blk)
s2 = size << 1
if file exist(filename)
delete file filename
endif
open to write 1, filename
write byte 1, asc("R")
write byte 1, asc("I")
write byte 1, asc("F")
write byte 1, asc("F")
write long 1, s2 + 42
write byte 1, asc("W")
write byte 1, asc("A")
write byte 1, asc("V")
write byte 1, asc("E")
write byte 1, asc("f")
write byte 1, asc("m")
write byte 1, asc("t")
write byte 1, asc(" ")
write long 1, 16
write word 1, *ptr
inc ptr, 4
write word 1, *ptr
inc ptr, 4
write long 1, *ptr
inc ptr, 4
write long 1, *ptr
inc ptr, 4
write word 1, *ptr
inc ptr, 4
write word 1, *ptr
inc ptr, 4
write byte 1, asc("d")
write byte 1, asc("a")
write byte 1, asc("t")
write byte 1, asc("a")
write long 1, s2
for k = 0 to size - 1
write word 1, *ptr
inc ptr, 2
next k
close file 1
endfunction
To use it, set the frequency (say, 440.0 for the note A), set theta to 0.0, calculate delta for the entire sample , and set the volume. (Volume can only equal 32767 total for 16 bit audio.)