Sound problem
Sound problem
I'm down to putting in a few basic sounds for my Space Invaders game. Nothing special, I don't think I'm very creative and while I understand the parameters of the ENVELOPE command I can't really translate that in my mind into the 'shape' of a particular sound. Regardless, a basic explosion sound was pretty easy to come up with on channel 0, and after some experimenting I came up with (what I think) is a reasonably passable attempt at the classic 2 pitch movement sound for the aliens. So it seemed ok, but I have a couple of issues. The first was when I get down to the last alien and it's moving very fast the sound was causing a problem as suddenly everything slowed down and became jerky. I'm guessing the alternate sounds were now playing too close together and queuing up, and in conjunction with executing the rest of the game code this is what caused the slow down. So I changed the sound from:
SOUND 0,-15,3,2
to
SOUND &0010,-15,3,2
...thereby immediately stopping the previous sound and preventing a queue. This seems to work...speed is back to normal, but now I have a new problem. I had a 2 second explosion sound on channel 0 play when the flying saucer gets hit, but of course this now gets truncated immediately as soon as the aliens move, so it sounds a bit weird. Obviously it was getting truncated anyway even when the aliens are moving slowly, but it's nowhere near as bad as when they are moving fast. I know the User Guide doesn't say you can do this but is there a way to play an 'effect' on a channel other than 0? Or 2 tones on channel 0? I'm guessing the answer is probably no, but it would be the simplest way of dealing with this I think.
I can only think of 2 other alternatives. One is to create an envelope and play a sound on a non-effect channel that mimics the movement effect sound, but I think that's beyond me. I just can't see the shape of the sound in my mind. I don't even know if it's possible to mimic that sound on one of the non-effects channels but I don't think I could do it. The other is to check if the saucer (or an alien for that matter) is being blown up during the alien movement phase and simply not play the movement sound at that time. That's more involved, but it's doable.
Any feedback / suggestions welcome.
SOUND 0,-15,3,2
to
SOUND &0010,-15,3,2
...thereby immediately stopping the previous sound and preventing a queue. This seems to work...speed is back to normal, but now I have a new problem. I had a 2 second explosion sound on channel 0 play when the flying saucer gets hit, but of course this now gets truncated immediately as soon as the aliens move, so it sounds a bit weird. Obviously it was getting truncated anyway even when the aliens are moving slowly, but it's nowhere near as bad as when they are moving fast. I know the User Guide doesn't say you can do this but is there a way to play an 'effect' on a channel other than 0? Or 2 tones on channel 0? I'm guessing the answer is probably no, but it would be the simplest way of dealing with this I think.
I can only think of 2 other alternatives. One is to create an envelope and play a sound on a non-effect channel that mimics the movement effect sound, but I think that's beyond me. I just can't see the shape of the sound in my mind. I don't even know if it's possible to mimic that sound on one of the non-effects channels but I don't think I could do it. The other is to check if the saucer (or an alien for that matter) is being blown up during the alien movement phase and simply not play the movement sound at that time. That's more involved, but it's doable.
Any feedback / suggestions welcome.
Re: Sound problem
I thought of another way round this but I can't get it working. If I want to prioritise explosions over movement sound, I thought I could do this:
SOUND &0010,3,6,20 \2sec explosion
SOUND 1,-1,135,1 \sets up hi pitch for alien movement
SOUND &1000,-15,3,2 \executes movement sound
As I understand it, the first line should kill any other sound on channel zero and play the explosion. The second line sets up the pitch for the first part of the movement sound. Line 3 should execute the sound, but ONLY if the sound on line 1 has finished.
So I thought I would be getting the desired effect. The movement sounds play until I blow up a saucer/ship, then the explosion sound takes priority and plays to completion, then the movement sounds should start playing again. But instead I get explosions, but no movement sound at all.
The way the User Guide describes the SOUND command, SOUND &HSFC,A,P,D , I would have thought this should work. Anyone tell me what I'm doing wrong?
SOUND &0010,3,6,20 \2sec explosion
SOUND 1,-1,135,1 \sets up hi pitch for alien movement
SOUND &1000,-15,3,2 \executes movement sound
As I understand it, the first line should kill any other sound on channel zero and play the explosion. The second line sets up the pitch for the first part of the movement sound. Line 3 should execute the sound, but ONLY if the sound on line 1 has finished.
So I thought I would be getting the desired effect. The movement sounds play until I blow up a saucer/ship, then the explosion sound takes priority and plays to completion, then the movement sounds should start playing again. But instead I get explosions, but no movement sound at all.
The way the User Guide describes the SOUND command, SOUND &HSFC,A,P,D , I would have thought this should work. Anyone tell me what I'm doing wrong?
Re: Sound problem
I can;t help with BASIC or the OS, but you might get away with some low pitches sounds on the tone channels for movement and the saucer explodes with more of a siren anyway.
I gave up trying to get things sounding correct in my Space Invaders but ended up playing samples for you shooting and the alien explosions as they seemed to me to be most iconic and they were the ones I got the most complaints for!
http://bbcmicro.co.uk/jsbeeb/play.php?a ... ssd&noseek
I gave up trying to get things sounding correct in my Space Invaders but ended up playing samples for you shooting and the alien explosions as they seemed to me to be most iconic and they were the ones I got the most complaints for!
http://bbcmicro.co.uk/jsbeeb/play.php?a ... ssd&noseek
- 1024MAK
- Posts: 12783
- Joined: Mon Apr 18, 2011 5:46 pm
- Location: Looking forward to summer in Somerset, UK...
- Contact:
Re: Sound problem
Keep in mind that the sound system is a combination of the actual hardware sound chip and the OS functions.
The sound chip has:
The ENVELOPE command is the BASIC command that sends data to the OS. Its the OS that produces the ENVELOPE, not the sound chip (which does not have this feature).
Mark
The sound chip has:
- 3 square wave tone generators
- A wide range of frequencies
- 16 different volume levels
- 1 noise generator
- 2 types (white noise and periodic)
- 3 different frequencies
- 16 different volume levels
The ENVELOPE command is the BASIC command that sends data to the OS. Its the OS that produces the ENVELOPE, not the sound chip (which does not have this feature).
Mark
For a "Complete BBC Games Archive" visit www.bbcmicro.co.uk NOW!
BeebWiki - for answers to many questions...
Fault finding index • Acorn BBC Model B minimal configuration • Logic Levels for 5V TTL Systems
BeebWiki - for answers to many questions...
Fault finding index • Acorn BBC Model B minimal configuration • Logic Levels for 5V TTL Systems
Re: Sound problem
Thanks. Seems to be an error when I click on the link?tricky wrote: ↑Tue Mar 05, 2024 4:01 pm I can;t help with BASIC or the OS, but you might get away with some low pitches sounds on the tone channels for movement and the saucer explodes with more of a siren anyway.
I gave up trying to get things sounding correct in my Space Invaders but ended up playing samples for you shooting and the alien explosions as they seemed to me to be most iconic and they were the ones I got the most complaints for!
http://bbcmicro.co.uk/jsbeeb/play.php?a ... ssd&noseek
It's not actually in BASIC, I'm executing the sounds in machine code, it's just that those are the equivalent BASIC commands. I thought it's the numbers that would be important. I'm just storing the values into a pre-reserved block of memory and then calling OSWORD with &07 loaded to execute the sound command in each instance, with 2 commands being executed for the 'movement' sound, the first to set the pitch and the second to execute the sound effect.
Re: Sound problem
I look through the site and found it. Now that's a proper version of Space Invaders! Not like what I'm writing.
I don't know how to play samples on the Beeb at the moment, but yeah, those sounds were spot on.
Re: Sound problem
Some browsers don;t like http anymore, I didn;t notice when I copied whilst on the site.
There is no BASIC or OS support for samples, there are a few ways, but basically you are setting the highest frequence and the changing the volume at say 10Khz from assembler!
It wouldn't surprize me if JGH/beebwiki https://beebwiki.mdfs.net/SOUND have a BASIC wrapper for it, but as it requires "bit banging" the hardware he may not have.
You may have noticed that you can actually tie the noise channel's frequence to one of the tone channels although you would generally set the volume to 0 for that channel - may be one for another day
There is no BASIC or OS support for samples, there are a few ways, but basically you are setting the highest frequence and the changing the volume at say 10Khz from assembler!
It wouldn't surprize me if JGH/beebwiki https://beebwiki.mdfs.net/SOUND have a BASIC wrapper for it, but as it requires "bit banging" the hardware he may not have.
You may have noticed that you can actually tie the noise channel's frequence to one of the tone channels although you would generally set the volume to 0 for that channel - may be one for another day
Re: Sound problem
If you mean setting the pitch on channel 1 and then executing the sound on channel 0 then yes, that's in fact what I'm doing to get the alternating sound frequencies for the alien movement. Although the User Guide says you can only use channel 1 for that so that's what I used.
I've really had a lot of problems with the sound, and that's apart from the fact that the sounds aren't arcade accurate. I tried to get the player shot sound working on channel 1 as I thought I could maybe get away with it as I was only using channel 1 intermittently to set the pitch for the alien movement, but it would never play the shot sound and for some reason I couldn't work out when I get down to the last alien and tried to fire a shot, the game crashes. Really bizarre. Only happens on the last alien. Everything freezes except the last alien which endlessly just goes between the left and right sides of the screen but never lands. Stop playing the shot sound on channel 1 and everything is back to normal. So I tried switching it to channel 2, which I was also using for the bomb drop sound as again I thought maybe I could get away with it as the sounds are quite short, but if I set the sounds up to play normally (i.e. without flushing the sound buffer) either one sound plays or the other, which I don't get at all as the sounds should just queue. In the end I put the shot sound on channel 3, same as the flying saucer, and that worked, but you can only hear it if the saucer isn't running of course. But I can live with that. I also changed the saucer explosion to the more siren type sound as you said, so that's ok as I can also play it on channel 3.
The only other sound was an individual alien blowing up which I had to do on channel zero, but I managed that by not allowing the movement sound during the explosion phase, and it seems to work ok.
So I've got the sounds working. They're not arcade accurate but at least I have some sound. Weird behaviour on some of the channels though. Maybe over time I will discover why.
Re: Sound problem
I can't help with the sound as I program the chip directly and it does exactly what I tell it to not always what I want it to!
Re: Sound problem
You can average two samples which will give that result, but with a small loss of quality made worse because the attenuation is non-linear, but maybe that is better!