This commit is contained in:
Paul 2000-10-09 23:30:58 +00:00
parent 06ec0fdcd6
commit 2a65a60186
4 changed files with 114 additions and 142 deletions

View File

@ -1,3 +1,10 @@
/*
reverb ( trigger from map? )
position
adjust channels ( watery-mario64 style music changes )
*/
/*=========================================================================
sound.cpp
@ -22,6 +29,7 @@
#include "system\dbg.h"
#endif
/* Std Lib
------- */
@ -44,7 +52,7 @@ typedef struct XMFILEDATA
typedef struct SFXDETAILS
{
int m_channelMask;
int m_pattern; // ..or instrument for loopers
int m_pattern; // ..or instrument number for loopers
int m_looping;
};
@ -57,39 +65,7 @@ typedef struct SFXDETAILS
Vars
---- */
static XMFILEDATA s_xmSongData[CSoundMediator::NUM_SONGIDS]=
{
{ MUSIC_HYPERMMX_VH, MUSIC_HYPERMMX_VB, MUSIC_HYPERMMX_PXM }, // HYPERMMX
{ MUSIC_DROPPOP_VH, MUSIC_DROPPOP_VB, MUSIC_DROPPOP_PXM }, // DROPPOP
{ MUSIC_MUSIC_VH, MUSIC_MUSIC_VB, MUSIC_MUSIC_PXM }, // MUSIC
};
static XMFILEDATA s_xmSfxData[CSoundMediator::NUM_SFXBANKIDS]=
{
{ SFX_INGAME_VH, SFX_INGAME_VB, SFX_INGAME_PXM }, // INGAME
};
static SFXDETAILS s_sfxDetails[]=
{
{ 1, 6, 1 },
{ 1, 1, 0 },
{ 1, 2, 0 },
{ 1, 0, 1 },
};
// Static stuff for CSoundMediator
int CSoundMediator::s_initialised=false;
int CSoundMediator::s_currentVolume[CSoundMediator::NUM_VOLUMETYPES];
@ -106,7 +82,34 @@ static CSpuSound *s_spuSound;
static CXMPlaySound *s_xmplaySound;
// Songs
static XMFILEDATA s_xmSongData[CSoundMediator::NUM_SONGIDS]=
{
{ MUSIC_HYPERMMX_VH, MUSIC_HYPERMMX_VB, MUSIC_HYPERMMX_PXM }, // HYPERMMX
{ MUSIC_DROPPOP_VH, MUSIC_DROPPOP_VB, MUSIC_DROPPOP_PXM }, // DROPPOP
{ MUSIC_MUSIC_VH, MUSIC_MUSIC_VB, MUSIC_MUSIC_PXM }, // MUSIC
};
// SFX banks
static XMFILEDATA s_xmSfxData[CSoundMediator::NUM_SFXBANKIDS]=
{
{ SFX_INGAME_VH, SFX_INGAME_VB, SFX_INGAME_PXM }, // INGAME
};
// Individual SFX details
static SFXDETAILS s_sfxDetails[]=
{
{ 1, 6, 1 },
{ 1, 1, 0 },
{ 1, 2, 0 },
{ 1, 0, 1 },
};
//
int s_songChannelCount=10;
//
/*----------------------------------------------------------------------
@ -261,7 +264,7 @@ void CSoundMediator::playSong()
ASSERT(s_songModId!=NO_SONG);
ASSERT(s_songPlayingId==NOT_PLAYING);
s_songPlayingId=s_xmplaySound->playSong(s_songSampleId,s_songModId,10); // pkg !?
s_songPlayingId=s_xmplaySound->playSong(s_songSampleId,s_songModId,s_songChannelCount);
s_volumeDirty[SONG]=true; // Force a volume update
}
@ -334,7 +337,11 @@ xmPlayingId CSoundMediator::playSfx(int _sfxId)
else
{
playId=s_xmplaySound->playSfx(s_sfxSampleId,s_sfxModId,sfx->m_pattern,sfx->m_channelMask,20);
if(playId!=NOT_PLAYING)s_xmplaySound->unlockPlayingId(playId); // We really don't care about one-shot sfx..
if(playId!=NOT_PLAYING)
{
s_xmplaySound->unlockPlayingId(playId); // We really don't care about one-shot sfx..
playId=NOT_PLAYING;
}
}
s_volumeDirty[SFX]=true; // Force a volume update
@ -348,10 +355,10 @@ xmPlayingId CSoundMediator::playSfx(int _sfxId)
Params:
Returns:
---------------------------------------------------------------------- */
void CSoundMediator::stopSfx(xmPlayingId _id)
void CSoundMediator::stopSfx(xmPlayingId _playingId)
{
s_xmplaySound->stopPlayingId(_id);
s_xmplaySound->unlockPlayingId(_id);
s_xmplaySound->stopPlayingId(_playingId);
s_xmplaySound->unlockPlayingId(_playingId);
}

