This commit is contained in:
Paul 2000-10-12 15:18:47 +00:00
parent 27b7ee5531
commit aad1689a44
7 changed files with 187 additions and 168 deletions

View File

@ -139,6 +139,7 @@ int pkill=0;
int mvol=10;
int svol=255;
VECTOR ppos;
int psp=0;
void CPaulScene::think()
{
@ -174,9 +175,11 @@ void CPaulScene::think()
}
if(pad&PAD_START)
{
PAUL_DBGMSG("stop loopers..");
CSoundMediator::stopSfx((xmPlayingId)ploopid1);
CSoundMediator::stopSfx((xmPlayingId)ploopid2);
// PAUL_DBGMSG("stop loopers..");
// CSoundMediator::stopSfx((xmPlayingId)ploopid1);
// CSoundMediator::stopSfx((xmPlayingId)ploopid2);
PAUL_DBGMSG("speech..\n");
CSoundMediator::playSpeech((SpeechEquate)psp);
}
if(pad&PAD_R2)
{
@ -218,12 +221,12 @@ void CPaulScene::think()
if(svol<CSoundMediator::MIN_VOLUME)svol=CSoundMediator::MIN_VOLUME;
setSfxVolume=true;
}
if(setSongVolume) CSoundMediator::setVolume(CSoundMediator::SONG,mvol);
if(setSongVolume) CSoundMediator::setVolume(CSoundMediator::SPEECH,mvol);
if(setSfxVolume) CSoundMediator::setVolume(CSoundMediator::SFX,svol);
if(setSongVolume||setSfxVolume)
{
PAUL_DBGMSG("song:%d sfx:%d",mvol,svol);
PAUL_DBGMSG("speech:%d sfx:%d",mvol,svol);
}
//CXAStream::ControlXA();

View File

