Skip to content

Commit 47c13f4

Browse files
committed
Square pan, add envelope tables
1 parent 2f5773e commit 47c13f4

File tree

9 files changed

+210
-70
lines changed

9 files changed

+210
-70
lines changed

JaiSeqXLJA/DSP/JAIDSPEnvelope.cs

+122-24
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,107 @@ public JAIDSPEnvelope(JEnvelopeVector[] env, short init, bool dbg = false)
3333
debug = dbg;
3434
swapNextVector();
3535
}
36+
public static readonly float[] CURVE_LINEAR = {
37+
1.0f,
38+
0.9375f,
39+
0.875f,
40+
0.8125f,
41+
0.75f,
42+
0.6875f,
43+
0.625f,
44+
0.5625f,
45+
0.5f,
46+
0.4375f,
47+
0.375f,
48+
0.3125f,
49+
0.25f,
50+
0.1875f,
51+
0.125f,
52+
0.0625f,
53+
0
54+
};
55+
56+
public static readonly float[] CURVE_SQUAREROOT = {
57+
1.0f,
58+
0.878906f,
59+
0.765625f,
60+
0.660156f,
61+
0.5625f,
62+
0.472656f,
63+
0.390625f,
64+
0.316406f,
65+
0.25f,
66+
0.191406f,
67+
0.140625f,
68+
0.097656f,
69+
0.0625f,
70+
0.0351562f,
71+
0.015625f,
72+
0.00390625f,
73+
0
74+
};
75+
76+
public static readonly float[] CURVE_SQUARE = {
77+
1.0f,
78+
0.96824598f,
79+
0.935414f,
80+
0.90138799f,
81+
0.86602497f,
82+
0.82915598f,
83+
0.790569f,
84+
0.75f,
85+
0.707107f,
86+
0.66143799f,
87+
0.61237198f,
88+
0.559017f,
89+
0.5f,
90+
0.43301299f,
91+
0.353553f,
92+
0.25f,
93+
0
94+
};
95+
96+
public static readonly float[] CURVE_SAMPLECELL = {
97+
1.0f,
98+
0.970489f,
99+
0.781274f,
100+
0.54628098f,
101+
0.39979199f,
102+
0.28931499f,
103+
0.21210399f,
104+
0.15747599f,
105+
0.112613f,
106+
0.081789598f,
107+
0.0579852f,
108+
0.0436415f,
109+
0.0308237f,
110+
0.0237129f,
111+
0.0152593f,
112+
0.00915555f,
113+
0
114+
};
115+
116+
public static float InterpolateTable(float[] curve, float depth)
117+
{
118+
if (depth > 1)
119+
depth = 1;
120+
121+
var real = depth * (curve.Length - 1);
122+
var integer = (int)Math.Floor(real);
123+
var frac = real - integer;
36124

125+
var d1 = curve[integer];
126+
var d2 = 0f;
127+
if (integer < curve.Length - 1)
128+
d2 = curve[integer + 1];
129+
130+
return d1 + (d2 - d1) * frac;
131+
}
132+
133+
public static float InterpolateTableInverse(float[] curve, float depth)
134+
{
135+
return 1f - InterpolateTable(curve, depth);
136+
}
37137
private void swapNextVector()
38138
{
39139

@@ -52,7 +152,7 @@ private void swapNextVector()
52152
var envVal = eVector.value;
53153
valueDelta = envVal - Value;
54154
lastValue = Value;
55-
155+
56156
if (eVector.time == 0)
57157
{
58158
Value = eVector.value;
@@ -76,34 +176,32 @@ public unsafe bool update(double ms)
76176
swapNextVector();
77177
return false;
78178
}
79-
80-
var deltaDepth = lastDuration - currentDuration;
81-
var fdeltaDepth = deltaDepth / lastDuration;
82179

83-
if (fdeltaDepth > 1)
84-
fdeltaDepth = 1f;
180+
var deltaDepth = lastDuration - currentDuration;
181+
var fdeltaDepth = (float)(deltaDepth / lastDuration);
85182

86-
switch (currentMode)
87-
{
88-
case JEnvelopeVectorMode.Linear:
89-
Value = (short)(lastValue + (valueDelta * fdeltaDepth));
90-
break;
91-
case JEnvelopeVectorMode.Square:
92-
Value = (short)(lastValue + valueDelta * Math.Pow(fdeltaDepth, 2));
93-
break;
94-
case JEnvelopeVectorMode.SampleCell:
95-
Value = (short)(lastValue + valueDelta * (Math.Pow(fdeltaDepth - 1,3) + 1f));
96-
break;
97-
case JEnvelopeVectorMode.SqRoot:
98-
Value = (short)(lastValue + valueDelta * Math.Sqrt(fdeltaDepth));
99-
break;
100-
101-
}
183+
if (fdeltaDepth > 1)
184+
fdeltaDepth = 1f;
185+
var table = CURVE_LINEAR;
186+
187+
switch (currentMode)
188+
{
189+
case JEnvelopeVectorMode.Square:
190+
table = CURVE_SQUARE;
191+
break;
192+
case JEnvelopeVectorMode.SampleCell:
193+
table = CURVE_SAMPLECELL;
194+
break;
195+
case JEnvelopeVectorMode.SqRoot:
196+
table = CURVE_SQUAREROOT;
197+
break;
198+
}
102199

103-
fValue = (float)Value / (float)0x7FFF;
200+
Value = (short)(lastValue + valueDelta * InterpolateTableInverse(table, fdeltaDepth));
201+
fValue = Value / 32767f;
104202

105203
if (currentDuration > 0)
106-
currentDuration-=ms;
204+
currentDuration -= ms;
107205
else
108206
swapNextVector();
109207

JaiSeqXLJA/DSP/JAIDSPVoice.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public void setPanMatrix(byte index, float pan)
9797
for (int i = 0; i < panMatrix.Length; i++)
9898
panValue *= ((panMatrix[i]) / 64f);
9999

100-
//panValue *= panValue;
100+
panValue = (float)Math.Sqrt(panValue);
101101
Bass.BASS_ChannelSetAttribute(voiceHandle, BASSAttribute.BASS_ATTRIB_PAN, panValue -1f );
102102
}
103103

