 # Sine Wave question

#1

So I have a question, I have a function sine that returns a float modeled from other sinewave generating algorithms but how does this produce a wave when the method returns a single float? is it because of my time variable I set in startNote?

``````float oscWaves::sine(float frequency)
{
if(frequency > TWO_PI)
{
frequency = fmodf(frequency, TWO_PI);
}

return sinf(frequency);
}
``````
`````` void startNote (int midiNoteNumber, float velocity, SynthesiserSound* sound, int currentPitchWheelPosition) override
{
env1.trigger = 1;
frequency = 0.0;
level = velocity;
tailOff = 0.0;

double noteNumber = MidiMessage::getMidiNoteInHertz (midiNoteNumber);
double phasePerSample = noteNumber / getSampleRate();

time = phasePerSample * 2.0 * double_Pi;
}
``````
#2

The actual sound generation happens in the renderNextBlock method, startNote just sets up things when a note begins. Your variable “frequency” has a misleading name in the oscWaves::sine function, it should really be called “phase”.

#3

okay so in the renderNextBlock when i’m looping through the number of samples that is when its plotting each float point on the graph to actually construct the wave ? Sorry for the phrasing of this I am trying to get a visual representation.

#4

Assumably you are increasing the “time” member variable inside the loop and giving that to the sine wave function. The result is that a sine wave is produced as the output. (Assuming things have been coded correctly…)

#5

Thank you so much im starting to get it now, so

``````double cyclesPerSample = noteNumber / getSampleRate();
time = cyclesPerSample * 2.0 * double_Pi;
``````

for time its essentially the duration for however long the note is being hold?