i'm attempting to add my own continuous pitch modulation (vibrato) to my OpenAL object by assigning the sound's pitch to the path of a sine wave. this is my callback method, which is repeating every 1/30 of a second, as well as the getter and setter for the pitch.
#define kMaximumAplitude 0.025
#define kVibratoDegreeIncrements is 45
#define kDegreesToRadians(x) (M_PI * (x) / 180)
- (void)vibratoCallBack:(NSTimer *)timer
{
float newPitch = kMaximumAplitude * sin(kDegreesToRadians(vibratoDegreeIncrements));
self.pitch += newPitch;
vibratoDegreeIncrements += kVibratoDegreeIncrements;
}
- (void)setPitch:(ALfloat)newPitch
{
pitch = newPitch;
alSourcef(sourceID, AL_PITCH, pitch);
}
- (ALfloat)pitch
{
return pitch;
}
the default pitch is set at 1.0, so the above outputs the following sine wave cycle:
Wrong Pitch: 1.000000
Wrong Pitch: 1.017678
Wrong Pitch: 1.042678
Wrong Pitch: 1.060355
Wrong Pitch: 1.060355
Wrong Pitch: 1.042678
Wrong Pitch: 1.017678
Wrong Pitch: 1.000000
however, if you look at those numbers they are not much of a sine wave. the reason, as far as i can see, is that self.pitch is adding itself along with the sine wave increments. i would like the base pitch (unmodulated pitch) to remain constant prior to the vibrato method's pitch change. doing so would allow me to continue to control the base pitch using a UISlider (for example) while the modulation effect can optionally and accuratelyoccur without affecting the base pitch. i can't find a way.
below is the proper sine wave output that i would like to add to the current pitch:
Correct Pitch: 0.000000
Correct Pitch: 0.017678
Correct Pitch: 0.025000
Correct Pitch: 0.017678
Correct Pitch: 0.000000
Correct Pitch: -0.017678
Correct Pitch: -0.025000
Correct Pitch: -0.017678
Correct Pitch: -0.000000
therefore, if the current, unmodulated pitch is at 1.5, i would like the output to look like this:
Desired Pitch: 1.500000
Desired Pitch: 1.517678
Desired Pitch: 1.525000
Desired Pitch: 1.517678
Desired Pitch: 1.500000
Desired Pitch: 1.482322
Desired Pitch: 1.475000
Desired Pitch: 1.482322
Desired Pitch: 1.500000
how is it possible to change the pitch without really effecting the pitch? is there a way to compensate for the modulation to take place inside the method so that the effect can occur on a moving (or movable) base pitch?