Skip to content

Commit

Permalink
Update MAC_SDK from 9.04 to 10.26
Browse files Browse the repository at this point in the history
- Original download location:
  https://monkeysaudio.com/files/MAC_1026_SDK.zip
  SHA256:
  cff58b2ee049bfbde131b050a7fabd216b1618d86ada3dd956e542490ae64394
- Update the CUETools specific MACLibDll.cpp and MACLibDll.h based on
  the upstream modifications to MACDll.cpp and MACDll.h, respectively.
  * c_APEDecompress_GetData:
    Use `unsigned char * pBuffer` instead of `char * pBuffer`
    Remark: The equivalent of unsigned char in C# is byte.
  * Rename macros from MAC_ to APE_ according to upstream (10.18) [1].
    MACLibDll.h:
      MAC_COMPRESSION_LEVEL_NORMAL -> APE_COMPRESSION_LEVEL_NORMAL
    MACLibDll.cpp:
      MAC_FILE_VERSION_NUMBER -> APE_FILE_VERSION_NUMBER
      MAC_VERSION_STRING -> APE_VERSION_STRING
  * `Seek()` is used again in IO.h since 10.00. Furthermore it returns
    int instead of int64 since 10.01 [1].
- Update ThirdParty_MAC_SDK_CUETools.patch accordingly
- The fix of the exception when decoding very small APE files (316f907)
  has been submitted upstream and merged in the meantime (9.10).
- Resolves #261

[1] https://monkeysaudio.com/versionhistory.html
  • Loading branch information
c72578 committed Nov 5, 2023
1 parent 287905e commit c088ed5
Show file tree
Hide file tree
Showing 11 changed files with 133 additions and 194 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
# yamllint disable-line rule:line-length
run: |
git apply --directory=ThirdParty/flac ThirdParty/submodule_flac_CUETools.patch --verbose --whitespace=nowarn
powershell -c "Expand-Archive ThirdParty/MAC_SDK/MAC_904_SDK.zip -DestinationPath ThirdParty/MAC_SDK/"
powershell -c "Expand-Archive ThirdParty/MAC_SDK/MAC_1026_SDK.zip -DestinationPath ThirdParty/MAC_SDK/"
git apply --directory=ThirdParty/MAC_SDK ThirdParty/ThirdParty_MAC_SDK_CUETools.patch --verbose
git apply --directory=ThirdParty/taglib-sharp ThirdParty/submodule_taglib-sharp_CUETools.patch --verbose
git apply --directory=ThirdParty/WavPack ThirdParty/submodule_WavPack_CUETools.patch --verbose
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
# yamllint disable-line rule:line-length
run: |
git apply --directory=ThirdParty/flac ThirdParty/submodule_flac_CUETools.patch --verbose --whitespace=nowarn
powershell -c "Expand-Archive ThirdParty/MAC_SDK/MAC_904_SDK.zip -DestinationPath ThirdParty/MAC_SDK/"
powershell -c "Expand-Archive ThirdParty/MAC_SDK/MAC_1026_SDK.zip -DestinationPath ThirdParty/MAC_SDK/"
git apply --directory=ThirdParty/MAC_SDK ThirdParty/ThirdParty_MAC_SDK_CUETools.patch --verbose
git apply --directory=ThirdParty/taglib-sharp ThirdParty/submodule_taglib-sharp_CUETools.patch --verbose
git apply --directory=ThirdParty/WavPack ThirdParty/submodule_WavPack_CUETools.patch --verbose
Expand Down
2 changes: 1 addition & 1 deletion CUETools.Codecs.MACLib/AudioDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public int Read(AudioBuffer buff, int maxLength)
long nBlocksRetrieved;
fixed (byte* pSampleBuffer = &_samplesBuffer[0])
{
int res = MACLibDll.c_APEDecompress_GetData(pAPEDecompress, (char*)pSampleBuffer, 16384, out nBlocksRetrieved);
int res = MACLibDll.c_APEDecompress_GetData(pAPEDecompress, pSampleBuffer, 16384, out nBlocksRetrieved);
if (res != 0)
throw new Exception("An error occurred while decoding: " + res.ToString());
}
Expand Down
4 changes: 3 additions & 1 deletion CUETools.Codecs.MACLib/MACLib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ internal enum APE_DECOMPRESS_FIELDS : int
APE_INFO_FRAME_BLOCKS = 1029, // blocks in a given frame [frame index, ignored]
APE_INFO_TAG = 1030, // point to tag (CAPETag *) [ignored, ignored]
APE_INFO_APL = 1031, // whether it's an APL file
APE_INFO_MD5 = 1032, // the MD5 checksum [buffer *, ignored]
APE_INFO_MD5_MATCHES = 1033, // an MD5 checksum to test (returns ERROR_INVALID_CHECKSUM or ERROR_SUCCESS) [buffer *, ignored]

