watermoccasin
07-22-2009, 11:05 PM
Hi, I'm new to the forums and just started working with the propeller, and have a few questions for my first project.
First a little about the project . . .
Currently dubbed the propellamin, the device will be a propeller-controlled theremin-like instrument, using sonar (PING) rather than radio-freqency as input for frequency and volume.
I have many ideas that will be able to take advantage of a digitized version of this instrument, and the first is programming a specific pitch to a range, allowing the musician to easily play in any key. With the help of forum member Casslan, I have tied an average (AVG) of ping readings to an existing pitch-generator program with a table linking range to pitch, but I cannot seem to play frequencies that are not a whole number. I am able to get very close to an actual scale, but especially at lower frequencies this is very limiting. Below is the code I currently have for playing this instrument in C Maj.
VAR
long range
long Samples, AVG, SUM
byte counter
long Frequency
byte numofsamples
OBJ
Term : "FullDuplexSerialPlus"
ping : "ping"
Synth : "Synth"
PUB Start
Term.StartPST(115200)
numofsamples:= 5
repeat
Term.CursorHome
repeat counter from 0 to numofsamples ' Repeat Forever
Samples[counter+1] := Samples[Counter]
Samples[0] := ping.Ticks(PING_Pin) ' Position Cursor ' Print Fractional Part
'waitcnt(clkfreq / 10 + cnt) ' Pause 1/10 Second
SUM:=0
repeat counter from 0 to numofsamples
SUM := SUM + Samples[counter]
AVG := (SUM/numofsamples)
AVG := AVG -100
case AVG
0..100: Frequency := 131 'C3
101..200: Frequency := 147 'D3
201..300: Frequency := 165 'E3
301..400: Frequency := 175 'F3
401..500: Frequency := 196 'G3
501..600: Frequency := 220 'A3
601..700: Frequency := 245 'B3
701..800: Frequency := 262 'C4
801..900: Frequency := 294 'D4
901..1000: Frequency := 330 'E4
1001..1100: Frequency := 349 'F4
1101..1200: Frequency := 392 'G4
1201..1300: Frequency := 440 'A4
1301..1400: Frequency := 494 'B4
1401..1500: Frequency := 523 'C5
Synth.Synth("A", 10, Frequency)
Term.Str(String("AVG-100: "))
Term.dec(AVG)
Term.str(string(" ")) ' Print Inches
Term.CarriageReturn
Term.Str(String("FRE: "))
Term.dec(Frequency)
Term.str(string(" ")) ' Print Inches
Term.CarriageReturn
Below is how the table should read:
0..100: Frequency := 130.81 'C3
101..200: Frequency := 146.83 'D3
201..300: Frequency := 164.81 'E3
301..400: Frequency := 174.61 'F3
401..500: Frequency := 196 'G3
501..600: Frequency := 220 'A3
601..700: Frequency := 246.94 'B3
701..800: Frequency := 261.63 'C4
801..900: Frequency := 293.66 'D4
901..1000: Frequency := 329.63 'E4
1001..1100: Frequency := 349.23 'F4
1101..1200: Frequency := 392 'G4
1201..1300: Frequency := 440 'A4
1301..1400: Frequency := 493.88 'B4
1401..1500: Frequency := 523.25 'C5
My first questions for the forum are these:
**How can I get the pitch generator to generate a pitch that is not a whole number?
Does anyone have an idea for the code that would allow the pitch to slide smoothly from one specific note to the next while playing?
Is there a way to control the volume for the pitch generator with programming? If not I plan on using a digital potentiometer to control the signal coming from the generator.
Thanks for your help. I will try to keep progress updated, and if anyone has any other ideas for this project I am happy to hear any advice!
First a little about the project . . .
Currently dubbed the propellamin, the device will be a propeller-controlled theremin-like instrument, using sonar (PING) rather than radio-freqency as input for frequency and volume.
I have many ideas that will be able to take advantage of a digitized version of this instrument, and the first is programming a specific pitch to a range, allowing the musician to easily play in any key. With the help of forum member Casslan, I have tied an average (AVG) of ping readings to an existing pitch-generator program with a table linking range to pitch, but I cannot seem to play frequencies that are not a whole number. I am able to get very close to an actual scale, but especially at lower frequencies this is very limiting. Below is the code I currently have for playing this instrument in C Maj.
VAR
long range
long Samples, AVG, SUM
byte counter
long Frequency
byte numofsamples
OBJ
Term : "FullDuplexSerialPlus"
ping : "ping"
Synth : "Synth"
PUB Start
Term.StartPST(115200)
numofsamples:= 5
repeat
Term.CursorHome
repeat counter from 0 to numofsamples ' Repeat Forever
Samples[counter+1] := Samples[Counter]
Samples[0] := ping.Ticks(PING_Pin) ' Position Cursor ' Print Fractional Part
'waitcnt(clkfreq / 10 + cnt) ' Pause 1/10 Second
SUM:=0
repeat counter from 0 to numofsamples
SUM := SUM + Samples[counter]
AVG := (SUM/numofsamples)
AVG := AVG -100
case AVG
0..100: Frequency := 131 'C3
101..200: Frequency := 147 'D3
201..300: Frequency := 165 'E3
301..400: Frequency := 175 'F3
401..500: Frequency := 196 'G3
501..600: Frequency := 220 'A3
601..700: Frequency := 245 'B3
701..800: Frequency := 262 'C4
801..900: Frequency := 294 'D4
901..1000: Frequency := 330 'E4
1001..1100: Frequency := 349 'F4
1101..1200: Frequency := 392 'G4
1201..1300: Frequency := 440 'A4
1301..1400: Frequency := 494 'B4
1401..1500: Frequency := 523 'C5
Synth.Synth("A", 10, Frequency)
Term.Str(String("AVG-100: "))
Term.dec(AVG)
Term.str(string(" ")) ' Print Inches
Term.CarriageReturn
Term.Str(String("FRE: "))
Term.dec(Frequency)
Term.str(string(" ")) ' Print Inches
Term.CarriageReturn
Below is how the table should read:
0..100: Frequency := 130.81 'C3
101..200: Frequency := 146.83 'D3
201..300: Frequency := 164.81 'E3
301..400: Frequency := 174.61 'F3
401..500: Frequency := 196 'G3
501..600: Frequency := 220 'A3
601..700: Frequency := 246.94 'B3
701..800: Frequency := 261.63 'C4
801..900: Frequency := 293.66 'D4
901..1000: Frequency := 329.63 'E4
1001..1100: Frequency := 349.23 'F4
1101..1200: Frequency := 392 'G4
1201..1300: Frequency := 440 'A4
1301..1400: Frequency := 493.88 'B4
1401..1500: Frequency := 523.25 'C5
My first questions for the forum are these:
**How can I get the pitch generator to generate a pitch that is not a whole number?
Does anyone have an idea for the code that would allow the pitch to slide smoothly from one specific note to the next while playing?
Is there a way to control the volume for the pitch generator with programming? If not I plan on using a digital potentiometer to control the signal coming from the generator.
Thanks for your help. I will try to keep progress updated, and if anyone has any other ideas for this project I am happy to hear any advice!