2012-06-02, 01:28 PM 
(This post was last modified: 2021-01-11, 12:16 PM by boriel.
 Edit Reason: Fix URL
)
		
	
	
		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:
And BeepFXPlayer would always be the same tweaks, so I present my version here:
Finally, you need to run beepfx, and compile just the sound data to asm.
You'll get something like this:
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:
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.
	
	
	
	
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.

 
 

 