APE_DECOMPRESS_CURRENT_BLOCK = 2000, // current block location [ignored, ignored]
APE_DECOMPRESS_CURRENT_MS = 2001, // current millisecond location [ignored, ignored]
Expand All @@ -58,7 +60,7 @@ internal enum APE_DECOMPRESS_FIELDS : int
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
internal unsafe delegate long CIO_GetSizeDelegate(void* pUserData);
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
internal unsafe delegate long CIO_SeekDelegate(void* pUserData, long delta, int mode);
internal unsafe delegate int CIO_SeekDelegate(void* pUserData, long delta, int mode);

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 2)]
public unsafe struct WAVEFORMATEX
Expand Down
2 changes: 1 addition & 1 deletion CUETools.Codecs.MACLib/MACLibDll.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ internal static extern int c_APECompress_StartEx(
internal static extern int c_APEDecompress_Seek(IntPtr hAPEDecompress, long nBlockOffset);

[DllImport(DllName, CallingConvention = DllCallingConvention)]
internal static extern int c_APEDecompress_GetData(IntPtr hAPEDecompress, char* pBuffer, long nBlocks, out long pBlocksRetrieved);
internal static extern int c_APEDecompress_GetData(IntPtr hAPEDecompress, byte* pBuffer, long nBlocks, out long pBlocksRetrieved);

[DllImport(DllName, CallingConvention = DllCallingConvention)]
internal static extern void c_APEDecompress_Destroy(IntPtr hAPEDecompress);
Expand Down
2 changes: 1 addition & 1 deletion CUETools.Codecs.MACLib/StreamIO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ long GetSizeCallback(void* id)
return m_stream.Length;
}

long SeekRelativeCallback(void* id, long delta, int mode)
int SeekRelativeCallback(void* id, long delta, int mode)
{
m_stream.Seek(delta, (SeekOrigin)(mode));
return 0;
Expand Down
Binary file added ThirdParty/MAC_SDK/MAC_1026_SDK.zip
Binary file not shown.
Binary file removed ThirdParty/MAC_SDK/MAC_904_SDK.zip
Binary file not shown.
10 changes: 5 additions & 5 deletions ThirdParty/MAC_SDK/Source/MACLibDll/MACLibDll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ class CallbackCIO : public CIO
}

// seek
APE::int64 PerformSeek()
int Seek(APE::int64 nDistance, APE::SeekMethod nMoveMode)
{
return m_CIO_Seek(m_pUserData, m_nSeekPosition, m_nSeekMethod);
return m_CIO_Seek(m_pUserData, nDistance, nMoveMode);
}

// other functions
Expand Down Expand Up @@ -95,12 +95,12 @@ class CallbackCIO : public CIO

int __stdcall GetVersionNumber()
{
return MAC_FILE_VERSION_NUMBER;
return APE_FILE_VERSION_NUMBER;
}

const wchar_t *__stdcall GetVersionString()
{
return MAC_VERSION_STRING;
return APE_VERSION_STRING;
}

APE_CIO_HANDLE __stdcall c_APECIO_Create(void* pUserData,
Expand Down Expand Up @@ -148,7 +148,7 @@ void __stdcall c_APEDecompress_Destroy(APE_DECOMPRESS_HANDLE hAPEDecompress)
delete pAPEDecompress;
}

