aboutsummaryrefslogtreecommitdiff
path: root/Src/Plugins/Library/ml_disc/ReplayGain.cpp
diff options
context:
space:
mode:
authorJef <jef@targetspot.com>2024-09-24 08:54:57 -0400
committerJef <jef@targetspot.com>2024-09-24 08:54:57 -0400
commit20d28e80a5c861a9d5f449ea911ab75b4f37ad0d (patch)
tree12f17f78986871dd2cfb0a56e5e93b545c1ae0d0 /Src/Plugins/Library/ml_disc/ReplayGain.cpp
parent537bcbc86291b32fc04ae4133ce4d7cac8ebe9a7 (diff)
downloadwinamp-20d28e80a5c861a9d5f449ea911ab75b4f37ad0d.tar.gz
Initial community commit
Diffstat (limited to 'Src/Plugins/Library/ml_disc/ReplayGain.cpp')
-rw-r--r--Src/Plugins/Library/ml_disc/ReplayGain.cpp95
1 files changed, 95 insertions, 0 deletions
diff --git a/Src/Plugins/Library/ml_disc/ReplayGain.cpp b/Src/Plugins/Library/ml_disc/ReplayGain.cpp
new file mode 100644
index 00000000..fdbd973c
--- /dev/null
+++ b/Src/Plugins/Library/ml_disc/ReplayGain.cpp
@@ -0,0 +1,95 @@
+#include "main.h"
+#include "ReplayGain.h"
+#include <api/service/waservicefactory.h>
+static obj_replaygain *replayGain = 0;
+HANDLE rgThread = 0;
+static HANDLE killSwitch = 0;
+extern HWND m_extract_wnd;
+
+template <class api_T>
+void ServiceBuild(api_T *&api_t, GUID factoryGUID_t)
+{
+ if (plugin.service)
+ {
+ waServiceFactory *factory = plugin.service->service_getServiceByGuid(factoryGUID_t);
+ if (factory)
+ api_t = reinterpret_cast<api_T *>( factory->getInterface() );
+ }
+}
+
+template <class api_T>
+void ServiceRelease(api_T *api_t, GUID factoryGUID_t)
+{
+ if (plugin.service && api_t)
+ {
+ waServiceFactory *factory = plugin.service->service_getServiceByGuid(factoryGUID_t);
+ if (factory)
+ factory->releaseInterface(api_t);
+ }
+ api_t = NULL;
+}
+
+DWORD WINAPI RGProc(void *data)
+{
+ while (WaitForSingleObjectEx(killSwitch, INFINITE, TRUE) != WAIT_OBJECT_0);
+
+ return 0;
+}
+
+void CreateGain()
+{
+ killSwitch = CreateEvent(0, FALSE, FALSE, 0);
+ DWORD dummy;
+ rgThread = CreateThread(0, 0, RGProc, 0, 0, &dummy);
+}
+
+void CALLBACK StartGain(ULONG_PTR data)
+{
+ int mode = (int)data;
+
+ ServiceBuild(replayGain, RGGUID);
+ if (replayGain)
+ replayGain->Open(mode);
+}
+
+void CALLBACK WriteGain(ULONG_PTR data)
+{
+ if (replayGain)
+ replayGain->Write();
+
+ HANDLE notifyHandle =(HANDLE)data;
+ if (notifyHandle)
+ SetEvent(notifyHandle);
+
+ PostMessage(m_extract_wnd, WM_APP+4, 0, 0);
+}
+
+void CALLBACK CalculateGain(ULONG_PTR data)
+{
+ wchar_t *lastfn = (wchar_t *)data;
+ if (replayGain)
+ {
+ PostMessage(m_extract_wnd, WM_APP+2, 0, 0);
+ replayGain->ProcessTrack(lastfn);
+ }
+ free(lastfn);
+ PostMessage(m_extract_wnd, WM_APP+3, 0, 0);
+}
+
+void CALLBACK CloseGain(ULONG_PTR data)
+{
+ if (replayGain)
+ {
+ replayGain->Close();
+ ServiceRelease(replayGain, RGGUID);
+ replayGain = 0;
+ }
+}
+
+void CALLBACK QuitThread(ULONG_PTR data)
+{
+ if (rgThread)
+ {
+ SetEvent(killSwitch);
+ }
+}