![]() |
Forum Index : Microcontroller and PC projects : Help on Play Sound - Variable Question - String ?
Author | Message | ||||
TweakerRay![]() Senior Member ![]() Joined: 01/08/2020 Location: GermanyPosts: 138 |
Hi! I was just working on some Soundprogramm and wondered is it possible to put a variblename like SOUND$ in the command : play sound for example: Play Sound 1,B,Sound$,frq,vol Because When I try to do this it does not work... only if there are hard written Variables like Q for squarewave N for noise or S for Sine... I was wondering if I can use a varible for the type of sound ? The varible for frequencie frq does work and also vol is no problem , but the type of sound can't be changed with a string like I tried... Any help from you cool smart programmers ? thanks in advance... http://tweakerray.bandcamp.com |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4311 |
I suspect not, you would need a wrapper subroutine something like the following (untested): Sub play_sound(sound_no%, channel_no%, type$, frequency%, volume%) If volume% = 0 Then volume% = 25 Select Case UCase$(type$) Case "N" : Play Sound sound_no%, channel_no%, N, frequency%, volume% Case "O" : Play Sound sound_no%, channel_no%, O, frequency%, volume% Case "P" : Play Sound sound_no%, channel_no%, P, frequency%, volume% Case "Q" : Play Sound sound_no%, channel_no%, Q, frequency%, volume% Case "S" : Play Sound sound_no%, channel_no%, S, frequency%, volume% Case "T" : Play Sound sound_no%, channel_no%, T, frequency%, volume% Case "W" : Play Sound sound_no%, channel_no%, W, frequency%, volume% Case Else : Error "Unknown sound type" End Select End Sub Best wishes, Tom MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
vegipete![]() Guru ![]() Joined: 29/01/2013 Location: CanadaPosts: 1132 |
Mauro solved this in his Hope Robot Programming Contest entry: EXECUTE "PLAY SOUND "+STR$(C)+",B,"+P$+","+STR$(F)+","+STR$(V) Visit Vegipete's *Mite Library for cool programs. |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4311 |
That's neat, wonder what the performance comparison is like, though it probably doesn't matter. Best wishes, Tom MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
TweakerRay![]() Senior Member ![]() Joined: 01/08/2020 Location: GermanyPosts: 138 |
Thanks a lot guys. Thats exactly what I was looking for ! Thank you very much ! Cheers TweakerRay http://tweakerray.bandcamp.com |
||||
vegipete![]() Guru ![]() Joined: 29/01/2013 Location: CanadaPosts: 1132 |
PS to Tom This is exactly why I shuddered a while back when you voiced your support for _named_ parameters for commands, instead of numeric ones. A name is certainly easier to remember, but as a result, contortions are needed to use variables. ![]() Visit Vegipete's *Mite Library for cool programs. |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4311 |
That's a very compelling argument although I have no recollection of what you are talking about ![]() Best wishes, Tom Edited 2021-05-15 04:58 by thwill MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |