First Spear Posted August 28, 2016 Share Posted August 28, 2016 I have code that plays a sound by reading DATA and sending the values to the PSG via the SOUND2 statement. A decision is made, a Procedure is called via GOSUB, and then a return. This "feels" very synchronous to me, and I am thinking about the capability to have a sound played "fire and forget" without blocking the caller until a sound play is completed. Is this possible, or am I way off? Thanks. Quote Link to comment Share on other sites More sharing options...
freewheel Posted August 28, 2016 Share Posted August 28, 2016 Yes, but possibly not how you mean.The PSG will continue to "play" whatever tone/noise you last sent it, until you tell it otherwise. There currently isn't a command to say "play this sound for X cycles/seconds, then turn off" (although I'll be lobbying for one if it's a feasible language inclusion). But there's no need to sit in a loop, possibly with WAIT statements, just to make a sound effect - sometimes that makes sense but not when you want your game to continue doing something. What you CAN do is control it with a timer (set the counter in your GOSUB, then after X ticks/seconds/whatever, just set the tone/volume to 0). If you're piping in DATA values, then another easy way is to have the last value be 0, and when you call your GOSUB and want the sound off, just set your DATA pointer to the last index. I've done a few sound effects this way, where I'm regularly hitting the PSG with SOUND, and *what* gets put into the command is entirely data/state driven. You're "wasting" calls to SOUND this way, but it's not a lot of instructions in the grand scheme of things. I'm sure there are a lot of other more elegant ways to handle this. Sound effects are still one of those things that I'm slowly figuring out ways to handle. 1 Quote Link to comment Share on other sites More sharing options...
+DZ-Jay Posted August 28, 2016 Share Posted August 28, 2016 Yes, but possibly not how you mean.The PSG will continue to "play" whatever tone/noise you last sent it, until you tell it otherwise. There currently isn't a command to say "play this sound for X cycles/seconds, then turn off" (although I'll be lobbying for one if it's a feasible language inclusion). But there's no need to sit in a loop, possibly with WAIT statements, just to make a sound effect - sometimes that makes sense but not when you want your game to continue doing something. What you CAN do is control it with a timer (set the counter in your GOSUB, then after X ticks/seconds/whatever, just set the tone/volume to 0). If you're piping in DATA values, then another easy way is to have the last value be 0, and when you call your GOSUB and want the sound off, just set your DATA pointer to the last index. I've done a few sound effects this way, where I'm regularly hitting the PSG with SOUND, and *what* gets put into the command is entirely data/state driven. You're "wasting" calls to SOUND this way, but it's not a lot of instructions in the grand scheme of things. I'm sure there are a lot of other more elegant ways to handle this. Sound effects are still one of those things that I'm slowly figuring out ways to handle. This is something that IntyBASIC should support, just like the PLAY command does not pause your game while playing music, the sound effects engine should have some sort of scripting framework to tell it how to update the sound over time, and have IntyBASIC do it. I know it is not trivial, but it would certainly be a great feature. -dZ. 1 Quote Link to comment Share on other sites More sharing options...
+nanochess Posted August 28, 2016 Share Posted August 28, 2016 Currently the easiest way is to use the ON FRAME GOSUB feature. For example: ON FRAME GOSUB sound_player main_loop: WHILE cont.key <> 12: WAIT: WEND WHILE cont.key = 12: WAIT: WEND IF cont.key = 1 THEN current_effect = 1:sound_state = 0 ' This is enough to get the sound played GOTO main_loop sound_player: PROCEDURE ON current_effect GOSUB sound_none,sound_ping END sound_none: PROCEDURE SOUND 2,1,0 END sound_ping: PROCEDURE SOUND 2,200-sound_state*10,15 sound_state=sound_state+1 IF sound_state=10 THEN current_effect=0 END You can play a lot of tricks with frequency and volume. If you're not using the noise channel with the music player you can also make pretty nice effects. 2 Quote Link to comment Share on other sites More sharing options...
+DZ-Jay Posted August 28, 2016 Share Posted August 28, 2016 Currently the easiest way is to use the ON FRAME GOSUB feature. For example: ON FRAME GOSUB sound_player main_loop: WHILE cont.key <> 12: WAIT: WEND WHILE cont.key = 12: WAIT: WEND IF cont.key = 1 THEN current_effect = 1:sound_state = 0 ' This is enough to get the sound played GOTO main_loop sound_player: PROCEDURE ON current_effect GOSUB sound_none,sound_ping END sound_none: PROCEDURE SOUND 2,1,0 END sound_ping: PROCEDURE SOUND 2,200-sound_state*10,15 sound_state=sound_state+1 IF sound_state=10 THEN current_effect=0 END This is where a nice state machine comes in handy. 2 Quote Link to comment Share on other sites More sharing options...
mmarrero Posted August 29, 2016 Share Posted August 29, 2016 In SpaceVersus there are 1-2 tone sfx at each frame, #data_addresses, play sfx until data is 0. I think it also tries to lower volume on odd values. I use 1 channel for both sfx, alternate odd/even when 2 are playing. Bad Asteroids music at 2nd channel, noise (explosions/freeze) use 3rd + envelope generator. Quote Link to comment Share on other sites More sharing options...
First Spear Posted December 23, 2016 Author Share Posted December 23, 2016 When you have a chance, could you explain how things are done in the Mummy game you created/converted? Currently the easiest way is to use the ON FRAME GOSUB feature. For example: ON FRAME GOSUB sound_player main_loop: WHILE cont.key <> 12: WAIT: WEND WHILE cont.key = 12: WAIT: WEND IF cont.key = 1 THEN current_effect = 1:sound_state = 0 ' This is enough to get the sound played GOTO main_loop sound_player: PROCEDURE ON current_effect GOSUB sound_none,sound_ping END sound_none: PROCEDURE SOUND 2,1,0 END sound_ping: PROCEDURE SOUND 2,200-sound_state*10,15 sound_state=sound_state+1 IF sound_state=10 THEN current_effect=0 END You can play a lot of tricks with frequency and volume. If you're not using the noise channel with the music player you can also make pretty nice effects. Quote Link to comment Share on other sites More sharing options...
+nanochess Posted December 23, 2016 Share Posted December 23, 2016 When you have a chance, could you explain how things are done in the Mummy game you created/converted? I need to give another look to source, I thought it had enough comments. If it doesn't, it could be a great chance for you to check your understanding of the language, or even better for someone with teacher prose to document it throughly. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.