main.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  1. /*
  2. ** nsv_coder_lame: main.cpp - LAME mp3 encoder plug-in
  3. ** (requires lame_enc.dll)
  4. **
  5. ** Copyright (C) 2001-2006 Nullsoft, Inc.
  6. **
  7. ** This software is provided 'as-is', without any express or implied warranty.
  8. ** In no event will the authors be held liable for any damages arising from the use of this software.
  9. **
  10. ** Permission is granted to anyone to use this software for any purpose, including commercial
  11. ** applications, and to alter it and redistribute it freely, subject to the following restrictions:
  12. ** 1. The origin of this software must not be misrepresented; you must not claim that you wrote the
  13. ** original software. If you use this software in a product, an acknowledgment in the product
  14. ** documentation would be appreciated but is not required.
  15. ** 2. Altered source versions must be plainly marked as such, and must not be misrepresented as
  16. ** being the original software.
  17. ** 3. This notice may not be removed or altered from any source distribution.
  18. */
  19. #define ENC_VERSION "v1.38"
  20. #include <stdio.h>
  21. #include "resource.h"
  22. #include "BladeMP3EncDLL.h"
  23. #include "MP3Coder.h"
  24. #include <strsafe.h>
  25. #include <shlwapi.h>
  26. #include <lame/lame.h>
  27. // wasabi based services for localisation support
  28. #include <api/service/waServiceFactory.h>
  29. #include "../Agave/Language/api_language.h"
  30. #include "../winamp/wa_ipc.h"
  31. HWND winampwnd = 0;
  32. api_service *WASABI_API_SVC = 0;
  33. api_language *WASABI_API_LNG = 0;
  34. HINSTANCE WASABI_API_LNG_HINST = 0, WASABI_API_ORIG_HINST = 0;
  35. int g_valid_bitrates[] = { 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, -1 };
  36. static wchar_t lamedll[MAX_PATH]=L"";
  37. HINSTANCE g_lamedll = 0;
  38. //BEINITSTREAM beInitStream=0;
  39. //BECLOSESTREAM beCloseStream=0;
  40. //BEENCODECHUNK beEncodeChunk=0;
  41. //BEDEINITSTREAM beDeinitStream=0;
  42. //BEWRITEVBRHEADER beWriteVBRHeader=0;
  43. //BEVERSION beVersion=0;
  44. //BEENCODECHUNKFLOATS16NI beEncodeChunkFloatS16NI=0;
  45. static HINSTANCE GetMyInstance()
  46. {
  47. MEMORY_BASIC_INFORMATION mbi = {0};
  48. if(VirtualQuery(GetMyInstance, &mbi, sizeof(mbi)))
  49. return (HINSTANCE)mbi.AllocationBase;
  50. return NULL;
  51. }
  52. void GetLocalisationApiService(void)
  53. {
  54. if(!WASABI_API_LNG)
  55. {
  56. // loader so that we can get the localisation service api for use
  57. if(!WASABI_API_SVC)
  58. {
  59. WASABI_API_SVC = (api_service*)SendMessage(winampwnd, WM_WA_IPC, 0, IPC_GET_API_SERVICE);
  60. if (WASABI_API_SVC == (api_service*)1)
  61. {
  62. WASABI_API_SVC = NULL;
  63. return;
  64. }
  65. }
  66. if(!WASABI_API_LNG)
  67. {
  68. waServiceFactory *sf;
  69. sf = WASABI_API_SVC->service_getServiceByGuid(languageApiGUID);
  70. if (sf) WASABI_API_LNG = reinterpret_cast<api_language*>(sf->getInterface());
  71. }
  72. // need to have this initialised before we try to do anything with localisation features
  73. WASABI_API_START_LANG(GetMyInstance(),EncLameLangGUID);
  74. }
  75. }
  76. /*
  77. BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
  78. {
  79. return TRUE;
  80. }*/
  81. typedef struct
  82. {
  83. configtype cfg;
  84. char configfile[MAX_PATH];
  85. }
  86. configwndrec;
  87. void BuildVersionString(wchar_t version[128])
  88. {
  89. BE_VERSION ver;
  90. beVersion(&ver);
  91. if (ver.byBetaLevel)
  92. StringCchPrintf(version, 128, L"%u.%ub%u", (unsigned int)ver.byMajorVersion, (unsigned int)ver.byMinorVersion, (unsigned int)ver.byBetaLevel);
  93. else if (ver.byAlphaLevel)
  94. StringCchPrintf(version, 128, L"%u.%ua%u", (unsigned int)ver.byMajorVersion, (unsigned int)ver.byMinorVersion, (unsigned int)ver.byAlphaLevel);
  95. else
  96. StringCchPrintf(version, 128, L"%u.%u", (unsigned int)ver.byMajorVersion, (unsigned int)ver.byMinorVersion);
  97. }
  98. void readconfig(char *configfile, configtype *cfg)
  99. {
  100. cfg->bitrate = 128;
  101. cfg->vbr_max_bitrate = 320;
  102. cfg->abr_bitrate = 128;
  103. cfg->stereo_mode = 1;
  104. cfg->quality = LQP_FAST_STANDARD;
  105. cfg->vbr = 2;
  106. cfg->vbr_method = VBR_METHOD_NEW;
  107. if (configfile)
  108. GetPrivateProfileStructA("audio_mp3l", "conf", cfg, sizeof(configtype), configfile);
  109. }
  110. void writeconfig(char* configfile, configtype *cfg)
  111. {
  112. if (configfile)
  113. WritePrivateProfileStructA("audio_mp3l", "conf", cfg, sizeof(configtype), configfile);
  114. }
  115. extern "C"
  116. {
  117. unsigned int __declspec(dllexport) GetAudioTypes3(int idx, char *desc)
  118. {
  119. //if ((g_lamedll != NULL) && (beInitStream != NULL) && (beCloseStream != NULL) && (beEncodeChunk != NULL) && (beDeinitStream != NULL) && (beWriteVBRHeader != NULL) && (beVersion != NULL))
  120. if (idx == 0)
  121. {
  122. GetLocalisationApiService();
  123. StringCchPrintfA(desc, 1024, WASABI_API_LNGSTRING(IDS_ENC_LAME_DESC), ENC_VERSION);
  124. return mmioFOURCC('M', 'P', '3', 'l');
  125. }
  126. return 0;
  127. }
  128. AudioCoder __declspec(dllexport) *CreateAudio3(int nch, int srate, int bps, unsigned int srct, unsigned int *outt, char *configfile)
  129. {
  130. if (nch > 2 || srate > 48000)
  131. return NULL;
  132. if (srct == mmioFOURCC('P', 'C', 'M', ' ') && *outt == mmioFOURCC('M', 'P', '3', 'l'))
  133. {
  134. configtype cfg;
  135. readconfig(configfile, &cfg);
  136. *outt = mmioFOURCC('M', 'P', '3', ' ');
  137. AudioCoderMP3 *t=0;
  138. if (bps != 16)
  139. t = new AudioCoderMP3_24(nch, srate, bps, &cfg);
  140. else
  141. t = new AudioCoderMP3(nch, srate, bps, &cfg);
  142. if (t->GetLastError())
  143. {
  144. delete t;
  145. return NULL;
  146. }
  147. return t;
  148. }
  149. return NULL;
  150. }
  151. void __declspec(dllexport) FinishAudio3(const char *filename, AudioCoder *coder)
  152. {
  153. //beWriteVBRHeader(filename);
  154. ((AudioCoderMP3*)coder)->setVbrFilename((char *)filename); //apparently this needs to be called after beCloseStream
  155. }
  156. void __declspec(dllexport) PrepareToFinish(const char *filename, AudioCoder *coder)
  157. {
  158. ((AudioCoderMP3*)coder)->PrepareToFinish();
  159. }
  160. static void setBitrates(HWND hwndDlg, int mi, int ma)
  161. {
  162. int i = 0;
  163. while (g_valid_bitrates[i] > 0)
  164. {
  165. if (g_valid_bitrates[i] == mi) SendDlgItemMessage(hwndDlg, IDC_BITRATE, CB_SETCURSEL, i, 0);
  166. if (g_valid_bitrates[i] == ma) SendDlgItemMessage(hwndDlg, IDC_MAXBITRATE, CB_SETCURSEL, i, 0);
  167. i++;
  168. }
  169. }
  170. BOOL CALLBACK DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  171. {
  172. if (uMsg == WM_USER + 666)
  173. {
  174. int vbr_meth = (int)SendDlgItemMessage(hwndDlg, IDC_VBRMETHOD, CB_GETCURSEL, 0, 0);
  175. if (vbr_meth == CB_ERR) vbr_meth = 0;
  176. vbr_meth--;
  177. EnableWindow(GetDlgItem(hwndDlg, IDC_VBRQ), vbr_meth != -1 && vbr_meth != 4);
  178. EnableWindow(GetDlgItem(hwndDlg, IDC_VBRQ_TEXT), vbr_meth != -1 && vbr_meth != 4);
  179. SetDlgItemTextW(hwndDlg, IDC_BITRATE_TEXT1, WASABI_API_LNGSTRINGW((vbr_meth == -1 ? IDS_BITRATE : vbr_meth == 4 ? IDS_ABR_MIN_BITRATE : IDS_VBR_MIN_BITRATE)));
  180. SetDlgItemTextW(hwndDlg, IDC_MAXBITRATE_TEXT1, WASABI_API_LNGSTRINGW((vbr_meth == -1 ? IDS_N_A : vbr_meth == 4 ? IDS_ABR_MAX_BITRATE : IDS_VBR_MAX_BITRATE)));
  181. SetDlgItemTextW(hwndDlg, IDC_AVGBITRATE_TEXT1, WASABI_API_LNGSTRINGW((vbr_meth != 4 ? IDS_N_A : IDS_AVERAGE_BITRATE)));
  182. EnableWindow(GetDlgItem(hwndDlg, IDC_MAXBITRATE_TEXT1), vbr_meth != -1);
  183. EnableWindow(GetDlgItem(hwndDlg, IDC_MAXBITRATE_TEXT2), vbr_meth != -1);
  184. EnableWindow(GetDlgItem(hwndDlg, IDC_MAXBITRATE), vbr_meth != -1);
  185. EnableWindow(GetDlgItem(hwndDlg, IDC_AVGBITRATE_TEXT1), vbr_meth == 4);
  186. EnableWindow(GetDlgItem(hwndDlg, IDC_AVGBITRATE_TEXT2), vbr_meth == 4);
  187. EnableWindow(GetDlgItem(hwndDlg, IDC_AVGBITRATE), vbr_meth == 4);
  188. int qual = (int)SendDlgItemMessage(hwndDlg, IDC_QUALITY, CB_GETCURSEL, 0, 0);
  189. if (qual == CB_ERR) qual = 0;
  190. switch (qual)
  191. {
  192. case LQP_R3MIX:
  193. case LQP_STANDARD:
  194. case LQP_FAST_STANDARD:
  195. case LQP_EXTREME:
  196. case LQP_FAST_EXTREME:
  197. case LQP_INSANE:
  198. case LQP_MEDIUM:
  199. case LQP_FAST_MEDIUM:
  200. case LQP_ABR:
  201. case LQP_CBR:
  202. EnableWindow(GetDlgItem(hwndDlg, IDC_STEREOMODE), 0);
  203. EnableWindow(GetDlgItem(hwndDlg, IDC_VBRMETHOD), 0);
  204. break;
  205. default:
  206. EnableWindow(GetDlgItem(hwndDlg, IDC_STEREOMODE), 1);
  207. EnableWindow(GetDlgItem(hwndDlg, IDC_VBRMETHOD), 1);
  208. break;
  209. }
  210. if (qual == 4) EnableWindow(GetDlgItem(hwndDlg, IDC_VBRQ), 0);
  211. }
  212. if (uMsg == WM_USER + 667)
  213. {
  214. int qual = (int)SendDlgItemMessage(hwndDlg, IDC_QUALITY, CB_GETCURSEL, 0, 0);
  215. if (qual == CB_ERR) qual = 0;
  216. switch (qual)
  217. {
  218. case LQP_R3MIX:
  219. SendDlgItemMessage(hwndDlg, IDC_VBRMETHOD, CB_SETCURSEL, 3, 0);
  220. setBitrates(hwndDlg, 96, 224);
  221. SendDlgItemMessage(hwndDlg, IDC_STEREOMODE, CB_SETCURSEL, 1, 0);
  222. SendDlgItemMessage(hwndDlg, IDC_VBRQ, CB_SETCURSEL, 1, 0);
  223. break;
  224. case LQP_STANDARD: /* check for alt-preset standard */
  225. SendDlgItemMessage(hwndDlg, IDC_VBRMETHOD, CB_SETCURSEL, 2, 0);
  226. setBitrates(hwndDlg, 32, 320);
  227. SendDlgItemMessage(hwndDlg, IDC_STEREOMODE, CB_SETCURSEL, 1, 0);
  228. SendDlgItemMessage(hwndDlg, IDC_VBRQ, CB_SETCURSEL, 2, 0);
  229. break;
  230. case LQP_FAST_STANDARD: /* check for alt-preset fast standard */
  231. SendDlgItemMessage(hwndDlg, IDC_VBRMETHOD, CB_SETCURSEL, 3, 0);
  232. setBitrates(hwndDlg, 32, 320);
  233. SendDlgItemMessage(hwndDlg, IDC_STEREOMODE, CB_SETCURSEL, 1, 0);
  234. SendDlgItemMessage(hwndDlg, IDC_VBRQ, CB_SETCURSEL, 2, 0);
  235. break;
  236. case LQP_MEDIUM: /* check for alt-preset medium */
  237. SendDlgItemMessage(hwndDlg, IDC_VBRMETHOD, CB_SETCURSEL, 2, 0);
  238. setBitrates(hwndDlg, 32, 320);
  239. SendDlgItemMessage(hwndDlg, IDC_STEREOMODE, CB_SETCURSEL, 1, 0);
  240. SendDlgItemMessage(hwndDlg, IDC_VBRQ, CB_SETCURSEL, 2, 0);
  241. break;
  242. case LQP_FAST_MEDIUM: /* check for alt-preset fast medium */
  243. SendDlgItemMessage(hwndDlg, IDC_VBRMETHOD, CB_SETCURSEL, 3, 0);
  244. setBitrates(hwndDlg, 32, 320);
  245. SendDlgItemMessage(hwndDlg, IDC_STEREOMODE, CB_SETCURSEL, 1, 0);
  246. SendDlgItemMessage(hwndDlg, IDC_VBRQ, CB_SETCURSEL, 2, 0);
  247. break;
  248. case LQP_EXTREME: /* check for alt-preset extreme */
  249. SendDlgItemMessage(hwndDlg, IDC_VBRMETHOD, CB_SETCURSEL, 2, 0);
  250. setBitrates(hwndDlg, 32, 320);
  251. SendDlgItemMessage(hwndDlg, IDC_STEREOMODE, CB_SETCURSEL, 1, 0);
  252. SendDlgItemMessage(hwndDlg, IDC_VBRQ, CB_SETCURSEL, 2, 0);
  253. break;
  254. case LQP_FAST_EXTREME: /* check for alt-preset fast extreme */
  255. SendDlgItemMessage(hwndDlg, IDC_VBRMETHOD, CB_SETCURSEL, 3, 0);
  256. setBitrates(hwndDlg, 32, 320);
  257. SendDlgItemMessage(hwndDlg, IDC_STEREOMODE, CB_SETCURSEL, 1, 0);
  258. SendDlgItemMessage(hwndDlg, IDC_VBRQ, CB_SETCURSEL, 2, 0);
  259. break;
  260. case LQP_INSANE: /* check for alt-preset fast insane */
  261. SendDlgItemMessage(hwndDlg, IDC_VBRMETHOD, CB_SETCURSEL, 0, 0);
  262. setBitrates(hwndDlg, 320, 320);
  263. SendDlgItemMessage(hwndDlg, IDC_STEREOMODE, CB_SETCURSEL, 1, 0);
  264. break;
  265. case LQP_ABR: /* check for alt-preset fast insane */
  266. SendDlgItemMessage(hwndDlg, IDC_VBRMETHOD, CB_SETCURSEL, 5, 0);
  267. setBitrates(hwndDlg, 64, 320);
  268. SendDlgItemMessage(hwndDlg, IDC_STEREOMODE, CB_SETCURSEL, 1, 0);
  269. SendDlgItemMessage(hwndDlg, IDC_VBRQ, CB_SETCURSEL, 2, 0);
  270. break;
  271. case LQP_CBR: /* check for alt-preset fast insane */
  272. SendDlgItemMessage(hwndDlg, IDC_VBRMETHOD, CB_SETCURSEL, 0, 0);
  273. SendDlgItemMessage(hwndDlg, IDC_STEREOMODE, CB_SETCURSEL, 1, 0);
  274. break;
  275. }
  276. SendMessage(hwndDlg, WM_USER + 666, 0, 0);
  277. }
  278. if (uMsg == WM_INITDIALOG)
  279. {
  280. #if defined (_WIN64)
  281. SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);
  282. #else
  283. SetWindowLong(hwndDlg, GWL_USERDATA, lParam);
  284. #endif
  285. wchar_t versionText[128] = {0};
  286. BuildVersionString(versionText);
  287. SetDlgItemText(hwndDlg, IDC_LAMEVERSION, versionText);
  288. if (lParam)
  289. {
  290. configwndrec *wc = (configwndrec*)lParam;
  291. // -1=none, 0=default, 1=old, 2=new, 3=mtrh, 4=abr
  292. SendDlgItemMessageW(hwndDlg, IDC_VBRMETHOD, CB_ADDSTRING, 0, (LPARAM)L"CBR");
  293. SendDlgItemMessageW(hwndDlg, IDC_VBRMETHOD, CB_ADDSTRING, 0, (LPARAM)L"VBR default");
  294. SendDlgItemMessageW(hwndDlg, IDC_VBRMETHOD, CB_ADDSTRING, 0, (LPARAM)L"VBR old");
  295. SendDlgItemMessageW(hwndDlg, IDC_VBRMETHOD, CB_ADDSTRING, 0, (LPARAM)L"VBR new");
  296. SendDlgItemMessageW(hwndDlg, IDC_VBRMETHOD, CB_ADDSTRING, 0, (LPARAM)L"VBR mtrh");
  297. SendDlgItemMessageW(hwndDlg, IDC_VBRMETHOD, CB_ADDSTRING, 0, (LPARAM)L"ABR");
  298. SendDlgItemMessageW(hwndDlg, IDC_VBRMETHOD, CB_SETCURSEL, wc->cfg.vbr_method + 1, 0);
  299. //0=stereo,1=jstereo,2=mchannel,3=mono
  300. SendDlgItemMessageW(hwndDlg, IDC_STEREOMODE, CB_ADDSTRING, 0, (LPARAM)WASABI_API_LNGSTRINGW(IDS_STEREO));
  301. SendDlgItemMessageW(hwndDlg, IDC_STEREOMODE, CB_ADDSTRING, 0, (LPARAM)WASABI_API_LNGSTRINGW(IDS_JOINT_STEREO));
  302. SendDlgItemMessageW(hwndDlg, IDC_STEREOMODE, CB_ADDSTRING, 0, (LPARAM)WASABI_API_LNGSTRINGW(IDS_MULTI_CHANNEL));
  303. SendDlgItemMessageW(hwndDlg, IDC_STEREOMODE, CB_ADDSTRING, 0, (LPARAM)WASABI_API_LNGSTRINGW(IDS_MONO));
  304. SendDlgItemMessageW(hwndDlg, IDC_STEREOMODE, CB_SETCURSEL, wc->cfg.stereo_mode, 0);
  305. {
  306. int i = 0;
  307. while (g_valid_bitrates[i] > 0)
  308. {
  309. wchar_t buf[64] = {0};
  310. StringCchPrintf(buf, 64, L"%d", g_valid_bitrates[i]);
  311. SendDlgItemMessage(hwndDlg, IDC_BITRATE , CB_ADDSTRING, 0, (LPARAM)buf);
  312. SendDlgItemMessage(hwndDlg, IDC_MAXBITRATE, CB_ADDSTRING, 0, (LPARAM)buf);
  313. SendDlgItemMessage(hwndDlg, IDC_AVGBITRATE, CB_ADDSTRING, 0, (LPARAM)buf);
  314. SendDlgItemMessage(hwndDlg, IDC_BITRATE , CB_SETITEMDATA, i, g_valid_bitrates[i]);
  315. SendDlgItemMessage(hwndDlg, IDC_MAXBITRATE, CB_SETITEMDATA, i, g_valid_bitrates[i]);
  316. SendDlgItemMessage(hwndDlg, IDC_AVGBITRATE, CB_SETITEMDATA, i, g_valid_bitrates[i]);
  317. i++;
  318. };
  319. i = 0;
  320. while (g_valid_bitrates[i] > 0)
  321. {
  322. if (g_valid_bitrates[i] == wc->cfg.bitrate ) SendDlgItemMessage(hwndDlg, IDC_BITRATE , CB_SETCURSEL, i, 0);
  323. if (g_valid_bitrates[i] == wc->cfg.abr_bitrate ) SendDlgItemMessage(hwndDlg, IDC_AVGBITRATE, CB_SETCURSEL, i, 0);
  324. if (g_valid_bitrates[i] == wc->cfg.vbr_max_bitrate) SendDlgItemMessage(hwndDlg, IDC_MAXBITRATE, CB_SETCURSEL, i, 0);
  325. i++;
  326. }
  327. }
  328. SendDlgItemMessageW(hwndDlg, IDC_QUALITY, CB_ADDSTRING, 0, (LPARAM)WASABI_API_LNGSTRINGW(IDS_NORMAL));
  329. SendDlgItemMessageW(hwndDlg, IDC_QUALITY, CB_ADDSTRING, 0, (LPARAM)WASABI_API_LNGSTRINGW(IDS_LOW));
  330. SendDlgItemMessageW(hwndDlg, IDC_QUALITY, CB_ADDSTRING, 0, (LPARAM)WASABI_API_LNGSTRINGW(IDS_HIGH));
  331. SendDlgItemMessageW(hwndDlg, IDC_QUALITY, CB_ADDSTRING, 0, (LPARAM)WASABI_API_LNGSTRINGW(IDS_VOICE));
  332. SendDlgItemMessageW(hwndDlg, IDC_QUALITY, CB_ADDSTRING, 0, (LPARAM)WASABI_API_LNGSTRINGW(IDS_R3MIX));
  333. SendDlgItemMessageW(hwndDlg, IDC_QUALITY, CB_ADDSTRING, 0, (LPARAM)WASABI_API_LNGSTRINGW(IDS_VERY_HIGH));
  334. SendDlgItemMessageW(hwndDlg, IDC_QUALITY, CB_ADDSTRING, 0, (LPARAM)L"--alt-preset standard");
  335. SendDlgItemMessageW(hwndDlg, IDC_QUALITY, CB_ADDSTRING, 0, (LPARAM)L"--alt-preset fast standard");
  336. SendDlgItemMessageW(hwndDlg, IDC_QUALITY, CB_ADDSTRING, 0, (LPARAM)L"--alt-preset extreme");
  337. SendDlgItemMessageW(hwndDlg, IDC_QUALITY, CB_ADDSTRING, 0, (LPARAM)L"--alt-preset fast extreme");
  338. SendDlgItemMessageW(hwndDlg, IDC_QUALITY, CB_ADDSTRING, 0, (LPARAM)L"--alt-preset insane");
  339. SendDlgItemMessageW(hwndDlg, IDC_QUALITY, CB_ADDSTRING, 0, (LPARAM)L"--alt-preset abr");
  340. SendDlgItemMessageW(hwndDlg, IDC_QUALITY, CB_ADDSTRING, 0, (LPARAM)L"--alt-preset cbr");
  341. SendDlgItemMessageW(hwndDlg, IDC_QUALITY, CB_ADDSTRING, 0, (LPARAM)L"--alt-preset medium");
  342. SendDlgItemMessageW(hwndDlg, IDC_QUALITY, CB_ADDSTRING, 0, (LPARAM)L"--alt-preset fast medium");
  343. SendDlgItemMessageW(hwndDlg, IDC_QUALITY, CB_SETCURSEL, wc->cfg.quality, 0);
  344. int x;
  345. for (x = 0; x < 10; x ++)
  346. {
  347. wchar_t buf[123] = {0};
  348. StringCchPrintfW(buf, 123, L"%d%s", x, x == 0 ? WASABI_API_LNGSTRINGW(IDS_HIGH_BRACKET) : x == 9 ? WASABI_API_LNGSTRINGW(IDS_LOW_BRACKET) : L"");
  349. SendDlgItemMessageW(hwndDlg, IDC_VBRQ, CB_ADDSTRING, 0, (LPARAM)buf);
  350. }
  351. SendDlgItemMessage(hwndDlg, IDC_VBRQ, CB_SETCURSEL, wc->cfg.vbr, 0);
  352. SendMessage(hwndDlg, WM_USER + 666, 0, 0);
  353. }
  354. }
  355. if (uMsg == WM_COMMAND)
  356. {
  357. if (LOWORD(wParam) == IDC_VBRMETHOD && HIWORD(wParam) == CBN_SELCHANGE)
  358. SendMessage(hwndDlg, WM_USER + 666, 0, 0);
  359. if (LOWORD(wParam) == IDC_QUALITY && HIWORD(wParam) == CBN_SELCHANGE)
  360. SendMessage(hwndDlg, WM_USER + 667, 0, 0);
  361. }
  362. if (uMsg == WM_DESTROY)
  363. {
  364. #if defined (_WIN64)
  365. configwndrec *wc = (configwndrec*)SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0);
  366. #else
  367. configwndrec* wc = (configwndrec*)SetWindowLong(hwndDlg, GWL_USERDATA, 0);
  368. #endif
  369. if (wc)
  370. {
  371. wc->cfg.bitrate = (int)SendDlgItemMessage(hwndDlg, IDC_BITRATE , CB_GETITEMDATA, SendDlgItemMessage(hwndDlg, IDC_BITRATE , CB_GETCURSEL, 0, 0), 0);
  372. wc->cfg.vbr_max_bitrate = (int)SendDlgItemMessage(hwndDlg, IDC_MAXBITRATE, CB_GETITEMDATA, SendDlgItemMessage(hwndDlg, IDC_MAXBITRATE, CB_GETCURSEL, 0, 0), 0);
  373. wc->cfg.abr_bitrate = (int)SendDlgItemMessage(hwndDlg, IDC_AVGBITRATE, CB_GETITEMDATA, SendDlgItemMessage(hwndDlg, IDC_AVGBITRATE, CB_GETCURSEL, 0, 0), 0);
  374. int vbr_meth = (int)SendDlgItemMessage(hwndDlg, IDC_VBRMETHOD, CB_GETCURSEL, 0, 0);
  375. if (vbr_meth == CB_ERR) vbr_meth = 0;
  376. wc->cfg.vbr_method = vbr_meth - 1;
  377. wc->cfg.stereo_mode = (int)SendDlgItemMessage(hwndDlg, IDC_STEREOMODE, CB_GETCURSEL, 0, 0);
  378. wc->cfg.quality = (int)SendDlgItemMessage(hwndDlg, IDC_QUALITY, CB_GETCURSEL, 0, 0);
  379. wc->cfg.vbr = (int)SendDlgItemMessage(hwndDlg, IDC_VBRQ, CB_GETCURSEL, 0, 0);
  380. writeconfig(wc->configfile, &wc->cfg);
  381. free(wc);
  382. }
  383. }
  384. return 0;
  385. }
  386. HWND __declspec(dllexport) ConfigAudio3(HWND hwndParent, HINSTANCE hinst, unsigned int outt, char*configfile)
  387. {
  388. if (outt == mmioFOURCC('M', 'P', '3', 'l'))
  389. {
  390. configwndrec *wr = (configwndrec*)malloc(sizeof(configwndrec));
  391. if (configfile) lstrcpynA(wr->configfile, configfile, MAX_PATH);
  392. else wr->configfile[0] = 0;
  393. readconfig(configfile, &wr->cfg);
  394. GetLocalisationApiService();
  395. return WASABI_API_CREATEDIALOGPARAMW(IDD_MP3, hwndParent, DlgProc, (LPARAM)wr);
  396. }
  397. return NULL;
  398. }
  399. int __declspec(dllexport) SetConfigItem(unsigned int outt, wchar_t*item, char *data, char* configfile)
  400. {
  401. if (outt == mmioFOURCC('M', 'P', '3', 'l'))
  402. {
  403. configtype cfg;
  404. readconfig(configfile, &cfg);
  405. if (!lstrcmpi(item, L"bitrate")) // assume CBR bitrate
  406. {
  407. cfg.abr_bitrate = cfg.bitrate = atoi(data);
  408. cfg.vbr_method = -1;
  409. }
  410. writeconfig(configfile, &cfg);
  411. return 1;
  412. }
  413. return 0;
  414. }
  415. int __declspec(dllexport) GetConfigItem(unsigned int outt, wchar_t *item, wchar_t *data, int len, char* configfile)
  416. {
  417. if (outt == mmioFOURCC('M', 'P', '3', 'l'))
  418. {
  419. configtype cfg;
  420. readconfig(configfile, &cfg);
  421. if (!lstrcmpi(item, L"bitrate"))
  422. {
  423. int bitrate;
  424. if(cfg.vbr_method == -1) bitrate = cfg.bitrate;
  425. else if(cfg.vbr_method == 4) bitrate = cfg.abr_bitrate;
  426. else bitrate = (cfg.bitrate + cfg.vbr_max_bitrate) / 2;
  427. StringCchPrintf(data,len,L"%d",bitrate);
  428. }
  429. return 1;
  430. }
  431. return 0;
  432. }
  433. void __declspec(dllexport) SetWinampHWND(HWND hwnd)
  434. {
  435. winampwnd = hwnd;
  436. // this is called when the encoder is needed (and is slightly better than the dllmain loading from before)
  437. /*if (!g_lamedll)
  438. {
  439. if (!lamedll[0])
  440. {
  441. PathCombineW(lamedll, (wchar_t*)SendMessage(hwnd, WM_WA_IPC, 0, IPC_GETSHAREDDLLDIRECTORYW),L"lame_enc.dll");
  442. }
  443. g_lamedll = LoadLibraryW(lamedll);
  444. }*/
  445. /*if (g_lamedll)
  446. {
  447. beInitStream = (BEINITSTREAM) &beInitStream;
  448. beCloseStream = (BECLOSESTREAM) GetProcAddress(g_lamedll, TEXT_BECLOSESTREAM);
  449. beEncodeChunk = (BEENCODECHUNK) GetProcAddress(g_lamedll, TEXT_BEENCODECHUNK);
  450. beDeinitStream = (BEDEINITSTREAM) GetProcAddress(g_lamedll, TEXT_BEDEINITSTREAM);
  451. beWriteVBRHeader = (BEWRITEVBRHEADER) GetProcAddress(g_lamedll, TEXT_BEWRITEVBRHEADER);
  452. beVersion = (BEVERSION) GetProcAddress(g_lamedll, TEXT_BEVERSION);
  453. beEncodeChunkFloatS16NI = (BEENCODECHUNKFLOATS16NI)GetProcAddress(g_lamedll, TEXT_BEENCODECHUNKFLOATS16NI);
  454. }*/
  455. }
  456. };