![]() |
|
The sound effect thread - Printable Version +- Boriel Basic Forum (https://forum.boriel.com) +-- Forum: Compilers and Computer Languages (https://forum.boriel.com/forumdisplay.php?fid=12) +--- Forum: ZX Basic Compiler (https://forum.boriel.com/forumdisplay.php?fid=11) +---- Forum: How-To & Tutorials (https://forum.boriel.com/forumdisplay.php?fid=13) +---- Thread: The sound effect thread (/showthread.php?tid=1891) |
The sound effect thread - worcestersource - 2022-02-19 Hello everyone, I thought this would be a nifty place to pop some routines to make sound effects without resorting to asm. Code: sub soundBwop()
dim x, y as uByte
do until x = 255
out 254, (y * 8)
let y = x
do until y > 239
let y = y + 16
loop
let x = x + 1
loop
end subWhich makes a nice 'bwop' sound. it'll also change your border colour, so add the border value to the out statement to stop it changing colour. For example, for the a blue border: Code: out 254, (y * 8) + 1You can play around with this, such as changing the 16 for an 8, or making y count down so the loop duration gets longer each time. Steve RE: The sound effect thread - boriel - 2022-02-19 A "classic" one made with beeps (will disrupt your interruptions a bit): Code: SUB explosion
BEEP 0.01,24
BEEP 0.01,0
BEEP 0.01,-2
BEEP 0.01,-3
BEEP 0.01,-5
END SUB
explosion()RE: The sound effect thread - Jbizzel - 2022-02-20 I use this white noise one all the time... Code: SUB noise ()
asm
noise: ld e,250 ; repeat 250 times.
ld hl,0 ; start pointer in ROM.
noise2: push de
ld b,32 ; length of step.
noise0: push bc
ld a,(hl) ; next "random" number.
inc hl ; pointer.
and 248 ; we want a black border.
out (254),a ; write to speaker.
ld a,e ; as e gets smaller...
cpl ; ...we increase the delay.
noise1: dec a ; decrement loop counter.
jr nz,noise1 ; delay loop.
pop bc
djnz noise0 ; next step.
pop de
ld a,e
sub 24 ; size of step.
cp 30 ; end of range.
ret z
ret c
ld e,a
cpl
noise3: ld b,40 ; silent period.
noise4: djnz noise4
dec a
jr nz,noise3
jr noise2
ret
end asm
END SUBRE: The sound effect thread - worcestersource - 2022-02-23 Fantastic effect! Steve |