问题
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?
回答1:
A continuous (in time) sine wave can be defined as A*sin(2*PI*f*t)
, where A
is some amplitude, PI
is, well, 3.14..., f
is the tone frequency in Hertz and t
is time in seconds.
Now, since you don't have continuous time, since your time is discrete, you substitute dt*i
in place of t
and get A*sin(2*PI*f*dt*i)
, where dt
is the time between samples or 1/sample rate
and i
is the sample number. You can spell it out as A*sin(2*PI*(f/Fs)*i)
. Beware that once you choose a certain sample rate Fs
(in samples/second or simply Hz), the highest tone can never be greater than Fs/2
Hz.
来源:https://stackoverflow.com/questions/8462996/how-can-i-play-a-single-tone-or-custom-wave-with-delphi