Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 08:57 01 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : String variables in PLAY SOUND

Author Message
hitsware2

Guru

Joined: 03/08/2019
Location: United States
Posts: 719
Posted: 12:31am 13 Aug 2020
Copy link to clipboard 
Print this post


'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: Australia
Posts: 6283
Posted: 02:55am 13 Aug 2020
Copy link to clipboard 
Print this post

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 States
Posts: 719
Posted: 02:52pm 13 Aug 2020
Copy link to clipboard 
Print this post

  TassyJim said  
One mistake you have made is in the DATA statements.
You should surround string data in quotes.

I also increased the first pause so you have time to hear the changes in sound level.


Jim

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 Kingdom
Posts: 267
Posted: 10:48am 15 Aug 2020
Copy link to clipboard 
Print this post

  hitsware2 said  It would be such an improvement if PLAY SOUND would accept 0 as a
'frequency' and/or 'volume' parameter resulting in silence ......

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 Kingdom
Posts: 10310
Posted: 11:22am 15 Aug 2020
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 267
Posted: 02:04pm 15 Aug 2020
Copy link to clipboard 
Print this post

  matherp said  Volume can be set to zero in V5.05.05b8 onwards. Frequencies are float, volumes are converted to integer 0-25

Thanks for clarifying that Peter  
 
hitsware2

Guru

Joined: 03/08/2019
Location: United States
Posts: 719
Posted: 02:48pm 15 Aug 2020
Copy link to clipboard 
Print this post

  Womble said  
Surely
PLAY SOUND 1,b,o
is functionally equivalent to a frequency or volume of 0 ?

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 States
Posts: 719
Posted: 02:52pm 15 Aug 2020
Copy link to clipboard 
Print this post

  matherp said  Volume can be set to zero in V5.05.05b8 onwards. Frequencies are float, volumes are converted to integer 0-25

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 Kingdom
Posts: 267
Posted: 04:22pm 15 Aug 2020
Copy link to clipboard 
Print this post

  hitsware2 said  
  matherp said  Volume can be set to zero in V5.05.05b8 onwards. Frequencies are float, volumes are converted to integer 0-25

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.
 
hitsware2

Guru

Joined: 03/08/2019
Location: United States
Posts: 719
Posted: 10:46pm 15 Aug 2020
Copy link to clipboard 
Print this post

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: Australia
Posts: 341
Posted: 01:50am 16 Aug 2020
Copy link to clipboard 
Print this post

  Womble said  
  hitsware2 said  
  matherp said  Volume can be set to zero in V5.05.05b8 onwards. Frequencies are float, volumes are converted to integer 0-25

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 Kingdom
Posts: 10310
Posted: 07:53am 16 Aug 2020
Copy link to clipboard 
Print this post

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 States
Posts: 719
Posted: 08:18am 16 Aug 2020
Copy link to clipboard 
Print this post

  matherp said  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


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 States
Posts: 719
Posted: 10:53pm 16 Aug 2020
Copy link to clipboard 
Print this post


'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 States
Posts: 719
Posted: 07:06pm 17 Aug 2020
Copy link to clipboard 
Print this post


'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 States
Posts: 719
Posted: 05:34pm 28 Oct 2021
Copy link to clipboard 
Print this post

  matherp said  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


Still True ( PicoMite ) ?
my site
 
handmixer

Newbie

Joined: 02/09/2020
Location: Denmark
Posts: 12
Posted: 05:41pm 28 Oct 2021
Copy link to clipboard 
Print this post

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
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025