For a coursework exercise I need to create a sine oscillator with which to alter the delay time in playing back an echo of the sound (a flanger). This oscillator needs to have an adjustable frequency.
The value returned by the function should be between 1 and -1, which I achieved with this function:
public void oscillateNumber(){
for (int i = 0; i < 200; i++){
oscResult = Math.sin((Number1* Math.PI)/180.0);
updateNumber();
}
}
And by having Number1 varying between -180 and 180 (found this solution here: How to use a Sine / Cosine wave to return an oscillating number)
How could I go about incorporating a frequency into this oscillator? The frequency needs to be adjustable between 0 and 5Hz...
I am completely new to this material so I am not entirely grasping the mechanics of this, another function I found is
public void oscillateNumber3(){
for (int i = 0; i < 400; i++){
oscResult = (float)Math.sin( angle );
angle += (float)(2*Math.PI) * frequency / 44100f;
java.lang.System.out.println(oscResult);
}
}
Where if I add this value to the delay it gives me a bit more resemblance to the effect but I am not sure it's actually correct...
Any pointer to this would be really appreciated.
UPDATE
Ok so following Oli's pointer I came up with this function for continuously modulating the delay with a number produced by the oscillator, I'm not quite sure about the loop though:
public void oscillatorNumber(int frequency, int sampleRate){
for (int t = 0; t < (sampleRate * frequency); t++){
oscResult = (float)Math.sin( angle );
angle += (float)(2*Math.PI) * 2 * (t / 44100); // sin(2*pi* f *(t/Fs))
java.lang.System.out.println(oscResult);
}
}
Does this look about right?