Skip to content

Commit

Permalink
Updated LibSidPlayFp to 2.12.0
Browse files Browse the repository at this point in the history
  • Loading branch information
neumatho committed Dec 9, 2024
1 parent 2c05461 commit 9f3472d
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 32 deletions.
2 changes: 1 addition & 1 deletion Source/Ports/LibSidPlayFp/LibSidPlayFp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<Product>NostalgicPlayer</Product>
<Description>This is a port of the libsidplayfp library created by Leandro Nini</Description>
<Platforms>AnyCPU</Platforms>
<Version>2.11.0</Version>
<Version>2.12.0</Version>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
Expand Down
22 changes: 15 additions & 7 deletions Source/Ports/LibSidPlayFp/Mixer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,15 @@ public int Get()
public const uint MAX_SIDS = 3;

private const int_least32_t SCALE_FACTOR = 1 << 16;
private const double SQRT_0_5 = 0.70710678118654746;
private const int_least32_t C1 = (int_least32_t)(1.0 / (1.0 + SQRT_0_5) * SCALE_FACTOR);
private const int_least32_t C2 = (int_least32_t)(SQRT_0_5 / (1.0 + SQRT_0_5) * SCALE_FACTOR);
private const double SQRT_2 = 1.41421356237;
private const double SQRT_3 = 1.73205080757;

private static readonly int_least32_t[] SCALE =
[
SCALE_FACTOR, // 1 chip, no scale
(int_least32_t)((1.0 / SQRT_2) * SCALE_FACTOR), // 2 chips, scale by sqrt(2)
(int_least32_t)((1.0 / SQRT_3) * SCALE_FACTOR) // 3 chips, scale by sqrt(3)
];

/// <summary>
/// Maximum allowed volume, must be a power of 2
Expand Down Expand Up @@ -195,6 +201,8 @@ public void Begin(short[] leftBuffer, short[] rightBuffer, uint32_t count)
sampleCount = count;
sampleBuffers[0] = leftBuffer;
sampleBuffers[1] = rightBuffer;

wait = false;
}


Expand Down Expand Up @@ -464,7 +472,7 @@ private int_least32_t Stereo_OneChip()
/********************************************************************/
private int_least32_t Stereo_Ch1_TwoChips()
{
return iSamples[0];
return (int_least32_t)(iSamples[0] + 0.5 * iSamples[1]) * SCALE[1] / SCALE_FACTOR;
}


Expand All @@ -476,7 +484,7 @@ private int_least32_t Stereo_Ch1_TwoChips()
/********************************************************************/
private int_least32_t Stereo_Ch2_TwoChips()
{
return iSamples[1];
return (int_least32_t)(0.5 * iSamples[0] + iSamples[1]) * SCALE[1] / SCALE_FACTOR;
}


Expand All @@ -488,7 +496,7 @@ private int_least32_t Stereo_Ch2_TwoChips()
/********************************************************************/
private int_least32_t Stereo_Ch1_ThreeChips()
{
return (C1 * iSamples[0] + C2 * iSamples[1]) / SCALE_FACTOR;
return (int_least32_t)(iSamples[0] + iSamples[1] + 0.5 * iSamples[2]) * SCALE[2] / SCALE_FACTOR;
}


