Changing pitch to play notes of an octave

BlitzMax Forums/BlitzMax Programming/Changing pitch to play notes of an octave

Hiya, Anyone know how much I should change the pitch that I play a channel in order to play the notes of an octave.

For example, let's say middle C is when the sample is played at 1.0 (normal), how much should I play at to get C#, D, etc all they way up to the nextg C (2.0). Thanks!

An excellent page describing 12 note entonation can be found here http://thinkzone.wlonk.com/Music/12Tone.htm

Excellent thanks, just what I needed! :-)

Graphics 800,600

Local note:Int ' zero is middle C
Local snd:TSound = LoadSound(RequestFile("find a sound..."))
Local chn:TChannel = PlayNote(snd,note)

Repeat
	Cls
	If KeyHit(KEY_UP) Then note:+1 ; chn = playnote(snd,note,chn)
	If KeyHit(KEY_DOWN) Then note:-1 ; chn = playnote(snd,note,chn)
	DrawText(note,10,10)
	Flip
Until KeyHit(KEY_ESCAPE) Or AppTerminate()

Function PlayNote:TChannel(sound:TSound, note:Float, channel:TChannel=Null,volume:Float=1)
	If Not channel channel = AllocChannel()
	CueSound(sound,channel)
	SetChannelVolume(channel,volume)
	SetChannelRate(channel, 2^(Note/12) )
	ResumeChannel(channel)	
	Return channel
EndFunction

Note is 0 for middle C, 1=C#, 2=D, 3=D#.. 12=C (+1 octave)
negative numbers also work.
you can even slide between notes by using a float value.

hope that helps

*EDIT* damn, didnt notice the math on that page til now. lol

Nice post.

Grey, you could have checked my sound system out. Working code in there to do it :-D

Cool, thanks Redi, I've used that 2^(Note/12) formula.

Cyg: Could've but I forgot ;-)

Is there an easy way to only play the notes of C major based on a Note sent in which is in the range 0-7? The only way I can think is to prefill an array and use Note to reference that. But that's a pain so I wondered if it was possible with a formula and a couple of IF ELSEIFs etc ?

Yes, i'd do it by an array,

One per chord. instead of using absolute values, use offsets. Any major chord would in this instance be [0,4,7]

You could probably cut it down to 2 notes in the array of each chord because obviously the first note of a C chord is going to be C. Since you pass this to the func anyway, you dont need to read it out of an array :-)

What are you up to Grey? I wouldnt mind a nose!

thanks. I'm making a gauge rise every time the user performs a certain action and I want it to play notes in a scale of C major so they don't go out of tune or key with the music.

Great idea. That should work well. Let me know if you get any problems. (I'll sign back up to Skype when I get home, but you shouldn't have any problems anyway.)