mirror of
https://github.com/tildearrow/furnace.git
synced 2024-11-01 18:42:40 +00:00
Small fix for potential undefined behavior in ESFM emulator
This commit is contained in:
parent
96fbd1524a
commit
39f29f49c3
2 changed files with 12 additions and 22 deletions
32
extern/ESFMu/esfm.c
vendored
32
extern/ESFMu/esfm.c
vendored
|
@ -196,13 +196,11 @@ static int13
|
|||
ESFM_envelope_calc_sin0(uint10 phase, uint10 envelope)
|
||||
{
|
||||
uint16 out = 0;
|
||||
uint13 neg = 0;
|
||||
bool inc = 0;
|
||||
int13 neg = 1;
|
||||
phase &= 0x3ff;
|
||||
if (phase & 0x200)
|
||||
{
|
||||
neg = ~(0);
|
||||
inc = 1;
|
||||
neg = -1;
|
||||
}
|
||||
if (phase & 0x100)
|
||||
{
|
||||
|
@ -212,7 +210,7 @@ ESFM_envelope_calc_sin0(uint10 phase, uint10 envelope)
|
|||
{
|
||||
out = logsinrom[phase & 0xff];
|
||||
}
|
||||
return (int13)(((uint13)ESFM_envelope_calc_exp(out + (envelope << 3)) ^ neg) + inc);
|
||||
return ESFM_envelope_calc_exp(out + (envelope << 3)) * neg;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
@ -275,13 +273,11 @@ static int13
|
|||
ESFM_envelope_calc_sin4(uint10 phase, uint10 envelope)
|
||||
{
|
||||
uint16 out = 0;
|
||||
int13 neg = 0;
|
||||
bool inc = 0;
|
||||
int13 neg = 1;
|
||||
phase &= 0x3ff;
|
||||
if ((phase & 0x300) == 0x100)
|
||||
{
|
||||
neg = ~(0);
|
||||
inc = 1;
|
||||
neg = -1;
|
||||
}
|
||||
if (phase & 0x200)
|
||||
{
|
||||
|
@ -295,7 +291,7 @@ ESFM_envelope_calc_sin4(uint10 phase, uint10 envelope)
|
|||
{
|
||||
out = logsinrom[(phase << 1) & 0xff];
|
||||
}
|
||||
return (int13)(((uint13)ESFM_envelope_calc_exp(out + (envelope << 3)) ^ neg) + inc);
|
||||
return ESFM_envelope_calc_exp(out + (envelope << 3)) * neg;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
@ -323,15 +319,13 @@ ESFM_envelope_calc_sin5(uint10 phase, uint10 envelope)
|
|||
static int13
|
||||
ESFM_envelope_calc_sin6(uint10 phase, uint10 envelope)
|
||||
{
|
||||
int13 neg = 0;
|
||||
bool inc = 0;
|
||||
int13 neg = 1;
|
||||
phase &= 0x3ff;
|
||||
if (phase & 0x200)
|
||||
{
|
||||
neg = ~(0);
|
||||
inc = 1;
|
||||
neg = -1;
|
||||
}
|
||||
return (int13)(((uint13)ESFM_envelope_calc_exp(envelope << 3) ^ neg) + inc);
|
||||
return ESFM_envelope_calc_exp(envelope << 3) * neg;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
@ -339,17 +333,15 @@ static int13
|
|||
ESFM_envelope_calc_sin7(uint10 phase, uint10 envelope)
|
||||
{
|
||||
uint16 out = 0;
|
||||
int13 neg = 0;
|
||||
bool inc = 0;
|
||||
int13 neg = 1;
|
||||
phase &= 0x3ff;
|
||||
if (phase & 0x200)
|
||||
{
|
||||
neg = ~(0);
|
||||
inc = 1;
|
||||
neg = -1;
|
||||
phase = (phase & 0x1ff) ^ 0x1ff;
|
||||
}
|
||||
out = phase << 3;
|
||||
return (int13)(((uint13)ESFM_envelope_calc_exp(out + (envelope << 3)) ^ neg) + inc);
|
||||
return ESFM_envelope_calc_exp(out + (envelope << 3)) * neg;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
|
2
extern/ESFMu/esfm.h
vendored
2
extern/ESFMu/esfm.h
vendored
|
@ -91,7 +91,6 @@ typedef uint_fast16_t uint9;
|
|||
typedef uint_fast16_t uint10;
|
||||
typedef uint_fast16_t uint11;
|
||||
typedef uint_fast16_t uint12;
|
||||
typedef uint_fast16_t uint13;
|
||||
typedef uint_fast16_t uint16;
|
||||
typedef uint_fast32_t uint19;
|
||||
typedef uint_fast32_t uint23;
|
||||
|
@ -115,7 +114,6 @@ typedef uint16_t uint9;
|
|||
typedef uint16_t uint10;
|
||||
typedef uint16_t uint11;
|
||||
typedef uint16_t uint12;
|
||||
typedef uint16_t uint13;
|
||||
typedef uint16_t uint16;
|
||||
typedef uint32_t uint19;
|
||||
typedef uint32_t uint23;
|
||||
|
|
Loading…
Reference in a new issue