English Amiga Board

English Amiga Board (https://eab.abime.net/index.php)
-   Coders. Blitz Basic (https://eab.abime.net/forumdisplay.php?f=126)
-   -   Protracker playback library with sound effects (https://eab.abime.net/showthread.php?t=87959)

idrougge 18 July 2017 01:34

Protracker playback library with sound effects
 
1 Attachment(s)
I've managed to translate Phx's Protracker playback routine (as used in Solid Gold and Sqrxz) into a Blitz library.

What sets this library apart from other tracker players is that it works with all system versions (and not only 2.0+ like Ciatrackerlib) and that it supports simultaneous sound effects. The player automatically chooses the most suitable channel to override with sound effects, but you can also reserve certain channels for music only.

To install, copy ptplayer.obj to Blitzlibs:Userlibs or Blitzlibs:Otherlibs and rebuild Deflibs using either Blitzlibs:Makedeflibs or using BlitzLibMan from Aminet.

Command reference:
LoadBank 0,"mod.song",2 (loads module into bank 0 in chipmem (2))
MTInstall PAL=True, NTSC=False (installs player in program)
MTInit Bank#, startpos (inserts module into player)
MTInit &module_addr, &instr_addr, startpos (inserts INCBIN module into player, set instr_addr to 0 for normal modules)
MTPlay On/Off (start/stop module playback)
MTEnd (Stop playing current module)
MTSoundFX Sound#, volume (0..64)
MTSoundFX &sample_addr.l, length.w, period.w, volume.w (0..64)
MTMasterVolume 0..64 (Master volume for all music channels)
MTMusicMask bitmask.b (Set bits 0-3 to reserve channels for music only.)
MTMusicChannels 0..4 (number of channels dedicated to music)
MTE8Trigger (Value of the last E8 command in case you want to trigger game events from a module)

Daedalus 18 July 2017 10:19

Excellent work, thanks!

idrougge 18 July 2017 12:36

Please tell me if it works or not so I can fix the code before I forget how it works.

ChefDeadpool 07 December 2017 15:49

I am in need of this library. I will try this out tonight and let you know how it goes. Sorry if this is a few months after you posted, but I just got a CDTV and am trying out development on it.

MickGyver 07 December 2017 19:51

Thanks for reminding me @ChefDeadpool! I will do some testing on the A1200 and CD32 when I find the time. Good work on this one @idrougge!

ChefDeadpool 08 December 2017 01:39

1 Attachment(s)
So, I tried it out. It does work, and seemingly without issue. I ran it in UAE at A500 speeds, and it doesn't seem like it creates a huge performance hit, but I think there is a slight one.

I built the game in this thread with your library.

I'm including the new code and exe as well as the original disk's executables here so you can see for yourself.

E-Penguin 22 December 2018 10:44

I'm just getting weird clicks - hippoplayer works with the mod and identifies it as a protracker mod so I think the mod isn't the issue... Do I need to put the "MTPlay On" in an interrupt on vblank?

Code:

WBStartup

LoadBank 0,"testmod.mod",2

MTInstall True
MTInit 0,0

MTMasterVolume 64

MTPlay On

While Joyb(0)=0
        VWait
        ; Put game here
Wend

MTEnd
End


roondar 22 December 2018 12:14

Quote:

Originally Posted by E-Penguin (Post 1292246)
I'm just getting weird clicks - hippoplayer works with the mod and identifies it as a protracker mod so I think the mod isn't the issue... Do I need to put the "MTPlay On" in an interrupt on vblank?

That should not be needed, PHX's player runs it's own CIA interrupts so it needs no timing code from you.

Not sure what the problem is, have you tried a different module just to be sure?

E-Penguin 22 December 2018 19:11

I think it was some disagreement between winuae and my computer. Restarting everything seems to have made it just work.

E-Penguin 23 December 2018 14:58

1 Attachment(s)
I've tracked down the issue - it's "MTInstall". If I comment it out, everything works fine (including the music, oddly enough). With it, Blitz crashes on the second compilation/execution of the code. That's what tripped me up; the first run through seems to work, but editing the source then having another go causes a guru.

The guru is nonsensical from what I can gather.

idrougge 23 December 2018 23:17

That's funny, I did a lot of "MTInstall" when building this library. Is the relevant source the one above or something else?

E-Penguin 23 December 2018 23:26

Yes, it's happened with that one; it happens more frequently with the game I'm writing (almost every time). I will be releasing it tomorrow (children permitting), with all the source etc so you can take a look. At the moment MTInstall is commented out and things run fine.

I'm running in winuae, standard a1200 conf + ks/wb3.1 + 8Mb fast.

E-Penguin 25 December 2018 14:19

Full source is included here : http://eab.abime.net/showthread.php?t=95593

Un-commenting MTInstall reliably causes crashes on second loading / compilation attempts. I'm using the arexx hooks to load compile, following MickGyver's guide.

MickGyver 18 February 2019 09:34

Quote:

Originally Posted by E-Penguin (Post 1292459)
I've tracked down the issue - it's "MTInstall". If I comment it out, everything works fine (including the music, oddly enough). With it, Blitz crashes on the second compilation/execution of the code. That's what tripped me up; the first run through seems to work, but editing the source then having another go causes a guru.

The guru is nonsensical from what I can gather.

Quote:

Originally Posted by idrougge (Post 1292519)
That's funny, I did a lot of "MTInstall" when building this library. Is the relevant source the one above or something else?

I'm having the same problem, MTInstall causes a crash / guru on the second compilation of the code (WinUAE, A1200 config).

EDIT: The crash is caused by the compilation itself, not when the game runs. If I first "compile and run" the game, it's all fine. If I then choose to create an executable after this, I get the crash. If I load the source and create the executable directly after a reset, it works, and I can run the game over and over without it crashing.

E-Penguin 05 March 2019 22:38

I'm glad it's not just me!

earok 10 July 2019 00:13

Somehow I missed this thread - I did my own implementation of PTPlayer, but as standard Blitz code rather than a lib (it incbins a compiled assembly of PTPlayer).

So I figure I should use the library here instead - but I'm concerned about the MTInstall thing - was this ever permanently addressed and fixed, or does it need to be worked around? (eg, compiling without running first)

EDIT: I read in the other thread (http://eab.abime.net/showpost.php?p=...4&postcount=58) idrougee mentioned that neither MTInstall or MTRemove are needed in the actual game code, as the library loads and unloads these automatically?


In any case, what I've done is in the Zone, with some detail below:



Tracker files need to be loaded into Chipram using the 'Bank' function, but sound effects can be loaded through the standard Blitz LoadSound function before being played through _mt_playfx.


Code:

;Uses PTPlayer by Frank Wille
;Blitz code by Earok

;The binary file
PTPlayer.l = ?PTPlayerBinary
Goto SkipPTPlayerBinary
PTPlayerBinary: INCBIN "PTPlayer.bin"
SkipPTPlayerBinary

;Structs
NEWTYPE .PTPlayer_Request
        sfx_ptr.l ;(pointer to sample start in Chip RAM, even address)
        sfx_len.w ;(sample length in words)
        sfx_per.w ;(hardware replay period for sample)
        sfx_vol.w ;(volume 0..64, is unaffected by the song's master volume)
        sfx_cha.b ;(0..3 selected replay channel, -1 selects best channel)
        sfx_pri.b ;(unsigned priority, must be non-zero)
End NEWTYPE
DEFTYPE .PTPlayer_Request PTRequest

NEWTYPE .PTPlayer_BlitzSound
        _data.l            ;00: NULL if no sound present, else pointer to sound data
        _period.w          ;04: period of sound
        _length.w          ;06: length, in words, of sound data
        _loop.l            ;08: repeat to loop position of sound
        _looplength.w      ;12: length of looping section, in words
        _pad.b[2]          ;14:
End NEWTYPE

;Constants
#_mt_custom = $dff000
#_mt_install_cia = $20
#_mt_remove_cia = $CA
#_mt_init = $202
#_mt_end = $312
#_mt_playfx = $350
#_mt_mastervol = $5AE
#_mt_musicmask = $580
#_mt_enable = $325A
#_mt_e8trigger = $325B
#_mt_musicchannels = $325C

;ASM Functions. Don't use these, they're for internal use only
Function.l GetVBR{}

;http://stingray.untergrund.net/MiniStartup.s
        movem.l        a0-a6,-(a7)
        bsr        GetVBR
        movem.l        (a7)+,a0-a6       
        ASMExit

GetVBR:       
                move.l        a5,-(a7)
                moveq        #0,d0                        ; default at $0
                move.l        $4,a6
                btst        #0,296+1(a6)                ; 68010+?
                beq.b        is68k                        ; nope.
                lea        getit(pc),a5
                jsr        -30(a6)                        ; SuperVisor()
               
is68k:
                move.l        (a7)+,a5
                rts

getit:       
                dc.w $4e7a,$0801 ;movec vbr,d0
                rte                                ; back to user state code
               
End Function

;Used for a simple (no parameter) call
Statement _mt_simple_asm{Address.l}

        movem.l        d0-d7/a0-a6,-(a7)
        Move.l #_mt_custom,A6
        Move.l D0,A0
        JSR (A0)
        movem.l        (a7)+,d0-d7/a0-a6
        ASMExit
       
End Statement

;Used for a simple (one parameter) call
Statement _mt_simple_parameter_asm{Value.l,Address.l}

        movem.l        d0-d7/a0-a6,-(a7)
        Move.l #_mt_custom,A6
        Move.l D1,A0
        JSR (A0)
        movem.l        (a7)+,d0-d7/a0-a6
        ASMExit
       
End Statement

Statement _mt_playfx_asm{SfxStructurePointer.l,Address.l}

; _mt_playfx(a6=CUSTOM, a0=SfxStructurePointer)
        movem.l        d0-d7/a0-a6,-(a7)
        Move.l #_mt_custom,A6
        Move.l D0,A0
        Move.l D1,A1
        JSR (A1)
        movem.l        (a7)+,d0-d7/a0-a6
        ASMExit
       
End Statement

Statement _mt_install_cia_asm{IsPal.b,AutoVecBase.l,Address.l}

        ; Install a CIA-B interrupt for calling _mt_music.
        ; a6 = CUSTOM
        ; a0 = AutoVecBase
        ; d0 = PALflag.b (0 is NTSC)
        movem.l        d0-d7/a0-a6,-(a7)
        Move.l #_mt_custom,A6
        Move.l D1,A0
        Move.l D2,A1
        JSR (A1)
        movem.l        (a7)+,d0-d7/a0-a6
        ASMExit
       
End Statement

Statement _mt_init_asm{InitialSongPos.b,TrackerModule.l,Samples.l,Address.l}
; _mt_init(a6=CUSTOM, a0=TrackerModule, a1=Samples|NULL, d0=InitialSongPos.b)
;  Initialize a new module.
;  Reset speed to 6, tempo to 125 and start at the given position.
;  Master volume is at 64 (maximum).
;  When a1 is NULL the samples are assumed to be stored after the patterns.
        movem.l        d0-d7/a0-a6,-(a7)
        Move.l #_mt_custom,A6
        Move.l D1,A0
        Move.l D2,A1       
        Move.l D3,A2
        JSR (A2)
        movem.l        (a7)+,d0-d7/a0-a6
        ASMExit       

End Statement

;Use these functions
Statement MTInstallCIA{}
        Shared PTPlayer
        _mt_install_cia_asm{NTSC=false,GetVBR{},PTPlayer+#_mt_install_cia}               
End Statement

Statement MTRemoveCIA{}
        Shared PTPlayer
        _mt_simple_asm{PTPlayer+#_mt_remove_cia}
End Statement

Statement MTInit{InitialSongPos.b,TrackerModule.l,Samples.l}
        Shared PTPlayer
        _mt_init_asm{InitialSongPos,TrackerModule,Samples,PTPlayer+#_mt_init}
End Statement

Statement MTEnd{}
        Shared PTPlayer
        _mt_simple_asm{PTPlayer+#_mt_end}
End Statement

Statement MTPlayFX{SoundID.w,Vol.w,Channel.b,Priority.b}

        Shared PTPlayer,PTRequest

        ;Priority must be non-zero
        if Priority=0
                Priority=1
        endif
       
        *BlitzSnd.PTPlayer_BlitzSound = Addr Sound(SoundID)
        PTRequest\sfx_ptr = *BlitzSnd\_data
        PTRequest\sfx_len = *BlitzSnd\_length
        PTRequest\sfx_per = *BlitzSnd\_period
        PTRequest\sfx_vol = Vol
        PTRequest\sfx_cha = Channel
        PTRequest\sfx_pri = Priority

        _mt_playfx_asm{&PTRequest,PTPlayer+#_mt_playfx}

End Statement

Statement MTMasterVolume{vol.w}
        Shared PTPlayer
        _mt_simple_parameter_asm{vol,PTPlayer+#_mt_mastervol}
End Statement

Statement MTMusicMask{mask.b}
        Shared PTPlayer
        _mt_simple_parameter_asm{mask,PTPlayer+#_mt_musicmask}
End Statement

;Setters and getters for variables
Statement MTEnable_Set{value.b}
        Shared PTPlayer
        Poke.b PTPlayer + #_mt_enable,value
End Statement

Function.b MTEnable_Get{}
        Shared PTPlayer
        Function Return Peek.b(PTPlayer + #_mt_enable)
End Function

Statement MTE8Trigger_Set{value.b}
        Shared PTPlayer
        Poke.b PTPlayer + #_mt_e8trigger,value
End Statement

Function.b MTE8Trigger_Get{}
        Shared PTPlayer
        Function Return Peek.b(PTPlayer + #_mt_e8trigger)
End Function

Statement MTMusicChannels_Set{value.b}
        Shared PTPlayer
        Poke.b PTPlayer + #_mt_musicchannels,value
End Statement

Function.b MTMusicChannels_Get{}
        Shared PTPlayer
        Function Return Peek.b(PTPlayer + #_mt_musicchannels)
End Function

;Load the song to chipram
LoadBank 0,"AlarcityMenus.mod",2

;SFX from alarcity
LoadSound 0,"buy.iff"
LoadSound 1,"entry.iff"
LoadSound 2,"health.iff"
LoadSound 3,"levelup.iff"
LoadSound 5,"rapid.iff"
LoadSound 6,"shopopened.iff"
LoadSound 7,"sniper.iff"
LoadSound 8,"spread.iff"

BLITZ

MTInstallCIA{}

;The demo
MTInit{0,Bank(0),0}
MTEnable_Set{true}

LastJoystickDir = 4

While Joyb(0)+Joyb(1) = 0

        ;Make a sound depending on the joystick direction
        JoystickDir = (JoyX(1)+1) + (JoyY(1)+1)*3
        if LastJoystickDir <> JoystickDir
                if JoystickDir <> 4
                        MTPlayFX{JoystickDir,64,-1,1}
                endif
                LastJoystickDir = JoystickDir
        endif
       
        VWait
       
Wend

;Fade out
for i = 0 to 64
        MTMasterVolume{64-i}
        VWait
next

MTEnd{}
MTEnable_Set{false}
MTRemoveCIA{}

End


earok 11 July 2019 05:43

Given this library a quick test. All works well. I've taken my attempt out of the zone as idrougge's library is so much better.

Cheers idrougge :great

E-Penguin 11 July 2019 17:10

How did you get on (or not) with MTInstall?

earok 12 July 2019 02:32

Quote:

Originally Posted by E-Penguin (Post 1331966)
How did you get on (or not) with MTInstall?

I left it out. The library automatically runs MTInstall so there doesn't seem to be a need to trigger it manually.

Shatterhand 01 September 2019 08:32

Can someone please help me with rebuilding deflibs?

I managed to do on Winuae and Amiblitz , running a custom 040 configuration. The library worked fine.

But on my vanilla A600 BlitzLibMan just crashes, and I have no idea of what is "Blitzlibs:Makedeflibs", since my Blitz 2 instalation does not have this file...


All times are GMT +2. The time now is 00:16.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.

Page generated in 0.05378 seconds with 11 queries