1
0
Fork 0

opl types update 3

This commit is contained in:
Sen 2025-08-25 14:44:30 +02:00
parent ce5770e58c
commit eb154e6e07
Signed by: sen
GPG key ID: 3AC50A6F47D1B722

View file

@ -13,7 +13,7 @@ public class OPLChip {
} }
private static interface WaveFunc { private static interface WaveFunc {
short calcPhase(short phase, short envelope); int calcPhase(int phase, int envelope);
} }
public class OPLSlot implements ModGen { public class OPLSlot implements ModGen {
@ -264,7 +264,7 @@ public class OPLChip {
this.pg_phase += (basefreq * MULT[this.reg_mult]) >> 1; this.pg_phase += (basefreq * MULT[this.reg_mult]) >> 1;
this.pg_phase_out = phase; this.pg_phase_out = phase;
// output // output
this.out = WAVE_FUNCS[this.reg_wf].calcPhase((short)(this.pg_phase_out + this.mod.getModulation()), this.eg_out); this.out = (short)WAVE_FUNCS[this.reg_wf].calcPhase(this.pg_phase_out + this.mod.getModulation(), this.eg_out);
} }
private void updateKSL() private void updateKSL()
@ -552,7 +552,7 @@ public class OPLChip {
//Tables //Tables
private static final short[] LOG_SIN = { private static final int[] LOG_SIN = {
0x859, 0x6c3, 0x607, 0x58b, 0x52e, 0x4e4, 0x4a6, 0x471, 0x859, 0x6c3, 0x607, 0x58b, 0x52e, 0x4e4, 0x4a6, 0x471,
0x443, 0x41a, 0x3f5, 0x3d3, 0x3b5, 0x398, 0x37e, 0x365, 0x443, 0x41a, 0x3f5, 0x3d3, 0x3b5, 0x398, 0x37e, 0x365,
0x34e, 0x339, 0x324, 0x311, 0x2ff, 0x2ed, 0x2dc, 0x2cd, 0x34e, 0x339, 0x324, 0x311, 0x2ff, 0x2ed, 0x2dc, 0x2cd,
@ -587,7 +587,7 @@ public class OPLChip {
0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000
}; };
private static final short[] EXP = { private static final int[] EXP = {
0x7fa, 0x7f5, 0x7ef, 0x7ea, 0x7e4, 0x7df, 0x7da, 0x7d4, 0x7fa, 0x7f5, 0x7ef, 0x7ea, 0x7e4, 0x7df, 0x7da, 0x7d4,
0x7cf, 0x7c9, 0x7c4, 0x7bf, 0x7b9, 0x7b4, 0x7ae, 0x7a9, 0x7cf, 0x7c9, 0x7c4, 0x7bf, 0x7b9, 0x7b4, 0x7ae, 0x7a9,
0x7a4, 0x79f, 0x799, 0x794, 0x78f, 0x78a, 0x784, 0x77f, 0x7a4, 0x79f, 0x799, 0x794, 0x78f, 0x78a, 0x784, 0x77f,
@ -709,23 +709,23 @@ public class OPLChip {
//Envelope generator //Envelope generator
private static short waveExp(int level) private static int waveExp(int level)
{ {
if (level > 0x1fff) if (level > 0x1fff)
{ {
level = 0x1fff; level = 0x1fff;
} }
return (short)((EXP[level & 0xff] << 1) >> (level >> 8)); return (EXP[level & 0xff] << 1) >> (level >> 8);
} }
private static short wave0(short phase, short envelope) private static int wave0(int phase, int envelope)
{ {
short out = 0; int out = 0;
short neg = 0; int neg = 0;
phase &= 0x3ff; phase &= 0x3ff;
if ((phase & 0x200) != 0) if ((phase & 0x200) != 0)
{ {
neg = (short)0xffff; neg = 0xffff;
} }
if ((phase & 0x100) != 0) if ((phase & 0x100) != 0)
{ {
@ -735,12 +735,12 @@ public class OPLChip {
{ {
out = LOG_SIN[phase & 0xff]; out = LOG_SIN[phase & 0xff];
} }
return (short)(waveExp(out + (envelope << 3)) ^ neg); return waveExp(out + (envelope << 3)) ^ neg;
} }
private static short wave1(short phase, short envelope) private static int wave1(int phase, int envelope)
{ {
short out = 0; int out = 0;
phase &= 0x3ff; phase &= 0x3ff;
if ((phase & 0x200) != 0) if ((phase & 0x200) != 0)
{ {
@ -757,9 +757,9 @@ public class OPLChip {
return waveExp(out + (envelope << 3)); return waveExp(out + (envelope << 3));
} }
private static short wave2(short phase, short envelope) private static int wave2(int phase, int envelope)
{ {
short out = 0; int out = 0;
phase &= 0x3ff; phase &= 0x3ff;
if ((phase & 0x100) != 0) if ((phase & 0x100) != 0)
{ {
@ -772,9 +772,9 @@ public class OPLChip {
return waveExp(out + (envelope << 3)); return waveExp(out + (envelope << 3));
} }
private static short wave3(short phase, short envelope) private static int wave3(int phase, int envelope)
{ {
short out = 0; int out = 0;
phase &= 0x3ff; phase &= 0x3ff;
if ((phase & 0x100) != 0) if ((phase & 0x100) != 0)
{ {
@ -787,14 +787,14 @@ public class OPLChip {
return waveExp(out + (envelope << 3)); return waveExp(out + (envelope << 3));
} }
private static short wave4(short phase, short envelope) private static int wave4(int phase, int envelope)
{ {
short out = 0; int out = 0;
short neg = 0; int neg = 0;
phase &= 0x3ff; phase &= 0x3ff;
if ((phase & 0x300) == 0x100) if ((phase & 0x300) == 0x100)
{ {
neg = (short)0xffff; neg = 0xffff;
} }
if ((phase & 0x200) != 0) if ((phase & 0x200) != 0)
{ {
@ -808,12 +808,12 @@ public class OPLChip {
{ {
out = LOG_SIN[(phase << 1) & 0xff]; out = LOG_SIN[(phase << 1) & 0xff];
} }
return (short)(waveExp(out + (envelope << 3)) ^ neg); return waveExp(out + (envelope << 3)) ^ neg;
} }
private static short wave5(short phase, short envelope) private static int wave5(int phase, int envelope)
{ {
short out = 0; int out = 0;
phase &= 0x3ff; phase &= 0x3ff;
if ((phase & 0x200) != 0) if ((phase & 0x200) != 0)
{ {
@ -830,29 +830,29 @@ public class OPLChip {
return waveExp(out + (envelope << 3)); return waveExp(out + (envelope << 3));
} }
private static short wave6(short phase, short envelope) private static int wave6(int phase, int envelope)
{ {
short neg = 0; int neg = 0;
phase &= 0x3ff; phase &= 0x3ff;
if ((phase & 0x200) != 0) if ((phase & 0x200) != 0)
{ {
neg = (short)0xffff; neg = 0xffff;
} }
return (short)(waveExp(envelope << 3) ^ neg); return waveExp(envelope << 3) ^ neg;
} }
private static short wave7(short phase, short envelope) private static int wave7(int phase, int envelope)
{ {
short out = 0; int out = 0;
short neg = 0; int neg = 0;
phase &= 0x3ff; phase &= 0x3ff;
if ((phase & 0x200) != 0) if ((phase & 0x200) != 0)
{ {
neg = (short)0xffff; neg = 0xffff;
phase = (short)((phase & 0x1ff) ^ 0x1ff); phase = (phase & 0x1ff) ^ 0x1ff;
} }
out = (short)(phase << 3); out = phase << 3;
return (short)(waveExp(out + (envelope << 3)) ^ neg); return waveExp(out + (envelope << 3)) ^ neg;
} }
private void genFrame() private void genFrame()