int __stdcall c_APEDecompress_GetData(APE_DECOMPRESS_HANDLE hAPEDecompress, char * pBuffer, APE::int64 nBlocks, APE::int64 * pBlocksRetrieved)
int __stdcall c_APEDecompress_GetData(APE_DECOMPRESS_HANDLE hAPEDecompress, unsigned char * pBuffer, APE::int64 nBlocks, APE::int64 * pBlocksRetrieved)
{
return (static_cast<IAPEDecompress *>(hAPEDecompress))->GetData(pBuffer, nBlocks, pBlocksRetrieved);
}
Expand Down
12 changes: 6 additions & 6 deletions ThirdParty/MAC_SDK/Source/MACLibDll/MACLibDll.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ typedef void * APE_CIO_HANDLE;

typedef int (__stdcall *proc_APECIO_Read)(void* pUserData, void * pBuffer, unsigned int nBytesToRead, unsigned int * pBytesRead);
typedef int (__stdcall *proc_APECIO_Write)(void* pUserData, const void * pBuffer, unsigned int nBytesToWrite, unsigned int * pBytesWritten);
typedef APE::int64 (__stdcall *proc_APECIO_Seek)(void* pUserData, APE::int64 nDistance, unsigned int nMoveMode);
typedef int (__stdcall *proc_APECIO_Seek)(void* pUserData, APE::int64 nDistance, unsigned int nMoveMode);
typedef APE::int64 (__stdcall *proc_APECIO_GetPosition)(void* pUserData);
typedef APE::int64 (__stdcall *proc_APECIO_GetSize)(void* pUserData);

