I looked up some code, seems like everything is creating some math function waves, but I want to a single tone, or a custom wave made with custom single tones.
I read this
How can I generate continuous tones of varying frequencies?
Which is close to my answer.
Assumin I’m gonna use waveOutWrite like in the above link, I can’t seem to figure out how the amp/freq is calculated for each Sample in HWAVEOUT.
In the code from the link It’s done like this:
Samples[i] := round(vol*sin(omega*t));
Assuming I want a 15kHz freq single tone with some amp (does not matter which), how would a Sample[1] be calculated?
A continuous (in time) sine wave can be defined as
A*sin(2*PI*f*t), whereAis some amplitude,PIis, well, 3.14…,fis the tone frequency in Hertz andtis time in seconds.Now, since you don’t have continuous time, since your time is discrete, you substitute
dt*iin place oftand getA*sin(2*PI*f*dt*i), wheredtis the time between samples or1/sample rateandiis the sample number. You can spell it out asA*sin(2*PI*(f/Fs)*i). Beware that once you choose a certain sample rateFs(in samples/second or simply Hz), the highest tone can never be greater thanFs/2Hz.