Can I play simultaneously effect sounds with BGM in BASIC?

Door msxdaisuki

Rookie (18)

afbeelding van msxdaisuki

08-12-2021, 14:20

I play BGM with "on interval = 120 gosub 9000" in BASIC. (see below sample code)

But, I realized I cannot play simultaneously, in other words, asynchronously the sound effect with BGM together.
When I push space, I want to play simultaneously the sound effect - play "cde", not synchronously! How can I do it?

50 clear 500
60 dim mu$(19)

70 open"b:musidata.txt" for input as #1
90 for i=0 to 19
91 input #1,mu$(i)
92 next i
94 close #1

290 'initialize
291 on interval=120 gosub 9000
292 interval on

293 on strig gosub 1000
294 strig(0) on

295 play"S0M10000"
300 'main loop
400 goto 300

1000 'on strig
1020 play"cde"
1030 return

9000 'bgm
9010 play mu$(nn):nn=(nn+1)mod 20
9020 return

Aangemeld of registreer om reacties te plaatsen

Van thegeps

Paragon (1029)

afbeelding van thegeps

08-12-2021, 18:16

I think that the only way, in basic, is to play sfx on different channel: you can use 2 channels for BGM and 1 for sfx: I'm writing from a smartphone now, so I can't test (and I don't remember if is doable this way) but you could try this:

1020 PLAY"","","cde"

If play doesn't accept empty quotation marks, put inside something low relevant. For example, if your music doesn't have octave changes you can write


Where you can change number 4 with your music octave, or instead if you haven't time changes use T and your time value, so you won't affect played music and will be able to play your sfx on last channel

Van msxdaisuki

Rookie (18)

afbeelding van msxdaisuki

09-12-2021, 08:04

It seem it doesn't work, but thank you. Murdoch
I changed the code like below. and it works. But What I want to do is, play on real time when I pushed space key. but the code have time delay of maximum of 120. I wonder, then, if I want to play immediately the sound effect, must I set the interval value to ,for example, 1 or very short value , and must call play event at very short intervals? does this possible?

for example, like , bullet sound effects on shooting game. Is this possible on BASIC?

1000 'on strig
1020 a$="V12cde"
1030 return

9000 'bgm
9010 play mu$(nn),a$:nn=(nn+1)mod 20
9015 if a$<>"" then a$=""
9020 return

Van Warchild

Paragon (1297)

afbeelding van Warchild

09-12-2021, 08:59

Maybe you can use SOUND instead of PLAY for the effects. About how to use, the best start point is the wiki here. I think this way it will work and you have the chance to find little sound effects from old magazines basic listings.

Van msxdaisuki

Rookie (18)

afbeelding van msxdaisuki

09-12-2021, 12:09

thank you for your help! I am going to study about Sound statement.