-
Notifications
You must be signed in to change notification settings - Fork 0
/
modplay.txt
42 lines (34 loc) · 3.64 KB
/
modplay.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
libmodplay README
-------------------------
libmodplay is a library which plays music module files on your PlayStation.
You can use it to play music in your productions.
This means you can grab many module files from the internet and use them very easily and (almost) transparently.
Control is provided over Sound RAM addresses and base voices which allows playing a music and playing your own sound effects without resorting to guesses and ugly hacks.
Little tutorial
-------------------------
The music module file you want to use must be loaded in memory. How to do this will not be explained here. You will also need to initialize the SPU of the PlayStation before you use the MODPlay() function.
Pass to MODLoad() as its only argument the pointer to the memory area in which loaded the music module file. MODLoad() will then return a pointer to ModMusic structure (ModMusic *). As all the data from the module file was copied to the structure you can free or otherwise use for another purpose the memory area whose pointer you passed to MODLoad().
At this point you must load the samples of the music module to Sound RAM. There are two ways of doing this:
1) Using MODUploadSamples(). This uses the samples in PCM data from the music module data, and before
being used by the SPU, they need to be converted at runtime (by the PS CPU) to ADPCM. This takes
a lot of time and the resulting quality is very poor. (I needed to make it not very dog slow and if anything I'm a beginner at codecs -nextvolume)
2) Using MOD4PSX_Upload(). This loads the samples from preconverted data. The samples here are
directly in ADPCM, and this way is both very fast and high quality. The only shortcoming is that
you need to use more RAM, but this problem is non-existent if you program in certain ways,
for example by loading data from the CD filesystem into a buffer. You could first load the MOD,
and *then* load the ADPCM sample data. An ADPCM sample data pack file is obtained from a music
module file by using the mod4psx tool included in the PSXSDK.
You pass the pointer to the memory area where this pack file is loaded to MOD4PSX_Upload() as
first argument.
The base_addr argument has the same meaning for both uploading functions; it specifies the
Sound RAM address to start uploading to. Then the two functions return the Sound RAM address
after the uploaded sample data. base_addr should be a multiple of 8 due to hardware limitations.
After doing this, to play your music you have to call MODPlay(), giving the pointer to the ModMusic structure as its only argument, fifty/sixty times a second. You can do so by setting up a counter which is increased every timeVSync/VBlank happens (this means it is slightly slower on PAL if done in this way, but it's the easiest method). Check the modplayer example for more information.
When you want to stop playing the music module, call MODStop() in the same way as you called MODPlay().
Basically, this is what you have to do. It is not hard at all, just remember that the default base sound voice is 0, and that you don't need to play anything on voices 0-7 yourself, or things will not work well. Eight voices are used because this is a limit of the Protracker MOD format.
You can change the number of the base sound voice to another value by using the MODSetBaseVoice() function before using MODPlay().
ISSUES
--------------------
- With ProTracker MODs, sample looping is not implemented yet when converting samples at runtime and many effects aren't implemented yet
so some modules could sound differently to how they should sound.
Always use MODs with few effects.