The pragmatic approach ...
... as soon this works one can think about to optimize it (e.g. loops instead of creating 10 Seconds of the same shape, stereo, etc.).
You like to play a sinus- sound:
Duration : [Sec]
SampleFrequency : [Sample Per Second]
Frequency : [Hz]
The above gives us the buffer size:
bufferSize= Duration * SampleFrequency
44'100 Samlpes per second
-> 441'000 samples
Keep in mind, these 441'000 samples represent something like a 'time line'.
Now coming to calculate the shape of the buffer. Here the formula
comes into acount (the background of that is too much to explain it here).
A: Amplitude (Volume)
f: Frequency of the sound
Note: Usually the function
expects a argument in
Again: We have the buffer of size bufferSize for a duration of 'Duration' [Sec], therefore we know that the time increment will be:
dt= Duration / bufferSize; // Make sure you to calculate that with double or float
Finally we need only to loop about the bufferSize.
double dT= duration / bufferSize;
for (int tIx= 0; tIx < bufferSize; tIx++)
double time= tIx * dT;
double sinValue= sin(2π(f * time))
buffer[tIx]= volume * sinValue;
All untested and written out of my memory after having my last lesson in 'communications engineering' before about 30 years and never used it since then. Nevertheless I hope it helps you ;)
Volume/Amplitude can be in the range of 0...about 32'000 in case you use 16 Bit Samples.