Added support for PSG white noise.

This commit is contained in:
luigi__ 2009-01-29 14:34:28 +00:00
parent a87501a235
commit 18fa16d748
2 changed files with 1507 additions and 1467 deletions

View File

@ -223,6 +223,9 @@ void SPU_struct::reset()
memset((void *)channels, 0, sizeof(channel_struct) * 16);
memset(sndbuf,0,bufsize*2*4);
memset(outbuf,0,bufsize*2*2);
for(int i = 0; i < 16; i++)
channels[i].num = i;
}
SPU_struct::SPU_struct(int buffersize)
@ -291,6 +294,7 @@ void SPU_struct::KeyOn(int channel)
}
case 3: // PSG
{
thischan.x = 0x7FFF;
break;
}
default: break;
@ -721,9 +725,42 @@ static INLINE void FetchADPCMData(channel_struct *chan, s32 *data)
//////////////////////////////////////////////////////////////////////////////
static INLINE void FetchPSGData(channel_struct *chan, s32 *data)
{
if(chan->num < 8)
{
*data = 0;
}
else if(chan->num < 14)
{
*data = (s32)wavedutytbl[chan->waveduty][((int)chan->sampcnt) & 0x7];
}
else
{
if(chan->lastsampcnt == (int)chan->sampcnt)
{
*data = chan->psgnoise_last;
return;
}
for(int i = chan->lastsampcnt; i < (int)chan->sampcnt; i++)
{
if(chan->x & 0x1)
{
chan->x = (chan->x >> 1);
chan->psgnoise_last = -0x7FFF;
}
else
{
chan->x = ((chan->x >> 1) ^ 0x6000);
chan->psgnoise_last = 0x7FFF;
}
}
chan->lastsampcnt = (int)chan->sampcnt;
*data = chan->psgnoise_last;
}
}
//////////////////////////////////////////////////////////////////////////////

View File

@ -45,6 +45,7 @@ extern SoundInterface_struct SNDFile;
struct channel_struct
{
int num;
u8 vol;
u8 datashift;
u8 hold;
@ -65,6 +66,8 @@ struct channel_struct
int lastsampcnt;
s16 pcm16b, pcm16b_last;
int index;
u16 x;
s16 psgnoise_last;
} ;
class SPU_struct