@@ -238,7 +238,7 @@ public byte updateVoice(double ms)
238238
var panValue = 1f;
239239
for (int i = 0; i < panMatrix.Length; i++)
240240
panValue *= ((panMatrix[i]) / 64f);
241-
//panValue *= panValue;
241+
panValue = (float)Math.Sqrt(panValue);
242242

243243
Bass.BASS_ChannelSetAttribute(voiceHandle, BASSAttribute.BASS_ATTRIB_PAN, panValue -1f );
244244

JaiSeqXLJA/JAISeqX.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net8.0</TargetFramework>
5+
<TargetFramework>net6.0</TargetFramework>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>

JaiSeqXLJA/Player/JAISeqPlayer.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ public static class JAISeqPlayer
3232
public static int syncCallbackValue = 0;
3333
public static int syncRegValue = 0;
3434
public static string awPath = "Banks";
35+
public static bool Debug = false;
36+
3537
public static void init()
3638
{
3739
paused = JaiSeqXLJA.findDynamicFlagArgument("-paused");
@@ -141,7 +143,7 @@ public static JAIDSPSampleBuffer loadSound(int wsys_id, int waveID, out JWave da
141143
{
142144
try
143145
{
144-
var w = File.OpenRead("Banks/" + waveData.wsysFile); //
146+
var w = File.OpenRead($"{awPath}/{waveData.wsysFile}"); //
145147
awHandles[waveData.wsysFile] = w;
146148
var fg = Console.ForegroundColor;
147149
Console.ForegroundColor = ConsoleColor.Red;

0 commit comments

Comments
 (0)