maxiOsc

#1

Hello, so what is the difference between the maxiOsc class sinewave method and the JUCE tutorial on building a sinewave,
how does the maxiOsc class goes about making the wave?

    //This is a sinewave oscillator
	output=sin (phase*(TWOPI));
	if ( phase >= 1.0 ) phase -= 1.0;
	phase += (1./(maxiSettings::sampleRate/(frequency)));
	return(output);
}
void updateAngleDelta()
{
    auto cyclesPerSample = frequencySlider.getValue() / currentSampleRate;         // [2]
    angleDelta = cyclesPerSample * 2.0 * MathConstants<double>::pi;                // [3]
}
void getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill) override
{
    auto level = 0.125f;
    auto* leftBuffer  = bufferToFill.buffer->getWritePointer (0, bufferToFill.startSample);
    auto* rightBuffer = bufferToFill.buffer->getWritePointer (1, bufferToFill.startSample);
    for (auto sample = 0; sample < bufferToFill.numSamples; ++sample)
    {
        auto currentSample = (float) std::sin (currentAngle);
        currentAngle += angleDelta;
        leftBuffer[sample]  = currentSample * level;
        rightBuffer[sample] = currentSample * level;
    }
}
#2

Both use the standard sin() function, so there’s no real difference. (The code calling the sin() function is just structured differently.)

Real alternative approaches would be if the code implemented the sine function itself or used a wavetable.

#3

Okay so in the case of maxiOsc, the output is essentially the time or duration of the wave?

#4

Neither, the output is the sine wave. (One sample at a time, so you need to call the generation function for each sample you need to generate.)

#5

There are 2 main operations: calculing the phase/angle/position that depends on the frequency played (the frequency is given by the user when he press a key/generates a note, but you have to implement it), and calculing the sine value of that phase/angle/position.
Then, as Xenakios said, you call that “output function” each time you need to fill a sample in your output buffer: in the JUCE example case (I guess is the last code snippet) for each of the buffer samples to fill they calculate the sine value of that phase/angle and put it in the buffer (well, technically it’s two buffers, left & right).