From: Elias P. <el...@us...> - 2004-02-17 14:11:55
|
On Tue, 2004-02-17 at 08:33, Captain Pork wrote: > I'd like to write a more advanced version of this which is capable of > playing simple melodies by setting the frequency argument of play_sample > to values which correspond to particular notes (C, D, G# etc). > > I'm not worried about making different samples harmonise with each other, > but just to make a series of repetitions of the same sample play a little > tune, without having a separate wav file for each note. Does anyone have > any idea what the frequency steps I would need to use are? Say 1000 > (unadjusted frequency) is C, does that make 2000 the next C up (IIRC from > high school science/music, each octave doubles the freqency)? If so, how > do I make it play the notes in between? > Yes, that's correct. The formula on the link in AJ's answer also works directly for the relative values you pass to play_sample: frequency = base_frequency * pow (2.0, note / 12.0) If note is 0, you get base_frequency, in this case 1000. If note is 12, you get the double frequency, in this case 2000. From 1 to 11 you get the values for all the notes in the octave. -- Elias Pschernig <el...@us...> |