mirror of
https://github.com/libretro/RACE.git
synced 2024-11-23 08:59:49 +00:00
Cleanups
This commit is contained in:
parent
16a7bbe0ab
commit
22e75e22c2
153
neopopsound.c
153
neopopsound.c
@ -77,121 +77,62 @@ static _u32 UpdateStep = 0; /* Number of steps during one sample. */
|
||||
|
||||
static _u16 sample_chip_tone(void)
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
int vol[3];
|
||||
unsigned int out;
|
||||
|
||||
int vol[3];
|
||||
unsigned int out;
|
||||
int left;
|
||||
/* vol[] keeps track of how long each square wave stays */
|
||||
/* in the 1 position during the sample period. */
|
||||
vol[0] = vol[1] = vol[2] = /*vol[3] = */ 0;
|
||||
|
||||
/* vol[] keeps track of how long each square wave stays */
|
||||
/* in the 1 position during the sample period. */
|
||||
vol[0] = vol[1] = vol[2] = /*vol[3] = */ 0;
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
if (toneChip.Output[i]) vol[i] += toneChip.Count[i];
|
||||
toneChip.Count[i] -= STEP;
|
||||
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
if (toneChip.Output[i]) vol[i] += toneChip.Count[i];
|
||||
toneChip.Count[i] -= STEP;
|
||||
/* Period[i] is the half period of the square wave. Here, in each */
|
||||
/* loop I add Period[i] twice, so that at the end of the loop the */
|
||||
/* square wave is in the same status (0 or 1) it was at the start. */
|
||||
/* vol[i] is also incremented by Period[i], since the wave has been 1 */
|
||||
/* exactly half of the time, regardless of the initial position. */
|
||||
/* If we exit the loop in the middle, Output[i] has to be inverted */
|
||||
/* and vol[i] incremented only if the exit status of the square */
|
||||
/* wave is 1. */
|
||||
|
||||
/* Period[i] is the half period of the square wave. Here, in each */
|
||||
/* loop I add Period[i] twice, so that at the end of the loop the */
|
||||
/* square wave is in the same status (0 or 1) it was at the start. */
|
||||
/* vol[i] is also incremented by Period[i], since the wave has been 1 */
|
||||
/* exactly half of the time, regardless of the initial position. */
|
||||
/* If we exit the loop in the middle, Output[i] has to be inverted */
|
||||
/* and vol[i] incremented only if the exit status of the square */
|
||||
/* wave is 1. */
|
||||
while (toneChip.Count[i] <= 0)
|
||||
{
|
||||
toneChip.Count[i] += toneChip.Period[i];
|
||||
if (toneChip.Count[i] > 0)
|
||||
{
|
||||
toneChip.Output[i] ^= 1;
|
||||
if (toneChip.Output[i]) vol[i] += toneChip.Period[i];
|
||||
break;
|
||||
}
|
||||
toneChip.Count[i] += toneChip.Period[i];
|
||||
vol[i] += toneChip.Period[i];
|
||||
}
|
||||
if (toneChip.Output[i]) vol[i] -= toneChip.Count[i];
|
||||
}
|
||||
|
||||
while (toneChip.Count[i] <= 0)
|
||||
{
|
||||
toneChip.Count[i] += toneChip.Period[i];
|
||||
if (toneChip.Count[i] > 0)
|
||||
{
|
||||
toneChip.Output[i] ^= 1;
|
||||
if (toneChip.Output[i]) vol[i] += toneChip.Period[i];
|
||||
break;
|
||||
}
|
||||
toneChip.Count[i] += toneChip.Period[i];
|
||||
vol[i] += toneChip.Period[i];
|
||||
}
|
||||
if (toneChip.Output[i]) vol[i] -= toneChip.Count[i];
|
||||
}
|
||||
/*
|
||||
left = STEP;
|
||||
do
|
||||
{
|
||||
int nextevent;
|
||||
out = vol[0] * toneChip.Volume[0] + vol[1] * toneChip.Volume[1] +
|
||||
vol[2] * toneChip.Volume[2];
|
||||
|
||||
if (toneChip.Count[3] < left) nextevent = toneChip.Count[3];
|
||||
else nextevent = left;
|
||||
|
||||
if (toneChip.Output[3]) vol[3] += toneChip.Count[3];
|
||||
toneChip.Count[3] -= nextevent;
|
||||
if (toneChip.Count[3] <= 0)
|
||||
{
|
||||
if (toneChip.RNG & 1) toneChip.RNG ^= toneChip.NoiseFB;
|
||||
toneChip.RNG >>= 1;
|
||||
toneChip.Output[3] = toneChip.RNG & 1;
|
||||
toneChip.Count[3] += toneChip.Period[3];
|
||||
if (toneChip.Output[3]) vol[3] += toneChip.Period[3];
|
||||
}
|
||||
if (toneChip.Output[3]) vol[3] -= toneChip.Count[3];
|
||||
|
||||
left -= nextevent;
|
||||
} while (left > 0);
|
||||
*/
|
||||
|
||||
out = vol[0] * toneChip.Volume[0] + vol[1] * toneChip.Volume[1] +
|
||||
vol[2] * toneChip.Volume[2];
|
||||
|
||||
if (out > MAX_OUTPUT_STEP)
|
||||
if (out > MAX_OUTPUT_STEP)
|
||||
out = MAX_OUTPUT_STEP;
|
||||
|
||||
return out>>STEP_SHIFT;
|
||||
return out>>STEP_SHIFT;
|
||||
}
|
||||
|
||||
/* ============================================================================= */
|
||||
|
||||
static _u16 sample_chip_noise(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
int vol3 = 0;
|
||||
unsigned int out;
|
||||
int left;
|
||||
|
||||
/* vol[] keeps track of how long each square wave stays */
|
||||
/* in the 1 position during the sample period. */
|
||||
/*
|
||||
vol[0] = vol[1] = vol[2] = vol[3] = 0;
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
if (noiseChip.Output[i]) vol[i] += noiseChip.Count[i];
|
||||
noiseChip.Count[i] -= STEP;
|
||||
|
||||
// Period[i] is the half period of the square wave. Here, in each
|
||||
// loop I add Period[i] twice, so that at the end of the loop the
|
||||
// square wave is in the same status (0 or 1) it was at the start.
|
||||
// vol[i] is also incremented by Period[i], since the wave has been 1
|
||||
// exactly half of the time, regardless of the initial position.
|
||||
// If we exit the loop in the middle, Output[i] has to be inverted
|
||||
// and vol[i] incremented only if the exit status of the square
|
||||
// wave is 1.
|
||||
|
||||
while (noiseChip.Count[i] <= 0)
|
||||
{
|
||||
noiseChip.Count[i] += noiseChip.Period[i];
|
||||
if (noiseChip.Count[i] > 0)
|
||||
{
|
||||
noiseChip.Output[i] ^= 1;
|
||||
if (noiseChip.Output[i]) vol[i] += noiseChip.Period[i];
|
||||
break;
|
||||
}
|
||||
noiseChip.Count[i] += noiseChip.Period[i];
|
||||
vol[i] += noiseChip.Period[i];
|
||||
}
|
||||
if (noiseChip.Output[i]) vol[i] -= noiseChip.Count[i];
|
||||
}
|
||||
*/
|
||||
if (noiseChip.Volume[3])
|
||||
{
|
||||
left = STEP;
|
||||
@ -199,24 +140,21 @@ static _u16 sample_chip_noise(void)
|
||||
{
|
||||
int nextevent = min(noiseChip.Count[3],left);
|
||||
|
||||
#if 0
|
||||
if (noiseChip.Count[3] < left)
|
||||
nextevent = noiseChip.Count[3];
|
||||
else
|
||||
nextevent = left;
|
||||
#endif
|
||||
|
||||
if (noiseChip.Output[3]) vol3 += noiseChip.Count[3];
|
||||
if (noiseChip.Output[3])
|
||||
vol3 += noiseChip.Count[3];
|
||||
noiseChip.Count[3] -= nextevent;
|
||||
if (noiseChip.Count[3] <= 0)
|
||||
{
|
||||
if (noiseChip.RNG & 1) noiseChip.RNG ^= noiseChip.NoiseFB;
|
||||
if (noiseChip.RNG & 1)
|
||||
noiseChip.RNG ^= noiseChip.NoiseFB;
|
||||
noiseChip.RNG >>= 1;
|
||||
noiseChip.Output[3] = noiseChip.RNG & 1;
|
||||
noiseChip.Count[3] += noiseChip.Period[3];
|
||||
if (noiseChip.Output[3]) vol3 += noiseChip.Period[3];
|
||||
if (noiseChip.Output[3])
|
||||
vol3 += noiseChip.Period[3];
|
||||
}
|
||||
if (noiseChip.Output[3]) vol3 -= noiseChip.Count[3];
|
||||
if (noiseChip.Output[3])
|
||||
vol3 -= noiseChip.Count[3];
|
||||
|
||||
left -= nextevent;
|
||||
} while (left > 0);
|
||||
@ -263,7 +201,8 @@ void WriteSoundChip(SoundChip* chip, _u8 data)
|
||||
case 2: /* tone 1 : frequency */
|
||||
case 4: /* tone 2 : frequency */
|
||||
chip->Period[c] = UpdateStep * chip->Register[r];
|
||||
if (chip->Period[c] == 0) chip->Period[c] = UpdateStep;
|
||||
if (chip->Period[c] == 0)
|
||||
chip->Period[c] = UpdateStep;
|
||||
if (r == 4)
|
||||
{
|
||||
/* update noise shift frequency */
|
||||
|
Loading…
Reference in New Issue
Block a user