Expand All @@ -500,7 +508,7 @@ private int_least32_t Stereo_Ch1_ThreeChips()
/********************************************************************/
private int_least32_t Stereo_Ch2_ThreeChips()
{
return (C2 * iSamples[1] + C1 * iSamples[2]) / SCALE_FACTOR;
return (int_least32_t)(0.5 * iSamples[0] + iSamples[1] + iSamples[2]) * SCALE[2] / SCALE_FACTOR;
}
#endregion
}
Expand Down
11 changes: 6 additions & 5 deletions Source/Ports/ReSidFp/ExternalFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ internal class ExternalFilter
// acts as a high-pass filter with a cutoff dependent on the attached audio
// equipment impedance. Here we suppose an impedance of 10kOhm resulting
// in a 3 dB attenuation at 1.6Hz.
// To operate properly the 6581 audio output needs a pull-down resistor
// (1KOhm recommended, not needed on 8580)
//
// ~~~
// 9/12V
Expand All @@ -30,15 +28,18 @@ internal class ExternalFilter
// | | pF +-C----o-----C-----+ 10k
// 470 | |
// GND GND pF R 1K | amp
// * * | +-----
// * ** | +-----
//
// GND
// ~~~
//
// The STC networks are connected with a [BJT] based [common collector]
// used as a voltage follower (featuring a 2SC1815 NPN transistor).
// * The C64c board additionally includes a [bootstrap] condenser to increase
// the input impedance of the common collector.
//
// * To operate properly the 6581 audio output needs a pull-down resistor
// (1KOhm recommended, not needed on 8580)
// ** The C64c board additionally includes a [bootstrap] condenser to increase
// the input impedance of the common collector.
//
// [BJT]: https://en.wikipedia.org/wiki/Bipolar_junction_transistor
// [common collector]: https://en.wikipedia.org/wiki/Common_collector
Expand Down
1 change: 1 addition & 0 deletions Source/Ports/ReSidFp/FilterModelConfig6581.cs
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ public ushort GetVcr_n_Ids_Term(int i)
/// on the envelope value
/// </summary>
/********************************************************************/
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected override double GetVoiceDc(uint env)
{
return voiceDc[env];
Expand Down
1 change: 1 addition & 0 deletions Source/Ports/ReSidFp/FilterModelConfig8580.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ public double GetVRef()
///
/// </summary>
/********************************************************************/
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected override double GetVoiceDc(uint env)
{
return GetVRef();
Expand Down
2 changes: 1 addition & 1 deletion Source/Ports/ReSidFp/ReSidFp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<Product>NostalgicPlayer</Product>
<Description>This is a port of the ReSidFp library created by Dag Lem and Leandro Nini</Description>
<Platforms>AnyCPU</Platforms>
<Version>2.11.0</Version>
<Version>2.12.0</Version>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
Expand Down
32 changes: 16 additions & 16 deletions Source/Ports/ReSidFp/WaveformCalculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,14 @@ public CombinedWaveformConfig(distance_t distFunc, float threshold, float topBit
},
new CombinedWaveformConfig[5]
{ // 8580 R5 1088 sampled by reFX-Mike
// TS error 10788 (354/32768) [RMS: 58.31]
new CombinedWaveformConfig(ExponentialDistance, 0.841851234f, 1.09233654f, 0.0f, 1.85262764f, 6.22224379f),
// TS error 10660 (353/32768) [RMS: 58.34]
new CombinedWaveformConfig(ExponentialDistance, 0.853578329f, 1.09615636f, 0.0f, 1.8819375f, 6.80794907f),
// PT error 10635 (289/32768) [RMS: 108.81]
new CombinedWaveformConfig(ExponentialDistance, 0.929835618f, 1.0f, 1.12836814f, 1.10453653f, 1.48065746f),
// PS error 12255 (554/32768) [RMS: 102.27]
new CombinedWaveformConfig(QuadraticDistance, 0.911938608f, 0.996440411f, 1.2278074f, 0.000117214302f, 0.18948476f),
// PTS error 6995 (139/32768) [RMS: 55.78]
new CombinedWaveformConfig(ExponentialDistance, 0.932317019f, 1.03892183f, 1.2068342f, 0.891974986f, 1.42451835f),
// PTS error 6913 (127/32768) [RMS: 55.80]
new CombinedWaveformConfig(ExponentialDistance, 0.938004673f, 1.04827631f, 1.21178246f, 0.915959001f, 1.42698038f),
// NP guessed
new CombinedWaveformConfig(ExponentialDistance, 0.95f, 1.0f, 1.15f, 1.0f, 1.45f),
}
Expand All @@ -139,25 +139,25 @@ public CombinedWaveformConfig(distance_t distFunc, float threshold, float topBit
{
new CombinedWaveformConfig[5]
{ // 6581 R2 4383 sampled by ltx128
// TS error 1858 (204/32768) [RMS: 62.49]
new CombinedWaveformConfig(ExponentialDistance, 0.886832297f, 1.0f, 0.0f, 2.14438701f, 9.51839447f),
// TS error 1474 (198/32768) [RMS: 62.81]
new CombinedWaveformConfig(ExponentialDistance, 0.892563999f, 1.11905622f, 0.0f, 2.21876144f, 9.63837719f),
// PT error 612 (102/32768) [RMS: 43.71]
new CombinedWaveformConfig(LinearDistance, 1.01262534f, 1.0f, 2.46070528f, 0.0537485816f, 0.0986242667f),
// PS error 8135 (575/32768) [RMS: 75.10]
new CombinedWaveformConfig(LinearDistance, 2.14896345f, 1.0216713f, 10.5400085f, 0.244498149f, 0.126134038f),
// PTS error 2505 (63/32768) [RMS: 24.37]
new CombinedWaveformConfig(LinearDistance, 1.29061747f, 0.9754318f, 3.15377498f, 0.0968349651f, 0.318573922f),
// PTS error 2489 (60/32768) [RMS: 24.41]
new CombinedWaveformConfig(LinearDistance, 1.22330308f, 0.933797896f, 2.83245254f, 0.0615176819f, 0.323831677f),
// NP guessed
new CombinedWaveformConfig(ExponentialDistance, 0.96f, 1.0f, 2.5f, 1.1f, 1.2f),
},
new CombinedWaveformConfig[5]
{ // 8580 R5 4887 sampled by reFX-Mike
// TS error 745 (77/32768) [RMS: 53.74]
new CombinedWaveformConfig(ExponentialDistance, 0.816124022f, 1.31208789f, 0.0f, 1.92347884f, 2.35027933f),
// TS error 741 (76/32768) [RMS: 53.74]
new CombinedWaveformConfig(ExponentialDistance, 0.812351167f, 1.1727736f, 0.0f, 1.87459648f, 2.31578159f),
// PT error 7199 (192/32768) [RMS: 88.43]
new CombinedWaveformConfig(ExponentialDistance, 0.917997837f, 1.0f, 1.01248944f, 1.05761552f, 1.37529826f),
// PS error 9864 (333/32768) [RMS: 86.29]
new CombinedWaveformConfig(QuadraticDistance, 0.970038712f, 1.00844693f, 1.30298805f, 0.0097996993f, 0.146854922f),
// PS error 9856 (332/32768) [RMS: 86.29]
new CombinedWaveformConfig(QuadraticDistance, 0.968754232f, 1.00669801f, 1.29909098f, 0.00962483883f, 0.146850556f),
// PTS error 4809 (60/32768) [RMS: 45.37]
new CombinedWaveformConfig(ExponentialDistance, 0.941834152f, 1.06401193f, 0.991132736f, 0.995310068f, 1.41105855f),
// NP guessed
Expand All @@ -171,8 +171,8 @@ public CombinedWaveformConfig(distance_t distFunc, float threshold, float topBit
{ // 6581 R2 0384 sampled by Trurl
// TS error 20337 (1579/32768) [RMS: 88.57]
new CombinedWaveformConfig(ExponentialDistance, 0.000637792516f, 1.56725872f, 0.0f, 0.00036806846f, 1.51800942f),
// PT error 5194 (240/32768) [RMS: 83.54]
new CombinedWaveformConfig(LinearDistance, 0.924824238f, 1.0f, 1.96749473f, 0.0891806409f, 0.234794483f),
// PT error 5190 (238/32768) [RMS: 83.54]
new CombinedWaveformConfig(LinearDistance, 0.924780309f, 1.0f, 1.96809769f, 0.0888123438f, 0.234606609f),
// PS error 31015 (2181/32768) [RMS: 114.99]
new CombinedWaveformConfig(LinearDistance, 1.2328074f, 0.73079139f, 3.9719491f, 0.00156516861f, 0.314677745f),
// PTS error 9874 (201/32768) [RMS: 52.30]
Expand All @@ -184,8 +184,8 @@ public CombinedWaveformConfig(distance_t distFunc, float threshold, float topBit
{ // 8580 R5 1489 sampled by reFX-Mike
// TS error 4837 (388/32768) [RMS: 76.07]
new CombinedWaveformConfig(ExponentialDistance, 0.89762634f, 56.7594185f, 0.0f, 7.68995237f, 12.0754194f),
// PT error 9298 (506/32768) [RMS: 128.15]
new CombinedWaveformConfig(ExponentialDistance, 0.867885351f, 1.0f, 1.4511894f, 1.07057536f, 1.43333757f),
// PT error 9266 (508/32768) [RMS: 127.83]
new CombinedWaveformConfig(ExponentialDistance, 0.87147671f, 1.0f, 1.44887495f, 1.05899632f, 1.43786001f),
// PS error 13168 (718/32768) [RMS: 123.35]
new CombinedWaveformConfig(QuadraticDistance, 0.89255774f, 1.2253896f, 1.75615835f, 0.0245045591f, 0.12982437f),
// PTS error 6702 (300/32768) [RMS: 71.01]
Expand Down
3 changes: 3 additions & 0 deletions Source/Ports/ReSidFp/WaveformGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,10 @@ public uint Output(WaveformGenerator ringModulator)
// In the 6581 the top bit of the accumulator may be driven low by combined waveforms
// when the sawtooth is selected
if (is6581 && ((waveform & 2) != 0) && ((waveform_output & 0x800) == 0))
{
msb_rising = false;
accumulator &= 0x7fffff;
}

Write_Shift_Register();
}
Expand Down
4 changes: 2 additions & 2 deletions Source/Ports/Tests/LibSidPlayFp.Test/TestSpline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Polycode.NostalgicPlayer.Ports.Tests.LibSidPlayFp.Test
[TestClass]
public class TestSpline
{
private const int OpAmpSize = 33;
private const uint OpAmpSize = 33;

private static readonly Spline.Point[] opamp_voltage =
{
Expand Down Expand Up @@ -86,7 +86,7 @@ public void TestPoints()
{
Spline s = new Spline(new List<Spline.Point>(opamp_voltage));

for (int i = 0; i < OpAmpSize; i++)
for (uint i = 0; i < OpAmpSize; i++)
{
Spline.Point o = s.Evaluate(opamp_voltage[i].x);
Assert.AreEqual(opamp_voltage[i].y, o.x);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public void TestSetTestBit()
matrix_t tables = WaveformCalculator.GetInstance().BuildPulldownTable(ChipModel.MOS6581, CombinedWaveforms.AVERAGE);

WaveformGenerator generator = new WaveformGenerator();
generator.SetModel(true);
generator.Reset();
generator.shift_register = 0x35555e;
generator.SetWaveformModels(waveTables);
Expand Down

0 comments on commit 9f3472d

Please sign in to comment.