FAQ  •  Register  •  Login

HOWTO: Put BeepFX Sound into ZXB code

<<

britlion

Posts: 766

Joined: Mon Apr 27, 2009 7:26 pm

Location: Slough, Berkshire, UK

Post Sat Jun 02, 2012 12:28 pm

HOWTO: Put BeepFX Sound into ZXB code

Shiru's Beepfx ( http://shiru.untergrund.net/files/beepfx102.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 sub


And 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 nextData


Finally, 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 #00


This 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 $00



you 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.
Last edited by britlion on Sun Jun 03, 2012 9:15 am, edited 1 time in total.
<<

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Sat Jun 02, 2012 2:49 pm

Re: HOWTO: Put BeepFX Sound into ZXB code

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.
<<

LCD

Posts: 596

Joined: Fri Feb 13, 2009 3:11 pm

Location: Vienna, Austria

Post Sat Jun 02, 2012 4:38 pm

Re: HOWTO: Put BeepFX Sound into ZXB code

Thank you! this will be great! By the way, DB and DW is supported by ZXBC too, so no need to change them.
------------------------------------------------------------
http://lcd-one.da.ru redirector is dead
Visit my http://members.inode.at/838331/index.html home page!
<<

britlion

Posts: 766

Joined: Mon Apr 27, 2009 7:26 pm

Location: Slough, Berkshire, UK

Post Sat Jun 02, 2012 8:46 pm

Re: HOWTO: Put BeepFX Sound into ZXB code

boriel wrote: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.


Way to go!

This will be harder to import, since it needs a chunk of extra data....
<<

britlion

Posts: 766

Joined: Mon Apr 27, 2009 7:26 pm

Location: Slough, Berkshire, UK

Post Sat Jun 02, 2012 8:46 pm

Re: HOWTO: Put BeepFX Sound into ZXB code

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.
<<

britlion

Posts: 766

Joined: Mon Apr 27, 2009 7:26 pm

Location: Slough, Berkshire, UK

Post Sat Jun 02, 2012 8:48 pm

Re: HOWTO: Put BeepFX Sound into ZXB code

Oh, the latest uploaded version of pacman now has sound, thanks to this! :)

Return to How-To & Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest

cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by Vjacheslav Trushkin for Free Forums/DivisionCore.

phpBB SEO