![]() |
Forum Index : Microcontroller and PC projects : String variables in PLAY SOUND
Author | Message | ||||
hitsware2![]() Guru ![]() Joined: 03/08/2019 Location: United StatesPosts: 719 |
'sound dim f$(7),n(7) for i=0 to 7:read f$(i):next i for i=0 to 7:read n(i):next i do for i=0 to 7 for e=25 to 1 step -1 play sound 1,b,f$(i),100*n(i),e pause 10 next e play sound 1,b,o,200,1 pause 1000 print f$(i) next i loop data s,o,o,o,s,o,o,o data 2,2,2,2,6,6,6,6 In the above the PRINT reflects the s's & o's , but the PLAY SOUND seems not to pick them up ? my site |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6283 |
You can use a SELECT CASE to do the first option All the remainder appear to get evaluated so are OK One mistake you have made is in the DATA statements. You should surround string data in quotes. Otherwise MMBasic get confused with variables. I also increased the first pause so you have time to hear the changes in sound level. 'sound dim f$(7),n(7) for i=0 to 7:read f$(i):next i for i=0 to 7:read n(i):next i do for i=0 to 7 print f$(i) for e=25 to 1 step -1 select case f$(i) case "s" play sound 1,b,s,100*n(i),e case "o" play sound 1,b,o,100*n(i),e end select pause 100 next e play sound 1,b,o,200,1 pause 1000 next i loop data "s","o","o","o","s","o","o","o" data 2,2,2,2,6,6,6,6 Jim VK7JH MMedit |
||||
hitsware2![]() Guru ![]() Joined: 03/08/2019 Location: United StatesPosts: 719 |
Thank You .... As Often ![]() ![]() The first pause needs to be short to give an ' envelope ' Hearing the steps ruins the effect . It would be such an improvement if PLAY SOUND would accept 0 as a 'frequency' and/or 'volume' parameter resulting in silence ...... ![]() Edited 2020-08-14 00:57 by hitsware2 my site |
||||
Womble![]() Senior Member ![]() Joined: 09/07/2020 Location: United KingdomPosts: 267 |
Surely PLAY SOUND 1,b,o is functionally equivalent to a frequency or volume of 0 ?Not sure if there is a finite time taken to start / stop playing sound which would introduce gaps/steps in the audio output. I agree that setting the frequency and/or volume to 0 would make things easier to code, but the change may not be necessary. One thing the manual does not stipulate is whether the frequency and volume parameters are integer values, or if they can be fractional values. Food for thought. Experimentation may be required, once I have my CMM2 to hand. |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10310 |
Volume can be set to zero in V5.05.05b8 onwards. Frequencies are float, volumes are converted to integer 0-25 Edited 2020-08-15 21:24 by matherp |
||||
Womble![]() Senior Member ![]() Joined: 09/07/2020 Location: United KingdomPosts: 267 |
Thanks for clarifying that Peter ![]() |
||||
hitsware2![]() Guru ![]() Joined: 03/08/2019 Location: United StatesPosts: 719 |
The problem being (that prompted this thread) the "o" cannot come from a DATA statement .... my site |
||||
hitsware2![]() Guru ![]() Joined: 03/08/2019 Location: United StatesPosts: 719 |
Thank You ! Geez .... Now I must figure out the re-flash procedure with my Raspberry Pi ..... ![]() my site |
||||
Womble![]() Senior Member ![]() Joined: 09/07/2020 Location: United KingdomPosts: 267 |
Appendix G in the Manual (latest version is in the firmware zip download) Its easy from Windows, use the STM32Cube Programmer, and "UPDATE FIRMWARE" command. This thread discusses updates from Linux/Raspberry Pi. The easiest cable to use is a USB-A to USB-A, but there are other options. |
||||
hitsware2![]() Guru ![]() Joined: 03/08/2019 Location: United StatesPosts: 719 |
Had to wimp out and use my Wife's Windows : ( '''' Down Where the Guitars Play '''' Being able dim c(29),m(7),p(7),v(7),o(2)' z$(2) < to use this for i=0 to 29: read c(i): next i for i=0 to 7: read m(i): next i for i=0 to 2: read o(i): next i for i=0 to 7: read p(i): next i for i=0 to 7: read v(i): next i 'for i=0 to 2: read z$(i) < and this data 10,12,9,10, 10,12,9,9, 10,12,9,10 data 8,9,10,10, 8,10,9,9, 8,10,9,9 data 8,10,9,9, 8,9 data 4,4,8,8,6,6,8,8 data 2,4,8, 4,0,2,2,9,0,2,2 data 9,0,9,0,9,0,9,0 'data t,q,s < and this for i=0 to 3: play sound 3,b,s,1024,15 pause 10: play sound 3,b,o,1,1 pause 500: next i do for x=0 to 29 play sound 1,b,w,24*c(x),5 play sound 2,b,w,16*c(x),5 for y=0 to 7: r=int(rnd*3) n=(c(x)*m(y))*o(r) play sound 3,b,s,1024,2*p(y) pause 10: play sound 3,b,s,1,0 'play sound 4,b,z$(r),n,v(y) < and this play sound 4,b,q,n,v(y)' < instead of this pause 75: play sound 4,b,q,n,0' Could yield far pause 50: next y: next x: loop' groovier tunes :) my site |
||||
capsikin Guru ![]() Joined: 30/06/2020 Location: AustraliaPosts: 341 |
Thank You ! Geez .... Now I must figure out the re-flash procedure with my Raspberry Pi ..... ![]() Appendix G in the Manual (latest version is in the firmware zip download) Its easy from Windows, use the STM32Cube Programmer, and "UPDATE FIRMWARE" command. This thread discusses updates from Linux/Raspberry Pi. The easiest cable to use is a USB-A to USB-A, but there are other options. I don't like that the manual calls it free software. They ask you to accept a licence agreement in exchange for downloading it (the manual did warn they'd want your name and e-mail address) It does look like you're allowed to distribute the software to other people though, with conditions, if I'm reading the licence correctly. |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10310 |
To have the sound type as a variable it would have to be a quoted string which would break too many existing programs. Sorry too late for this as a change |
||||
hitsware2![]() Guru ![]() Joined: 03/08/2019 Location: United StatesPosts: 719 |
Ninguna problema ..... ![]() Found a more effective plan ... What would be the most elegant MMBasic way to do this ? my site |
||||
hitsware2![]() Guru ![]() Joined: 03/08/2019 Location: United StatesPosts: 719 |
'Not exactly the answer to my Dream (but it works) dim c(29),m(7),p(7),v(7),o(2) for i=0 to 29:read c(i): next i'''''root frequencies for i=0 to 7: read m(i): next i'''''multipliers for i=0 to 7: read p(i): next i'''''percussion volumes for i=0 to 7: read v(i): next i'''''synth triggers data 10,12,9,10, 10,12,9,9, 10,12,9,10 data 8,9,10,10, 8,10,9,9, 8,10,9,9 data 8,10,9,9, 8,9, 4,4,8,8,6,6,8,8 data 4,0,2,2,9,0,2,2, 1,0,1,0,1,0,1,0 do: for x=0 to 29'''''''''''''''''''play back chords play sound 1,b,t,24*c(x),3''''''''''fifth play sound 2,b,t,16*c(x),3''''''''''root for y=0 to 7: n=(c(x)*m(y))*2'''''''8 beats / measure ''''''''''''''''''''''''''''''''''''calculate frequencies play sound 3,b,s,1024,2*p(y)'''''''' pause 10: play sound 3,b,s,1024,0'''percussion select case int(rnd *3)'''''''''''''choose synth voice case 0: play sound 4,b,t,n,v(y)*25''''''''low pause 125: play sound 4,b,t,n,0: pause 0 case 1: play sound 4,b,w,2*n,v(y)*10'''''''mid pause 75: play sound 4,b,w,2*n,0: pause 50 case 2: play sound 4,b,s,4*n,v(y)*10'''''''high pause 50:play sound 4,b,q,2*n,0: pause 75 end select: next y: next x: loop my site |
||||
hitsware2![]() Guru ![]() Joined: 03/08/2019 Location: United StatesPosts: 719 |
'we don't need no stinkin' 'string variables : ) ' 'simpler but more effective : dim c(29),m(7),p(7),v(7),o(2) for i=0 to 29:read c(i): next i for i=0 to 7: read m(i): next i for i=0 to 7: read p(i): next i data 10,12,9,10, 10,12,9,9 data 10,12,9,10, 8,9,10,10 data 8,10,9,9, 8,10,9,9 data 8,10,9,9, 8,9 data 16,16,32,32,24,24,32,32 data 4,0,2,2,9,0,2,2 do: for x=0 to 29 play sound 1,b,t,16*c(x),5 play sound 2,b,t,24*c(x),5 for y=0 to 7: z=abs((y mod 2)-1) n%=(c(x)*m(y))*2^(int(rnd*3)) play sound 3,b,s,1024,2*p(y) pause 10: play sound 3,b,s,1024,0 play sound 4,b,q,n%,z*(1800/n%) pause 120: next y: next x: loop Edited 2020-08-18 05:07 by hitsware2 my site |
||||
hitsware2![]() Guru ![]() Joined: 03/08/2019 Location: United StatesPosts: 719 |
Still True ( PicoMite ) ? my site |
||||
handmixer![]() Newbie ![]() Joined: 02/09/2020 Location: DenmarkPosts: 12 |
A workaround that may work is to use the EVAL function: Fist build the play sound command in a string variable and then use the EVAL to run the command. Edited 2021-10-29 03:44 by handmixer /H |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |