![]() |
![]() |
#1 |
Registered User
Join Date: Sep 2007
Location: Stockholm
Posts: 4,377
|
Protracker playback library with sound effects
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) Last edited by idrougge; 08 September 2018 at 13:30. Reason: Forgot MTInstall command |
![]() |
![]() |
#2 |
Registered User
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,413
|
Excellent work, thanks!
|
![]() |
![]() |
#3 |
Registered User
Join Date: Sep 2007
Location: Stockholm
Posts: 4,377
|
Please tell me if it works or not so I can fix the code before I forget how it works.
|
![]() |
![]() |
#4 |
Registered User
Join Date: Nov 2017
Location: Tomball, TX, USA
Posts: 60
|
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.
|
![]() |
![]() |
#5 |
Registered User
Join Date: Oct 2008
Location: Finland
Posts: 643
|
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!
|
![]() |
![]() |
#6 |
Registered User
Join Date: Nov 2017
Location: Tomball, TX, USA
Posts: 60
|
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. |
![]() |
![]() |
#7 |
Banana
Join Date: Jul 2016
Location: Darmstadt
Posts: 1,217
|
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 |
![]() |
![]() |
#8 | |
Registered User
Join Date: Jul 2015
Location: The Netherlands
Posts: 3,464
|
Quote:
Not sure what the problem is, have you tried a different module just to be sure? |
|
![]() |
![]() |
#9 |
Banana
Join Date: Jul 2016
Location: Darmstadt
Posts: 1,217
|
I think it was some disagreement between winuae and my computer. Restarting everything seems to have made it just work.
|
![]() |
![]() |
#10 |
Banana
Join Date: Jul 2016
Location: Darmstadt
Posts: 1,217
|
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. |
![]() |
![]() |
#11 |
Registered User
Join Date: Sep 2007
Location: Stockholm
Posts: 4,377
|
That's funny, I did a lot of "MTInstall" when building this library. Is the relevant source the one above or something else?
|
![]() |
![]() |
#12 |
Banana
Join Date: Jul 2016
Location: Darmstadt
Posts: 1,217
|
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. |
![]() |
![]() |
#13 |
Banana
Join Date: Jul 2016
Location: Darmstadt
Posts: 1,217
|
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. |
![]() |
![]() |
#14 | ||
Registered User
Join Date: Oct 2008
Location: Finland
Posts: 643
|
Quote:
Quote:
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. Last edited by MickGyver; 18 February 2019 at 09:51. |
||
![]() |
![]() |
#15 |
Banana
Join Date: Jul 2016
Location: Darmstadt
Posts: 1,217
|
I'm glad it's not just me!
|
![]() |
![]() |
#16 |
Registered User
Join Date: Dec 2013
Location: Auckland
Posts: 3,561
|
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 Last edited by earok; 10 July 2019 at 00:55. |
![]() |
![]() |
#17 |
Registered User
Join Date: Dec 2013
Location: Auckland
Posts: 3,561
|
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 ![]() |
![]() |
![]() |
#18 |
Banana
Join Date: Jul 2016
Location: Darmstadt
Posts: 1,217
|
How did you get on (or not) with MTInstall?
|
![]() |
![]() |
#19 |
Registered User
Join Date: Dec 2013
Location: Auckland
Posts: 3,561
|
|
![]() |
![]() |
#20 |
Warhasneverbeensomuchfun
Join Date: Jun 2001
Location: Rio de Janeiro / Brazil
Age: 41
Posts: 3,450
|
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... |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Demos with music or sound effects in time with graphic effects | mark_k | request.Demos | 7 | 07 December 2016 20:23 |
Sound issue, not all sound effects played. | Connorsdad | support.WinUAE | 16 | 23 February 2015 16:32 |
Sound Effects in IK+ | noel411 | support.Games | 3 | 07 September 2007 03:12 |
IK+ sound effects not working | andreas | support.WinUAE | 4 | 26 July 2005 20:21 |
How to rip sound / effects | wlcina | support.Games | 16 | 18 April 2005 03:09 |
|
|