main.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. #define ENC_VERSION "v1.02a"
  2. #include "Config.h"
  3. #include "resource.h"
  4. #include "../nsv/enc_if.h"
  5. #include "ACMEncoder.h"
  6. #include "WAVEncoder.h"
  7. #include "../nu/AutoWideFn.h"
  8. BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
  9. {
  10. return TRUE;
  11. }
  12. // wasabi based services for localisation support
  13. #include <api/service/waServiceFactory.h>
  14. #include "../Agave/Language/api_language.h"
  15. #include "../winamp/wa_ipc.h"
  16. #include <strsafe.h>
  17. HWND winampwnd = 0;
  18. api_service *WASABI_API_SVC = 0;
  19. api_language *WASABI_API_LNG = 0;
  20. HINSTANCE WASABI_API_LNG_HINST = 0, WASABI_API_ORIG_HINST = 0;
  21. static const WAVEFORMATEX wfx_default =
  22. {
  23. WAVE_FORMAT_PCM,
  24. 2,
  25. 44100,
  26. 44100 * 4,
  27. 4,
  28. 16,
  29. 0
  30. };
  31. static void ReadConfig(ACMConfig *config, char *INI_FILE)
  32. {
  33. int l = GetPrivateProfileIntA("enc_wav", "fmtsize", 0, INI_FILE);
  34. EXT_WFX convert_wfx_temp;
  35. if (GetPrivateProfileStructA("enc_wav", "fmt", &convert_wfx_temp, sizeof(WAVEFORMATEX) + l, INI_FILE))
  36. memcpy(&config->convert_wfx, &convert_wfx_temp, sizeof(config->convert_wfx));
  37. else
  38. config->convert_wfx.wfx = wfx_default;
  39. GetPrivateProfileStringA("enc_wav", "ext", "WAV", config->wav_ext, sizeof(config->wav_ext), INI_FILE);
  40. config->header = !!GetPrivateProfileIntA("enc_wav", "header", 1, INI_FILE);
  41. config->convert = !!GetPrivateProfileIntA("enc_wav", "convert", 0, INI_FILE);
  42. }
  43. static HINSTANCE GetMyInstance()
  44. {
  45. MEMORY_BASIC_INFORMATION mbi = {0};
  46. if(VirtualQuery(GetMyInstance, &mbi, sizeof(mbi)))
  47. return (HINSTANCE)mbi.AllocationBase;
  48. return NULL;
  49. }
  50. void GetLocalisationApiService(void)
  51. {
  52. if(!WASABI_API_LNG)
  53. {
  54. // loader so that we can get the localisation service api for use
  55. if(!WASABI_API_SVC)
  56. {
  57. WASABI_API_SVC = (api_service*)SendMessage(winampwnd, WM_WA_IPC, 0, IPC_GET_API_SERVICE);
  58. if (WASABI_API_SVC == (api_service*)1)
  59. {
  60. WASABI_API_SVC = NULL;
  61. return;
  62. }
  63. }
  64. if(!WASABI_API_LNG)
  65. {
  66. waServiceFactory *sf;
  67. sf = WASABI_API_SVC->service_getServiceByGuid(languageApiGUID);
  68. if (sf) WASABI_API_LNG = reinterpret_cast<api_language*>(sf->getInterface());
  69. }
  70. // need to have this initialised before we try to do anything with localisation features
  71. WASABI_API_START_LANG(GetMyInstance(),EncWavLangGUID);
  72. }
  73. }
  74. extern "C"
  75. {
  76. AudioCoder __declspec(dllexport) *CreateAudio3(int nch, int srate, int bps, unsigned int srct, unsigned int *outt, char *configfile)
  77. {
  78. if (srct == mmioFOURCC('P','C','M',' '))
  79. {
  80. if (*outt == mmioFOURCC('A','C','M',' '))
  81. {
  82. ACMConfig config;
  83. ReadConfig(&config, configfile);
  84. if (config.convert)
  85. {
  86. ACMEncoder *encoder = new ACMEncoder(srate, nch, bps, &config);
  87. if (encoder->GetLastError())
  88. {
  89. delete encoder;
  90. encoder=0;
  91. }
  92. return encoder;
  93. }
  94. else
  95. {
  96. return new WAVEncoder(nch, srate, bps, &config);
  97. }
  98. }
  99. else if (*outt == mmioFOURCC('W','A','V',' '))
  100. {
  101. ACMConfig config;
  102. ReadConfig(&config, configfile);
  103. return new WAVEncoder(nch, srate, bps, &config);
  104. }
  105. }
  106. return 0;
  107. }
  108. unsigned int __declspec(dllexport) GetAudioTypes3(int idx, char *desc)
  109. {
  110. switch(idx)
  111. {
  112. case 0:
  113. GetLocalisationApiService();
  114. StringCchPrintfA(desc, 1024, WASABI_API_LNGSTRING(IDS_ENC_WAV_DESC), ENC_VERSION);
  115. return mmioFOURCC('A','C','M',' ');
  116. }
  117. return 0;
  118. }
  119. HWND __declspec(dllexport) ConfigAudio3(HWND hwndParent, HINSTANCE hinst, unsigned int outt, char *configfile)
  120. {
  121. if (outt == mmioFOURCC('A', 'C','M',' '))
  122. {
  123. ConfigWnd configwnd;
  124. ReadConfig(&configwnd.cfg, configfile);
  125. configwnd.configfile = configfile;
  126. GetLocalisationApiService();
  127. return WASABI_API_CREATEDIALOGPARAMW(IDD_CONFIG, hwndParent, DlgProc, (LPARAM)&configwnd);
  128. }
  129. return 0;
  130. }
  131. void __declspec(dllexport) FinishAudio3(const char *filename, AudioCoder *coder)
  132. {
  133. ((AudioCommon*)coder)->FinishAudio(AutoWideFn(filename));
  134. }
  135. void __declspec(dllexport) FinishAudio3W(const wchar_t *filename, AudioCoder *coder)
  136. {
  137. ((AudioCommon*)coder)->FinishAudio(filename);
  138. }
  139. int __declspec(dllexport) GetConfigItem(unsigned int outt, char *item, char *data, int len, char *configfile)
  140. {
  141. if (outt==mmioFOURCC('A','C','M',' '))
  142. {
  143. ACMConfig config;
  144. ReadConfig(&config, configfile);
  145. if (!_stricmp(item, "extension"))
  146. {
  147. lstrcpynA(data, config.wav_ext, len);
  148. return 1;
  149. }
  150. }
  151. return 0;
  152. }
  153. void __declspec(dllexport) SetWinampHWND(HWND hwnd)
  154. {
  155. winampwnd = hwnd;
  156. }
  157. };