views:

98

answers:

1

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?

+1  A: 

I think you just need to separate the data apart. Have one pitch store your base pitch, which would he an unmodified sine wave. Then you need another method to produce a vibrato sound wave, that is in sync with your base pitch. Then you need a getter to return the current pitch of the final waveform. In other words, you don't need to store the pitch of the final waveform, as you're doing now, you just need to calculate it on demand.

- (ALfloat) getFinalPitch
{
return getBasePitch() + getVibratoPitch();
} 
Dolph
of course! why didn't i realize that?! thank you! i'd vote you up but i don't have enough rep yet. i vote you up in spirit :)
TheDarkInI1978
Lol just glad I could help! I was worried I wasn't explaining myself clearly. I'm trying to write on a phone! :P
Dolph