mirror of
https://github.com/claunia/cuetools.net.git
synced 2025-12-16 18:14:25 +00:00
misc cleanup
This commit is contained in:
@@ -16,18 +16,18 @@ namespace CUETools.Codecs.MACLib
|
||||
m_StreamIO = new StreamIO(m_stream);
|
||||
|
||||
int errorCode = 0;
|
||||
pAPEDecompress = MACLibDll.c_APEDecompress_CreateEx(m_StreamIO.Callbacks, out errorCode);
|
||||
pAPEDecompress = MACLibDll.c_APEDecompress_CreateEx(m_StreamIO.CIO, out errorCode);
|
||||
if (pAPEDecompress == null) {
|
||||
throw new Exception("Unable to initialize the decoder: " + errorCode);
|
||||
}
|
||||
|
||||
pcm = new AudioPCMConfig(
|
||||
MACLibDll.c_APEDecompress_GetInfo(pAPEDecompress, APE_DECOMPRESS_FIELDS.APE_INFO_BITS_PER_SAMPLE, 0, 0),
|
||||
MACLibDll.c_APEDecompress_GetInfo(pAPEDecompress, APE_DECOMPRESS_FIELDS.APE_INFO_CHANNELS, 0, 0),
|
||||
MACLibDll.c_APEDecompress_GetInfo(pAPEDecompress, APE_DECOMPRESS_FIELDS.APE_INFO_SAMPLE_RATE, 0, 0),
|
||||
MACLibDll.c_APEDecompress_GetInfo(pAPEDecompress, APE_DECOMPRESS_FIELDS.APE_INFO_BITS_PER_SAMPLE, 0, 0).ToInt32(),
|
||||
MACLibDll.c_APEDecompress_GetInfo(pAPEDecompress, APE_DECOMPRESS_FIELDS.APE_INFO_CHANNELS, 0, 0).ToInt32(),
|
||||
MACLibDll.c_APEDecompress_GetInfo(pAPEDecompress, APE_DECOMPRESS_FIELDS.APE_INFO_SAMPLE_RATE, 0, 0).ToInt32(),
|
||||
(AudioPCMConfig.SpeakerConfig)0);
|
||||
_samplesBuffer = new byte[16384 * pcm.BlockAlign];
|
||||
_sampleCount = MACLibDll.c_APEDecompress_GetInfo(pAPEDecompress, APE_DECOMPRESS_FIELDS.APE_DECOMPRESS_TOTAL_BLOCKS, 0, 0);
|
||||
_sampleCount = MACLibDll.c_APEDecompress_GetInfo(pAPEDecompress, APE_DECOMPRESS_FIELDS.APE_DECOMPRESS_TOTAL_BLOCKS, 0, 0).ToInt64();
|
||||
_sampleOffset = 0;
|
||||
}
|
||||
|
||||
@@ -66,8 +66,6 @@ namespace CUETools.Codecs.MACLib
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
// TODO: intn should always be 64 bit? Or should we use different interface in 32-bit mode?
|
||||
|
||||
private DecoderSettings m_settings;
|
||||
|
||||
public IAudioDecoderSettings Settings => m_settings;
|
||||
|
||||
@@ -133,7 +133,7 @@ namespace CUETools.Codecs.MACLib
|
||||
|
||||
int res = MACLibDll.c_APECompress_StartEx(
|
||||
pAPECompress,
|
||||
m_StreamIO.Callbacks,
|
||||
m_StreamIO.CIO,
|
||||
pWaveFormatEx,
|
||||
(m_finalSampleCount == 0) ? -1 : (int) (m_finalSampleCount * m_settings.PCM.BlockAlign),
|
||||
compressionLevel,
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\CUETools.Codecs\CUETools.Codecs.csproj" />
|
||||
<ProjectReference Include="..\ThirdParty\MAC_SDK\Source\Projects\VS2017\MACLibDll\MACLibDll.vcxproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -49,15 +49,15 @@ namespace CUETools.Codecs.MACLib
|
||||
};
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
|
||||
internal unsafe delegate int CIO_ReadDelegate(APE_CIO_Callbacks* pCIO, void* pBuffer, int nBytesToRead, out int pBytesRead);
|
||||
internal unsafe delegate int CIO_ReadDelegate(void* pUserData, void* pBuffer, int nBytesToRead, out int pBytesRead);
|
||||
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
|
||||
internal unsafe delegate int CIO_WriteDelegate(APE_CIO_Callbacks* pCIO, void* pBuffer, int nBytesToWrite, out int pBytesWritten);
|
||||
internal unsafe delegate int CIO_WriteDelegate(void* pUserData, void* pBuffer, int nBytesToWrite, out int pBytesWritten);
|
||||
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
|
||||
internal unsafe delegate int CIO_GetPositionDelegate(APE_CIO_Callbacks* pCIO);
|
||||
internal unsafe delegate int CIO_GetPositionDelegate(void* pUserData);
|
||||
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
|
||||
internal unsafe delegate uint CIO_GetSizeDelegate(APE_CIO_Callbacks* pCIO);
|
||||
internal unsafe delegate uint CIO_GetSizeDelegate(void* pUserData);
|
||||
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
|
||||
internal unsafe delegate int CIO_SeekDelegate(APE_CIO_Callbacks* pCIO, IntPtr delta, int mode);
|
||||
internal unsafe delegate int CIO_SeekDelegate(void* pUserData, IntPtr delta, int mode);
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 2)]
|
||||
public unsafe struct WAVEFORMATEX
|
||||
@@ -77,14 +77,4 @@ namespace CUETools.Codecs.MACLib
|
||||
/// <summary>number of following bytes</summary>
|
||||
internal short extraSize;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential), Serializable]
|
||||
internal unsafe struct APE_CIO_Callbacks
|
||||
{
|
||||
internal IntPtr read_bytes;
|
||||
internal IntPtr write_bytes;
|
||||
internal IntPtr seek;
|
||||
internal IntPtr get_pos;
|
||||
internal IntPtr get_size;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -17,6 +17,18 @@ namespace CUETools.Codecs.MACLib
|
||||
[DllImport(DllName, CallingConvention = DllCallingConvention)]
|
||||
internal static extern IntPtr GetVersionString();
|
||||
|
||||
[DllImport(DllName, CallingConvention = DllCallingConvention)]
|
||||
internal static extern IntPtr c_APECIO_Create(
|
||||
void* pUserData,
|
||||
CIO_ReadDelegate CIO_Read,
|
||||
CIO_WriteDelegate CIO_Write,
|
||||
CIO_SeekDelegate CIO_Seek,
|
||||
CIO_GetPositionDelegate CIO_GetPosition,
|
||||
CIO_GetSizeDelegate CIO_GetSize);
|
||||
|
||||
[DllImport(DllName, CallingConvention = DllCallingConvention)]
|
||||
internal static extern void c_APECIO_Destroy(IntPtr hCIO);
|
||||
|
||||
[DllImport(DllName, CallingConvention = DllCallingConvention)]
|
||||
internal static extern IntPtr c_APECompress_Create(out int error);
|
||||
|
||||
@@ -32,7 +44,7 @@ namespace CUETools.Codecs.MACLib
|
||||
[DllImport(DllName, CallingConvention = DllCallingConvention)]
|
||||
internal static extern int c_APECompress_StartEx(
|
||||
IntPtr hAPECompress,
|
||||
APE_CIO_Callbacks* pCIO,
|
||||
IntPtr hCIO,
|
||||
WAVEFORMATEX* pwfeInput,
|
||||
int nMaxAudioBytes,
|
||||
int nCompressionLevel,
|
||||
@@ -40,10 +52,10 @@ namespace CUETools.Codecs.MACLib
|
||||
int nHeaderBytes);
|
||||
|
||||
[DllImport(DllName, CallingConvention = DllCallingConvention)]
|
||||
internal static extern IntPtr c_APEDecompress_CreateEx(APE_CIO_Callbacks* pCIO, out int pErrorCode);
|
||||
internal static extern IntPtr c_APEDecompress_CreateEx(IntPtr hCIO, out int pErrorCode);
|
||||
|
||||
[DllImport(DllName, CallingConvention = DllCallingConvention)]
|
||||
internal static extern int c_APEDecompress_GetInfo(IntPtr hAPEDecompress, APE_DECOMPRESS_FIELDS Field, int nParam1 = 0, int nParam2 = 0);
|
||||
internal static extern IntPtr c_APEDecompress_GetInfo(IntPtr hAPEDecompress, APE_DECOMPRESS_FIELDS Field, int nParam1 = 0, int nParam2 = 0);
|
||||
|
||||
[DllImport(DllName, CallingConvention = DllCallingConvention)]
|
||||
internal static extern int c_APEDecompress_Seek(IntPtr hAPEDecompress, int nBlockOffset);
|
||||
|
||||
@@ -12,18 +12,15 @@ namespace CUETools.Codecs.MACLib
|
||||
{
|
||||
m_stream = stream;
|
||||
|
||||
// We keep the references to those callbacks to
|
||||
// prevent them from being garbage collected.
|
||||
m_read_bytes = ReadCallback;
|
||||
m_write_bytes = WriteCallback;
|
||||
m_get_pos = TellCallback;
|
||||
m_get_size = GetSizeCallback;
|
||||
m_seek = SeekRelativeCallback;
|
||||
|
||||
m_callbacks = (APE_CIO_Callbacks*)Marshal.AllocHGlobal(sizeof(APE_CIO_Callbacks)).ToPointer();
|
||||
m_callbacks->read_bytes = Marshal.GetFunctionPointerForDelegate(m_read_bytes);
|
||||
m_callbacks->write_bytes = Marshal.GetFunctionPointerForDelegate(m_write_bytes);
|
||||
m_callbacks->get_pos = Marshal.GetFunctionPointerForDelegate(m_get_pos);
|
||||
m_callbacks->get_size = Marshal.GetFunctionPointerForDelegate(m_get_size);
|
||||
m_callbacks->seek = Marshal.GetFunctionPointerForDelegate(m_seek);
|
||||
m_hCIO = MACLibDll.c_APECIO_Create(null, m_read_bytes, m_write_bytes, m_seek, m_get_pos, m_get_size);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
@@ -40,8 +37,8 @@ namespace CUETools.Codecs.MACLib
|
||||
_readBuffer = null;
|
||||
}
|
||||
|
||||
if (m_callbacks != null) Marshal.FreeHGlobal((IntPtr)m_callbacks);
|
||||
m_callbacks = null;
|
||||
MACLibDll.c_APECIO_Destroy(m_hCIO);
|
||||
m_hCIO = IntPtr.Zero;
|
||||
}
|
||||
|
||||
~StreamIO()
|
||||
@@ -49,7 +46,7 @@ namespace CUETools.Codecs.MACLib
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
private int ReadCallback(APE_CIO_Callbacks* id, void* data, int bcount, out int pBytesRead)
|
||||
private int ReadCallback(void* id, void* data, int bcount, out int pBytesRead)
|
||||
{
|
||||
if (_readBuffer == null || _readBuffer.Length < bcount)
|
||||
_readBuffer = new byte[Math.Max(bcount, 0x4000)];
|
||||
@@ -59,7 +56,7 @@ namespace CUETools.Codecs.MACLib
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int WriteCallback(APE_CIO_Callbacks* id, void* data, int bcount, out int pBytesWritten)
|
||||
private int WriteCallback(void* id, void* data, int bcount, out int pBytesWritten)
|
||||
{
|
||||
if (_readBuffer == null || _readBuffer.Length < bcount)
|
||||
_readBuffer = new byte[Math.Max(bcount, 0x4000)];
|
||||
@@ -69,25 +66,24 @@ namespace CUETools.Codecs.MACLib
|
||||
return 0;
|
||||
}
|
||||
|
||||
int TellCallback(APE_CIO_Callbacks* id)
|
||||
int TellCallback(void* id)
|
||||
{
|
||||
return (int)m_stream.Position;
|
||||
}
|
||||
|
||||
uint GetSizeCallback(APE_CIO_Callbacks* id)
|
||||
uint GetSizeCallback(void* id)
|
||||
{
|
||||
return (uint)m_stream.Length;
|
||||
}
|
||||
|
||||
int SeekRelativeCallback(APE_CIO_Callbacks* id, IntPtr delta, int mode)
|
||||
int SeekRelativeCallback(void* id, IntPtr delta, int mode)
|
||||
{
|
||||
m_stream.Seek((long)delta, (SeekOrigin)(mode));
|
||||
return 0;
|
||||
}
|
||||
|
||||
internal APE_CIO_Callbacks* Callbacks => m_callbacks;
|
||||
internal IntPtr CIO => m_hCIO;
|
||||
|
||||
APE_CIO_Callbacks* m_callbacks;
|
||||
Stream m_stream;
|
||||
byte[] _readBuffer;
|
||||
CIO_ReadDelegate m_read_bytes;
|
||||
@@ -95,5 +91,6 @@ namespace CUETools.Codecs.MACLib
|
||||
CIO_GetPositionDelegate m_get_pos;
|
||||
CIO_GetSizeDelegate m_get_size;
|
||||
CIO_SeekDelegate m_seek;
|
||||
internal IntPtr m_hCIO;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user