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