Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 09:06 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 : Help on Play Sound - Variable Question - String ?

Author Message
TweakerRay

Senior Member

Joined: 01/08/2020
Location: Germany
Posts: 138
Posted: 02:58pm 14 May 2021
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 4311
Posted: 03:20pm 14 May 2021
Copy link to clipboard 
Print this post

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: Canada
Posts: 1132
Posted: 03:48pm 14 May 2021
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 4311
Posted: 04:13pm 14 May 2021
Copy link to clipboard 
Print this post

  vegipete said  Mauro solved this in his Hope Robot Programming Contest entry:

EXECUTE "PLAY SOUND "+STR$(C)+",B,"+P$+","+STR$(F)+","+STR$(V)


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: Germany
Posts: 138
Posted: 04:42pm 14 May 2021
Copy link to clipboard 
Print this post

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: Canada
Posts: 1132
Posted: 06:23pm 14 May 2021
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 4311
Posted: 06:47pm 14 May 2021
Copy link to clipboard 
Print this post

  vegipete said  PS to Tom

This is exactly why I shuddered a while back ...


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