English Amiga Board


Go Back   English Amiga Board > Coders > Coders. General

 
 
Thread Tools
Old 10 January 2010, 04:25   #1
Hungry Horace
Wipe-Out Enthusiast
 
Hungry Horace's Avatar
 
Join Date: Nov 2005
Location: .
Age: 43
Posts: 2,544
Blitz Basic - MED problems

Ok, i've decided to take the plunge and try to pull myself away from AMOS. ("at last" some of you cry)

But.... i've thrown myself into a mire straight away. One of the reasons i want to learn BB is because of a particular project i want to work on. The only part of this project so-far completed is the Music, loveling crafted in OctamedSoundstudio, using the MMD1 format, and with some Octamed-Only commands in there.

I know, it's bad to start a project with the music, but i figure, if i cant use my music with Blitz, i frankly dont want to use the language at all!

Now, i would have been quite content had the in-built MED commands worked, but they play things at the wrong speed. It ignores the BPM speed set in the MEDs and it doesnt much like the SPD setting either. (Even then, you need to use multiple calls of 'PlayMED' within one interupt, which to me, sounds totally wrong)

Given that the BB2 manual says to call 'PlayMED' as such:

Quote:
PlayMed
- this needs to be called after every Vwait (every 50th of a second) or after every interrupt #5 (see SetInt)
The playback routine is obviously timing from Vblanks and not CIA, as the Octamed Playback sources reveals this:

Quote:
;****** Timing control ******
;
VBLANK EQU 0 ;1 = use VBlank interrupt (when absolutely necessary)
CIAB EQU 1 ;1 = use CIA timers (default)
;
; Please use CIAB whenever possible to avoid problems with variable
; VBlank speeds and to allow the use of command F01 - FF0 (set tempo)
; If both are set to 0, the timing is left for you (never set both to 1!!),
; then you just call _IntHandler for each timing pulse.
So, i believe the problem to be how that was set up in the BB2 command. I dont see any way of fixing that myself.


Now i must ask, can anyone assist with some BB2 knowledge? At the moment, i see possible solutions as;

