views:

381

answers:

2

Hi,

I have an OpenAl sound engine on my iPhone app. When I play a sound that I have loaded, I can control it's pitch.

In OpenAl a pitch set to 1.0 has no effect. If you double it to 2.0, it plays the note 1 octave higher(12 semitones). If you halve it, to 0.5, it will be an octave lower (12 semitones).

So, my original sample is playing a C. I assumed that if I divide 1 by 12 (semitones) I could get the pitch for the individual notes in that octave. But this does not seem to be the case. Which makes we think that semitones are not equal values. Is that true?

Does anyone know how I can work out the openAl pitch value for individual notes in an octave?

Thank you

+5  A: 

Semitones are equal ratios. So, if your sample is C, C# will be the 12th root of two. If you count semitones C=0, C#=1 etc, the ratio is pow(2.0, n*1.0/12.0)

Works for negative numbers, too.

I should note, this is not strictly true in every tuning scheme... but this is a good start. If you really care about the full complexities of musical tuning, I can find you some references.

Andrew McGregor
Thank you Andrew! this is perfect!... exactly what I was after!And yes references would be great. In particular the relationship between pitch and length of sample. Thanks again.
Jonathan
Oh, well, the length just gets shorter by the same ratio. I'll find a good introduction to scales and tuning.
Andrew McGregor
http://en.wikipedia.org/wiki/Mathematics_of_musical_scales and http://en.wikipedia.org/wiki/Equal_temperament will get you into the thicket of wikipedia articles about this topic. It gets hugely complicated after a while, but it's also very important to practical music, especially if you're working with string or wind instruments.
Andrew McGregor
A: 

Can anyone tell me why the volume in openal becomes lower and lower if I change the pitch higher and higher? Thanks in advance.

alSourcef(source, AL_PITCH, 1.2f); alSourcef(source, AL_GAIN, 1.0f);

with this setting, the volume is still very very low. is there a way to cheat it to make the gain above 1?

FYI, the source is a voice recorded from AVrecorder, so I cant set the source volume any higher.

Xiu