This commit is contained in:
Paul 2001-07-18 20:11:46 +00:00
parent 41b1bd58d1
commit 548fff4a27
4 changed files with 59 additions and 36 deletions

View File

@ -593,7 +593,7 @@ void CSoundMediator::setSfxBank(SFXBANKID _bankId)
same time as *lots* of other sfx.
Returns:
---------------------------------------------------------------------- */
xmPlayingId CSoundMediator::playSfx(SFXID _sfxId,int _lock=false)
xmPlayingId CSoundMediator::playSfx(SFXID _sfxId,int _lock=false,int _dontPlayIfSFXAlreadyAudible=false)
{
if(!s_canPlaySfx)
{
@ -609,6 +609,12 @@ xmPlayingId CSoundMediator::playSfx(SFXID _sfxId,int _lock=false)
// Play!
sfx=&s_sfxDetails[_sfxId];
if(_dontPlayIfSFXAlreadyAudible&&s_xmplaySound->isSfxPatternPlaying(sfx->m_pattern))
{
return NOT_PLAYING;
}
if(sfx->m_looping)
{
playId=s_xmplaySound->playLoopingSfx(s_sfxSampleId,s_sfxModId,sfx->m_pattern,10);

View File

@ -203,7 +203,7 @@ public:
// SFX interface
static void setSfxBank(SFXBANKID _bankId);
static xmPlayingId playSfx(SFXID _sfxId,int _lock=false);
static xmPlayingId playSfx(SFXID _sfxId,int _lock=false,int _dontPlayIfSFXAlreadyAudible=false);
static void setposition(xmPlayingId _playingId,VECTOR *pos);
static void stopAndUnlockSfx(xmPlayingId _playingId);
static void stopAllSfx();

View File

@ -163,15 +163,12 @@ void CXMPlaySound::think()
#ifdef __USER_paul__
if(dump)
{
static char *text[]={"SONG","SFX","LOOPINGSFX","SILENT","FREE","CONTINUE"};
static char *text[]={"SONG","SFX","LOOPINGSFX","SILENTSONG","SILENTSFX","FREE","CONTINUE"};
spuChannelUse *ch=m_spuChannelUse;
PAUL_DBGMSG("=======");
for(int i=0;i<24;i++,ch++)
{
PAUL_DBGMSG("%02d] u:%s l:%d pid:%04x",i,text[ch->m_useType],ch->m_locked,ch->m_playingId);
#ifdef SFX_DEBUG
PAUL_DBGMSG(" sfxId:%d",ch->m_sfxId);
#endif
PAUL_DBGMSG("%02d] u:%s l:%d pid:%04x sPtn:%03d",i,text[ch->m_useType],ch->m_locked,ch->m_playingId,ch->m_startPattern);
}
PAUL_DBGMSG("=======");
dump=false;
@ -191,7 +188,8 @@ void CXMPlaySound::think()
switch(ch->m_useType)
{
// Silent and unlocked sounds can be freed
case SILENT:
case SILENTSONG:
case SILENTSFX:
if(!ch->m_locked)
{
do
@ -208,11 +206,9 @@ void CXMPlaySound::think()
case SONG:
case SFX:
if(XM_GetFeedback(ch->m_internalId,&fb))
// XM_GetFeedback(ch->m_internalId,&fb);
// if(fb.Status==XM_STOPPED)
{
// Just mark it as silent, if it's unlocked then it'll die next frame
ch->m_useType=SILENT;
ch->m_useType=ch->m_useType==SFX?SILENTSFX:SILENTSONG;
// And kill it in the player
XM_Quit(ch->m_internalId);
@ -235,12 +231,13 @@ if(PadGetDown(1)&PAD_L1&&PadGetHeld(1)&(PAD_L2|PAD_R1|PAD_R2))
}
if(sounddebug)
{
static const int colours[6][3]=
static const int colours[7][3]=
{
{ 255,255,255 }, // SONG
{ 255, 0,255 }, // SFX
{ 0, 0,255 }, // LOOPINGSFX
{ 255,255, 0 }, // SILENT
{ 255,255, 0 }, // SILENTSONG
{ 255,255, 0 }, // SILENTSFX
{ 0,255, 0 }, // FREE
{ 128,128,128 }, // CONTINUE
};
@ -535,7 +532,8 @@ void CXMPlaySound::setVolume(xmPlayingId _playingId,unsigned char _volume)
ch->m_vol=_volume; // Update volume
switch(ch->m_useType)
{
case SILENT:
case SILENTSONG:
case SILENTSFX:
break;
case SONG:
@ -581,7 +579,8 @@ void CXMPlaySound::setPanning(xmPlayingId _playingId,char _pan)
ch->m_pan=_pan; // Update pan
switch(ch->m_useType)
{
case SILENT:
case SILENTSONG:
case SILENTSFX:
break;
case SONG:
@ -699,9 +698,7 @@ xmPlayingId CXMPlaySound::playSong(xmSampleId _sampleId,xmModId _modId,int _star
XM_Music, // Music
_startPattern); // Where to start from
markChannelsAsActive(baseChannel,channelCount,SONG,retId,id,255);
#ifdef SFX_DEBUG
m_spuChannelUse[baseChannel].m_sfxId=_startPattern;
#endif
m_spuChannelUse[baseChannel].m_startPattern=_startPattern;
setVolume(retId,MAX_VOLUME);
}
else
@ -726,7 +723,7 @@ int CXMPlaySound::isStillPlaying(xmPlayingId _playingId)
if(ch->m_playingId==_playingId)
{
ASSERT(ch->m_locked!=false); // Can't do this on an unlocked sound!
return ch->m_useType!=SILENT;
return ch->m_useType!=SILENTSFX&&ch->m_useType!=SILENTSONG;
}
ASSERT(0); // Couldn't find the sound to check it!
@ -734,6 +731,31 @@ int CXMPlaySound::isStillPlaying(xmPlayingId _playingId)
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
int CXMPlaySound::isSfxPatternPlaying(int _startPattern)
{
spuChannelUse *ch;
int i;
ch=m_spuChannelUse;
for(i=0;i<NUM_SPU_CHANNELS;i++)
{
if((ch->m_useType==SFX||ch->m_useType==SILENTSFX)&&ch->m_startPattern==_startPattern)
{
return true;
}
ch++;
}
return false;
}
/*----------------------------------------------------------------------
Function:
Purpose:
@ -777,16 +799,17 @@ void CXMPlaySound::stopPlayingId(xmPlayingId _playingId)
{
XM_PlayStop(ch->m_internalId);
XM_Quit(ch->m_internalId);
ch->m_useType=SILENT;
ch->m_useType=ch->m_useType==SFX?SILENTSFX:SILENTSONG;
}
break;
case LOOPINGSFX:
XM_StopSample(ch->m_internalId);
ch->m_useType=SILENT;
ch->m_useType=SILENTSFX;
break;
case SILENT:
case SILENTSONG:
case SILENTSFX:
break;
case FREE:
@ -849,9 +872,7 @@ xmPlayingId CXMPlaySound::playSfx(xmSampleId _sampleId,xmModId _modId,int _sfxPa
_sfxPattern); // SFX pattern to play
XM_ClearSFXRange();
markChannelsAsActive(baseChannel,channelCount,SFX,retId,id,_priority);
#ifdef SFX_DEBUG
m_spuChannelUse[baseChannel].m_sfxId=_sfxPattern;
#endif
m_spuChannelUse[baseChannel].m_startPattern=_sfxPattern;
setVolume(retId,MAX_VOLUME);
}
else
@ -915,8 +936,10 @@ xmPlayingId CXMPlaySound::getNextSparePlayingId(int _baseChannel)
ch=m_spuChannelUse;
for(i=0;i<NUM_SPU_CHANNELS&&validId!=NOT_PLAYING;i++)
{
if(ch->m_playingId==validId&&!(ch->m_locked==false&&ch->m_useType==SILENT))
if(ch->m_playingId==validId&&!(ch->m_locked==false&&(ch->m_useType==SILENTSONG||ch->m_useType==SILENTSFX)))
{
validId=NOT_PLAYING;
}
ch++;
}
}

View File

@ -39,12 +39,6 @@ typedef enum {NOT_PLAYING=-1} xmPlayingId;
// 8 bits are the base channel of the playing sound.
// Define this to store the SFX number in the channel details. Useful for finding tracing sounds
// that are being left locked
//#define SFX_DEBUG
/*----------------------------------------------------------------------
Structure defintions
-------------------- */
@ -87,6 +81,7 @@ public:
xmPlayingId playLoopingSfx(xmSampleId _sampleId,xmModId _modId,int _soundId,u8 _priority,int _pitch=0x400);
int isStillPlaying(xmPlayingId _playingId);
int isSfxPatternPlaying(int _startPattern);
void unlockPlayingId(xmPlayingId _playingId);
void stopPlayingId(xmPlayingId _playingId);
@ -110,7 +105,8 @@ private:
SFX,
LOOPINGSFX,
SILENT, // Channel is silent
SILENTSONG, // Channel is silent
SILENTSFX, // " " " "
FREE, // Channel is free for re-allocation
CONTINUE, // Channel is a continuation of the previous channel
} CHANNELUSETYPE;
@ -140,9 +136,7 @@ private:
u8 m_priority;
u8 m_locked;
u8 m_vol,m_pan;
#ifdef SFX_DEBUG
u8 m_sfxId;
#endif
u8 m_startPattern;
} spuChannelUse;
xmPlayingId getNextSparePlayingId(int _baseChannel);