- Butcher my MEDs to 'sort of' work with the crappy playback commands already there (i've tried this, and the results are not very pleasing)

- Find a set of replacement BB commands which have working MED functions. (i've been searching Aminet for may hours but maybe someone has a suggestion, or better still, one they have used themselves?)

- Compile the OctamedSS playback source (proplayer.a - http://aminet.net/package/dev/src/OcSS_src ) in asm, and call it from Blitz code...

This option seems the most likely to achieve the right result, but throws a lot of difficulties for me. Basically, i havent much idea where/how to start doing this!

I would i guess have to feed it the filename in an address register, perhaps butchering some of the playback code from the source above?

I assume then i just 'load' the code into an address (i assume blitz has data banks like AMOS?) and JMP/JSR to it as required?

How would i call other functions like telling it to start at a different pattern to 0 ? Do i need to know the offsets into the compiled code, by disassembling it? (e.g. putting the code at A1 and using JSR $100(a1) to call a different function $100 bytes into it?)

Is this method still going to need me to call the compiled equivalent of PlayMED on every CIA interupt? If so, that's another address/function i'll need to find in my compiled code.


Any thoughts / tips / help / general guidance on getting this going would be most appreciated.



edit: perhaps this: http://aminet.net/package/dev/basic/BlitzASMInclud might help create some working/decent MED commands for BB2

Last edited by Hungry Horace; 10 January 2010 at 05:16.
Hungry Horace is offline  
Old 11 January 2010, 15:08   #2
Leffmann
 
Join Date: Jul 2008
Location: Sweden
Posts: 2,269
Do you know if BB2 can use AmigaOS shared libraries? If so then the medplayer.library is the easiest way to get your song to play properly.
Leffmann is offline  
Old 11 January 2010, 18:02   #3
BippyM
Global Moderator
 
BippyM's Avatar
 
Join Date: Nov 2001
Location: Derby, UK
Age: 48
Posts: 9,355
Blitz can use shared libraries and I am certain med.library will be supported somewhere.. Check aminet I guess
BippyM is offline  
Old 11 January 2010, 18:46   #4
Hungry Horace
Wipe-Out Enthusiast
 
Hungry Horace's Avatar
 
Join Date: Nov 2005
Location: .
Age: 43
Posts: 2,544
Quote:
Originally Posted by bippym View Post
Blitz can use shared libraries and I am certain med.library will be supported somewhere.. Check aminet I guess

it is, but it's vblank timed not CIA timed, which is why i would like to build new commands based on the sources above


I've looked on aminet and theres no alternative. I'm currently using a good Protracker set of commands i got from there but it's not ideal.
Hungry Horace is offline  
Old 11 January 2010, 18:55   #5
Leffmann
 
Join Date: Jul 2008
Location: Sweden
Posts: 2,269
Just in case you didn't know this, the medplayer.library is just what it says, a MED player. It abstracts the replay routine and does proper allocation of audio channels, timers and interrupts for you, and will play all MED songs correctly. It's far less work than assembling the replay routine and implementing new commands for use within BB.
Leffmann is offline  
Old 11 January 2010, 19:35   #6
Hungry Horace
Wipe-Out Enthusiast
 
Hungry Horace's Avatar
 
Join Date: Nov 2005
Location: .
Age: 43
Posts: 2,544
Quote:
Originally Posted by Leffmann View Post
Just in case you didn't know this, the medplayer.library is just what it says, a MED player. It abstracts the replay routine and does proper allocation of audio channels, timers and interrupts for you, and will play all MED songs correctly. It's far less work than assembling the replay routine and implementing new commands for use within BB.
yes, i get the theory, but as i had previously mentioned, it clearly isnt implemented correctly in the current commands then it's a fact that it does -not- run off the the CIA (thus why the manual says you -have- to use Vblanks when calling 'PlayMedModule')

either creating something to call medplayer.lib "properly" or using the 'standalone' player in the OSS source via new commands seems to be the only option. There arent any alternatives (that i've found, and i've done a lot of searching) which do it.
Hungry Horace is offline  
Old 11 January 2010, 20:19   #7
Leffmann
 
Join Date: Jul 2008
Location: Sweden
Posts: 2,269
It's possible that the BB MED commands use an old version of the replay routine which simply didn't include timer automization. You don't have to call the replay routine 50 or 60 time a second during vertical blanks. You can call it at any rate you want using any means.

I looked a bit at the part about implementing new BB commands but it was very convoluted. The help file in the BB2 package I found mentions some commands that look to be used for accessing shared libraries, but they tell nothing and just reference other help files and manuals. Do you know if these manuals are freely downloadable somewhere?
Leffmann is offline  
Old 11 January 2010, 21:31   #8
pmc
gone
 
pmc's Avatar
 
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
Quote:
Originally Posted by Leffman
You don't have to call the replay routine 50 or 60 time a second during vertical blanks. You can call it at any rate you want using any means.
Surely you'd have to call the player each vbl for the module to play at the correct speed though...?
pmc is offline  
Old 11 January 2010, 21:34   #9
Samurai_Crow
Total Chaos forever!
 
Samurai_Crow's Avatar
 
Join Date: Aug 2007
Location: Waterville, MN, USA
Age: 49
Posts: 2,188
@Leffman

http://utilitybase.com/ref/?action=L...oup=BlitzBasic is kind of old but should tell you what to use.
Samurai_Crow is offline  
Old 11 January 2010, 21:36   #10
StingRay
move.l #$c0ff33,throat
 
StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,863
Maybe I am missing something but BB supports in-line asm so why not just use that to open the external medplayer.library and play the songs?
StingRay is offline  
Old 11 January 2010, 21:56   #11
BippyM
Global Moderator
 
BippyM's Avatar
 
Join Date: Nov 2001
Location: Derby, UK
Age: 48
Posts: 9,355
Blitz will fully support the medplayer.library if the FD us converted (I tghink blitzlibman is used).
BippyM is offline  
Old 11 January 2010, 22:03   #12
StingRay
move.l #$c0ff33,throat
 
StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,863
Libraries are independent of any Compiler/language, so BB does "support" the medplayer library, it's just a matter of calling its functions with the correct parameters, i.e. a standard include file for the medplayer lib is enough.
StingRay is offline  
Old 11 January 2010, 22:42   #13
Leffmann
 
Join Date: Jul 2008
Location: Sweden
Posts: 2,269
Quote:
Originally Posted by pmc View Post
Surely you'd have to call the player each vbl for the module to play at the correct speed though...?
If it's using pattern speed and not tempo speed then it's made to be called either 60 or in the majority of cases 50 times a second yeah. With tempos you can set an exact BPM which might not be a multiple of the vertical frequency and so calling the replayer once per 50Hz frame will make it play too fast or too slow.

Samurai Crow, thanks, it seems to be the exact same help file I already have.

If you can do inline asm in BB2 then here's a simple stand alone example of how you can use the medplayer.library:

Code:
OpenLibrary         = -552
CloseLibrary        = -414
GetPlayer           = -30
FreePlayer          = -36
PlayModule          = -42
StopPlayer          = -54
LoadModule          = -72
UnloadModule        = -78


;-------------------------------------------------------------------------------
                    section   code_p

                    ; Start the song and wait for the user to click the mouse
                    ; before we exit

Start               bsr       Play
                    bne       .exit

.waitpress          btst      #6, $bfe001
                    bne       .waitpress
.waitrelease        btst      #6, $bfe001
                    beq       .waitrelease

                    bsr       Stop

                    moveq     #0, d0
.exit               rts



Play                ; Open the library

                    move.l    4.w, a6
                    lea       library(pc), a1
                    moveq     #0, d0
                    jsr       OpenLibrary(a6)
                    tst.l     d0
                    beq       .error

                    ; Call GetPlayer to initialize and pass 0 in D0 for audio
                    ; output. Passing 1 will play MIDI over the serial

                    move.l    d0, a6
                    move.l    d0, librarybase
                    moveq     #0, d0
                    jsr       GetPlayer(a6)
                    tst.l     d0
                    bne       .closelibrary

                    ; Load the song from disk

                    lea       module(pc), a0
                    jsr       LoadModule(a6)
                    move.l    d0, modulepointer
                    beq       .freeplayer
                    
                    ; Start the song
                    
                    move.l    d0, a0
                    jsr       PlayModule(a6)
                    moveq     #0, d0
                    rts

.freeplayer         jsr       FreePlayer(a6)

.closelibrary       move.l    a6, a1
                    move.l    4.w, a6
                    jsr       CloseLibrary(a6)

.error              moveq     #-1, d0
                    rts



Stop                ; Call StopPlayer, UnloadModule and FreePlayer in order

                    move.l    librarybase(pc), a6
                    jsr       StopPlayer(a6)

                    move.l    modulepointer(pc), a0
                    jsr       UnloadModule(a6)

                    jsr       FreePlayer(a6)
                    
                    move.l    a6, a1
                    move.l    4.w, a6
                    jsr       CloseLibrary(a6)
                    rts



modulepointer       dc.l      0
librarybase         dc.l      0
library             dc.b      "medplayer.library", 0
module              dc.b      "med.my_test_song", 0
Leffmann is offline  
Old 12 January 2010, 01:28   #14
Hungry Horace
Wipe-Out Enthusiast
 
Hungry Horace's Avatar
 
Join Date: Nov 2005
Location: .
Age: 43
Posts: 2,544
Hi Leffman,

Many thanks for that code. I managed to get it playing my MED files, with correct tempos, after tweeking that code a lot to suit the BB2 assembler. So this is a big step forward!

one bit of code in particular it didnt like (besides the labels, and constants that i had to remove) was

Code:
move.l   4.w,a6
which changed to
Code:
move.l   4,a6
seemed to work fine, but i wasnt sure if the more asm minded might have something to say about that!


My only problem now will be if i need to access any additional functions? In particular i' like to be able to start my MED file from a different point in the sequence, say at '14' instead of '0' , so it can play a different variation, or say i want to access the global volume control so that i can fade the MED volume to zero?

looking over the library.doc file my understanding of the library constants still isnt great (i can just about see where you got the values from in libproto.h), but I cant see either of these referenced at all?

anyway, this is still a big help so far, so thankyou for that
Hungry Horace is offline  
Old 12 January 2010, 08:43   #15
pmc
gone
 
pmc's Avatar
 
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
@ HungryHorace - .w as in

Code:
move.l     4.w,a6
is the Motorola standard for denoting absolute short addressing.

It's either not supported by the BB2 assembler or the BB2 assembler requires you to use a different syntax.
pmc is offline  
Old 12 January 2010, 18:34   #16
Leffmann
 
Join Date: Jul 2008
Location: Sweden
Posts: 2,269
Quote:
Originally Posted by Hungry Horace View Post
My only problem now will be if i need to access any additional functions? In particular i' like to be able to start my MED file from a different point in the sequence, say at '14' instead of '0' , so it can play a different variation, or say i want to access the global volume control so that i can fade the MED volume to zero?

looking over the library.doc file my understanding of the library constants still isnt great (i can just about see where you got the values from in libproto.h), but I cant see either of these referenced at all?
The library has a function for setting what song to play, if you have a multi song module. You call it before calling PlayModule, f.ex like this:

Code:
SetModNum = -96

          ; Play the second song

          move.l    librarybase(pc), a6
          moveq     #1, d0
          jsr       SetModNum(a6)
          rts
There are no functions in the library to set neither the track position nor the volume, and I can't find any mention in the replay routine source of how to set the volume either. There are some bytes in the module containing the master volume but there's no mention that you can set the volume in real time by poking those. If it's doable then at least it's not obvious how to.

The library offsets are the hexadecimal values listed right after each function name in the libproto.h file, e.g. offset -$2A for PlayModule.
Leffmann is offline  
Old 12 January 2010, 20:48   #17
Hungry Horace
Wipe-Out Enthusiast
 
Hungry Horace's Avatar
 
Join Date: Nov 2005
Location: .
Age: 43
Posts: 2,544
Quote:
Originally Posted by Leffmann View Post
There are no functions in the library to set neither the track position nor the volume, and I can't find any mention in the replay routine source of how to set the volume either.
Hmm. curious. They are definately options in the current MED commands in BB2 (obviously not med.lib based then, although i thought i had read somewhere they were)

The multimodule might be enough (although you have to duplicate any blocks used in both sub-songs, which seems a bit of waste of space to me) - could the overall volume be altered by tapping the h/w directly?
Hungry Horace is offline  
Old 12 January 2010, 21:06   #18
pmc
gone
 
pmc's Avatar
 
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
Quote:
Originally Posted by HungryHorace
could the overall volume be altered by tapping the h/w directly?
You should be able to use the BB2 assembler to move values to the audio channel volume custom registers to set volume.

Volume can be set per audio channel with the AUDxVOL registers. Replace x with the audio channel number (0, 1, 2 or 3)

Valid values are 0 - 64.

For reference the volume regs are:

$dff0a8
$dff0b8
$dff0c8
$dff0d8
pmc is offline  
Old 12 January 2010, 21:55   #19
Hungry Horace
Wipe-Out Enthusiast
 
Hungry Horace's Avatar
 
Join Date: Nov 2005
Location: .
Age: 43
Posts: 2,544
thanks pmc

firstly, i just noticed there is a 'volume' control in BB2 to do exactly that anyway, but that produces the same effect as directly accessing the h/w registers. The result is not good!

I think the two are 'fighting' for the volumem, overriding each other - whilst i am telling it to go lower, the med.library player is setting it at its "wanted" volume and a horrible crackling sound is produced.
Hungry Horace is offline  
Old 12 January 2010, 22:09   #20
pmc
gone
 
pmc's Avatar
 
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
Hmmm, that's annoying.

Where do you set volume? Have you tried doing something like this:

call player
set your volume
call player
set your volume

So that (hopefully) your volume settings continually override what the player code just set. Bear in mind that I know nothing about BB2 and how you handle interrupt calls with it (which is I presume how the player code is called) so I might be talking total rubbish!

Alternatively I wonder if there's any mileage in picking apart the med player and trying to work out where / how volume is set and then altering the code to suit your needs?

As another suggestion, do you have to use med? You might have more options by using ProTracker for example as you'd have more choice of player code...

Just throwing around ideas - no guarantees any of these are good or elegant solutions!
pmc 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
AMOS or Blitz Basic 2 Dreedo Coders. General 42 23 September 2014 21:48
Blitz basic 2 Help Havie Coders. Blitz Basic 30 08 September 2013 09:15
blitz basic petza request.Apps 11 08 April 2007 01:49
Blitz Basic 2 anyone? jobro request.Apps 12 28 November 2005 18:15
Blitz Basic 2 LaundroMat Retrogaming General Discussion 5 24 July 2001 08:10

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 14:29.

Top

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