@ -32,21 +32,28 @@
#endif
/*****************************************************************************/
XA_MODE CXAStream::Mode=XA_MODE_NOTINIT;
int CXAStream::Status;
int CXAStream::StartSector;
sXAStream CXAStream::Stream[XA_STREAM_MAX];
int CXAStream::CurrentStream;
int CXAStream::PauseFlag;
CXAStream::XA_MODE CXAStream::Mode=XA_MODE_NOTINIT;
int CXAStream::Status;
int CXAStream::StartSector;
CXAStream::sXAStream CXAStream::Stream[XA_STREAM_MAX];
int CXAStream::CurrentStream;
int CXAStream::PauseFlag;
// Speech
SpeechEquate CXAStream::Queue[XA_QUEUE_MAX];
u16 CXAStream::QueueCount;
SpeechEquate CXAStream::Queue[XA_QUEUE_MAX];
u16 CXAStream::QueueCount;
// Volume
int CXAStream::s_masterVolumeL=XA_DEFAULT_VOL;
int CXAStream::s_masterVolumeR=XA_DEFAULT_VOL;
/*****************************************************************************/
/*****************************************************************************/
/*****************************************************************************/
void XACDReadyCallback(int Intr, u8 *Result)
void CXAStream::XACDReadyCallback(int Intr, u8 *Result)
{
static int ErrorRetry;
u32 XABuffer[8];
@ -226,7 +233,7 @@ sXAStream &ThisStream=Stream[CurrentStream];
break;
case XA_MODE_PLAY:
if (Status==CdlDiskError) Mode=XA_MODE_RESUME;
SetVolume(XA_DEFAULT_VOL,XA_DEFAULT_VOL);
SetVolume(s_masterVolumeL,s_masterVolumeL);
break;
case XA_MODE_END:
SetVolumeOff();
@ -292,26 +299,15 @@ void CXAStream::SetVolume(s32 LVol,s32 RVol)
{
CdlATV CDVol;
SpuCommonAttr Attr;
//int VolumeSetting;
//
// if (CurrentStream==XA_STREAM_SPEECH)
// VolumeSetting=CSfxFactory::SNDVOL_SFX;
// else
// VolumeSetting=CSfxFactory::SNDVOL_MUSIC;
//
// LVol=(LVol*CSfxFactory::getVolumeLevel(VolumeSetting))/256;
// RVol=(RVol*CSfxFactory::getVolumeLevel(VolumeSetting))/256;
Attr.mask = (SPU_COMMON_CDVOLL|SPU_COMMON_CDVOLR|SPU_COMMON_CDMIX);
Attr.cd.volume.left =LVol;
Attr.cd.volume.right=RVol;
Attr.cd.mix=SPU_ON;
SpuSetCommonAttr(&Attr);
CDVol.val0 = 127; // CdL -> SpuL
CDVol.val1 = 127; // CdL -> SpuR
CDVol.val2 = 127; // CdR -> SpuR
CDVol.val3 = 127; // CdR -> SpuL
CdMix(&CDVol);
SpuSetCommonCDVolume(LVol,RVol);
SpuSetCommonCDMix(SPU_ON);
CDVol.val0 = 127; // CdL -> SpuL
CDVol.val1 = 127; // CdL -> SpuR
CDVol.val2 = 127; // CdR -> SpuR
CDVol.val3 = 127; // CdR -> SpuL
CdMix(&CDVol);
}
/*****************************************************************************/
@ -319,23 +315,25 @@ void CXAStream::SetVolumeOff()
{
CdlATV CDVol;
SpuCommonAttr Attr;
// SsSetSerialVol(SS_SERIAL_A,0,0);
// Attr.mask = (SPU_COMMON_CDVOLL|SPU_COMMON_CDVOLR|SPU_COMMON_CDMIX);
// Attr.cd.volume.left =0;
// Attr.cd.volume.right=0;
// Attr.cd.mix=SPU_ON;
// SpuSetCommonAttr(&Attr);
SpuSetCommonCDVolume(0,0);
SpuSetCommonCDMix(SPU_ON);
SpuSetCommonCDVolume(0,0);
SpuSetCommonCDMix(SPU_ON);
CDVol.val0 = 0; // CdL -> SpuL
CDVol.val1 = 0; // CdL -> SpuR
CDVol.val2 = 0; // CdR -> SpuR
CDVol.val3 = 0; // CdR -> SpuL
CdMix(&CDVol);
CDVol.val0 = 0; // CdL -> SpuL
CDVol.val1 = 0; // CdL -> SpuR
CDVol.val2 = 0; // CdR -> SpuR
CDVol.val3 = 0; // CdR -> SpuL
CdMix(&CDVol);
}
/*****************************************************************************/
void CXAStream::setMasterVolume(int _volumeL,int _volumeR)
{
ASSERT(_volumeL>=MIN_VOLUME) ASSERT(_volumeL<=MAX_VOLUME);
ASSERT(_volumeR>=MIN_VOLUME) ASSERT(_volumeR<=MAX_VOLUME);
s_masterVolumeL=_volumeL;
s_masterVolumeR=_volumeR;
}

View File

@ -9,104 +9,113 @@
#include "sound/Speech.h"
/*****************************************************************************/
enum XA_ENUM
{
XA_MUSIC_TRACK =1,
XA_SPEECH_TRACK =2,
XA_QUEUE_MAX =8,
XA_TRACK_MAX =32,
XA_DEFAULT_VOL =32000,
XA_CHANNEL_SHIFT =16,
XA_CHANNEL_MASK =(0xffffffff<<XA_CHANNEL_SHIFT),
XA_SPEECH_MASK =(0xffffffff-XA_CHANNEL_MASK),
};
enum XA_STREAMS
{
XA_STREAM_MUSIC=0,
XA_STREAM_SPEECH,
XA_STREAM_MAX
};
/*****************************************************************************/
enum XA_MODE
{
XA_MODE_NOTINIT=-1,
XA_MODE_IDLE=0,
XA_MODE_START,
XA_MODE_PLAY,
XA_MODE_END,
XA_MODE_PAUSE,
XA_MODE_RESUME,
XA_MODE_STOP,
};
struct sXAEntry
{
u32 Channel;
u32 StartSector,CurrentSector;
s32 LVol,RVol;
};
struct sXAStream
{
int BaseChannel;
sXAEntry Entry;
// int Volume;
CdlLOC CDPos;
} ;
/*
struct sXAStream
{
int BaseChannel,Channel;
// int Volume;
int CurrentSector;
CdlLOC CDPos;
} ;
*/
/*****************************************************************************/
class CXAStream
{
public:
enum
{
MIN_VOLUME=0,
MAX_VOLUME=0x7fff,
};
CXAStream(){};
~CXAStream(){};
static void Init();
static void Start(int Str,u32 Sector,u32 Channel,s32 LVol,s32 RVol);
static void Stop();
static void Init();
static void Start(int Str,u32 Sector,u32 Channel,s32 LVol,s32 RVol);
static void Stop();
static void PlayMusic(u32 Track);
static void StopMusic() {Stop();}
static void PlaySpeech(SpeechEquate SpeechNo,int ForcePlay=0);
static void StopSpeech() {Stop();}
static void PlayMusic(u32 Track);
static void PlaySpeech(SpeechEquate SpeechNo,int ForcePlay=0);
static void ControlXA();
static void SetVolumeOff();
static void SetVolume(s32 LVol,s32 RVol);
static void Interrupt();
static void Pause();
static void Resume();
static void SetSector(u32 Sector) {StartSector=Sector;}
static void SetLanguage(int Lang) {Stream[XA_STREAM_SPEECH].BaseChannel=XA_SPEECH_TRACK+Lang;}
static void ControlXA();
static int IsPlaying() {return(Mode==XA_MODE_PLAY);}
static void Reset();
static int IsPlaying() {return(Mode==XA_MODE_PLAY);}
static XA_MODE Mode;
static int Status;
static int StartSector;
static sXAStream Stream[XA_STREAM_MAX];
static int CurrentStream;
static int PauseFlag;
static void setMasterVolume(int _volumeL,int _volumeR);
static int CurrentChannel;
private:
enum XA_ENUM
{
XA_MUSIC_TRACK =1,
XA_SPEECH_TRACK =2,
XA_QUEUE_MAX =8,
XA_TRACK_MAX =32,
XA_DEFAULT_VOL =32000,
XA_CHANNEL_SHIFT =16,
XA_CHANNEL_MASK =(0xffffffff<<XA_CHANNEL_SHIFT),
XA_SPEECH_MASK =(0xffffffff-XA_CHANNEL_MASK),
};
// Speech
static SpeechEquate Queue[XA_QUEUE_MAX];
static u16 QueueCount;
static int SpeechChannel;
enum XA_STREAMS
{
XA_STREAM_MUSIC=0,
XA_STREAM_SPEECH,
XA_STREAM_MAX
};
enum XA_MODE
{
XA_MODE_NOTINIT=-1,
XA_MODE_IDLE=0,
XA_MODE_START,
XA_MODE_PLAY,
XA_MODE_END,
XA_MODE_PAUSE,
XA_MODE_RESUME,
XA_MODE_STOP,
};
struct sXAEntry
{
u32 Channel;
u32 StartSector,CurrentSector;
s32 LVol,RVol;
};
struct sXAStream
{
int BaseChannel;
sXAEntry Entry;
CdlLOC CDPos;
} ;
static void SetVolumeOff();
static void SetVolume(s32 LVol,s32 RVol);
static void Interrupt();
static void Pause();
static void Resume();
static void SetSector(u32 Sector) {StartSector=Sector;}
static void SetLanguage(int Lang) {Stream[XA_STREAM_SPEECH].BaseChannel=XA_SPEECH_TRACK+Lang;}
static void Reset();
static XA_MODE Mode;
static int Status;
static int StartSector;
static sXAStream Stream[XA_STREAM_MAX];
static int CurrentStream;
static int PauseFlag;
static int CurrentChannel;
// Speech
static SpeechEquate Queue[XA_QUEUE_MAX];
static u16 QueueCount;
static int SpeechChannel;
static int s_masterVolumeL,s_masterVolumeR;
static void XACDReadyCallback(int Intr, u8 *Result);
};

View File

@ -140,8 +140,9 @@ void CSoundMediator::initialise()
s_targetVolume[i]=INITIAL_VOLUME;
s_volumeDirty[i]=true;
}
// ASSERT(CXAStream::MIN_VOLUME==0); // Just incase someone decides to change any of these.. things in here will break ( PKG )
// ASSERT(CXAStream::MAX_VOLUME==32767);
ASSERT(CXAStream::MIN_VOLUME==0); // Just incase someone decides to change any of these.. things in here will break ( PKG )
ASSERT(CXAStream::MAX_VOLUME==32767);
// Initial reverb settings
setReverbType(NONE);//ECHO_TEST);
@ -212,7 +213,7 @@ void CSoundMediator::think(int _frames)
}
// Update of anything that needs it
// CXAStream::ControlXA();
CXAStream::ControlXA();
s_xmplaySound->think();
@ -227,12 +228,12 @@ void CSoundMediator::think(int _frames)
s_xmplaySound->setMasterSfxVolume(s_currentVolume[SFX]);
s_volumeDirty[SFX]=false;
}
// if(s_volumeDirty[SPEECH])
// {
// int vol=s_currentVolume[SPEECH]<<7;
// CXAStream::SetVolume(vol,vol);
// s_volumeDirty[SPEECH]=false;
// }
if(s_volumeDirty[SPEECH])
{
int vol=s_currentVolume[SPEECH]<<7;
CXAStream::setMasterVolume(vol,vol);
s_volumeDirty[SPEECH]=false;
}
}
@ -414,13 +415,25 @@ void CSoundMediator::stopSfx(xmPlayingId _playingId)
---------------------------------------------------------------------- */
void CSoundMediator::playSpeech(SpeechEquate _speech)
{
// if(CXAStream::IsPlaying())
// CXAStream::Stop();
// CXAStream::PlaySpeech(_speech);
stopSpeech();
CXAStream::PlaySpeech(_speech);
// s_volumeDirty[SPEECH]=true; // Force a volume update
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CSoundMediator::stopSpeech()
{
if(CXAStream::IsPlaying())
CXAStream::Stop();
}
/*----------------------------------------------------------------------
Function:
Purpose:
@ -457,6 +470,7 @@ int CSoundMediator::getVolume(VOLUMETYPE _type)
void CSoundMediator::stopAllSound()
{
s_xmplaySound->stopAndUnlockAllSound();
CXAStream::Stop();
}

View File

@ -105,6 +105,7 @@ public:
// Speech interface
static void playSpeech(SpeechEquate _speech);
static void stopSpeech();
// Control
static void setVolume(VOLUMETYPE _type,int _val);

View File

@ -147,7 +147,7 @@ void CXMPlaySound::think()
PAUL_DBGMSG("=======");
for(int i=0;i<24;i++,ch++)
{
PAUL_DBGMSG("%02d] u:%s l:%d pid:%d",i,text[ch->m_useType],ch->m_locked,ch->m_playingId);
PAUL_DBGMSG("%02d] u:%s l:%d pid:%04x",i,text[ch->m_useType],ch->m_locked,ch->m_playingId);
}
PAUL_DBGMSG("=======");
dump=false;
@ -434,12 +434,12 @@ void CXMPlaySound::setStereo(int _stereo)
---------------------------------------------------------------------- */
void CXMPlaySound::setVolume(xmPlayingId _playingId,unsigned char _volume)
{
int i;
// int i;
spuChannelUse *ch;
int vol;
ch=m_spuChannelUse;
for(i=0;i<NUM_SPU_CHANNELS;i++,ch++)
ch=&m_spuChannelUse[_playingId&0xff];
// for(i=0;i<NUM_SPU_CHANNELS;i++,ch++)
{
if(ch->m_playingId==_playingId)
{
@ -464,12 +464,9 @@ void CXMPlaySound::setVolume(xmPlayingId _playingId,unsigned char _volume)
updateLoopingSfx(ch);
break;
// Shouldn't ever get a locked FREE channel!
case FREE:
ASSERT(0);
break;
case CONTINUE:
ASSERT(0);
break;
}
return;
@ -487,11 +484,11 @@ void CXMPlaySound::setVolume(xmPlayingId _playingId,unsigned char _volume)
---------------------------------------------------------------------- */
void CXMPlaySound::setPanning(xmPlayingId _playingId,char _pan)
{
int i;
// int i;
spuChannelUse *ch;
ch=m_spuChannelUse;
for(i=0;i<NUM_SPU_CHANNELS;i++,ch++)
ch=&m_spuChannelUse[_playingId&0xff];
// for(i=0;i<NUM_SPU_CHANNELS;i++,ch++)
{
if(ch->m_playingId==_playingId)
{
@ -514,12 +511,9 @@ void CXMPlaySound::setPanning(xmPlayingId _playingId,char _pan)
updateLoopingSfx(ch);
break;
// Shouldn't ever get a locked FREE channel!
case FREE:
ASSERT(0);
break;
case CONTINUE:
ASSERT(0);
break;
}
return;
@ -582,7 +576,7 @@ xmPlayingId CXMPlaySound::playSong(xmSampleId _sampleId,xmModId _modId)
baseChannel=findSpareChannels(channelCount,255);
if(baseChannel!=-1)
{
retId=getNextSparePlayingId();
retId=getNextSparePlayingId(baseChannel);
vab=&m_xmVabs[_sampleId];
id=XM_Init(vab->m_vabId, // id from XM_VABInit
_modId, // XM id ( as passed to InitXMData )
@ -644,20 +638,17 @@ void CXMPlaySound::unlockPlayingId(xmPlayingId _playingId)
---------------------------------------------------------------------- */
void CXMPlaySound::stopPlayingId(xmPlayingId _playingId)
{
int i;
// int i;
spuChannelUse *ch;
ch=m_spuChannelUse;
for(i=0;i<NUM_SPU_CHANNELS;i++,ch++)
ch=&m_spuChannelUse[_playingId&0xff];
// for(i=0;i<NUM_SPU_CHANNELS;i++,ch++)
{
if(ch->m_playingId==_playingId)
{
ASSERT(ch->m_locked!=false); // Cant stop unlocked channels!
switch(ch->m_useType)
{
case SILENT:
break;
case SONG:
case SFX:
{
@ -675,6 +666,7 @@ void CXMPlaySound::stopPlayingId(xmPlayingId _playingId)
XM_StopSample(ch->m_internalId);
break;
case SILENT:
case FREE:
case CONTINUE:
ASSERT(0);
@ -728,7 +720,7 @@ xmPlayingId CXMPlaySound::playSfx(xmSampleId _sampleId,xmModId _modId,int _sfxPa
baseChannel=findSpareChannels(channelCount,_priority);
if(baseChannel!=-1)
{
retId=getNextSparePlayingId();
retId=getNextSparePlayingId(baseChannel);
vab=&m_xmVabs[_sampleId];
XM_SetSFXRange(baseChannel,channelCount);
id=XM_Init(vab->m_vabId, // id from XM_VABInit
@ -767,7 +759,7 @@ xmPlayingId CXMPlaySound::playLoopingSfx(xmSampleId _sampleId,xmModId _modId,int
baseChannel=findSpareChannels(1,_priority);
if(baseChannel!=-1)
{
retId=getNextSparePlayingId();
retId=getNextSparePlayingId(baseChannel);
//PAUL_DBGMSG("playLoopingSfx %d/- ( on %d-%d )",retId,baseChannel,baseChannel);
XM_PlaySample(XM_GetSampleAddress(_sampleId,_soundId),baseChannel,0x3fff,0x3fff,_pitch);
markChannelsAsActive(baseChannel,1,LOOPINGSFX,retId,baseChannel,_priority);
@ -788,7 +780,7 @@ xmPlayingId CXMPlaySound::playLoopingSfx(xmSampleId _sampleId,xmModId _modId,int
Params:
Returns:
---------------------------------------------------------------------- */
xmPlayingId CXMPlaySound::getNextSparePlayingId()
xmPlayingId CXMPlaySound::getNextSparePlayingId(int _baseChannel)
{
xmPlayingId validId;
int i;
@ -802,7 +794,7 @@ xmPlayingId CXMPlaySound::getNextSparePlayingId()
nextId=(xmPlayingId)((nextId+1)&0xff); // gives 256 unique id numbers
// Is this id still in use?
validId=nextId;
validId=(xmPlayingId)((nextId<<8)+_baseChannel);
ch=m_spuChannelUse;
for(i=0;i<NUM_SPU_CHANNELS&&validId!=NOT_PLAYING;i++)
{

View File

@ -35,6 +35,8 @@
typedef enum {NO_SAMPLE=-1} xmSampleId;
typedef enum {NO_SONG=-1} xmModId;
typedef enum {NOT_PLAYING=-1} xmPlayingId;
// Note that a playing id is a 16 bit value. Top 8 bits are an ( effectively ) random number and the bottom
// 8 bits are the base channel of the playing sound.
/*----------------------------------------------------------------------
@ -132,7 +134,7 @@ private:
u8 m_vol,m_pan;
} spuChannelUse;
xmPlayingId getNextSparePlayingId();
xmPlayingId getNextSparePlayingId(int _baseChannel);
int findSpareChannels(int _channelCount,int _priority);
void markChannelsAsActive(int _baseChannel,int _channelCount,CHANNELUSETYPE _useType,xmPlayingId _playingId,int _internalId,u8 _priority);