sx/b freqout in subroutine
algorhythm
Posts: 4
Hello. I'm new to the forum and to sx programming.
I need to make a subroutine that will play notes based on values passed into it. I need the pitch accuracy of FREQOUT but unfortunately it only accepts constants to specify frequency. I want to be able to feed the subroutine a list of frequencies and durations but I get this error:
CONSTANT EXPECTED "__PARAM1"
note:
pitch = __PARAM1
time = __PARAM2
freqout pin, pitch, time
return
Start:
gosub note, 440, 100 ' make a 440Hz 100ms tone
END
What is the best way to solve this problem?
I need to make a subroutine that will play notes based on values passed into it. I need the pitch accuracy of FREQOUT but unfortunately it only accepts constants to specify frequency. I want to be able to feed the subroutine a list of frequencies and durations but I get this error:
CONSTANT EXPECTED "__PARAM1"
note:
pitch = __PARAM1
time = __PARAM2
freqout pin, pitch, time
return
Start:
gosub note, 440, 100 ' make a 440Hz 100ms tone
END
What is the best way to solve this problem?
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
PlayLoop:
· MyNote = 440
· MyTime = 500 ' 1/2 second
·' NoteIndex gets: 0,···· 1,·· 2, ...
·LOOKUP MyNote, (0, 440,480,3,4,5,6,7,8,9,10), NoteIndex
·BRANCH NoteIndex, (Note0, Note1, Note2, Note3) ' ...
BR_CONT:· ' pseudo-RETURN destination -- 'BRANCH' is 'GOTO' only.
··············
' Do more stuff...
· GOTO PlayLoop
Note0:· '
· GOTO BR_Cont
Note1:· ' I don't know the 'size' of FREQOUT assembly -- these may have to go on multiple pages.
· FREQOUT SoundPin, 440, MyTime
· GOTO BR_Cont
Note2:
· FREQOUT SoundPin, 480, MyTime
· GOTO BR_Cont
'etc...
Post Edited (allanlane5) : 12/28/2004 3:49:27 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
Man, only having 'BYTE' values is limiting. I suppose you're working on that though, right? right? Please?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
Bean.
If SX/B has a WRITE statement like BS2, you could identify the location in memory where the constaint for FREQOUT is stored and overwrite it with the desired value. I would be a hassle as there's no syntax to get the address of a variable, like 'C', so if the location moves around with changing code you'd have to adjust the WRITE address for each revision of the code.
Like I said. This is probably a bad idea. But it might do what you needed as a last resort... or at least a last resort other then assembler.
Jim
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas, TX· USA
Jim