int spos;\r
int sinc;\r
\r
- unsigned char * pStart; // start ptr into sound mem\r
unsigned char * pCurr; // current pos in sound mem\r
unsigned char * pLoop; // loop ptr in sound mem\r
\r
unsigned int bStop:1; // is channel stopped (sample _can_ still be playing, ADSR Release phase)\r
unsigned int bReverb:1; // can we do reverb on this channel? must have ctrl register bit, to get active\r
- unsigned int bIgnoreLoop:1; // ignore loop bit, if an external loop address is used\r
unsigned int bRVBActive:1; // reverb active flag\r
unsigned int bNoise:1; // noise active flag\r
unsigned int bFMod:2; // freq mod (0=off, 1=sound channel, 2=freq channel)\r
\r
- int iActFreq; // current psx pitch\r
- int iUsedFreq; // current pc pitch\r
int iLeftVolume; // left volume\r
int iRightVolume; // right volume\r
ADSRInfoEx ADSRX;\r
#include "externals.h"\r
#include "registers.h"\r
#include "spu.h"\r
-#include "regs.h"\r
\r
////////////////////////////////////////////////////////////////////////\r
// freeze structs\r
d->spos = s->spos;\r
d->sinc = s->sinc;\r
memcpy(d->SB, s->SB, sizeof(d->SB));\r
- d->pStart = s->pStart;\r
+ d->pStart = (unsigned char *)((regAreaGet(ch,6)&~1)<<3);\r
d->pCurr = s->pCurr;\r
d->pLoop = s->pLoop;\r
d->bOn = !!(dwChannelOn & (1<<ch));\r
d->bStop = s->bStop;\r
d->bReverb = s->bReverb;\r
- d->iActFreq = s->iActFreq;\r
- d->iUsedFreq = s->iUsedFreq;\r
+ d->iActFreq = 1;\r
+ d->iUsedFreq = 2;\r
d->iLeftVolume = s->iLeftVolume;\r
- d->bIgnoreLoop = s->bIgnoreLoop;\r
+ d->bIgnoreLoop = 0;\r
d->iRightVolume = s->iRightVolume;\r
d->iRawPitch = s->iRawPitch;\r
d->s_1 = s->SB[27]; // yes it's reversed\r
d->spos = s->spos;\r
d->sinc = s->sinc;\r
memcpy(d->SB, s->SB, sizeof(d->SB));\r
- d->pStart = (void *)((long)s->pStart & 0x7fff0);\r
d->pCurr = (void *)((long)s->pCurr & 0x7fff0);\r
d->pLoop = (void *)((long)s->pLoop & 0x7fff0);\r
if (s->bOn) dwChannelOn |= 1<<ch;\r
d->bStop = s->bStop;\r
d->bReverb = s->bReverb;\r
- d->iActFreq = s->iActFreq;\r
- d->iUsedFreq = s->iUsedFreq;\r
d->iLeftVolume = s->iLeftVolume;\r
- d->bIgnoreLoop = s->bIgnoreLoop;\r
d->iRightVolume = s->iRightVolume;\r
d->iRawPitch = s->iRawPitch;\r
d->bRVBActive = s->bRVBActive;\r
for(i=0;i<MAXCHAN;i++)\r
{\r
save_channel(&pFO->s_chan[i],&s_chan[i],i);\r
- if(pFO->s_chan[i].pStart)\r
- pFO->s_chan[i].pStart-=(unsigned long)spuMemC;\r
if(pFO->s_chan[i].pCurr)\r
pFO->s_chan[i].pCurr-=(unsigned long)spuMemC;\r
if(pFO->s_chan[i].pLoop)\r
{\r
load_channel(&s_chan[i],&pFO->s_chan[i],i);\r
\r
- s_chan[i].pStart+=(unsigned long)spuMemC;\r
s_chan[i].pCurr+=(unsigned long)spuMemC;\r
s_chan[i].pLoop+=(unsigned long)spuMemC;\r
}\r
{\r
s_chan[i].bStop=0;\r
s_chan[i].pLoop=spuMemC;\r
- s_chan[i].pStart=spuMemC;\r
- s_chan[i].pLoop=spuMemC;\r
}\r
\r
dwNewChannel=0;\r
\r
#include "externals.h"\r
#include "registers.h"\r
-#include "regs.h"\r
\r
/*\r
// adsr time values (in ms) by James Higgs ... see the end of\r
#define SUSTAIN_MS 441L\r
#define RELEASE_MS 437L\r
\r
+static void SoundOn(int start,int end,unsigned short val);\r
+static void SoundOff(int start,int end,unsigned short val);\r
+static void FModOn(int start,int end,unsigned short val);\r
+static void NoiseOn(int start,int end,unsigned short val);\r
+static void SetVolumeL(unsigned char ch,short vol);\r
+static void SetVolumeR(unsigned char ch,short vol);\r
+static void SetPitch(int ch,unsigned short val);\r
+static void ReverbOn(int start,int end,unsigned short val);\r
+\r
////////////////////////////////////////////////////////////////////////\r
// WRITE REGISTERS: called by main emu\r
////////////////////////////////////////////////////////////////////////\r
break;\r
//------------------------------------------------// start\r
case 6: \r
- // Brain Dead 13 - align to 16 boundary\r
- s_chan[ch].pStart= spuMemC+(unsigned long)((val<<3)&~0xf);\r
+ // taken from regArea later\r
break;\r
//------------------------------------------------// level with pre-calcs\r
case 8:\r
break;\r
//------------------------------------------------//\r
case 14: // loop?\r
- //WaitForSingleObject(s_chan[ch].hMutex,2000); // -> no multithread fuckups\r
- s_chan[ch].pLoop=spuMemC+((unsigned long)((val<<3)&~0xf));\r
- //s_chan[ch].bIgnoreLoop=1;\r
- //ReleaseMutex(s_chan[ch].hMutex); // -> oki, on with the thread\r
- dwChannelDead&=~(1<<ch);\r
+ s_chan[ch].pLoop=spuMemC+((val&~1)<<3);\r
break;\r
//------------------------------------------------//\r
}\r
// SOUND ON register write\r
////////////////////////////////////////////////////////////////////////\r
\r
-void SoundOn(int start,int end,unsigned short val) // SOUND ON PSX COMAND\r
+static void SoundOn(int start,int end,unsigned short val)\r
{\r
int ch;\r
\r
{\r
if((val&1) && regAreaGet(ch,6)) // mmm... start has to be set before key on !?!\r
{\r
- s_chan[ch].bIgnoreLoop=0;\r
-\r
// do this here, not in StartSound\r
// - fixes fussy timing issues\r
s_chan[ch].bStop=0;\r
// SOUND OFF register write\r
////////////////////////////////////////////////////////////////////////\r
\r
-void SoundOff(int start,int end,unsigned short val) // SOUND OFF PSX COMMAND\r
+static void SoundOff(int start,int end,unsigned short val)\r
{\r
int ch;\r
for(ch=start;ch<end;ch++,val>>=1) // loop channels\r
// FMOD register write\r
////////////////////////////////////////////////////////////////////////\r
\r
-void FModOn(int start,int end,unsigned short val) // FMOD ON PSX COMMAND\r
+static void FModOn(int start,int end,unsigned short val)\r
{\r
int ch;\r
\r
// NOISE register write\r
////////////////////////////////////////////////////////////////////////\r
\r
-void NoiseOn(int start,int end,unsigned short val) // NOISE ON PSX COMMAND\r
+static void NoiseOn(int start,int end,unsigned short val)\r
{\r
int ch;\r
\r
// please note: sweep and phase invert are wrong... but I've never seen\r
// them used\r
\r
-void SetVolumeL(unsigned char ch,short vol) // LEFT VOLUME\r
+static void SetVolumeL(unsigned char ch,short vol) // LEFT VOLUME\r
{\r
if(vol&0x8000) // sweep?\r
{\r
// RIGHT VOLUME register write\r
////////////////////////////////////////////////////////////////////////\r
\r
-void SetVolumeR(unsigned char ch,short vol) // RIGHT VOLUME\r
+static void SetVolumeR(unsigned char ch,short vol) // RIGHT VOLUME\r
{\r
if(vol&0x8000) // comments... see above :)\r
{\r
// PITCH register write\r
////////////////////////////////////////////////////////////////////////\r
\r
-void SetPitch(int ch,unsigned short val) // SET PITCH\r
+static void SetPitch(int ch,unsigned short val) // SET PITCH\r
{\r
int NP;\r
if(val>0x3fff) NP=0x3fff; // get pitch val\r
else NP=val;\r
\r
s_chan[ch].iRawPitch=NP;\r
-\r
- NP=(44100L*NP)/4096L; // calc frequency\r
- if(NP<1) NP=1; // some security\r
- s_chan[ch].iActFreq=NP; // store frequency\r
+ s_chan[ch].sinc=(NP<<4)|8;\r
+ if(iUseInterpolation==1) s_chan[ch].SB[32]=1; // -> freq change in simple interpolation mode: set flag\r
}\r
\r
////////////////////////////////////////////////////////////////////////\r
// REVERB register write\r
////////////////////////////////////////////////////////////////////////\r
\r
-void ReverbOn(int start,int end,unsigned short val) // REVERB ON PSX COMMAND\r
+static void ReverbOn(int start,int end,unsigned short val)\r
{\r
int ch;\r
\r
\r
#define STAT_IRQ 0x40\r
\r
+///////////////////////////////////////////////////////////\r
+\r
+void CALLBACK SPUwriteRegister(unsigned long reg, unsigned short val);\r
+\r
+++ /dev/null
-/***************************************************************************\r
- regs.h - description\r
- -------------------\r
- begin : Wed May 15 2002\r
- copyright : (C) 2002 by Pete Bernert\r
- email : BlackDove@addcom.de\r
- ***************************************************************************/\r
-/***************************************************************************\r
- * *\r
- * This program is free software; you can redistribute it and/or modify *\r
- * it under the terms of the GNU General Public License as published by *\r
- * the Free Software Foundation; either version 2 of the License, or *\r
- * (at your option) any later version. See also the license.txt file for *\r
- * additional informations. *\r
- * *\r
- ***************************************************************************/\r
-\r
-void SoundOn(int start,int end,unsigned short val);\r
-void SoundOff(int start,int end,unsigned short val);\r
-void FModOn(int start,int end,unsigned short val);\r
-void NoiseOn(int start,int end,unsigned short val);\r
-void SetVolumeL(unsigned char ch,short vol);\r
-void SetVolumeR(unsigned char ch,short vol);\r
-void SetPitch(int ch,unsigned short val);\r
-void ReverbOn(int start,int end,unsigned short val);\r
-void CALLBACK SPUwriteRegister(unsigned long reg, unsigned short val);\r
-\r
#include "registers.h"
#include "cfg.h"
#include "dsoundoss.h"
-#include "regs.h"
#ifdef ENABLE_NLS
#include <libintl.h>
// ALL KIND OF HELPERS
////////////////////////////////////////////////////////////////////////
-INLINE void VoiceChangeFrequency(int ch)
-{
- s_chan[ch].iUsedFreq=s_chan[ch].iActFreq; // -> take it and calc steps
- s_chan[ch].sinc=s_chan[ch].iRawPitch<<4;
- if(!s_chan[ch].sinc) s_chan[ch].sinc=1;
- if(iUseInterpolation==1) s_chan[ch].SB[32]=1; // -> freq change in simle imterpolation mode: set flag
-}
-
-////////////////////////////////////////////////////////////////////////
-
INLINE int FModChangeFrequency(int ch,int ns)
{
- int NP=s_chan[ch].iRawPitch;
+ unsigned int NP=s_chan[ch].iRawPitch;
int sinc;
NP=((32768L+iFMod[ns])*NP)/32768L;
if(NP>0x3fff) NP=0x3fff;
if(NP<0x1) NP=0x1;
- NP=(44100L*NP)/(4096L); // calc frequency
-
- s_chan[ch].iActFreq=NP;
- s_chan[ch].iUsedFreq=NP;
- sinc=(((NP/10)<<16)/4410);
- if(!sinc) sinc=1;
+ sinc=NP<<4; // calc frequency
if(iUseInterpolation==1) // freq change in simple interpolation mode
s_chan[ch].SB[32]=1;
iFMod[ns]=0;
int flags = start[1];
int ret = 0;
- // Tron Bonne hack, probably wrong (could be wrong memory contents..)
- if(flags & ~7) flags = 0;
-
if(start == pSpuIrq)
{
do_irq();
if(dwNewChannel&(1<<ch)) StartSound(ch); // start new sound
if(!(dwChannelOn&(1<<ch))) continue; // channel not playing? next
- if(s_chan[ch].iActFreq!=s_chan[ch].iUsedFreq) // new psx frequency?
- VoiceChangeFrequency(ch);
-
if(s_chan[ch].bNoise)
d=do_samples_noise(ch, ns_from, ns_to);
else if(s_chan[ch].bFMod==2 || (s_chan[ch].bFMod==0 && iUseInterpolation==0))
if(s_chan[ch].pCurr > pSpuIrq && s_chan[ch].pLoop > pSpuIrq)
continue;
- if(s_chan[ch].iActFreq!=s_chan[ch].iUsedFreq) // new psx frequency?
- VoiceChangeFrequency(ch);
-
s_chan[ch].spos += s_chan[ch].sinc * NSSIZE;
while(s_chan[ch].spos >= 28 * 0x10000)
{
- unsigned char *start=s_chan[ch].pCurr;
+ unsigned char *start = s_chan[ch].pCurr;
// no need for bIRQReturn since the channel is silent
iSpuAsyncWait |= skip_block(ch);
if(start == s_chan[ch].pCurr)
{
// looping on self
- dwChannelDead|=1<<ch;
+ dwChannelDead |= 1<<ch;
+ s_chan[ch].spos = 0;
break;
}
// s_chan[i].hMutex=CreateMutex(NULL,FALSE,NULL);
s_chan[i].ADSRX.SustainLevel = 0xf; // -> init sustain
s_chan[i].pLoop=spuMemC;
- s_chan[i].pStart=spuMemC;
s_chan[i].pCurr=spuMemC;
}