![]() |
|
HOWTO: Put BeepFX Sound into ZXB code - 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: HOWTO: Put BeepFX Sound into ZXB code (/showthread.php?tid=466) |
HOWTO: Put BeepFX Sound into ZXB code - britlion - 2012-06-02 Shiru's Beepfx (http://shiru.untergrund.net/files/beepfx.zip) is quite an interesting tool for sound effects. He doesn't believe it can be used for tunes - but it can do different pitched "tones" and include pauses, and that spells tune to me. Beepola is probably a better choice for real tune making, though. Anyway - the asm it produces is not compatible with zxb's assembler. So I did the working out of how to tweak it to work. So the sound calling routine would look like this: Code: SUB sound(soundNum as uByte)
asm
#include "BeepFXPlayer.asm"
#include "SoundData.asm"
SoundEnd:
pop IX
end asm
end subAnd BeepFXPlayer would always be the same tweaks, so I present my version here: Code: playBasic:
play:
ld hl,soundEffectsData ;address of sound effects data
di
push ix
push iy
ld b,0
ld c,a
add hl,bc
add hl,bc
ld a,(hl)
inc hl
ld h,(hl)
ld l,a
push hl
pop ix ;put it into ix
ld a,(23624) ;get border color from BASIC vars to keep it unchanged
rra
rra
rra
and 7
ld (sfxRoutineToneborder+1),a
ld (sfxRoutineNoiseborder+1),a
readData:
ld a,(ix+0) ;read block type
or a
jr nz,readDatasound
pop iy
ei
jp SoundEnd
readDatasound:
ld c,(ix+1) ;read duration 1
ld b,(ix+2)
ld e,(ix+3) ;read duration 2
ld d,(ix+4)
push de
pop iy
dec a
jr nz,sfxRoutineNoise
;this routine generate tone with many parameters
sfxRoutineTone:
ld e,(ix+5) ;freq
ld d,(ix+6)
ld a,(ix+9) ;duty
ld (sfxRoutineToneduty+1),a
ld hl,0
sfxRoutineTonel0:
push bc
push iy
pop bc
sfxRoutineTonel1:
add hl,de
ld a,h
sfxRoutineToneduty:
cp 0
sbc a,a
and 16
sfxRoutineToneborder:
or 0
out ($fe),a
#line 78
dec bc
ld a,b
or c
jr nz,sfxRoutineTonel1
ld a,(sfxRoutineToneduty+1)
add a,(ix+10) ;duty change
ld (sfxRoutineToneduty+1),a
ld c,(ix+7) ;slide
ld b,(ix+8)
ex de,hl
add hl,bc
ex de,hl
pop bc
dec bc
ld a,b
or c
jr nz,sfxRoutineTonel0
ld c,11
nextData:
add ix,bc ;skip to the next block
jr readData
;this routine generate noise with two parameters
sfxRoutineNoise:
ld e,(ix+5) ;pitch
ld d,1
ld h,d
ld l,d
sfxRoutineNoisel0:
push bc
push iy
pop bc
sfxRoutineNoisel1:
ld a,(hl)
and 16
sfxRoutineNoiseborder:
or 0
out ($fe),a
dec d
jr nz,sfxRoutineNoisel2
ld d,e
inc hl
ld a,h
and $1f
ld h,a
sfxRoutineNoisel2:
dec bc
ld a,b
or c
jr nz,sfxRoutineNoisel1
ld a,e
add a,(ix+6) ;slide
ld e,a
pop bc
dec bc
ld a,b
or c
jr nz,sfxRoutineNoisel0
ld c,7
jr nextDataFinally, you need to run beepfx, and compile just the sound data to asm. You'll get something like this: Code: soundEffectsData
dw .sfx0
.sfx0
db #01
dw #0032,#0064,#01f4,#ffec,#0080
db #00This needs some massaging to work. Change "soundEffectsData" to "soundEffectsData:" Change "." to "soundEffectsData" And make labels have a : on the end. Search and replace "db" with "defb" Search and replace "dw" with "defw" Replace # with $ All done! Worked example: Code: soundEffectsData:
defw soundEffectsDatasfx0
defw soundEffectsDatasfx1
soundEffectsDatasfx0:
defb $01
defw $0032,$0064,$01f4,$ffec,$0080
defb $00
soundEffectsDatasfx1:
defb $01
defw $0014,$0190,$00c8,$0005,$0110
defb $01
defw $001e,$0190,$00c8,$0008,$0110
defb $00you can then save this as something lime soundata.asm and #'include this file into the sound routine listed above. Call with sound (n) for the sound number. Re: HOWTO: Put BeepFX Sound into ZXB code - boriel - 2012-06-02 Britlion, seriously, this is FANTASTIC! :o BTW: I've finally integrated the SPPixel routines within ZX Basic (Draw already uses them). I'm porting SPFill into the library as #include <SP/fill.bas>. Once it's done, I could try to include this one. Re: HOWTO: Put BeepFX Sound into ZXB code - LCD - 2012-06-02 Thank you! this will be great! By the way, DB and DW is supported by ZXBC too, so no need to change them. Re: HOWTO: Put BeepFX Sound into ZXB code - britlion - 2012-06-02 boriel Wrote:Britlion, seriously, this is FANTASTIC! :o Way to go! This will be harder to import, since it needs a chunk of extra data.... Re: HOWTO: Put BeepFX Sound into ZXB code - britlion - 2012-06-02 LCD Wrote:Thank you! this will be great! By the way, DB and DW is supported by ZXBC too, so no need to change them. Hmm. I was sure that failed to compile when I tried it. I'll have a look next time. Re: HOWTO: Put BeepFX Sound into ZXB code - britlion - 2012-06-02 Oh, the latest uploaded version of pacman now has sound, thanks to this!
|