+Random Terrain Posted November 26, 2007 Share Posted November 26, 2007 If you want a cool sound that is more than just a beep, you can't just jump to a subroutine once. How do you add a complicated sound without stopping the game? My first guess would be that you would use a variable to check if a sound is supposed to play. Each time during the main loop, that variable would be checked. If it's time to play a sound, the program would jump to a subroutine and read from a list of numbers and play the next tone. The program would keep jumping to the subroutine until it reaches the end of the list and the variable would be set to zero which would tell the program to stop jumping to the subroutine. Is that even close to what you're supposed to do? Thanks. Quote Link to comment Share on other sites More sharing options...
potatohead Posted November 26, 2007 Share Posted November 26, 2007 One good way is to put your sound commands into game loops. This way, they are keyed to actions. Here's an example: Let's say you've got a player shot moving across the screen. There is gonna be a variable associated to the shot position, right? Leverage that for your sound. In the part of the program responsible for initiating the shot, turn on one of the voices, and set a volume. That starts the sound when the bullet starts. Keyed to action. As the bullet moves, incorporate changes to the sound using the shot position to vary the sound. One very straightforward approach is to modulate the pitch. Maybe divide that variable by something, or multiply to get a variation that sounds interesting. One could also use the player position for added variation in the overall sound. Maybe one position is lower volume, another one higher volume. For stuff like shots, you want to avoid the pure tones. Tinker with the noise settings, once you have the commands setup and running in your game loop. The sound chip will make a given tone, without you doing anything. This means it really only takes a moment to start, stop or change what it's doing. The majority of the time, your program is off doing it's thing. You've got two voices too. Use one for sporadic sounds, and the other for more constant ones, like moving, or something. That general rule will balance out your effects nicely. One other thing: Say you've one sound in progress, but another event happens. You can just start the new sound, right away. There generally is no need to be nice about this. Starting a sound is really just changing the sound. At least that's how I see it. That sound chip is always doing something. No sound is really just volume 0. Finally, in the part of the program that ends the bullet, cut the volume to zero, ending the sound. I like to use the sound registers directly. I've not used the bB sound commands. Maybe they make things harder! I'll go and try to dig up some of the stuff I did for Ooze. It uses these techniques and works register direct. Didn't take all that long to get some pretty great sounds. Perhaps you can look some code snippets over and go from there. Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted November 26, 2007 Author Share Posted November 26, 2007 Thanks. That makes more sense. As you said, looking at some code might help too. Quote Link to comment Share on other sites More sharing options...
potatohead Posted November 26, 2007 Share Posted November 26, 2007 (edited) This is an old version of Ooze. I'm posting it because it's really simple and I hope that makes seeing the sound stuff easier. You can find newer versions in my blog, or via the search. I'll sprinkle comments in, marked with ## It really does not take all that many commands to get interesting sounds. It's the placement of them, and what variables get used to modulate them that's key. If I were you, I would take one loop and one event and try it this way. Won't take long until you get some good sounds. Batari Basic games loop once each 1/60 sec NTSC. That's a lot of potential to modulate the sounds! BTW: One could do music by including a subroutine that hits the sound registers every so often, then include values from data tables to form simple tunes. Make a table of pitches and volumes, then apply them to one of the voices. Use a counter to make sure that routine only runs part of the time, or it will take a *lot* of data tables to make anything that has length. data 10, 8 data 10, 0 data 20, 12 data 20, 12 data 10, 8 data 0,0 data 0,0 This would equal a higher pitch, played short, silence of the same duration, a lower pitch played louder and of twice the duration, followed by the higher pitch of the original duration. Do --Doo, Do -- Loop through that, and you've got a little beat, with only a coupla lines of code! rem smartbranching on reset gosub title rem Init Game code rem rem x, w, v = ship and bullet position variables rem rem rem COLUP0 = 34 : COLUP1 = 47 : AUDV0 = 0 : AUDV1 = 0 : AUDC1 = 12 : AUDC0 = 8 AUDF0 = 0 : AUDF1 = 0 ## In the line above, sound registers are initalized. Volumes on both voices are at zero. ## Note also the noise settings for both voices. x = 50 : w = 60 : v = 60 rem s = 0 rem s = game status flags rem s(0) = bullet launched rem q = counter / temp rem Clear ooze storage space a - p for temp1 = 0 to 15 : a[temp1] = 0 : next rem ooze growth factors z = 30 : y = 10 rem clear playfield --try again with hline and vline commands later asm ldx #47 lda #0 clearxx sta playfield,x dex bpl clearxx end gameloop COLUPF = 182 : COLUP0 = 120 : scorecolor = 70 : COLUP1 = 47 PF0 = 140 player1x = w : player1y = v : player0x = x : player0y = 89 player0: %01000010 %11100111 %11111111 %01111110 %00111100 %00011000 %00011000 %00011000 end player1: %00011000 %00010000 %00001000 %00010000 %00001000 end drawscreen rem GameCode rem gosub bug, using gotos for right now... goto ooze oozereturn gosub checkswitches gosub moveship gosub moveshot goto gameloop rem Subroutines Live below Here ooze rem check for collision rem grab a random number for later t = rand AUDV1 = 0 ## Here, voice one is always set to zero. This is what helps to form the semi-musical ## short tones that occur when the Ooze shows up on screen. ## If you run a newer Ooze, you will hear an almost musical beep, boop, sound that ## is associated with Ooze appearing on screen. ## The cool part about doing something like this is you can use that voice for lots of ## different, brief effects, without worrying about having to turn it off. Basically, ## you can set voice 1, and a very short time later it's just turned off. ## That's how I used it here, anyway. if CXP1FB > 64 then goto hit goto growooze hit ## the 'hit' label above marks a subroutine. Just trying to clarify ## this older bB code. rem water down bullet x pos into ooze column position q = w - 29 : q = q + 4 q = q / 2 : q = q / 2 : q = q / 2 t = q * 2 r = a[q] pfpixel t r flip a[q] = a[q] - 1 if a[q] = 255 then a[q] = 0 rem turn the bullet off & put it back, kill sound s(0) = 0 w = x : v = 89 - 8 : AUDV0 = 0 ## This routine is the bullet hit something routine. Note how voice zero is turned ## off at this time. rem shuffle random number growooze u = u + 1 if u < z then goto oozedone if rand > 40 then t = t * 2 : t = t + w rem increase difficulty z = z - 1 if z < 10 then z = 10 u = 0 asm lda t lsr lsr lsr lsr sta t end a[t] = a + 1 if a[t] > 8 then a[t] = 8 q = a[t] : r = t * 2 AUDF1 = 12 - q : AUDV1 = 6 + q pfpixel r q on ## This is the grow ooze routine. Basically, it sometimes places a bit of ooze. ## Voice one is the ooze voice, and it gets a pitch and volume, that are ## keyed to the ooze vertical position. Lower is louder, and higher pitch. ## ## This used to say, "random pitch and volume". I edited this comment ## because the pitch and volume is not random, but in fact, keyed ## directly to the ooze vertical position on screen when it appears. ## ## The start of the sound is random, just like the ooze is. When one piece ## appears on screen, the sound is triggered then also. Just thought I ## would make that clear. ## Note it only takes a small change to the registers, for a brief moment, ## combined to make a game sound make sense and be interesting! oozedone goto oozereturn moveship if joy0left then x = x - 1 if joy0right then x = x + 1 if x < 29 then x = 29 if x > 153 then x = 153 return moveshot if !s(0) then goto fire if joy0fire then s(0) = 1 : goto fire w = x : v = 89 - 8 goto shotdone rem bit operators are working backward, change this code when it gets rem fixed. Symptom will be always shooting. fire v = v - 4 AUDF0 = v : AUDV0 = 10 ## This is the routine that moves the shot up on the screen. It's using voice 0 ## pitch changes right with the bullet vertical position. Go and look at the init ## code to see the noise setting made on this voice to get something zapper like. if v < 3 then s(0) = 0 : v = 89 - 8 : w = x : AUDV0 = 0 ## If the bullet leaves the playfield, cut the sound. This is one of two events ## that stops the bullet sound, the other one being collision with ooze! shotdone return checkswitches if switchreset then goto reset return title COLUPF = 45 : a = 0 : b = 0 titleloop COLUPF = b drawscreen if joy0fire then goto titleexit if switchreset then goto reset gosub drawdot goto titleloop data titlemap 0,0,0,0,1,1,0,0,0,1,1,0,0,1,1,1,1,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0 0,0,0,1,0,0,1,0,1,0,0,1,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0 0,0,0,1,0,0,1,0,1,0,0,1,0,0,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0 0,0,0,1,0,0,1,0,1,0,0,1,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0 0,0,0,0,1,1,0,0,0,1,1,0,0,1,1,1,1,0,1,1,1,1,0,1,0,1,0,1,0,0,0,0 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 0,0,0,1,1,1,0,1,0,1,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 0,0,0,1,1,1,1,0,1,0,1,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0 end drawdot if b > 240 then b = 0 : x = 0 : a = 0 if titlemap[b] = 1 then d = a + 2 : pfpixel x d flip x = x + 1 if x > 32 then a = a + 1 : x = 0 b = b + 1 return titleexit for y = 0 to 9 pfhline 0 y 31 off next return Edited November 29, 2007 by potatohead Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted November 26, 2007 Author Share Posted November 26, 2007 Thanks. I think not knowing the best way to do sound was boosting my procrastination. Now maybe I'll get some games made. Thanks again. Quote Link to comment Share on other sites More sharing options...
potatohead Posted November 26, 2007 Share Posted November 26, 2007 No worries. Yeah, get cracking man! I know you've got a solid one bottled up in there. We need to play it! Seriously, with all the nice work you did on documentation, you deserve to get some reasonable answers to your sound question. Quote Link to comment Share on other sites More sharing options...
MausGames Posted November 29, 2007 Share Posted November 29, 2007 Seriously, with all the nice work you did on documentation, you deserve to get some reasonable answers to your sound question. Agreed. If I got to team up with anyone here for a project, RT would definately be my first choice. The methods discussed here definately beat mine. I don't use data tables, just counters that activate specific tones and frequencies, ie: k = k + 1 if k = 1 || k = 10 || k = 20 || k = 30 then AUDV0 = 5 : AUDC0 = 6 : AUDF0 = 12 else AUDV0 = 0 if k = 40 then k = 0 Which is about the crappiest way possible. 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.