Expand Down Expand Up @@ -69,10 +69,10 @@ extern "C"
DLLEXPORT APE_COMPRESS_HANDLE __stdcall c_APECompress_Create(int * pErrorCode = NULL);
DLLEXPORT void __stdcall c_APECompress_Destroy(APE_COMPRESS_HANDLE hAPECompress);
#ifndef EXCLUDE_CIO
DLLEXPORT int __stdcall c_APECompress_Start(APE_COMPRESS_HANDLE hAPECompress, const char * pOutputFilename, const APE::WAVEFORMATEX * pwfeInput, APE::int64 nMaxAudioBytes = MAX_AUDIO_BYTES_UNKNOWN, int nCompressionLevel = MAC_COMPRESSION_LEVEL_NORMAL, const void * pHeaderData = NULL, APE::int64 nHeaderBytes = CREATE_WAV_HEADER_ON_DECOMPRESSION);
DLLEXPORT int __stdcall c_APECompress_StartW(APE_COMPRESS_HANDLE hAPECompress, const APE::str_utfn * pOutputFilename, const APE::WAVEFORMATEX * pwfeInput, APE::int64 nMaxAudioBytes = MAX_AUDIO_BYTES_UNKNOWN, int nCompressionLevel = MAC_COMPRESSION_LEVEL_NORMAL, const void * pHeaderData = NULL, APE::int64 nHeaderBytes = CREATE_WAV_HEADER_ON_DECOMPRESSION);
DLLEXPORT int __stdcall c_APECompress_Start(APE_COMPRESS_HANDLE hAPECompress, const char * pOutputFilename, const APE::WAVEFORMATEX * pwfeInput, APE::int64 nMaxAudioBytes = MAX_AUDIO_BYTES_UNKNOWN, int nCompressionLevel = APE_COMPRESSION_LEVEL_NORMAL, const void * pHeaderData = NULL, APE::int64 nHeaderBytes = CREATE_WAV_HEADER_ON_DECOMPRESSION);
DLLEXPORT int __stdcall c_APECompress_StartW(APE_COMPRESS_HANDLE hAPECompress, const APE::str_utfn * pOutputFilename, const APE::WAVEFORMATEX * pwfeInput, APE::int64 nMaxAudioBytes = MAX_AUDIO_BYTES_UNKNOWN, int nCompressionLevel = APE_COMPRESSION_LEVEL_NORMAL, const void * pHeaderData = NULL, APE::int64 nHeaderBytes = CREATE_WAV_HEADER_ON_DECOMPRESSION);
#endif
DLLEXPORT int __stdcall c_APECompress_StartEx(APE_COMPRESS_HANDLE hAPECompress, APE_CIO_HANDLE hCIO, const APE::WAVEFORMATEX * pwfeInput, APE::int64 nMaxAudioBytes = MAX_AUDIO_BYTES_UNKNOWN, int nCompressionLevel = MAC_COMPRESSION_LEVEL_NORMAL, const void * pHeaderData = NULL, APE::int64 nHeaderBytes = CREATE_WAV_HEADER_ON_DECOMPRESSION);
DLLEXPORT int __stdcall c_APECompress_StartEx(APE_COMPRESS_HANDLE hAPECompress, APE_CIO_HANDLE hCIO, const APE::WAVEFORMATEX * pwfeInput, APE::int64 nMaxAudioBytes = MAX_AUDIO_BYTES_UNKNOWN, int nCompressionLevel = APE_COMPRESSION_LEVEL_NORMAL, const void * pHeaderData = NULL, APE::int64 nHeaderBytes = CREATE_WAV_HEADER_ON_DECOMPRESSION);
DLLEXPORT APE::int64 __stdcall c_APECompress_AddData(APE_COMPRESS_HANDLE hAPECompress, unsigned char * pData, int nBytes);
DLLEXPORT int __stdcall c_APECompress_GetBufferBytesAvailable(APE_COMPRESS_HANDLE hAPECompress);
DLLEXPORT unsigned char * __stdcall c_APECompress_LockBuffer(APE_COMPRESS_HANDLE hAPECompress, APE::int64 * pBytesAvailable);
Expand All @@ -92,7 +92,7 @@ typedef APE_DECOMPRESS_HANDLE (__stdcall * proc_APEDecompress_CreateW)(const APE
#endif
typedef APE_DECOMPRESS_HANDLE (__stdcall * proc_APEDecompress_CreateEx)(APE_CIO_HANDLE, int *);
typedef void (__stdcall * proc_APEDecompress_Destroy)(APE_DECOMPRESS_HANDLE);
typedef int (__stdcall * proc_APEDecompress_GetData)(APE_DECOMPRESS_HANDLE, char *, APE::int64, APE::int64 *);
typedef int (__stdcall * proc_APEDecompress_GetData)(APE_DECOMPRESS_HANDLE, unsigned char *, APE::int64, APE::int64 *);
typedef int (__stdcall * proc_APEDecompress_Seek)(APE_DECOMPRESS_HANDLE, APE::int64);
typedef APE::int64 (__stdcall * proc_APEDecompress_GetInfo)(APE_DECOMPRESS_HANDLE, APE::IAPEDecompress::APE_DECOMPRESS_FIELDS, APE::int64, APE::int64);

Expand All @@ -104,7 +104,7 @@ extern "C"
#endif
DLLEXPORT APE_DECOMPRESS_HANDLE __stdcall c_APEDecompress_CreateEx(APE_CIO_HANDLE hCIO, int * pErrorCode = NULL);
DLLEXPORT void __stdcall c_APEDecompress_Destroy(APE_DECOMPRESS_HANDLE hAPEDecompress);
DLLEXPORT int __stdcall c_APEDecompress_GetData(APE_DECOMPRESS_HANDLE hAPEDecompress, char * pBuffer, APE::int64 nBlocks, APE::int64 * pBlocksRetrieved);
DLLEXPORT int __stdcall c_APEDecompress_GetData(APE_DECOMPRESS_HANDLE hAPEDecompress, unsigned char * pBuffer, APE::int64 nBlocks, APE::int64 * pBlocksRetrieved);
DLLEXPORT int __stdcall c_APEDecompress_Seek(APE_DECOMPRESS_HANDLE hAPEDecompress, APE::int64 nBlockOffset);
DLLEXPORT APE::int64 __stdcall c_APEDecompress_GetInfo(APE_DECOMPRESS_HANDLE hAPEDecompress, APE::IAPEDecompress::APE_DECOMPRESS_FIELDS Field, APE::int64 nParam1 = 0, APE::int64 nParam2 = 0);
}
Loading

0 comments on commit c088ed5

Please sign in to comment.