13 #define M_PI (3.14159265358979323846)
20 uint32_t& cycleSample,
28 double scale = (double)((uint32_t)(1<<(numBits-1)));
33 for (channel = 0; channel < numChannels; channel++)
35 cycleLength[channel] = sampleRate / frequency[channel];
36 cycleCurrent[channel] = cycleSample;
39 for (sample = 0; sample < numSamples; sample++)
41 for (channel = 0; channel < numChannels; channel++)
43 float nextFloat = (float)(sin(cycleCurrent[channel] / cycleLength[channel] * (
M_PI * 2.0)) * amplitude[channel]);
44 uint32_t value =
static_cast<uint32_t
>((nextFloat * scale) + 0.5);
50 *audioBuffer++ = value;
52 cycleCurrent[channel] += 1.0;
53 if (cycleCurrent[channel] > cycleLength[channel])
55 cycleCurrent[channel] -= cycleLength[channel];
61 return numSamples*4*numChannels;