English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. Blitz Basic

 
 
Thread Tools
Old 18 July 2017, 02:34   #1
idrougge
Registered User
 
Join Date: Sep 2007
Location: Stockholm
Posts: 3,927
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)
Attached Files
File Type: lha BlitzPhxPlayer.lha (5.8 KB, 138 views)

Last edited by idrougge; 08 September 2018 at 14:30. Reason: Forgot MTInstall command
idrougge is offline  
Old 18 July 2017, 11:19   #2
Daedalus
Registered User

Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 4,286
Excellent work, thanks!
Daedalus is offline  
Old 18 July 2017, 13:36   #3
idrougge
Registered User
 
Join Date: Sep 2007
Location: Stockholm
Posts: 3,927
Please tell me if it works or not so I can fix the code before I forget how it works.
idrougge is offline  
Old 07 December 2017, 16:49   #4
ChefDeadpool
Registered User
ChefDeadpool's Avatar
 
Join Date: Nov 2017
Location: Spring, TX, USA
Posts: 44
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.
ChefDeadpool is offline  
Old 07 December 2017, 20:51   #5
MickGyver
Registered User

MickGyver's Avatar
 
Join Date: Oct 2008
Location: Finland
Posts: 471
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!
MickGyver is offline  
Old 08 December 2017, 02:39   #6
ChefDeadpool
Registered User
ChefDeadpool's Avatar
 
Join Date: Nov 2017
Location: Spring, TX, USA
Posts: 44
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.
Attached Files
File Type: zip SOR_ModTest.zip (1.3 KB, 68 views)
ChefDeadpool is offline  
Old 22 December 2018, 11:44   #7
E-Penguin
Banana

E-Penguin's Avatar
 
Join Date: Jul 2016
Location: Darmstadt
Posts: 850
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
E-Penguin is offline  
Old 22 December 2018, 13:14   #8
roondar
Registered User

 
Join Date: Jul 2015
Location: The Netherlands
Posts: 1,364
Quote:
Originally Posted by E-Penguin View Post
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?
roondar is offline  
Old 22 December 2018, 20:11   #9
E-Penguin
Banana

E-Penguin's Avatar
 
Join Date: Jul 2016
Location: Darmstadt
Posts: 850
I think it was some disagreement between winuae and my computer. Restarting everything seems to have made it just work.
E-Penguin is offline  
Old 23 December 2018, 15:58   #10
E-Penguin
Banana

E-Penguin's Avatar
 
Join Date: Jul 2016
Location: Darmstadt
Posts: 850
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.
Attached Thumbnails
Click image for larger version

Name:	Untitled.png
Views:	52
Size:	6.1 KB
ID:	61286  
E-Penguin is offline  
Old 24 December 2018, 00:17   #11
idrougge
Registered User
 
Join Date: Sep 2007
Location: Stockholm
Posts: 3,927
That's funny, I did a lot of "MTInstall" when building this library. Is the relevant source the one above or something else?
idrougge is offline  
Old 24 December 2018, 00:26   #12
E-Penguin
Banana

E-Penguin's Avatar
 
Join Date: Jul 2016
Location: Darmstadt
Posts: 850
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 is offline  
Old 25 December 2018, 15:19   #13
E-Penguin
Banana

E-Penguin's Avatar
 
Join Date: Jul 2016
Location: Darmstadt
Posts: 850
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.
E-Penguin is offline  
Old 18 February 2019, 10:34   #14
MickGyver
Registered User

MickGyver's Avatar
 
Join Date: Oct 2008
Location: Finland
Posts: 471
Quote:
Originally Posted by E-Penguin View Post
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 View Post
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.

Last edited by MickGyver; 18 February 2019 at 10:51.
MickGyver is offline  
Old 05 March 2019, 23:38   #15
E-Penguin
Banana

E-Penguin's Avatar
 
Join Date: Jul 2016
Location: Darmstadt
Posts: 850
I'm glad it's not just me!
E-Penguin is offline  
Old 10 July 2019, 01:13   #16
earok
Registered User

 
Join Date: Dec 2013
Location: Auckland
Posts: 2,152
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 01:55.
earok is offline  
Old 11 July 2019, 06:43   #17
earok
Registered User

 
Join Date: Dec 2013
Location: Auckland
Posts: 2,152
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
earok is offline  
Old 11 July 2019, 18:10   #18
E-Penguin
Banana

E-Penguin's Avatar
 
Join Date: Jul 2016
Location: Darmstadt
Posts: 850
How did you get on (or not) with MTInstall?
E-Penguin is offline  
Old 12 July 2019, 03:32   #19
earok
Registered User

 
Join Date: Dec 2013
Location: Auckland
Posts: 2,152
Quote:
Originally Posted by E-Penguin View Post
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.
earok is offline  
Old 01 September 2019, 09:32   #20
Shatterhand
Warhasneverbeensomuchfun

Shatterhand's Avatar
 
Join Date: Jun 2001
Location: Rio de Janeiro / Brazil
Age: 36
Posts: 3,430
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...
Shatterhand is offline  
 


Currently Active Users Viewing This Thread: 2 (1 members and 1 guests)
TheoTheoderich
Thread Tools

Similar Threads
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 21:23
Sound issue, not all sound effects played. Connorsdad support.WinUAE 16 23 February 2015 17:32
Sound Effects in IK+ noel411 support.Games 3 07 September 2007 04:12
IK+ sound effects not working andreas support.WinUAE 4 26 July 2005 21:21
How to rip sound / effects wlcina support.Games 16 18 April 2005 04:09

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 22:58.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.
Page generated in 0.09399 seconds with 14 queries