diff --git a/source/paul/paul.cpp b/source/paul/paul.cpp index dddccb606..e6d9c2c4c 100644 --- a/source/paul/paul.cpp +++ b/source/paul/paul.cpp @@ -74,7 +74,8 @@ char *s_mem[3]; Params: Returns: ---------------------------------------------------------------------- */ -int ploopid=0; +int ploopid1=0; +int ploopid2=0; void CPaulScene::init() { s_fontBank.initialise(&standardFont); @@ -89,7 +90,8 @@ void CPaulScene::init() //CXAStream::Init(); PAUL_DBGMSG("initialised.."); - ploopid=CSoundMediator::playSfx(0); + ploopid1=CSoundMediator::playSfx(0); + ploopid2=CSoundMediator::playSfx(0); } @@ -172,14 +174,22 @@ void CPaulScene::think() } if(pad&PAD_START) { - PAUL_DBGMSG("stop %d",pkill); - CSoundMediator::stopSfx((xmPlayingId)pkill); + PAUL_DBGMSG("stop loopers.."); + CSoundMediator::stopSfx((xmPlayingId)ploopid1); + CSoundMediator::stopSfx((xmPlayingId)ploopid2); } if(pad&PAD_R2) { PAUL_DBGMSG("stop all"); CSoundMediator::stopAllSound(); } +#ifdef __USER_paul__ + if(pad&PAD_L2) + { + extern int dump; + dump=true; + } +#endif //CSoundMediator::setposition((xmPlayingId)ploopid,&ppos); diff --git a/source/sound/xmplay.cpp b/source/sound/xmplay.cpp index 62fc55a58..10cff744f 100644 --- a/source/sound/xmplay.cpp +++ b/source/sound/xmplay.cpp @@ -100,8 +100,13 @@ void CXMPlaySound::initialise() for(i=0;im_useType],ch->m_locked,ch->m_playingId); + } + PAUL_DBGMSG("======="); + dump=false; + } +#endif + int i; int id; spuChannelUse *ch; @@ -138,29 +161,54 @@ void CXMPlaySound::think() // Check to see if any of the sounds have finished id=-1; - ch=m_spuChannelUse; for(i=0;im_locked==false&&ch->m_useType!=SILENT) + ch=&m_spuChannelUse[i]; // I know! + switch(ch->m_useType) { - id=ch->m_playingId; - if(id!=-1) - { + // Silent and unlocked sounds can be freed + case SILENT: + if(!ch->m_locked) + { + do + { +PAUL_DBGMSG("freed channel %d ( %d )",i,ch->m_playingId); + ch->m_useType=FREE; +#ifdef __VERSION_DEBUG__ + ch->m_internalId=0; + ch->m_playingId=NOT_PLAYING; + ch->m_priority=0; + ch->m_locked=false; + ch->m_vol=MIN_VOLUME; + ch->m_pan=PAN_CENTRE; +#endif + ch++; + } + while(ch->m_useType==CONTINUE); + } + break; + + + // See if these have finished playing + case SONG: + case SFX: if(XM_GetFeedback(ch->m_internalId,&fb)) { - //PAUL_DBGMSG("%d finished.. ( was on chnl %d )",id,i); - while(ch->m_playingId==id&&im_useType=SILENT; ch++; - i++; } - ch--; + while(ch->m_useType==CONTINUE); } - } + break; + + case LOOPINGSFX: + case FREE: + case CONTINUE: + break; } - ch++; } } @@ -415,6 +463,14 @@ void CXMPlaySound::setVolume(xmPlayingId _playingId,unsigned char _volume) case LOOPINGSFX: updateLoopingSfx(ch); break; + + // Shouldn't ever get a locked FREE channel! + case FREE: + ASSERT(0); + break; + + case CONTINUE: + break; } return; } @@ -457,6 +513,14 @@ void CXMPlaySound::setPanning(xmPlayingId _playingId,char _pan) case LOOPINGSFX: updateLoopingSfx(ch); break; + + // Shouldn't ever get a locked FREE channel! + case FREE: + ASSERT(0); + break; + + case CONTINUE: + break; } return; } @@ -475,20 +539,21 @@ void CXMPlaySound::setPanning(xmPlayingId _playingId,char _pan) void CXMPlaySound::stopAndUnlockAllSound() { int i; - spuChannelUse *ch; + spuChannelUse *ch; ch=m_spuChannelUse; for(i=0;im_useType!=SILENT) + if(ch->m_useType==SONG|| + ch->m_useType==SFX|| + ch->m_useType==LOOPINGSFX) { - int oldLock=ch->m_locked; // hmm.. - ch->m_locked=true; // not too.. + ch->m_locked=true; // hmm.. not too ugly I suppose + setVolume(ch->m_playingId,0); stopPlayingId(ch->m_playingId); - ch->m_locked=oldLock; // ..ugly I suppose // Need to unlock too - if(oldLock)unlockPlayingId(ch->m_playingId); + unlockPlayingId(ch->m_playingId); } } } @@ -558,11 +623,12 @@ void CXMPlaySound::unlockPlayingId(xmPlayingId _playingId) { //PAUL_DBGMSG("unlocking %d",_playingId); ASSERT(ch->m_locked!=false); - while(ch->m_playingId==_playingId) + do { ch->m_locked=false; ch++; } + while(ch->m_useType==CONTINUE); return; } } @@ -593,23 +659,34 @@ void CXMPlaySound::stopPlayingId(xmPlayingId _playingId) break; case SONG: - XM_PlayStop(ch->m_internalId); - break; - case SFX: - XM_PlayStop(ch->m_internalId); + { + XM_Feedback fb; + do + { + XM_PlayStop(ch->m_internalId); + XM_GetFeedback(ch->m_internalId,&fb); + } + while(fb.Status!=XM_STOPPED); + } break; case LOOPINGSFX: XM_StopSample(ch->m_internalId); break; + + case FREE: + case CONTINUE: + ASSERT(0); + break; } - - while(ch->m_playingId==_playingId) + + do { ch->m_useType=SILENT; ch++; } + while(ch->m_useType==CONTINUE); return; } } @@ -750,7 +827,7 @@ int CXMPlaySound::findSpareChannels(int _channelCount,int _priority) { int i,j; int valid; - + // First we search for channels that are marked as unused valid=false; for(i=0;im_useType=_useType; + ch->m_internalId=_internalId; + ch->m_playingId=_playingId; + ch->m_priority=_priority; + ch->m_locked=true; + ch->m_vol=MAX_VOLUME; + ch->m_pan=PAN_CENTRE; + + ch++; + for(i=_baseChannel+1;i<_baseChannel+_channelCount;i++,ch++) + { + ch->m_useType=CONTINUE; +#ifdef __VERSION_DEBUG__ + ch->m_internalId=0; + ch->m_playingId=NOT_PLAYING; + ch->m_priority=0; + ch->m_locked=false; + ch->m_vol=MIN_VOLUME; + ch->m_pan=PAN_CENTRE; +#endif + } } diff --git a/source/sound/xmplay.h b/source/sound/xmplay.h index 5b40f64c0..0418a36f5 100644 --- a/source/sound/xmplay.h +++ b/source/sound/xmplay.h @@ -95,10 +95,13 @@ private: typedef enum { - SILENT, SONG, SFX, LOOPINGSFX, + + SILENT, // Channel is silent + FREE, // Channel is free for re-allocation + CONTINUE, // Channel is a continuation of the previous channel } CHANNELUSETYPE; // Internal representation of loaded mods