4 /*****************************************************************************************
5 Cross platform building switch
6 *****************************************************************************************/
7 //#define BUILD_CROSS_PLATFORM
9 /*****************************************************************************************
11 *****************************************************************************************/
16 #endif // #ifdef _UNICODE
19 /*****************************************************************************************
21 *****************************************************************************************/
22 #ifndef BUILD_CROSS_PLATFORM
23 // #include <windows.h>
33 #include <sys/types.h>
35 #include "NoWindows.h"
45 /*****************************************************************************************
46 Global compiler settings (useful for porting)
47 *****************************************************************************************/
48 #ifndef BUILD_CROSS_PLATFORM
49 #define ENABLE_ASSEMBLY
52 #define BACKWARDS_COMPATIBILITY
54 #define ENABLE_COMPRESSION_MODE_FAST
55 #define ENABLE_COMPRESSION_MODE_NORMAL
56 #define ENABLE_COMPRESSION_MODE_HIGH
57 #define ENABLE_COMPRESSION_MODE_EXTRA_HIGH
60 typedef unsigned __int32 uint32
;
61 typedef __int32 int32
;
62 typedef unsigned __int16 uint16
;
63 typedef __int16 int16
;
64 typedef unsigned __int8 uint8
;
66 typedef char str_ansi
;
67 typedef unsigned char str_utf8
;
68 typedef wchar_t str_utf16
;
70 #define IO_USE_WIN_FILE_IO
71 #define IO_HEADER_FILE "WinFileIO.h"
72 #define IO_CLASS_NAME CWinFileIO
73 #define DLLEXPORT __declspec(dllexport)
74 #define SLEEP(MILLISECONDS) ::Sleep(MILLISECONDS)
75 #define MESSAGEBOX(PARENT, TEXT, CAPTION, TYPE) ::MessageBox(PARENT, TEXT, CAPTION, TYPE)
76 #define PUMP_MESSAGE_LOOP { MSG Msg; while (PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE) != 0) { TranslateMessage(&Msg); DispatchMessage(&Msg); } }
77 #define ODS OutputDebugString
78 #define TICK_COUNT_TYPE unsigned long
79 #define TICK_COUNT_READ(VARIABLE) VARIABLE = GetTickCount()
80 #define TICK_COUNT_FREQ 1000
82 #define IO_USE_STD_LIB_FILE_IO
83 #define IO_HEADER_FILE "StdLibFileIO.h"
84 #define IO_CLASS_NAME CStdLibFileIO
86 #define SLEEP(MILLISECONDS) { struct timespec t; t.tv_sec = (MILLISECONDS) / 1000; t.tv_nsec = (MILLISECONDS) % 1000 * 1000000; nanosleep(&t, NULL); }
87 #define MESSAGEBOX(PARENT, TEXT, CAPTION, TYPE)
88 #define PUMP_MESSAGE_LOOP
90 #define TICK_COUNT_TYPE unsigned long long
91 #define TICK_COUNT_READ(VARIABLE) { struct timeval t; gettimeofday(&t, NULL); VARIABLE = t.tv_sec * 1000000LLU + t.tv_usec; }
92 #define TICK_COUNT_FREQ 1000000
95 /*****************************************************************************************
97 *****************************************************************************************/
98 #define MAC_VERSION_NUMBER 3990
99 #define MAC_VERSION_STRING _T("3.99")
100 #define MAC_NAME _T("Monkey's Audio 3.99")
101 #define PLUGIN_NAME "Monkey's Audio Player v3.99"
102 #define MJ_PLUGIN_NAME _T("APE Plugin (v3.99)")
103 #define CONSOLE_NAME "--- Monkey's Audio Console Front End (v 3.99) (c) Matthew T. Ashland ---\n"
104 #define PLUGIN_ABOUT _T("Monkey's Audio Player v3.99\nCopyrighted (c) 2000-2004 by Matthew T. Ashland")
105 #define MAC_DLL_INTERFACE_VERSION_NUMBER 1000
107 /*****************************************************************************************
109 *****************************************************************************************/
110 //#define __LITTLE_ENDIAN 1234
111 //#define __BIG_ENDIAN 4321
112 //#define __BYTE_ORDER __LITTLE_ENDIAN
114 /*****************************************************************************************
116 *****************************************************************************************/
117 #define MB(TEST) MESSAGEBOX(NULL, TEST, _T("Information"), MB_OK);
118 #define MBN(NUMBER) { TCHAR cNumber[16]; _stprintf(cNumber, _T("%d"), NUMBER); MESSAGEBOX(NULL, cNumber, _T("Information"), MB_OK); }
120 #define SAFE_DELETE(POINTER) if (POINTER) { delete POINTER; POINTER = NULL; }
121 #define SAFE_ARRAY_DELETE(POINTER) if (POINTER) { delete [] POINTER; POINTER = NULL; }
122 #define SAFE_VOID_CLASS_DELETE(POINTER, Class) { Class *pClass = (Class *) POINTER; if (pClass) { delete pClass; POINTER = NULL; } }
123 #define SAFE_FILE_CLOSE(HANDLE) if (HANDLE != INVALID_HANDLE_VALUE) { CloseHandle(HANDLE); HANDLE = INVALID_HANDLE_VALUE; }
125 #define ODN(NUMBER) { TCHAR cNumber[16]; _stprintf(cNumber, _T("%d\n"), int(NUMBER)); ODS(cNumber); }
127 #define CATCH_ERRORS(CODE) try { CODE } catch(...) { }
129 #define RETURN_ON_ERROR(FUNCTION) { int nRetVal = FUNCTION; if (nRetVal != 0) { return nRetVal; } }
130 #define RETURN_VALUE_ON_ERROR(FUNCTION, VALUE) { int nRetVal = FUNCTION; if (nRetVal != 0) { return VALUE; } }
131 #define RETURN_ON_EXCEPTION(CODE, VALUE) { try { CODE } catch(...) { return VALUE; } }
133 #define THROW_ON_ERROR(CODE) { int nRetVal = CODE; if (nRetVal != 0) throw(nRetVal); }
135 #define EXPAND_1_TIMES(CODE) CODE
136 #define EXPAND_2_TIMES(CODE) CODE CODE
137 #define EXPAND_3_TIMES(CODE) CODE CODE CODE
138 #define EXPAND_4_TIMES(CODE) CODE CODE CODE CODE
139 #define EXPAND_5_TIMES(CODE) CODE CODE CODE CODE CODE
140 #define EXPAND_6_TIMES(CODE) CODE CODE CODE CODE CODE CODE
141 #define EXPAND_7_TIMES(CODE) CODE CODE CODE CODE CODE CODE CODE
142 #define EXPAND_8_TIMES(CODE) CODE CODE CODE CODE CODE CODE CODE CODE
143 #define EXPAND_9_TIMES(CODE) CODE CODE CODE CODE CODE CODE CODE CODE CODE
144 #define EXPAND_12_TIMES(CODE) CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE
145 #define EXPAND_14_TIMES(CODE) CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE
146 #define EXPAND_15_TIMES(CODE) CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE
147 #define EXPAND_16_TIMES(CODE) CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE
148 #define EXPAND_30_TIMES(CODE) CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE
149 #define EXPAND_31_TIMES(CODE) CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE
150 #define EXPAND_32_TIMES(CODE) CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE
151 #define EXPAND_64_TIMES(CODE) CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE CODE
152 #define EXPAND_N_TIMES(NUMBER, CODE) EXPAND_##NUMBER##_TIMES(CODE)
154 #define UNROLL_4_TIMES(MACRO) MACRO(0) MACRO(1) MACRO(2) MACRO(3)
155 #define UNROLL_8_TIMES(MACRO) MACRO(0) MACRO(1) MACRO(2) MACRO(3) MACRO(4) MACRO(5) MACRO(6) MACRO(7)
156 #define UNROLL_15_TIMES(MACRO) MACRO(0) MACRO(1) MACRO(2) MACRO(3) MACRO(4) MACRO(5) MACRO(6) MACRO(7) MACRO(8) MACRO(9) MACRO(10) MACRO(11) MACRO(12) MACRO(13) MACRO(14)
157 #define UNROLL_16_TIMES(MACRO) MACRO(0) MACRO(1) MACRO(2) MACRO(3) MACRO(4) MACRO(5) MACRO(6) MACRO(7) MACRO(8) MACRO(9) MACRO(10) MACRO(11) MACRO(12) MACRO(13) MACRO(14) MACRO(15)
158 #define UNROLL_64_TIMES(MACRO) MACRO(0) MACRO(1) MACRO(2) MACRO(3) MACRO(4) MACRO(5) MACRO(6) MACRO(7) MACRO(8) MACRO(9) MACRO(10) MACRO(11) MACRO(12) MACRO(13) MACRO(14) MACRO(15) MACRO(16) MACRO(17) MACRO(18) MACRO(19) MACRO(20) MACRO(21) MACRO(22) MACRO(23) MACRO(24) MACRO(25) MACRO(26) MACRO(27) MACRO(28) MACRO(29) MACRO(30) MACRO(31) MACRO(32) MACRO(33) MACRO(34) MACRO(35) MACRO(36) MACRO(37) MACRO(38) MACRO(39) MACRO(40) MACRO(41) MACRO(42) MACRO(43) MACRO(44) MACRO(45) MACRO(46) MACRO(47) MACRO(48) MACRO(49) MACRO(50) MACRO(51) MACRO(52) MACRO(53) MACRO(54) MACRO(55) MACRO(56) MACRO(57) MACRO(58) MACRO(59) MACRO(60) MACRO(61) MACRO(62) MACRO(63)
159 #define UNROLL_128_TIMES(MACRO) MACRO(0) MACRO(1) MACRO(2) MACRO(3) MACRO(4) MACRO(5) MACRO(6) MACRO(7) MACRO(8) MACRO(9) MACRO(10) MACRO(11) MACRO(12) MACRO(13) MACRO(14) MACRO(15) MACRO(16) MACRO(17) MACRO(18) MACRO(19) MACRO(20) MACRO(21) MACRO(22) MACRO(23) MACRO(24) MACRO(25) MACRO(26) MACRO(27) MACRO(28) MACRO(29) MACRO(30) MACRO(31) MACRO(32) MACRO(33) MACRO(34) MACRO(35) MACRO(36) MACRO(37) MACRO(38) MACRO(39) MACRO(40) MACRO(41) MACRO(42) MACRO(43) MACRO(44) MACRO(45) MACRO(46) MACRO(47) MACRO(48) MACRO(49) MACRO(50) MACRO(51) MACRO(52) MACRO(53) MACRO(54) MACRO(55) MACRO(56) MACRO(57) MACRO(58) MACRO(59) MACRO(60) MACRO(61) MACRO(62) MACRO(63) MACRO(64) MACRO(65) MACRO(66) MACRO(67) MACRO(68) MACRO(69) MACRO(70) MACRO(71) MACRO(72) MACRO(73) MACRO(74) MACRO(75) MACRO(76) MACRO(77) MACRO(78) MACRO(79) MACRO(80) MACRO(81) MACRO(82) MACRO(83) MACRO(84) MACRO(85) MACRO(86) MACRO(87) MACRO(88) MACRO(89) MACRO(90) MACRO(91) MACRO(92) MACRO(93) MACRO(94) MACRO(95) MACRO(96) MACRO(97) MACRO(98) MACRO(99) MACRO(100) MACRO(101) MACRO(102) MACRO(103) MACRO(104) MACRO(105) MACRO(106) MACRO(107) MACRO(108) MACRO(109) MACRO(110) MACRO(111) MACRO(112) MACRO(113) MACRO(114) MACRO(115) MACRO(116) MACRO(117) MACRO(118) MACRO(119) MACRO(120) MACRO(121) MACRO(122) MACRO(123) MACRO(124) MACRO(125) MACRO(126) MACRO(127)
160 #define UNROLL_256_TIMES(MACRO) MACRO(0) MACRO(1) MACRO(2) MACRO(3) MACRO(4) MACRO(5) MACRO(6) MACRO(7) MACRO(8) MACRO(9) MACRO(10) MACRO(11) MACRO(12) MACRO(13) MACRO(14) MACRO(15) MACRO(16) MACRO(17) MACRO(18) MACRO(19) MACRO(20) MACRO(21) MACRO(22) MACRO(23) MACRO(24) MACRO(25) MACRO(26) MACRO(27) MACRO(28) MACRO(29) MACRO(30) MACRO(31) MACRO(32) MACRO(33) MACRO(34) MACRO(35) MACRO(36) MACRO(37) MACRO(38) MACRO(39) MACRO(40) MACRO(41) MACRO(42) MACRO(43) MACRO(44) MACRO(45) MACRO(46) MACRO(47) MACRO(48) MACRO(49) MACRO(50) MACRO(51) MACRO(52) MACRO(53) MACRO(54) MACRO(55) MACRO(56) MACRO(57) MACRO(58) MACRO(59) MACRO(60) MACRO(61) MACRO(62) MACRO(63) MACRO(64) MACRO(65) MACRO(66) MACRO(67) MACRO(68) MACRO(69) MACRO(70) MACRO(71) MACRO(72) MACRO(73) MACRO(74) MACRO(75) MACRO(76) MACRO(77) MACRO(78) MACRO(79) MACRO(80) MACRO(81) MACRO(82) MACRO(83) MACRO(84) MACRO(85) MACRO(86) MACRO(87) MACRO(88) MACRO(89) MACRO(90) MACRO(91) MACRO(92) MACRO(93) MACRO(94) MACRO(95) MACRO(96) MACRO(97) MACRO(98) MACRO(99) MACRO(100) MACRO(101) MACRO(102) MACRO(103) MACRO(104) MACRO(105) MACRO(106) MACRO(107) MACRO(108) MACRO(109) MACRO(110) MACRO(111) MACRO(112) MACRO(113) MACRO(114) MACRO(115) MACRO(116) MACRO(117) MACRO(118) MACRO(119) MACRO(120) MACRO(121) MACRO(122) MACRO(123) MACRO(124) MACRO(125) MACRO(126) MACRO(127) \
161 MACRO(128) MACRO(129) MACRO(130) MACRO(131) MACRO(132) MACRO(133) MACRO(134) MACRO(135) MACRO(136) MACRO(137) MACRO(138) MACRO(139) MACRO(140) MACRO(141) MACRO(142) MACRO(143) MACRO(144) MACRO(145) MACRO(146) MACRO(147) MACRO(148) MACRO(149) MACRO(150) MACRO(151) MACRO(152) MACRO(153) MACRO(154) MACRO(155) MACRO(156) MACRO(157) MACRO(158) MACRO(159) MACRO(160) MACRO(161) MACRO(162) MACRO(163) MACRO(164) MACRO(165) MACRO(166) MACRO(167) MACRO(168) MACRO(169) MACRO(170) MACRO(171) MACRO(172) MACRO(173) MACRO(174) MACRO(175) MACRO(176) MACRO(177) MACRO(178) MACRO(179) MACRO(180) MACRO(181) MACRO(182) MACRO(183) MACRO(184) MACRO(185) MACRO(186) MACRO(187) MACRO(188) MACRO(189) MACRO(190) MACRO(191) MACRO(192) MACRO(193) MACRO(194) MACRO(195) MACRO(196) MACRO(197) MACRO(198) MACRO(199) MACRO(200) MACRO(201) MACRO(202) MACRO(203) MACRO(204) MACRO(205) MACRO(206) MACRO(207) MACRO(208) MACRO(209) MACRO(210) MACRO(211) MACRO(212) MACRO(213) MACRO(214) MACRO(215) MACRO(216) MACRO(217) MACRO(218) MACRO(219) MACRO(220) MACRO(221) MACRO(222) MACRO(223) MACRO(224) MACRO(225) MACRO(226) MACRO(227) MACRO(228) MACRO(229) MACRO(230) MACRO(231) MACRO(232) MACRO(233) MACRO(234) MACRO(235) MACRO(236) MACRO(237) MACRO(238) MACRO(239) MACRO(240) MACRO(241) MACRO(242) MACRO(243) MACRO(244) MACRO(245) MACRO(246) MACRO(247) MACRO(248) MACRO(249) MACRO(250) MACRO(251) MACRO(252) MACRO(253) MACRO(254) MACRO(255)
163 /*****************************************************************************************
165 *****************************************************************************************/
168 #ifndef ERROR_SUCCESS
169 #define ERROR_SUCCESS 0
172 // file and i/o errors (1000's)
173 #define ERROR_IO_READ 1000
174 #define ERROR_IO_WRITE 1001
175 #define ERROR_INVALID_INPUT_FILE 1002
176 #define ERROR_INVALID_OUTPUT_FILE 1003
177 #define ERROR_INPUT_FILE_TOO_LARGE 1004
178 #define ERROR_INPUT_FILE_UNSUPPORTED_BIT_DEPTH 1005
179 #define ERROR_INPUT_FILE_UNSUPPORTED_SAMPLE_RATE 1006
180 #define ERROR_INPUT_FILE_UNSUPPORTED_CHANNEL_COUNT 1007
181 #define ERROR_INPUT_FILE_TOO_SMALL 1008
182 #define ERROR_INVALID_CHECKSUM 1009
183 #define ERROR_DECOMPRESSING_FRAME 1010
184 #define ERROR_INITIALIZING_UNMAC 1011
185 #define ERROR_INVALID_FUNCTION_PARAMETER 1012
186 #define ERROR_UNSUPPORTED_FILE_TYPE 1013
187 #define ERROR_UPSUPPORTED_FILE_VERSION 1014
189 // memory errors (2000's)
190 #define ERROR_INSUFFICIENT_MEMORY 2000
192 // dll errors (3000's)
193 #define ERROR_LOADINGAPE_DLL 3000
194 #define ERROR_LOADINGAPE_INFO_DLL 3001
195 #define ERROR_LOADING_UNMAC_DLL 3002
197 // general and misc errors
198 #define ERROR_USER_STOPPED_PROCESSING 4000
199 #define ERROR_SKIPPED 4001
202 #define ERROR_BAD_PARAMETER 5000
204 // IAPECompress errors
205 #define ERROR_APE_COMPRESS_TOO_MUCH_DATA 6000
208 #define ERROR_UNDEFINED -1
210 #define ERROR_EXPLANATION \
211 { ERROR_IO_READ , "I/O read error" }, \
212 { ERROR_IO_WRITE , "I/O write error" }, \
213 { ERROR_INVALID_INPUT_FILE , "invalid input file" }, \
214 { ERROR_INVALID_OUTPUT_FILE , "invalid output file" }, \
215 { ERROR_INPUT_FILE_TOO_LARGE , "input file file too large" }, \
216 { ERROR_INPUT_FILE_UNSUPPORTED_BIT_DEPTH , "input file unsupported bit depth" }, \
217 { ERROR_INPUT_FILE_UNSUPPORTED_SAMPLE_RATE , "input file unsupported sample rate" }, \
218 { ERROR_INPUT_FILE_UNSUPPORTED_CHANNEL_COUNT , "input file unsupported channel count" }, \
219 { ERROR_INPUT_FILE_TOO_SMALL , "input file too small" }, \
220 { ERROR_INVALID_CHECKSUM , "invalid checksum" }, \
221 { ERROR_DECOMPRESSING_FRAME , "decompressing frame" }, \
222 { ERROR_INITIALIZING_UNMAC , "initializing unmac" }, \
223 { ERROR_INVALID_FUNCTION_PARAMETER , "invalid function parameter" }, \
224 { ERROR_UNSUPPORTED_FILE_TYPE , "unsupported file type" }, \
225 { ERROR_INSUFFICIENT_MEMORY , "insufficient memory" }, \
226 { ERROR_LOADINGAPE_DLL , "loading MAC.dll" }, \
227 { ERROR_LOADINGAPE_INFO_DLL , "loading MACinfo.dll" }, \
228 { ERROR_LOADING_UNMAC_DLL , "loading UnMAC.dll" }, \
229 { ERROR_USER_STOPPED_PROCESSING , "user stopped processing" }, \
230 { ERROR_SKIPPED , "skipped" }, \
231 { ERROR_BAD_PARAMETER , "bad parameter" }, \
232 { ERROR_APE_COMPRESS_TOO_MUCH_DATA , "APE compress too much data" }, \
233 { ERROR_UNDEFINED , "undefined" }, \
235 #endif // #ifndef APE_ALL_H