aboutsummaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorNebuleon Fumika2013-01-12 03:08:07 -0500
committerNebuleon Fumika2013-01-12 03:08:07 -0500
commit4717df648553565d4ed657c455c8675ae55ac77e (patch)
treee6fac0793eeb3db3cc2febf4da8386e2d627d195 /source
parent40d30e35ca1e2198988347ac73e645e471a117aa (diff)
downloadsnesemu-4717df648553565d4ed657c455c8675ae55ac77e.tar.gz
snesemu-4717df648553565d4ed657c455c8675ae55ac77e.tar.bz2
snesemu-4717df648553565d4ed657c455c8675ae55ac77e.zip
Revert "Remove shifted envelope heights from the code, because one is always set from the other and the shifted height is not used in saved states."
This reverts commit e3bb4a5f62ab6b38eb1a58e700b7d713b4e397b0.
Diffstat (limited to 'source')
-rw-r--r--source/soundux.cpp40
-rw-r--r--source/soundux.h1
2 files changed, 24 insertions, 17 deletions
diff --git a/source/soundux.cpp b/source/soundux.cpp
index 6f41f64..8c7841b 100644
--- a/source/soundux.cpp
+++ b/source/soundux.cpp
@@ -385,6 +385,7 @@ void S9xFixSoundAfterSnapshotLoad ()
{
SoundData.channels[i].needs_decode = TRUE;
S9xSetSoundFrequency (i, SoundData.channels[i].hertz);
+ SoundData.channels [i].envxx = SoundData.channels [i].envx << ENVX_SHIFT;
SoundData.channels [i].next_sample = 0;
SoundData.channels [i].interpolate = 0;
SoundData.channels [i].previous [0] = (int32) SoundData.channels [i].previous16 [0];
@@ -442,6 +443,7 @@ void S9xSetEnvelopeHeight (int channel, int level)
Channel *ch = &SoundData.channels[channel];
ch->envx = level;
+ ch->envxx = level << ENVX_SHIFT;
ch->left_vol_level = (level * ch->volume_left) / 128;
ch->right_vol_level = (level * ch->volume_right) / 128;
@@ -942,17 +944,18 @@ void MixStereo (int sample_count)
if (ch->env_error >= FIXED_POINT)
{
uint32 step = ch->env_error >> FIXED_POINT_SHIFT;
- int32 envx_shifted;
switch (ch->state)
{
case SOUND_ATTACK:
ch->env_error &= FIXED_POINT_REMAINDER;
ch->envx += step << 1;
+ ch->envxx = ch->envx << ENVX_SHIFT;
if (ch->envx >= 126)
{
ch->envx = 127;
+ ch->envxx = 127 << ENVX_SHIFT;
ch->state = SOUND_DECAY;
if (ch->sustain_level != 8)
{
@@ -967,13 +970,12 @@ void MixStereo (int sample_count)
break;
case SOUND_DECAY:
- envx_shifted = ch->envx << ENVX_SHIFT;
while (ch->env_error >= FIXED_POINT)
{
- envx_shifted = (envx_shifted >> 8) * 255;
+ ch->envxx = (ch->envxx >> 8) * 255;
ch->env_error -= FIXED_POINT;
}
- ch->envx = envx_shifted >> ENVX_SHIFT;
+ ch->envx = ch->envxx >> ENVX_SHIFT;
if (ch->envx <= ch->envx_target)
{
if (ch->envx <= 0)
@@ -987,13 +989,12 @@ void MixStereo (int sample_count)
break;
case SOUND_SUSTAIN:
- envx_shifted = ch->envx << ENVX_SHIFT;
while (ch->env_error >= FIXED_POINT)
{
- envx_shifted = (envx_shifted >> 8) * 255;
+ ch->envxx = (ch->envxx >> 8) * 255;
ch->env_error -= FIXED_POINT;
}
- ch->envx = envx_shifted >> ENVX_SHIFT;
+ ch->envx = ch->envxx >> ENVX_SHIFT;
if (ch->envx <= 0)
{
S9xAPUSetEndOfSample (J, ch);
@@ -1002,13 +1003,12 @@ void MixStereo (int sample_count)
break;
case SOUND_RELEASE:
- envx_shifted = ch->envx << ENVX_SHIFT;
while (ch->env_error >= FIXED_POINT)
{
- envx_shifted -= (MAX_ENVELOPE_HEIGHT << ENVX_SHIFT) / 256;
+ ch->envxx -= (MAX_ENVELOPE_HEIGHT << ENVX_SHIFT) / 256;
ch->env_error -= FIXED_POINT;
}
- ch->envx = envx_shifted >> ENVX_SHIFT;
+ ch->envx = ch->envxx >> ENVX_SHIFT;
if (ch->envx <= 0)
{
S9xAPUSetEndOfSample (J, ch);
@@ -1019,10 +1019,12 @@ void MixStereo (int sample_count)
case SOUND_INCREASE_LINEAR:
ch->env_error &= FIXED_POINT_REMAINDER;
ch->envx += step << 1;
+ ch->envxx = ch->envx << ENVX_SHIFT;
if (ch->envx >= 126)
{
ch->envx = 127;
+ ch->envxx = 127 << ENVX_SHIFT;
ch->state = SOUND_GAIN;
ch->mode = MODE_GAIN;
S9xSetEnvRate (ch, 0, -1, 0);
@@ -1032,23 +1034,24 @@ void MixStereo (int sample_count)
case SOUND_INCREASE_BENT_LINE:
if (ch->envx >= (MAX_ENVELOPE_HEIGHT * 3) / 4)
{
- envx_shifted = ch->envx << ENVX_SHIFT;
while (ch->env_error >= FIXED_POINT)
{
- envx_shifted += (MAX_ENVELOPE_HEIGHT << ENVX_SHIFT) / 256;
+ ch->envxx += (MAX_ENVELOPE_HEIGHT << ENVX_SHIFT) / 256;
ch->env_error -= FIXED_POINT;
}
- ch->envx = envx_shifted >> ENVX_SHIFT;
+ ch->envx = ch->envxx >> ENVX_SHIFT;
}
else
{
ch->env_error &= FIXED_POINT_REMAINDER;
ch->envx += step << 1;
+ ch->envxx = ch->envx << ENVX_SHIFT;
}
if (ch->envx >= 126)
{
ch->envx = 127;
+ ch->envxx = 127 << ENVX_SHIFT;
ch->state = SOUND_GAIN;
ch->mode = MODE_GAIN;
S9xSetEnvRate (ch, 0, -1, 0);
@@ -1058,6 +1061,7 @@ void MixStereo (int sample_count)
case SOUND_DECREASE_LINEAR:
ch->env_error &= FIXED_POINT_REMAINDER;
ch->envx -= step << 1;
+ ch->envxx = ch->envx << ENVX_SHIFT;
if (ch->envx <= 0)
{
S9xAPUSetEndOfSample (J, ch);
@@ -1066,13 +1070,12 @@ void MixStereo (int sample_count)
break;
case SOUND_DECREASE_EXPONENTIAL:
- envx_shifted = ch->envx << ENVX_SHIFT;
while (ch->env_error >= FIXED_POINT)
{
- envx_shifted = (envx_shifted >> 8) * 255;
+ ch->envxx = (ch->envxx >> 8) * 255;
ch->env_error -= FIXED_POINT;
}
- ch->envx = envx_shifted >> ENVX_SHIFT;
+ ch->envx = ch->envxx >> ENVX_SHIFT;
if (ch->envx <= 0)
{
S9xAPUSetEndOfSample (J, ch);
@@ -1818,7 +1821,7 @@ END_OF_FUNCTION(S9xMixSamples);
void S9xResetSound (bool8 full)
{
- for (int i = 0; i < NUM_CHANNELS; i++)
+ for (int i = 0; i < 8; i++)
{
SoundData.channels[i].state = SOUND_SILENT;
SoundData.channels[i].mode = MODE_NONE;
@@ -1832,6 +1835,7 @@ void S9xResetSound (bool8 full)
SoundData.channels[i].env_error = 0;
SoundData.channels[i].erate = 0;
SoundData.channels[i].envx = 0;
+ SoundData.channels[i].envxx = 0;
SoundData.channels[i].left_vol_level = 0;
SoundData.channels[i].right_vol_level = 0;
SoundData.channels[i].direction = 0;
@@ -2000,6 +2004,7 @@ void S9xPlaySample (int channel)
ch->state = SOUND_SILENT;
ch->mode = MODE_NONE;
ch->envx = 0;
+ ch->envxx = 0;
S9xFixEnvelope (channel,
APU.DSP [APU_GAIN + (channel << 4)],
@@ -2052,6 +2057,7 @@ void S9xPlaySample (int channel)
ch->right_vol_level = 0;
S9xSetEnvRate (ch, ch->attack_rate, 1, MAX_ENVELOPE_HEIGHT);
}
+ ch->envxx = ch->envx << ENVX_SHIFT;
break;
case MODE_GAIN:
diff --git a/source/soundux.h b/source/soundux.h
index 5484e89..ad8cba1 100644
--- a/source/soundux.h
+++ b/source/soundux.h
@@ -178,6 +178,7 @@ typedef struct {
uint32 sample_pointer;
int *echo_buf_ptr;
int mode;
+ int32 envxx;
signed short next_sample;
int32 interpolate;
int32 previous [2];