View File

@ -95,7 +95,7 @@ public:
static void setSfxBank(SFXBANKID _bankId);
static xmPlayingId playSfx(int _sfxId);
// static void setposition(int _playId,vector pos );
static void stopSfx(xmPlayingId _id);
static void stopSfx(xmPlayingId _playingId);
// Speech interface
static void playSpeech(SpeechEquate _speech);

View File

@ -1,6 +1,6 @@
/*=========================================================================
spu.cpp
xmplay.cpp
Author: PKG
Created:
@ -42,31 +42,10 @@
Tyepdefs && Defines
------------------- */
#define MAX_XM_SONGS 5
#define MAX_XM_VABS 5
/*----------------------------------------------------------------------
Structure defintions
-------------------- */
typedef struct XMSong
{
unsigned char *m_xmData;
FileEquate m_file;
int m_refCount;
// refcount these!
};
static XMSong s_xmSongs[MAX_XM_SONGS];
typedef struct XMVab
{
int m_vabId;
FileEquate m_vhFile,m_vbFile;
int m_refCount;
};
static XMVab s_xmVabs[MAX_XM_VABS];
/*----------------------------------------------------------------------
Function Prototypes
------------------- */
@ -110,8 +89,8 @@ void CXMPlaySound::initialise()
// Clear internal data
for(i=0;i<MAX_XM_SONGS;i++)
{
XMSong *song=&s_xmSongs[i];
song->m_refCount=0;
XMMod *mod=&s_xmMods[i];
mod->m_refCount=0;
}
for(i=0;i<MAX_XM_VABS;i++)
{
@ -148,7 +127,6 @@ void CXMPlaySound::shutdown()
Params:
Returns:
---------------------------------------------------------------------- */
int spuflags[24];
void CXMPlaySound::think()
{
int i;
@ -161,9 +139,8 @@ void CXMPlaySound::think()
ch=m_spuChannelUse;
for(i=0;i<NUM_SPU_CHANNELS;i++)
{
//pkg tidy
// Only unlocked SFX need to be checked
if(ch->m_locked==false&&ch->m_useType==SFX)
// Only unlocked stuff needs to be checked
if(ch->m_locked==false&&ch->m_useType!=SILENT)
{
id=ch->m_playingId;
if(id!=-1)
@ -183,9 +160,6 @@ PAUL_DBGMSG("%d finished.. ( was on chnl %d )",id,i);
}
ch++;
}
for(i=0;i<24;i++)
spuflags[i]=m_spuChannelUse[i].m_useType;
}
@ -214,8 +188,6 @@ xmSampleId CXMPlaySound::loadSampleData(FileEquate _vhFe,FileEquate _vbFe)
}
}
// PKG - Can be neatened up a bit..
// Find next free vab slot
vabId=0;
vab=s_xmVabs;
@ -227,7 +199,6 @@ xmSampleId CXMPlaySound::loadSampleData(FileEquate _vhFe,FileEquate _vbFe)
VhPtr=(u8*)CFileIO::loadFile(_vhFe);
VbPtr=(u8*)CFileIO::loadFile(_vbFe);
vab->m_vabId=XM_VABInit(VhPtr,VbPtr);
//defragSpuMemory(); somewhere around here..
MemFree(VhPtr);
MemFree(VbPtr);
vab->m_vhFile=_vhFe;
@ -248,43 +219,41 @@ xmSampleId CXMPlaySound::loadSampleData(FileEquate _vhFe,FileEquate _vbFe)
Params:
Returns:
---------------------------------------------------------------------- */
xmModId CXMPlaySound::loadModData(FileEquate _songFe)
xmModId CXMPlaySound::loadModData(FileEquate _modFe)
{
int songId;
XMSong *song;
int modId;
XMMod *mod;
// Is the song already loaded?
song=s_xmSongs;
for(songId=0;songId<MAX_XM_SONGS;songId++)
// Is the mod already loaded?
mod=s_xmMods;
for(modId=0;modId<MAX_XM_SONGS;modId++)
{
if(song->m_refCount&&song->m_file==_songFe)
if(mod->m_refCount&&mod->m_file==_modFe)
{
// Yup..
song->m_refCount++;
return(xmModId)songId;
mod->m_refCount++;
return(xmModId)modId;
}
}
// PKG - Can be neatened up a bit..
// Find next free song slot
song=s_xmSongs;
songId=0;
mod=s_xmMods;
modId=0;
while(1)
{
ASSERT(songId<MAX_XM_SONGS);
if(song->m_refCount==0)
ASSERT(modId<MAX_XM_SONGS);
if(mod->m_refCount==0)
{
song->m_xmData=(u8*)CFileIO::loadFile(_songFe);
InitXMData(song->m_xmData,songId,XM_UseS3MPanning);
song->m_file=_songFe;
song->m_refCount=1;
mod->m_xmData=(u8*)CFileIO::loadFile(_modFe);
InitXMData(mod->m_xmData,modId,XM_UseS3MPanning);
mod->m_file=_modFe;
mod->m_refCount=1;
break;
}
songId++;song++;
modId++;mod++;
}
return (xmModId)songId;
return (xmModId)modId;
}
@ -313,15 +282,15 @@ void CXMPlaySound::dumpSampleData(xmSampleId _sampleId)
Params:
Returns:
---------------------------------------------------------------------- */
void CXMPlaySound::dumpModData(xmModId _songId)
void CXMPlaySound::dumpModData(xmModId _modId)
{
XMSong *song;
XMMod *mod;
song=&s_xmSongs[_songId];
song->m_refCount--;
if(song->m_refCount==0)
mod=&s_xmMods[_modId];
mod->m_refCount--;
if(mod->m_refCount==0)
{
MemFree(song->m_xmData);
MemFree(mod->m_xmData);
}
}
@ -347,9 +316,9 @@ void CXMPlaySound::setStereo(int _stereo)
Params:
Returns:
---------------------------------------------------------------------- */
void CXMPlaySound::setVolume(xmPlayingId _songId,unsigned char _volume)
void CXMPlaySound::setVolume(xmPlayingId _playingId,unsigned char _volume)
{
XM_SetMasterVol(_songId,_volume>>1);
XM_SetMasterVol(_playingId,_volume>>1);
}
@ -359,9 +328,9 @@ void CXMPlaySound::setVolume(xmPlayingId _songId,unsigned char _volume)
Params:
Returns:
---------------------------------------------------------------------- */
void CXMPlaySound::setPanning(xmPlayingId _songId,char _pan)
void CXMPlaySound::setPanning(xmPlayingId _playingId,char _pan)
{
XM_SetMasterPan(_songId,_pan);
XM_SetMasterPan(_playingId,_pan);
}
@ -379,7 +348,7 @@ xmPlayingId CXMPlaySound::playSong(xmSampleId _sampleId,xmModId _songId,int _cha
xmPlayingId retId;
ASSERT(s_xmVabs[_sampleId].m_refCount!=0);
ASSERT(s_xmSongs[_songId].m_refCount!=0);
ASSERT(s_xmMods[_songId].m_refCount!=0);
baseChannel=findSpareChannels(_channelCount,255);
if(baseChannel!=-1)
@ -444,9 +413,6 @@ PAUL_DBGMSG("unlocking %d",_playingId);
---------------------------------------------------------------------- */
void CXMPlaySound::stopPlayingId(xmPlayingId _playingId)
{
// ASSERT(m_spuChannelUse[_playingId].m_locked!=true); // Unlock channel first!
int i;
spuChannelUse *ch;
@ -507,7 +473,7 @@ xmPlayingId CXMPlaySound::playSfx(xmSampleId _sampleId,xmModId _songId,int _sfxP
xmPlayingId retId;
ASSERT(s_xmVabs[_sampleId].m_refCount!=0);
ASSERT(s_xmSongs[_songId].m_refCount!=0);
ASSERT(s_xmMods[_songId].m_refCount!=0);
// Count channels
maskCopy=_playMask;
@ -634,32 +600,8 @@ int CXMPlaySound::findSpareChannels(int _channelCount,int _priority)
i=j;
}
/*
// Couldn't find one.. can we kill off a lower priority sound?
if(valid==false)
{
int lowestPrioity=_priority;
int possibleBase=-1;
int id;
// Find the lowest priority sound with enuf spare channels
i=0;
while(i<24)
{
if(m_spuChannelUse[i].m_priority<=lowestPriority&&m_spuChannelUse[j].m_useType!=SILENT)
{
valid=true;
id=m_spuChannelUse[i].m_id;
for(j=i;j<i+_channelCount&&valid;j++)
{
if(m_spuChannelUse[j].m_id!=id) valid=false;
}
// PKG - Add priority stuff here!!
}
i++;
}
}
*/
// Can't play it :(
return -1;
}

View File

@ -49,14 +49,14 @@ public:
void think();
xmSampleId loadSampleData(FileEquate _vhFe,FileEquate _vbFe);
xmModId loadModData(FileEquate _songFe);
xmModId loadModData(FileEquate _modFe);
void dumpSampleData(xmSampleId _sampleId);
void dumpModData(xmModId _songId);
void dumpModData(xmModId _modId);
void setStereo(int _stereo);
void setVolume(xmPlayingId _songId,unsigned char _volume);
void setPanning(xmPlayingId _songId,char _pan);
void setVolume(xmPlayingId _playingId,unsigned char _volume);
void setPanning(xmPlayingId _playingId,char _pan);
xmPlayingId playSong(xmSampleId _sampleId,xmModId _songId,int _channelCount);
xmPlayingId playSfx(xmSampleId _sampleId,xmModId _songId,int _sfxPattern,int _playMask,u8 _priority);
@ -69,8 +69,11 @@ public:
private:
enum
{
MAX_XM_HEADERS=8,
MAX_SONG_HEADERS=24,
MAX_XM_SONGS=5, // How many mods our internal loader copes with
MAX_XM_VABS=5, // How many vabs our internal loader copes with
MAX_SONG_HEADERS=24, // Number of mods that xmplay can play at once
MAX_XM_HEADERS=MAX_XM_SONGS, // Number of mods that xmplay can load at once
NUM_SPU_CHANNELS=24,
};
@ -83,10 +86,28 @@ private:
LOOPINGSFX,
} CHANNELUSETYPE;
// Internal representation of loaded songs
typedef struct XMMod
{
unsigned char *m_xmData;
FileEquate m_file;
int m_refCount;
// refcount these!
};
// Internal representation of loaded vabs
typedef struct XMVab
{
int m_vabId;
FileEquate m_vhFile,m_vbFile;
int m_refCount;
};
// Structure that records what is going on for each SPU channel
typedef struct
{
CHANNELUSETYPE m_useType;
xmPlayingId m_playingId; // extern id
xmPlayingId m_playingId;
u8 m_internalId;
u8 m_priority;
u8 m_locked;
@ -100,6 +121,8 @@ private:
unsigned char *m_fhPtr[MAX_XM_HEADERS];
unsigned char *m_songPtr[MAX_SONG_HEADERS];
XMMod s_xmMods[MAX_XM_SONGS];
XMVab s_xmVabs[MAX_XM_VABS];
spuChannelUse m_spuChannelUse[NUM_SPU_CHANNELS];
};