English Amiga Board


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

 
 
Thread Tools
Old 11 August 2023, 13:54   #161
E-Penguin
Banana
 
E-Penguin's Avatar
 
Join Date: Jul 2016
Location: Darmstadt
Posts: 1,217
Updated .obj and .asm here (maybe phx could check I'm not doing anything stupid!).

To use MTPlayFX you have to pass the address of an
SfxStructure
object and return a pointer to an
SfxChanStatus
object.

You probably want to create a few newtypes for it. Something like:

Code:
NewType SfxStructure
    sfx_ptr.l     ; Pointer to sample start in Chip RAM
    sfx_len.w     ; Sample length in words
    sfx_per.w     ; Hardware replay period for sample
    sfx_vol.w     ; Volume 0..64
    sfx_cha.b     ; 0..3 selected replay channel, -1 selects best channel
    sfx_pri.b     ; Priority range 1..127
End NewType

NewType SfxChanStatus
    n_note.w      ; UWORD translates to word (.w) in Blitz Basic
    n_cmd.w       ; Another word
    n_index.b     ; UBYTE translates to byte (.b) in Blitz Basic
    n_sfxpri.b    ; Another byte
End NewType
Unfortunately I'm not in a position to test anything at the moment, maybe later this evening, children permitting!

---
edited to remove attachment, updated one below

Last edited by E-Penguin; 11 August 2023 at 15:15.
E-Penguin is offline  
Old 11 August 2023, 14:35   #162
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,551
Quote:
Originally Posted by E-Penguin View Post
Updated .obj and .asm here (maybe phx could check I'm not doing anything stupid!).
I noticed that you moved the SfxStructure pointer from d0 to a0 in
_mt_loopfx_stub
, but you didn't do that in
_mt_playfx_stub
. Does Blitz always pass a
long
argument in d0?

There might also be some room for optimization, as you only have to save/restore the registers which you modify in the stubs (mostly a6). All ptplayer functions follow the standard M68k-ABI, which means only d0-d1 and a0-a1 are scratch registers. The rest is preserved.
phx is offline  
Old 11 August 2023, 15:14   #163
E-Penguin
Banana
 
E-Penguin's Avatar
 
Join Date: Jul 2016
Location: Darmstadt
Posts: 1,217
Ah, I'd overlooked that. (another) updated library+src attached. I'll push it to github once someone's tested it.

Blitz passes in arguments in d0-d5 (pg 34 of the BlitzUM) and expects a4-a6 to be restored to initial values at the end of it all. I'm following idrougge's examples from his original blitz-wrapper.

Quote:
The Statement or Function is defined as usual with a list of parameters enclosed in curly brackets. When using assembler, the parameters passed to the procedure are
loaded in data registers D0..D5.

Care must be taken to ensure that address registers A4-A6 are restored to their inital
state before the code exits from the procedure using the AsmExit command.
To set the return value in assembler for Functions simply load the register DO with the
value before the AsmExit command.
------------------------

Edited to remove old version of the library

Last edited by E-Penguin; 11 August 2023 at 20:30.
E-Penguin is offline  
Old 11 August 2023, 15:57   #164
TheoTheoderich
Registered User
 
Join Date: Jun 2017
Location: Ruhrgebiet / Germany
Posts: 55
@E-Pinguin
Thank you very much for your help.

But sadly I donĀ“t know what this sentence means:
Quote:
To use MTPlayFX you have to pass the address of an SfxStructure object and return a pointer to an SfxChanStatus object.
The NewType SfxStructure already exists in the sample ptplayer_inc.ab3 and i added the NewType SfxChanStatus.
But I can not figure out, how to use it.
I am trying the example file for ptplayer which came with AmiBlitz3


DEFTYPE .sfx means your SfxStructure

Code:
WBSTARTUP

NEWTYPE .sound
  _data.l
  _period.w
  _length.w
  _loop.l
  _looplength.w
  _pad.b[2]
End NEWTYPE

NEWTYPE .sfx
  sfxPtr.l ; Pointer to sample start in chip ram, even address
  sfxLen.w ; Sample length
  sfxPer.w ; Hardware replay period for sample
  sfxVol.w ; Volume 0..64, is unaffected by the song's master volume
  sfxCha.b ; 0..3 selected replay channel, -1 selects best channel
  sfxPri.b ; unsigned priority, must be non-zero
  ;sfxSiz.b
End NEWTYPE

Statement SFXInit {*fx.sfx, snd.w, vol.w, cha.b, pri.b}
  *_snd.sound = Peek.l(Addr Sound(snd))  ; Get the pointer to the sound
  *fx\sfxPtr=*_snd\_data       ; Copy the data
  *fx\sfxLen=*_snd\_length     ; ...
  *fx\sfxPer=*_snd\_period
  *fx\sfxVol=vol
  *fx\sfxCha=cha
  *fx\sfxPri=pri
  ;*fx\sfxSiz=siz
End Statement

NEWTYPE .SfxChanStatus
    n_note.w      ; UWORD translates to word (.w) in Blitz Basic
    n_cmd.w       ; Another word
    n_index.b     ; UBYTE translates to byte (.b) in Blitz Basic
    n_sfxpri.b    ; Another byte
End NEWTYPE


MTInstall 1 ; Install the CIA MOD player routine (1=PAL,0=NTSC)

DEFTYPE .sfx clap
LoadSound 0,"909Clapp.iff"
; Initialize a sfx for ptplayer
SFXInit{&clap,0,64,-1,1} ; {*pointer.sfx, sound_index, volume, channel (-1=best), priority (>0) }

MTPlayFx &clap

MTEnd    ; Stop playing the current mod
MTRemove ; Remove the CIA MOD player routine

End
I get an error in the MTPlayFX line:
Return value needed for this function call

Sorry for all my questions...but I am still learning.
TheoTheoderich is offline  
Old 11 August 2023, 16:16   #165
E-Penguin
Banana
 
E-Penguin's Avatar
 
Join Date: Jul 2016
Location: Darmstadt
Posts: 1,217
chan_status.l = MTPlayFx &clap


if chan_status != 0 then it should have played properly.

It didn't previously return a value, now it does. In Blitz you must put the return value somewhere even if you don't do anything with it.
E-Penguin is offline  
Old 11 August 2023, 16:22   #166
TheoTheoderich
Registered User
 
Join Date: Jun 2017
Location: Ruhrgebiet / Germany
Posts: 55
Thanks, but there must still be something wrong.

With chan_status.l = MTPlayFx(&clap), only a buzz comes out of the speakers.

With MTSoundFX the sound is at least played once before an error message (Guru -. illigal instruction) comes, so at least I know that the sound file is OK.

Last edited by TheoTheoderich; 11 August 2023 at 16:29.
TheoTheoderich is offline  
Old 11 August 2023, 16:30   #167
E-Penguin
Banana
 
E-Penguin's Avatar
 
Join Date: Jul 2016
Location: Darmstadt
Posts: 1,217
Debugging time... Can you print out the value of the sfx object fields?

I wonder whether it's being created properly.
E-Penguin is offline  
Old 11 August 2023, 19:43   #168
E-Penguin
Banana
 
E-Penguin's Avatar
 
Join Date: Jul 2016
Location: Darmstadt
Posts: 1,217
OK, the problem definitely isn't you, it's the library. I've tested it with some old code which I know works with the previous version (based on an older version of the ptplayer.asm). Either I made a mistake when I upgraded to the latest version on aminet (most likely) or we've somehow uncovered a bug in phx's code (least likely). I'll review my diffs.

---------------------------

OK, I found the problem. The solution is a bit nasty.

_mt_soundfx
internally calls
_mt_playfx
. The blitz library wraps these with "stubs" to save off registers a3-a6 and restore them at the end. Previously,
_mt_playfx
wasn't exposed to blitz so it didn't do any register saving. Now however, it is exposed so must also do a save/restore. This wasn't being done properly, it is now, so
_mt_playfx
should work.

The downside is that calling
_mt_soundfx
now saves/restores the registers twice, once itself and once again when calling through to
_mt_playfx
.

I don't know the best way of improving it.
exit_playfx
would need to know whether it had been called via
_mt_soundfx
or directly via
_mt_playfx
and only restore the registers in the latter case (else let the registers be restored at the end of
_mt_soundfx
). Maybe it doesn't matter for the sake of a few cycles every now and then, I guess you're not hammering sound effects at it every frame.
Attached Files
File Type: zip blitz_ptplayer.zip (26.2 KB, 47 views)

Last edited by E-Penguin; 11 August 2023 at 20:29.
E-Penguin is offline  
Old 11 August 2023, 21:10   #169
E-Penguin
Banana
 
E-Penguin's Avatar
 
Join Date: Jul 2016
Location: Darmstadt
Posts: 1,217
So, this works.

Note the changes in SFXInit, and MTInit has to be called otherwise there's weird background sound. I guess it requires a mod to be at least loaded, if not actually playing.

Code:
WBStartup

NEWTYPE .sound
  _data.l
  _period.w
  _length.w
  _loop.l
  _looplength.w
  _pad.b[2]
End NEWTYPE

NEWTYPE .sfx
  sfxPtr.l ; Pointer to sample start in chip ram, even address
  sfxLen.w ; Sample length
  sfxPer.w ; Hardware replay period for sample
  sfxVol.w ; Volume 0..64, is unaffected by the song's master volume
  sfxCha.b ; 0..3 selected replay channel, -1 selects best channel
  sfxPri.b ; unsigned priority, must be non-zero
  ;sfxSiz.b
End NEWTYPE

Statement SFXInit {*fx.sfx, snd.w, vol.w, cha.b, pri.b}
  *_snd.sound = Addr Sound(snd)  ; Get the pointer to the sound
  *fx\sfxPtr=*_snd\_data       ; Copy the data
  *fx\sfxLen=*_snd\_length     ; ...
  *fx\sfxPer=*_snd\_period
  *fx\sfxVol=vol
  *fx\sfxCha=cha
  *fx\sfxPri=pri
  ;*fx\sfxSiz=siz
End Statement

NEWTYPE .SfxChanStatus
    n_note.w      ; UWORD translates to word (.w) in Blitz Basic
    n_cmd.w       ; Another word
    n_index.b     ; UBYTE translates to byte (.b) in Blitz Basic
    n_sfxpri.b    ; Another byte
End NEWTYPE


MTInstall 1 ; Install the CIA MOD player routine (1=PAL,0=NTSC)

LoadBank 0,"test_it_.mod",2

MTInit 0,0 ; Weirdness happens if this isn't called to point to some valid mod

DEFTYPE .sfx clap
LoadSound 0,"ow-sound.8svx"

; Initialize a sfx for ptplayer
SFXInit{&clap,0,64,-1,1} ; {*pointer.sfx, sound_index, volume, channel (-1=best), priority (>0) }

; Start the music play loop, if you want to
;MTPlay On

; Wait 10s
VWait 500

ad.l = 0

For i=0 To 10
  ad = MTPlayFx(&clap)
  VWait 50
Next i


MTEnd    ; Stop playing the current mod
MTRemove ; Remove the CIA MOD player routine


End
E-Penguin is offline  
Old 12 August 2023, 00:43   #170
TheoTheoderich
Registered User
 
Join Date: Jun 2017
Location: Ruhrgebiet / Germany
Posts: 55
Thank you very much.
This new code was also not working, due to the error:
"CanĀ“t convert types"
in the Statement SFXInit line:
"*_snd.sound = Addr Sound(snd) ; Get the pointer to the sound"


But I found out, that changing the SFXInit snd parameter from "snd.w" to "snd.l" solves this problem.
Now the MTPlayFX command is working fine

Tomorrow I will try to implement it into my game Settle the World and will do some more testing

Thank you very much for your help @E-Pinguin.
TheoTheoderich is offline  
Old 23 August 2023, 18:18   #171
Zener
Registered User
 
Zener's Avatar
 
Join Date: Jan 2009
Location: Barcelona / Spain
Posts: 434
Hi, I tried to update Blitz libs with this new version, and although it seems to be working, it changes the order of all the commands for older source codes. What was MasterSetVolume is now MTSoundFX, etc, etc.

Is it possible to keep the order of the commands? otherwise it is a mess. Thanks!

Quote:
Originally Posted by E-Penguin View Post
So, this works.

Note the changes in SFXInit, and MTInit has to be called otherwise there's weird background sound. I guess it requires a mod to be at least loaded, if not actually playing.

Code:
WBStartup

NEWTYPE .sound
  _data.l
  _period.w
  _length.w
  _loop.l
  _looplength.w
  _pad.b[2]
End NEWTYPE

NEWTYPE .sfx
  sfxPtr.l ; Pointer to sample start in chip ram, even address
  sfxLen.w ; Sample length
  sfxPer.w ; Hardware replay period for sample
  sfxVol.w ; Volume 0..64, is unaffected by the song's master volume
  sfxCha.b ; 0..3 selected replay channel, -1 selects best channel
  sfxPri.b ; unsigned priority, must be non-zero
  ;sfxSiz.b
End NEWTYPE

Statement SFXInit {*fx.sfx, snd.w, vol.w, cha.b, pri.b}
  *_snd.sound = Addr Sound(snd)  ; Get the pointer to the sound
  *fx\sfxPtr=*_snd\_data       ; Copy the data
  *fx\sfxLen=*_snd\_length     ; ...
  *fx\sfxPer=*_snd\_period
  *fx\sfxVol=vol
  *fx\sfxCha=cha
  *fx\sfxPri=pri
  ;*fx\sfxSiz=siz
End Statement

NEWTYPE .SfxChanStatus
    n_note.w      ; UWORD translates to word (.w) in Blitz Basic
    n_cmd.w       ; Another word
    n_index.b     ; UBYTE translates to byte (.b) in Blitz Basic
    n_sfxpri.b    ; Another byte
End NEWTYPE


MTInstall 1 ; Install the CIA MOD player routine (1=PAL,0=NTSC)

LoadBank 0,"test_it_.mod",2

MTInit 0,0 ; Weirdness happens if this isn't called to point to some valid mod

DEFTYPE .sfx clap
LoadSound 0,"ow-sound.8svx"

; Initialize a sfx for ptplayer
SFXInit{&clap,0,64,-1,1} ; {*pointer.sfx, sound_index, volume, channel (-1=best), priority (>0) }

; Start the music play loop, if you want to
;MTPlay On

; Wait 10s
VWait 500

ad.l = 0

For i=0 To 10
  ad = MTPlayFx(&clap)
  VWait 50
Next i


MTEnd    ; Stop playing the current mod
MTRemove ; Remove the CIA MOD player routine


End
Zener is offline  
Old 26 August 2023, 14:26   #172
earok
Registered User
 
Join Date: Dec 2013
Location: Auckland
Posts: 3,548
I've created another wrapper (but based on the existing one) for the purposes of the Scorpion Engine, but I've put it on github if anyone has any use for it or wants to submit pull requests.

It's mainly different in that it doesn't use the bank library, sound library etc, and that Blitz specific code is kept separate from ptplayer.asm so future updates can be dropped in without needing to merge. It uses the 6.4 beta (cheers Phx), which may be final if there's no further changes.

https://github.com/earok/ptplayer_blitzwrapper_scorpion
earok is offline  
Old 04 September 2023, 18:59   #173
Zener
Registered User
 
Zener's Avatar
 
Join Date: Jan 2009
Location: Barcelona / Spain
Posts: 434
Thanks for sharing it! I have tried it and I have the same problem with function names not being the correct ones. I think it is related with latests versions of Amiblitz, it doesn't happen in Amiblitz 3.8, for example

Quote:
Originally Posted by earok View Post
I've created another wrapper (but based on the existing one) for the purposes of the Scorpion Engine, but I've put it on github if anyone has any use for it or wants to submit pull requests.

It's mainly different in that it doesn't use the bank library, sound library etc, and that Blitz specific code is kept separate from ptplayer.asm so future updates can be dropped in without needing to merge. It uses the 6.4 beta (cheers Phx), which may be final if there's no further changes.

https://github.com/earok/ptplayer_blitzwrapper_scorpion
Zener is offline  
Old 05 September 2023, 02:50   #174
earok
Registered User
 
Join Date: Dec 2013
Location: Auckland
Posts: 3,548
Quote:
Originally Posted by Zener View Post
Thanks for sharing it! I have tried it and I have the same problem with function names not being the correct ones. I think it is related with latests versions of Amiblitz, it doesn't happen in Amiblitz 3.8, for example
That is really strange. I'm unfortunately not very familiar with Amiblitz, does Amiblitz still use tokenisation?

Is there another copy of the library present that could be conflicting?
earok is offline  
Old 05 September 2023, 16:48   #175
E-Penguin
Banana
 
E-Penguin's Avatar
 
Join Date: Jul 2016
Location: Darmstadt
Posts: 1,217
Quote:
Originally Posted by earok View Post
I've created another wrapper (but based on the existing one) for the purposes of the Scorpion Engine, but I've put it on github if anyone has any use for it or wants to submit pull requests.

It's mainly different in that it doesn't use the bank library, sound library etc, and that Blitz specific code is kept separate from ptplayer.asm so future updates can be dropped in without needing to merge. It uses the 6.4 beta (cheers Phx), which may be final if there's no further changes.

https://github.com/earok/ptplayer_blitzwrapper_scorpion
I'll take a look and see if I can merge my changes with yours, better than maintaining two different-but-similar libraries.

Quote:
Originally Posted by Zener View Post
Thanks for sharing it! I have tried it and I have the same problem with function names not being the correct ones. I think it is related with latests versions of Amiblitz, it doesn't happen in Amiblitz 3.8, for example
Which order would you like?
E-Penguin is offline  
Old 05 September 2023, 18:29   #176
Zener
Registered User
 
Zener's Avatar
 
Join Date: Jan 2009
Location: Barcelona / Spain
Posts: 434
Quote:
Originally Posted by E-Penguin View Post
I'll take a look and see if I can merge my changes with yours, better than maintaining two different-but-similar libraries.

Which order would you like?
Amiblitz has a tool to replace libraries that usually has worked just fine for me in the past. I am not sure what order it is expecting but this is the order it shows in the tool:
Zener is offline  
Old 06 September 2023, 10:27   #177
Honitos
Registered User
 
Honitos's Avatar
 
Join Date: Nov 2019
Location: Celle / Germany
Posts: 147
Sorry, I missed this topic.

The Problem may be, that AmiBlitz3 uses a faster tokenization-routine - yes, the compiler stills needs tokenized sources.

As the commands are reordered in the blitzlib, the tokens have changed.
The tokenization routine that runs when loading a source does not know the new tokens.
But you can use the menu-option "help/update instruction index" once to update the token-hashmap.

Anyother problem with reordering of commands is, that AmiBlitz3 used the first command in each lib to identify the libname - as there is no other effective way to do it.
After replacing a lib with reordered commands, you have to update the file "system/token_mapping_libs.txt".


---

I'd like to update the distribution with the changed playerlib.
Can someone provide me please the lasted version ?

Last edited by Honitos; 06 September 2023 at 11:31.
Honitos is offline  
Old 08 September 2023, 17:42   #178
Zener
Registered User
 
Zener's Avatar
 
Join Date: Jan 2009
Location: Barcelona / Spain
Posts: 434
Thank you, I was able to update the library following the provided steps!!!
Now the first function is MTInstall instead of MTinit, changing it fixed it.

I noticed there isn't MTPlay anymore, it looks like MTEnable is the replacement.


Quote:
Originally Posted by Honitos View Post
Sorry, I missed this topic.

The Problem may be, that AmiBlitz3 uses a faster tokenization-routine - yes, the compiler stills needs tokenized sources.

As the commands are reordered in the blitzlib, the tokens have changed.
The tokenization routine that runs when loading a source does not know the new tokens.
But you can use the menu-option "help/update instruction index" once to update the token-hashmap.

Anyother problem with reordering of commands is, that AmiBlitz3 used the first command in each lib to identify the libname - as there is no other effective way to do it.
After replacing a lib with reordered commands, you have to update the file "system/token_mapping_libs.txt".


---

I'd like to update the distribution with the changed playerlib.
Can someone provide me please the lasted version ?
Zener is offline  
Old 16 November 2023, 22:34   #179
jotd
This cat is no more
 
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,381
zoned tunes where tempo doesn't seem to register (sbagman.mod). Works with any tracker but not with ptplayer.
jotd is offline  
Old 12 January 2024, 11:02   #180
carrion
Registered User
 
carrion's Avatar
 
Join Date: Dec 2016
Location: Warsaw area
Posts: 153
Im working on my game Robot Jet Action 2 https://eab.abime.net/showthread.php?t=116486
The game is developed in BB2.
And I was wondering if I can play sub tunes in module with ptplayer?
TIA
carrion is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 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

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

Top

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