Finally got this code to work... and it's very laggy indeed when notes are called that require the processor to run slowly and/ or pwm DIV to equal a low value:-
I will have to produce the notes in a different way; with the processor speed set as high as possible to minimise lag due to processing time. I could use picaxe 'tune', although from memory that has a range of 18 notes only; I'd need some sort of frequency divider/multiplier circuit to extend that to the 4 1/2 octaves (52 notes) I need for this project. I have no idea how that could be acheived in a small package, using the picaxe's non square wave sound output.
Does anyone have any other/ better suggestions for how to produce 4 1/2 octaves of accurately (ish) tuned sound out of a picaxe? An mp3 of each note? Midi? Out of my depth a bit at this point.
Code:
'violin synth with 4 strings, too slow
'G string C.4 pin6
'D string B.3 pin15
'A string C.0 pin10
'E string B.2 pin16
'pwm1 = C.2 pin5
'adc = C.7 pin3
' G1 G#1 A2 Bb2
EEPROM 0,(m4,64,78, m4,64,75, m4,64,70, m4,64,66)
' B2 C2 C#2 D2
EEPROM 12,(m4,16,252, m4,16,238, m4,16,224, m4,16,212)
' Eb2 E2 F2 F#2
EEPROM 24,(m4,16,200, m4,16,189, m4,16,178, m4,16,168)
' G2 G#2 A3 Bb3
EEPROM 36,(m4,16,158, m4,16,150, m4,16,141, m4,16,133)
' B3 C3 C#3 D3
EEPROM 48,(m2,4,252, m2,4,238, m4,16,112, m2,4,212)
' Eb3 E3 F3 F#3
EEPROM 60,(m2,4,200, m4,16,94, m2,4,178, m2,4,168)
' G3 G#3 A4 Bb4
EEPROM 72,(m2,4,159, m2,4,150, m2,4,141, m4,16,66)
' B4 C4 C#4 D4
EEPROM 84,(m4,4,252, m4,4,238, m4,4,224, m4,4,212)
' Eb4 E4 F4 F#4
EEPROM 96,(m4,4,200, m4,4,189, m4,4,178, m4,4,168)
' G4 G#4 A5 Bb5
EEPROM 108,(m4,4,158, m4,4,150, m4,4,141, m4,4,133)
' B5 C5 C#5 D5
EEPROM 120,(m8,4,252, m8,4,238, m4,4,112, m8,4,212)
' Eb5 E5 F5 F#5
EEPROM 132,(m8,4,200, m4,4,94, m8,4,178, m8,4,168)
' G5 G#5 A6 Bb6
EEPROM 144,(m8,4,159, m8,4,150, m4,4,70, m4,4,66)
main:
b2 = 0
high C.4 ; starting with G string notes
low B.2
b2 = 1
gosub readAdcVal
low C.4 ; D string notes
high B.3
b2 = 2
gosub readAdcVal
low B.3 ; A string notes
high C.0
b2 = 3
gosub readAdcVal
low C.0 ; E string notes
high B.2
b2 = 4
gosub readAdcVal
goto main
readAdcVal:
readadc c.7,b0 'b0 is the adc value
If b0 > 4 Then
b1 = 12
do
If b0 < b1 then lookUpData
if b1 > 244 then exit
b1 = b1 + 8
loop
Else
'pwmout pwmdiv4,C.2,0,0
return
End If
lookUpData:
b0 = 0
select case b2
case 1
b1 = b1- 12: b1 = b1 * 3 / 8: goto playNote
case 2
b1 = b1 - 12: b1 = b1 * 3 / 8: b1 = b1 + 21: goto playNote
case 3
b1 = b1 - 12: b1 = b1 * 3 / 8: b1 = b1 + 42: goto playNote
case 4
b1 = b1 - 12: b1 = b1 * 3 / 8: b1 = b1 + 63: goto playNote
else
end select
playNote:
read b1, b10, b11, b12 'read data from the next 3 bytes of eeprom, starting from address that has same value as b1
b13 = b12 * 2
select case b11
case 4 : setfreq b10: pwmout pwmdiv4, C.2, b12, b13
case 16 : setfreq b10: pwmout pwmdiv16, C.2, b12, b13
case 64 : setfreq b10: pwmout pwmdiv64, C.2, b12, b13
end select
return
Does anyone have any other/ better suggestions for how to produce 4 1/2 octaves of accurately (ish) tuned sound out of a picaxe? An mp3 of each note? Midi? Out of my depth a bit at this point.