PSXSDK
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
Macros | Functions | Variables
modplay.c File Reference
#include <psx.h>
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <stdlib.h>
#include <adpcm.h>
#include "modplay.h"
#include "modplay_int.h"

Macros

#define ADPCM_BUFFER_SIZE   0x4000
 

Functions

ModMusicMODLoad (void *d)
 Just like MODLoadEx() but with the flags parameters set to zero, i.e.
 
ModMusicMODLoadEx (void *d, unsigned int flags)
 Allocate a ModMusic structure and copy data to it from data in memory containing a music module file.
 
void MODUnload (ModMusic *m)
 Free memory allocated for music module.
 
void MODPlay_func (ModMusic *m, int c, int s, int p, int vl, int vr)
 MODPlay: internal prototypes.
 
void MODPlay (ModMusic *m, int *t)
 Play a tick of a music.
 
void MODStop (ModMusic *m)
 Stop a music.
 
int MODUploadSamples (ModMusic *m, int base_addr)
 Upload the samples of the module music to Sound RAM.
 
int MOD4PSX_Upload (void *d, int base_addr)
 Upload preconverted ADPCM samples, as generated by the mod4psx tool.
 
void MODSetBaseVoice (int base_voice)
 Sets the SPU voice to use as the first channel when playing music.
 
void MODSetMaxVolume (unsigned short max_volume)
 Set maximum volume for MODPlay.
 
void MODRewind (ModMusic *m)
 Rewind music, that is, make it restart from the beginning.
 
void MODSetTranspose (ModMusic *m, short transpose)
 Sets transpose for music.
 
void MODSetMono (int value)
 Set mono mode.
 

Variables

int modplay_base_voice = 0
 
int modplay_max_vol = 0x3fff
 
int modplay_chan_vols [8]
 
int modplay_int_cnt = 0
 
int modplay_samples_off [32]
 
int modplay_chan_mask = 0
 
int modplay_is_mono = 0
 
unsigned char modplay_adpcm_buffer [ADPCM_BUFFER_SIZE]
 
unsigned int modload_flags = 0
 

Macro Definition Documentation

#define ADPCM_BUFFER_SIZE   0x4000

Function Documentation

int MOD4PSX_Upload ( void *  d,
int  base_addr 
)

Upload preconverted ADPCM samples, as generated by the mod4psx tool.

Parameters
dPointer to buffer containing the ADPCM samples archive
base_addrBase address at which the samples will start to be uploaded.
Returns
The sound address after all the uploaded samples
ModMusic* MODLoad ( void *  d)

Just like MODLoadEx() but with the flags parameters set to zero, i.e.

default behaviour.

Parameters
dPointer to a buffer containing a music module file
Returns
Pointer to newly allocated ModMusic structure.
ModMusic* MODLoadEx ( void *  d,
unsigned int  flags 
)

Allocate a ModMusic structure and copy data to it from data in memory containing a music module file.

Almost all data from the music module file is copied into another location in memory for the ModMusic structure.

This means your free memory should be roughly the double of the size of the MOD you're loading.

You can avoid loading the samples in the module file's native format, thus saving useful memory, by passing the MODLOAD_NOSAMPLES flag. This is especially the case when you use MOD4PSX_Upload().

Parameters
dPointer to a buffer containing a music module file
flagsFlag bitmask.
Returns
Pointer to newly allocated ModMusic structure.
void MODPlay ( ModMusic m,
int *  t 
)

Play a tick of a music.

This has to be called 60 / 50 times per second.

MODPlay decreases the value referenced by t every time the music finishes.

Set the variable pointed by t when you want to set the number of times again!

Parameters
mPointer to ModMusic structure
tPointer to an int which contains how many times the music module has to be played. i.e. if *t == 1, play once, if *t == 2, play twice, ..., if *t == -1, loop endlessly
void MODPlay_func ( ModMusic m,
int  c,
int  s,
int  p,
int  vl,
int  vr 
)

MODPlay: internal prototypes.

void MODRewind ( ModMusic m)

Rewind music, that is, make it restart from the beginning.

Parameters
mPointer to ModMusic structure for the music.
void MODSetBaseVoice ( int  base_voice)

Sets the SPU voice to use as the first channel when playing music.

The voice for the second channel will then be this (value+1), and so on...

Usually the base voice is 0; a MOD file can have up to eight channels, so take care of that.

A 669 file can always have 8 channels.

Parameters
base_voiceDesired base voice (0-23)
void MODSetMaxVolume ( unsigned short  max_volume)

Set maximum volume for MODPlay.

Parameters
max_volumeMaximum volume desired (0-0x3FFF)
void MODSetMono ( int  value)

Set mono mode.

Parameters
valueIf 0 set stereo mode, if 1 set mono mode
void MODSetTranspose ( ModMusic m,
short  transpose 
)

Sets transpose for music.

Changing the transpose value for a music shifts the frequency its samples are played at, but the music's tempo is unchanged.

Parameters
mPointer to ModMusic structure
transposeTranspose value
void MODStop ( ModMusic m)

Stop a music.

Parameters
mPointer to ModMusic structure for the music.
void MODUnload ( ModMusic m)

Free memory allocated for music module.

Parameters
mPointer to ModMusic structure
int MODUploadSamples ( ModMusic m,
int  base_addr 
)

Upload the samples of the module music to Sound RAM.

Parameters
mPointer to ModMusic structure for the music.
base_addrSound RAM address to start from when uploading to Sound RAM If -1 it is interpreted to be the same as the start of the section for sound data in Sound RAM (SPU_DATA_BASE_ADDR). base_addr must be a multiply of 8.
Returns
The sound address after all the uploaded samples

Variable Documentation

unsigned int modload_flags = 0
unsigned char modplay_adpcm_buffer[ADPCM_BUFFER_SIZE]
int modplay_base_voice = 0
int modplay_chan_mask = 0
int modplay_chan_vols[8]
int modplay_int_cnt = 0
int modplay_is_mono = 0
int modplay_max_vol = 0x3fff
int modplay_samples_off[32]