Skip to content

Commit

Permalink
Moved all C helper classes into its own CKit project + updated all re…
Browse files Browse the repository at this point in the history
…ferences.
  • Loading branch information
neumatho committed Jan 2, 2025
1 parent 61e5ccc commit 22b9972
Show file tree
Hide file tree
Showing 171 changed files with 1,000 additions and 987 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using System.IO;
using System.Runtime.InteropServices;
using Polycode.NostalgicPlayer.Agent.ModuleConverter.Mo3Converter.Containers;
using Polycode.NostalgicPlayer.Kit.Utility;
using Polycode.NostalgicPlayer.CKit;
using Polycode.NostalgicPlayer.Ports.LibVorbis;
using Polycode.NostalgicPlayer.Ports.LibVorbis.Containers;
using Polycode.NostalgicPlayer.Ports.LibVorbisFile;
Expand Down Expand Up @@ -95,7 +95,7 @@ private bool VorbisDecode(MemoryStream ms, out short[] decodedBuffer)

while (todo > 0)
{
int done = vorbisFile.Ov_Read_Float(out Pointer<float>[] buffer, (int)todo, out _);
int done = vorbisFile.Ov_Read_Float(out CPointer<float>[] buffer, (int)todo, out _);
if (done == (int)VorbisError.Hole)
continue;

Expand Down
4 changes: 2 additions & 2 deletions Source/Agents/Players/OggVorbis/OggVorbisWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
using System.IO;
using System.Text;
using Polycode.NostalgicPlayer.Agent.Player.OggVorbis.Containers;
using Polycode.NostalgicPlayer.CKit;
using Polycode.NostalgicPlayer.Kit.Bases;
using Polycode.NostalgicPlayer.Kit.Containers;
using Polycode.NostalgicPlayer.Kit.Streams;
using Polycode.NostalgicPlayer.Kit.Utility;
using Polycode.NostalgicPlayer.Ports.LibVorbis;
using Polycode.NostalgicPlayer.Ports.LibVorbis.Containers;
using Polycode.NostalgicPlayer.Ports.LibVorbisFile;
Expand Down Expand Up @@ -677,7 +677,7 @@ private int LoadData(int[] outputBuffer, int count)

while (count > 0)
{
int done = vorbisFile.Ov_Read_Float(out Pointer<float>[] buffer, count / channels, out _);
int done = vorbisFile.Ov_Read_Float(out CPointer<float>[] buffer, count / channels, out _);
if (done == (int)VorbisError.Hole)
continue;

Expand Down
1 change: 1 addition & 0 deletions Source/Agents/SampleConverters/AudioIff/AudioIff.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\NostalgicPlayerCKit\NostalgicPlayerCKit.csproj" />
<ProjectReference Include="..\..\..\NostalgicPlayerKit\NostalgicPlayerKit.csproj">
<Private>false</Private>
</ProjectReference>
Expand Down
2 changes: 1 addition & 1 deletion Source/Agents/SampleConverters/AudioIff/IeeeExtended.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/******************************************************************************/
using System;
using System.Runtime.CompilerServices;
using Polycode.NostalgicPlayer.Kit.Utility;
using Polycode.NostalgicPlayer.CKit;

namespace Polycode.NostalgicPlayer.Agent.SampleConverter.AudioIff
{
Expand Down
18 changes: 18 additions & 0 deletions Source/NostalgicPlayer.sln
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibVorbisFile", "Ports\LibV
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibVorbis", "Ports\LibVorbis\LibVorbis.csproj", "{01471ED9-8505-4492-93B4-0E97FD995129}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NostalgicPlayerCKit", "NostalgicPlayerCKit\NostalgicPlayerCKit.csproj", "{3C34B7FD-0415-421E-89B3-1EAFA3E0D9FC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -1492,6 +1494,22 @@ Global
{01471ED9-8505-4492-93B4-0E97FD995129}.Release|x64.Build.0 = Release|Any CPU
{01471ED9-8505-4492-93B4-0E97FD995129}.Release|x86.ActiveCfg = Release|Any CPU
{01471ED9-8505-4492-93B4-0E97FD995129}.Release|x86.Build.0 = Release|Any CPU
{3C34B7FD-0415-421E-89B3-1EAFA3E0D9FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3C34B7FD-0415-421E-89B3-1EAFA3E0D9FC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3C34B7FD-0415-421E-89B3-1EAFA3E0D9FC}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{3C34B7FD-0415-421E-89B3-1EAFA3E0D9FC}.Debug|ARM64.Build.0 = Debug|Any CPU
{3C34B7FD-0415-421E-89B3-1EAFA3E0D9FC}.Debug|x64.ActiveCfg = Debug|Any CPU
{3C34B7FD-0415-421E-89B3-1EAFA3E0D9FC}.Debug|x64.Build.0 = Debug|Any CPU
{3C34B7FD-0415-421E-89B3-1EAFA3E0D9FC}.Debug|x86.ActiveCfg = Debug|Any CPU
{3C34B7FD-0415-421E-89B3-1EAFA3E0D9FC}.Debug|x86.Build.0 = Debug|Any CPU
{3C34B7FD-0415-421E-89B3-1EAFA3E0D9FC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3C34B7FD-0415-421E-89B3-1EAFA3E0D9FC}.Release|Any CPU.Build.0 = Release|Any CPU
{3C34B7FD-0415-421E-89B3-1EAFA3E0D9FC}.Release|ARM64.ActiveCfg = Release|Any CPU
{3C34B7FD-0415-421E-89B3-1EAFA3E0D9FC}.Release|ARM64.Build.0 = Release|Any CPU
{3C34B7FD-0415-421E-89B3-1EAFA3E0D9FC}.Release|x64.ActiveCfg = Release|Any CPU
{3C34B7FD-0415-421E-89B3-1EAFA3E0D9FC}.Release|x64.Build.0 = Release|Any CPU
{3C34B7FD-0415-421E-89B3-1EAFA3E0D9FC}.Release|x86.ActiveCfg = Release|Any CPU
{3C34B7FD-0415-421E-89B3-1EAFA3E0D9FC}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Declare assembly as CLS compliant.
//[assembly: System.CLSCompliant(true)]

namespace Polycode.NostalgicPlayer.Kit.Utility
namespace Polycode.NostalgicPlayer.CKit
{
/// <summary>
/// Implements several <a href="http://en.cppreference.com/w/c/numeric/math">C Standard</a> mathematical functions that are missing from the .NET framework.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
using System;
using System.Runtime.CompilerServices;
using System.Text;
using Polycode.NostalgicPlayer.Kit.Utility;

namespace Polycode.NostalgicPlayer.Kit.Utility
namespace Polycode.NostalgicPlayer.CKit
{
/// <summary>
/// C like memory methods
Expand All @@ -20,7 +21,7 @@ public static class CMemory
/// </summary>
/********************************************************************/
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Pointer<T> MAlloc<T>(int size) where T : struct
public static CPointer<T> MAlloc<T>(int size) where T : struct
{
return CAlloc<T>(size);
}
Expand All @@ -33,7 +34,7 @@ public static Pointer<T> MAlloc<T>(int size) where T : struct
/// </summary>
/********************************************************************/
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Pointer<T> MAllocObj<T>(int size) where T : new()
public static CPointer<T> MAllocObj<T>(int size) where T : new()
{
return CAllocObj<T>(size);
}
Expand All @@ -46,9 +47,9 @@ public static Pointer<T> MAlloc<T>(int size) where T : struct
/// </summary>
/********************************************************************/
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Pointer<T> CAlloc<T>(int size) where T : struct
public static CPointer<T> CAlloc<T>(int size) where T : struct
{
return new Pointer<T>(size);
return new CPointer<T>(size);
}


Expand All @@ -59,11 +60,11 @@ public static Pointer<T> CAlloc<T>(int size) where T : struct
/// </summary>
/********************************************************************/
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Pointer<T> CAllocObj<T>(int size) where T : new()
public static CPointer<T> CAllocObj<T>(int size) where T : new()
{
T[] array = ArrayHelper.InitializeArray<T>(size);

return new Pointer<T>(array);
return new CPointer<T>(array);
}


Expand All @@ -74,7 +75,7 @@ public static Pointer<T> CAlloc<T>(int size) where T : struct
/// </summary>
/********************************************************************/
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Pointer<T> Realloc<T>(Pointer<T> ptr, int newSize) where T : struct
public static CPointer<T> Realloc<T>(CPointer<T> ptr, int newSize) where T : struct
{
if (ptr.IsNull)
return MAlloc<T>(newSize);
Expand All @@ -85,7 +86,7 @@ public static Pointer<T> Realloc<T>(Pointer<T> ptr, int newSize) where T : struc
T[] newArray = new T[newSize];
Array.Copy(ptr.Buffer, ptr.Offset, newArray, 0, Math.Min(newSize, ptr.Length));

return new Pointer<T>(newArray);
return new CPointer<T>(newArray);
}


Expand All @@ -96,7 +97,7 @@ public static Pointer<T> Realloc<T>(Pointer<T> ptr, int newSize) where T : struc
/// </summary>
/********************************************************************/
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Pointer<T> ReallocObj<T>(Pointer<T> ptr, int newSize) where T : new()
public static CPointer<T> ReallocObj<T>(CPointer<T> ptr, int newSize) where T : new()
{
if (ptr.IsNull)
return MAllocObj<T>(newSize);
Expand All @@ -111,7 +112,7 @@ public static Pointer<T> Realloc<T>(Pointer<T> ptr, int newSize) where T : struc
for (int i = copyLength; i < newSize; i++)
newArray[i] = new T();

return new Pointer<T>(newArray);
return new CPointer<T>(newArray);
}


Expand All @@ -122,7 +123,7 @@ public static Pointer<T> Realloc<T>(Pointer<T> ptr, int newSize) where T : struc
/// </summary>
/********************************************************************/
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Free<T>(Pointer<T> ptr)
public static void Free<T>(CPointer<T> ptr)
{
}

Expand All @@ -134,7 +135,7 @@ public static void Free<T>(Pointer<T> ptr)
/// </summary>
/********************************************************************/
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void MemMove<T>(Pointer<T> dest, Pointer<T> source, int length)
public static void MemMove<T>(CPointer<T> dest, CPointer<T> source, int length)
{
if (length > 0)
Array.Copy(source.Buffer, source.Offset, dest.Buffer, dest.Offset, length);
Expand All @@ -148,7 +149,7 @@ public static void MemMove<T>(Pointer<T> dest, Pointer<T> source, int length)
/// </summary>
/********************************************************************/
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void MemCpy<T>(Pointer<T> dest, Pointer<T> source, int length)
public static void MemCpy<T>(CPointer<T> dest, CPointer<T> source, int length)
{
if (length > 0)
Array.Copy(source.Buffer, source.Offset, dest.Buffer, dest.Offset, length);
Expand Down Expand Up @@ -176,7 +177,7 @@ public static void MemCpy<T>(T[] dest, string str, int length)
/// </summary>
/********************************************************************/
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int MemCmp(Pointer<byte> ptr1, Pointer<byte> ptr2, int length)
public static int MemCmp(CPointer<byte> ptr1, CPointer<byte> ptr2, int length)
{
for (int i = 0; i < length; i++)
{
Expand All @@ -198,7 +199,7 @@ public static int MemCmp(Pointer<byte> ptr1, Pointer<byte> ptr2, int length)
/// </summary>
/********************************************************************/
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int MemCmp(Pointer<byte> ptr, string compareString, int length)
public static int MemCmp(CPointer<byte> ptr, string compareString, int length)
{
return MemCmp(ptr, Encoding.Latin1.GetBytes(compareString), length);
}
Expand All @@ -211,7 +212,7 @@ public static int MemCmp(Pointer<byte> ptr, string compareString, int length)
/// </summary>
/********************************************************************/
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int StrCmp(Pointer<byte> ptr, string compareString)
public static int StrCmp(CPointer<byte> ptr, string compareString)
{
byte[] strBuf = Encoding.Latin1.GetBytes(compareString);
return MemCmp(ptr, strBuf, strBuf.Length);
Expand All @@ -225,7 +226,7 @@ public static int StrCmp(Pointer<byte> ptr, string compareString)
/// </summary>
/********************************************************************/
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void MemSet<T>(Pointer<T> ptr, T value, int length)
public static void MemSet<T>(CPointer<T> ptr, T value, int length)
{
ptr.Buffer.AsSpan(ptr.Offset, length).Fill(value);
}
Expand All @@ -238,14 +239,14 @@ public static void MemSet<T>(Pointer<T> ptr, T value, int length)
/// </summary>
/********************************************************************/
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Pointer<T> MemChr<T>(Pointer<T> ptr, T ch, int count)
public static CPointer<T> MemChr<T>(CPointer<T> ptr, T ch, int count)
{
int searchLength = Math.Min(count, ptr.Length);

for (int i = 0; i < searchLength; i++)
{
if (ptr[i].Equals(ch))
return new Pointer<T>(ptr.Buffer, ptr.Offset + i);
return new CPointer<T>(ptr.Buffer, ptr.Offset + i);
}

return null;
Expand Down
Loading

0 comments on commit 22b9972

Please sign in to comment.