SOUND4 BIGVOICE.CL Library [1.1.11]
Loading...
Searching...
No Matches
sound4.bigvoice.cl_dyn.hpp
Go to the documentation of this file.
1
7#pragma once
8
9#include <string>
10#include <exception>
11#include <thread>
12#include <functional>
13#include <memory>
14#include <array>
15#include <assert.h>
16#include <stdexcept>
17#include <filesystem>
18#include <string.h>
19
20#if defined(__unix__) || defined(__APPLE__)
21 #define UNIXLIKE 1
22#else
23 #define UNIXLIKE 0
24#endif
25
26#if UNIXLIKE
27 #include <dlfcn.h>
28#elif defined(_WIN32)
29 #include <libloaderapi.h>
30#else
31 #error "Unsupported OS"
32#endif
33
34// Needed to have function declarations
35#include "sound4.bigvoice.cl.h"
36
37
38#ifdef _WIN32
39 #include <stringapiset.h>
40 #include <wchar.h>
42 #define fs_strdup wcsdup
43 #ifdef _MSC_VER
44 #pragma warning(disable : 4996)
45 #endif
46#else // !_WIN32
48 #define fs_strdup strdup
49#endif // !_WIN32
50
51// bridge C callbacks to CPresetLoader
52extern "C" {
53 static char *bigvoice_custom_reader(const fs_char *filename, void* userdata);
54 static void bigvoice_custom_reader_free(char *content, void* userdata);
55 static int bigvoice_custom_writer(const fs_char *filename, const char *content, void* userdata);
56 static int bigvoice_custom_exists(const fs_char *filename, void* userdata);
57 static fs_char** bigvoice_custom_getall(void* userdata);
58 static void bigvoice_custom_getall_free(fs_char** all, void* userdata);
59 static int bigvoice_custom_remove(const fs_char *filename, void* userdata);
60 static int bigvoice_custom_rename(const fs_char *from, const fs_char *to, void* userdata);
61};
62
66namespace sound4 {
70namespace bigvoice {
74namespace dyn {
75
79 namespace helper {
80
86 template <typename T>
88 // Storage definition, depending on OS
89 #if UNIXLIKE
90 using DynFunc_t = void *;
91 #else
92 using DynFunc_t = FARPROC;
93 #endif
94 private:
95 DynFunc_t m_ptr = NULL;
96 public:
97 DynFuncHolder() = default;
98 DynFuncHolder(DynFunc_t a_ptr) : m_ptr(a_ptr) {}
99 operator bool() const { return (m_ptr!=NULL); }
100 bool IsOk() const { return m_ptr!=NULL; }
101 operator T* () const { return reinterpret_cast<T*>(m_ptr); }
102 };
103
109 // Storage definition, depending on OS
110 #if UNIXLIKE
111 using DynLib_t = void *;
112 #else
113 using DynLib_t = HMODULE;
114 #endif
115 private:
116 DynLib_t m_lib {};
117 public:
118 CDynLoader() = default;
119 CDynLoader(CDynLoader&&) = default;
120 // No copy allowed
121 CDynLoader(const CDynLoader&) = delete;
122 CDynLoader& operator=(CDynLoader const&) = delete;
123 operator bool() const {
124 return (m_lib!=NULL);
125 }
126 bool IsOk() const {
127 return (m_lib!=NULL);
128 }
129 #if UNIXLIKE
130 void Close() {
131 if (IsOk()) {
132 #ifndef __SANITIZE_ADDRESS__ // avoid unloading to keep call stack
133 dlclose(m_lib);
134 #endif // __SANITIZE_ADDRESS__
135 m_lib=NULL;
136 }
137 }
138 bool Load(const std::filesystem::path& dynlib)
139 {
140 Close();
141 m_lib=dlopen(dynlib.c_str(), RTLD_NOW|RTLD_LOCAL);
142 return IsOk();
143 }
144 template <typename T>
145 DynFuncHolder<T> GetSymbol(const std::string& name) {
146 auto ptr=dlsym(m_lib, name.c_str());
147 if (!ptr) {
148 throw std::runtime_error("Missing function in library");
149 }
150 return DynFuncHolder<T>(ptr);
151 }
152 template <typename T>
153 DynFuncHolder<T> GetSymbol_safe(const std::string& name) {
154 auto ptr=dlsym(m_lib, name.c_str());
155 return DynFuncHolder<T>(ptr);
156 }
157 static std::filesystem::path GetThisLibraryPath(void) {
158 static Dl_info info;
159 if (! dladdr((void *) GetThisLibraryPath, & info)) return {};
160 auto rp=realpath(info.dli_fname, NULL);
161 if (!rp) {
162 #if defined(__unix__)
163 rp=realpath("/proc/self/exe", NULL);
164 #elif defined(__APPLE__)
165 // How to solve this for Apple ?
166 #endif
167 }
168 std::filesystem::path p(rp);
169 free(rp);
170 return p;
171 }
172 #else
179 void Close() {
180 if (IsOk()) {
181 // NOTE: On Windows, FreeLibrary may create a lot of troubles, should use FreeLibraryAndExitThread but...
182 // So define SOUND4_CALL_FREELIBRARY before including this file if you really want to unload the library dynamically
183 #if defined(SOUND4_CALL_FREELIBRARYANDEXITTHREAD)
184 FreeLibraryAndExitThread(m_lib, 0);
185 #elif defined(SOUND4_CALL_FREELIBRARY)
186 FreeLibrary(m_lib);
187 #endif // SOUND4_CALL_FREELIBRARY
188 m_lib=NULL;
189 }
190 }
191 template <typename T>
192 DynFuncHolder<T> GetSymbol(const std::string& name) {
193 auto ptr=GetProcAddress(m_lib, name.c_str());
194 if (!ptr) {
195 throw std::runtime_error("Missing function in library");
196 }
197 return DynFuncHolder<T>(ptr);
198 }
199 template <typename T>
200 DynFuncHolder<T> GetSymbol_safe(const std::string& name) {
201 auto ptr=GetProcAddress(m_lib, name.c_str());
202 return DynFuncHolder<T>(ptr);
203 }
204 static std::filesystem::path GetThisLibraryPath(void) {
205 static wchar_t path[MAX_PATH]={};
206 HMODULE hm = NULL;
210 {
211 if (GetModuleFileNameW(hm, path, MAX_PATH) > 0) {
212 return std::filesystem::path(path);
213 }
214 }
215 return {};
216 }
217 #endif
218 virtual ~CDynLoader() {
219 Close();
220 }
221 }; // class CDynLoader
222 }; // namespace helper
223
230 class CDynLib {
231 private:
232 helper::CDynLoader m_lib;
233 bool m_bOK = false;
234 public:
235 CDynLib() = default;
236
237 // All those wrapped functions have the same signature as there C bigvoice_XXX
282#if BIGVOICE_HAS_WEBSERVER
288#endif // BIGVOICE_HAS_WEBSERVER
289
290 // added 2023-03-22
293
294 // added 2023-05-22
298
299 // added 2023-06-20
302
303 // added 2023-09-21
307
308#if BIGVOICE_HAS_CLOUDBUS
309 // added 2023-06-26
313#endif // BIGVOICE_HAS_CLOUDBUS
314
315 // added 2024-02-19
317
318#if BIGVOICE_HAS_WEBSERVER
319 // added 2024-05-23
323#endif // BIGVOICE_HAS_WEBSERVER
324
325#ifdef _WIN32
326 // added 2025-05-28
329#endif // _WIN32
330
338 bool Load(const std::filesystem::path& path = {}) {
339 std::string filename;
340 #if defined(__APPLE__)
341 filename="libsound4.bigvoice.cl.dylib";
342 #elif defined(__unix__)
343 filename="libsound4.bigvoice.cl.so";
344 #else
345 filename="sound4.bigvoice.cl.dll";
346 #endif
347 m_lib.Close();
348 // If a path is given, use it directly and do not try other path
349 if (!path.empty() && !m_lib.Load(path / filename)) {
350 return false;
351 } else if (!m_lib.IsOk()) {
352 auto thisdir=helper::CDynLoader::GetThisLibraryPath().parent_path();
353 #ifndef _WIN32
354 // Linux: if in a bin directory, try ../lib first
355 if (!m_lib.IsOk() && thisdir.filename()=="bin") {
356 auto libdir = thisdir.parent_path() / "lib";
357 m_lib.Load(libdir / filename);
358 }
359 #endif // !_WIN32
360 if (!m_lib.IsOk()) {
361 // Search in the same directory this code is in
362 m_lib.Load(thisdir / filename);
363 }
364 if (!m_lib.IsOk()) {
365 // Try current path
366 std::error_code ec;
367 auto p = std::filesystem::current_path(ec);
368 if (!ec) {
369 m_lib.Load(p / filename);
370 }
371 }
372 if (!m_lib.IsOk()) {
373 return false;
374 }
375 }
376 // Load all C functions
377 try {
378 GetVersion = m_lib.GetSymbol< decltype(bigvoice_GetVersion ) >("bigvoice_GetVersion" );
379 GetChunkSizeInFrames = m_lib.GetSymbol< decltype(bigvoice_GetChunkSizeInFrames ) >("bigvoice_GetChunkSizeInFrames" );
380 GetChannelCount = m_lib.GetSymbol< decltype(bigvoice_GetChannelCount ) >("bigvoice_GetChannelCount" );
381 GetAudioInputCount = m_lib.GetSymbol< decltype(bigvoice_GetAudioInputCount ) >("bigvoice_GetAudioInputCount" );
382 GetAudioOutputCount = m_lib.GetSymbol< decltype(bigvoice_GetAudioOutputCount ) >("bigvoice_GetAudioOutputCount" );
383 GetSampleRate = m_lib.GetSymbol< decltype(bigvoice_GetSampleRate ) >("bigvoice_GetSampleRate" );
384 SetLoggerCallback = m_lib.GetSymbol< decltype(bigvoice_SetLoggerCallback ) >("bigvoice_SetLoggerCallback" );
385 SetLogSeverity = m_lib.GetSymbol< decltype(bigvoice_SetLogSeverity ) >("bigvoice_SetLogSeverity" );
386 NewParameters = m_lib.GetSymbol< decltype(bigvoice_NewParameters ) >("bigvoice_NewParameters" );
387 FreeParameters = m_lib.GetSymbol< decltype(bigvoice_FreeParameters ) >("bigvoice_FreeParameters" );
388 SetParameter = m_lib.GetSymbol< decltype(bigvoice_SetParameter ) >("bigvoice_SetParameter" );
389 GetParameter = m_lib.GetSymbol< decltype(bigvoice_GetParameter ) >("bigvoice_GetParameter" );
390 FreeParameterValue = m_lib.GetSymbol< decltype(bigvoice_FreeParameterValue ) >("bigvoice_FreeParameterValue" );
391 InitProcess = m_lib.GetSymbol< decltype(bigvoice_InitProcess ) >("bigvoice_InitProcess" );
392 InitProcess2 = m_lib.GetSymbol< decltype(bigvoice_InitProcess2 ) >("bigvoice_InitProcess2" );
393 TerminateProcess = m_lib.GetSymbol< decltype(bigvoice_TerminateProcess ) >("bigvoice_TerminateProcess" );
394 ExitProcess = m_lib.GetSymbol< decltype(bigvoice_ExitProcess ) >("bigvoice_ExitProcess" );
395 StartUpdateThread = m_lib.GetSymbol< decltype(bigvoice_StartUpdateThread ) >("bigvoice_StartUpdateThread" );
396 StopUpdateThread = m_lib.GetSymbol< decltype(bigvoice_StopUpdateThread ) >("bigvoice_StopUpdateThread" );
397 WaitUpdateThreadReady = m_lib.GetSymbol< decltype(bigvoice_WaitUpdateThreadReady ) >("bigvoice_WaitUpdateThreadReady" );
398 ProcessAudio = m_lib.GetSymbol< decltype(bigvoice_ProcessAudio ) >("bigvoice_ProcessAudio" );
399 ProcessAudio_Planar = m_lib.GetSymbol< decltype(bigvoice_ProcessAudio_Planar ) >("bigvoice_ProcessAudio_Planar" );
400 GetBufferIn = m_lib.GetSymbol< decltype(bigvoice_GetBufferIn ) >("bigvoice_GetBufferIn" );
401 GetBufferOut = m_lib.GetSymbol< decltype(bigvoice_GetBufferOut ) >("bigvoice_GetBufferOut" );
402 GetEstimatedDelay = m_lib.GetSymbol< decltype(bigvoice_GetEstimatedDelay ) >("bigvoice_GetEstimatedDelay" );
403 GetFormatName = m_lib.GetSymbol< decltype(bigvoice_GetFormatName ) >("bigvoice_GetFormatName" );
404 GetFormatFromName = m_lib.GetSymbol< decltype(bigvoice_GetFormatFromName ) >("bigvoice_GetFormatFromName" );
405 GetBytesFromFormat = m_lib.GetSymbol< decltype(bigvoice_GetBytesFromFormat ) >("bigvoice_GetBytesFromFormat" );
406 GetMaxPacketFrame = m_lib.GetSymbol< decltype(bigvoice_GetMaxPacketFrame ) >("bigvoice_GetMaxPacketFrame" );
407 AddAudio = m_lib.GetSymbol< decltype(bigvoice_AddAudio ) >("bigvoice_AddAudio" );
408 AddPadAudio = m_lib.GetSymbol< decltype(bigvoice_AddPadAudio ) >("bigvoice_AddPadAudio" );
409 GetOutputCount = m_lib.GetSymbol< decltype(bigvoice_GetOutputCount ) >("bigvoice_GetOutputCount" );
410 GetAudio = m_lib.GetSymbol< decltype(bigvoice_GetAudio ) >("bigvoice_GetAudio" );
411 AudioConvertFrom = m_lib.GetSymbol< decltype(bigvoice_AudioConvertFrom ) >("bigvoice_AudioConvertFrom" );
412 AudioConvertTo = m_lib.GetSymbol< decltype(bigvoice_AudioConvertTo ) >("bigvoice_AudioConvertTo" );
413 StereoToMono = m_lib.GetSymbol< decltype(bigvoice_StereoToMono ) >("bigvoice_StereoToMono" );
414 MonoToStereo = m_lib.GetSymbol< decltype(bigvoice_MonoToStereo ) >("bigvoice_MonoToStereo" );
415 AudioMonoFromLiveStereo = m_lib.GetSymbol< decltype(bigvoice_AudioMonoFromLiveStereo) >("bigvoice_AudioMonoFromLiveStereo");
416 AudioMonoToLiveStereo = m_lib.GetSymbol< decltype(bigvoice_AudioMonoToLiveStereo ) >("bigvoice_AudioMonoToLiveStereo" );
417 NewClient = m_lib.GetSymbol< decltype(bigvoice_NewClient ) >("bigvoice_NewClient" );
418 DeleteClient = m_lib.GetSymbol< decltype(bigvoice_DeleteClient ) >("bigvoice_DeleteClient" );
419 ProcessJson = m_lib.GetSymbol< decltype(bigvoice_ProcessJson ) >("bigvoice_ProcessJson" );
420 FreeJsonAnswer = m_lib.GetSymbol< decltype(bigvoice_FreeJsonAnswer ) >("bigvoice_FreeJsonAnswer" );
421 SaveState = m_lib.GetSymbol< decltype(bigvoice_SaveState ) >("bigvoice_SaveState" );
422#if BIGVOICE_HAS_WEBSERVER
423 Webserver_tcp = m_lib.GetSymbol< decltype(bigvoice_Webserver_tcp ) >("bigvoice_Webserver_tcp" );
424 Webserver_tcp2 = m_lib.GetSymbol< decltype(bigvoice_Webserver_tcp2 ) >("bigvoice_Webserver_tcp2" );
425 Webserver = m_lib.GetSymbol< decltype(bigvoice_Webserver ) >("bigvoice_Webserver" );
426 Webserver_Stop = m_lib.GetSymbol< decltype(bigvoice_Webserver_Stop ) >("bigvoice_Webserver_Stop" );
427 Webserver_Status = m_lib.GetSymbol< decltype(bigvoice_Webserver_Status ) >("bigvoice_Webserver_Status" );
428#endif // BIGVOICE_HAS_WEBSERVER
429
430 // added 2023-03-22
431 StereoToMono_Planar = m_lib.GetSymbol< decltype(bigvoice_StereoToMono_Planar ) >("bigvoice_StereoToMono_Planar" );
432 MonoToStereo_Planar = m_lib.GetSymbol< decltype(bigvoice_MonoToStereo_Planar ) >("bigvoice_MonoToStereo_Planar" );
433
434 } catch (std::runtime_error& ) {
435 return false;
436 }
437 // C functions allowed to be missing
438 try {
439 // added 2023-05-22
440 SetMetadata = m_lib.GetSymbol< decltype(bigvoice_SetMetadata ) >("bigvoice_SetMetadata" );
441 GetMetadataInfos = m_lib.GetSymbol< decltype(bigvoice_GetMetadataInfos ) >("bigvoice_GetMetadataInfos" );
442 FreeMetadataInfos = m_lib.GetSymbol< decltype(bigvoice_FreeMetadataInfos ) >("bigvoice_FreeMetadataInfos" );
443 // added 2023-06-20
444 SetPresetManager = m_lib.GetSymbol< decltype(bigvoice_SetPresetManager ) >("bigvoice_SetPresetManager" );
445 PresetManager_InformChange = m_lib.GetSymbol< decltype(bigvoice_PresetManager_InformChange ) >("bigvoice_PresetManager_InformChange" );
446
447 // added 2023-09-21
448 GetPossibleChunkSizeInFrames = m_lib.GetSymbol< decltype(bigvoice_GetPossibleChunkSizeInFrames ) >("bigvoice_GetPossibleChunkSizeInFrames" );
449 GetProcessChunkFrames = m_lib.GetSymbol< decltype(bigvoice_GetProcessChunkFrames ) >("bigvoice_GetProcessChunkFrames" );
450 InitProcess3 = m_lib.GetSymbol< decltype(bigvoice_InitProcess3 ) >("bigvoice_InitProcess3" );
451
452#if BIGVOICE_HAS_CLOUDBUS
453 // added 2023-06-26
454 NewBus = m_lib.GetSymbol< decltype(bigvoice_NewBus ) >("bigvoice_NewBus" );
455 FreeBus = m_lib.GetSymbol< decltype(bigvoice_FreeBus ) >("bigvoice_FreeBus" );
456 SetInstanceBus = m_lib.GetSymbol< decltype(bigvoice_SetInstanceBus ) >("bigvoice_SetInstanceBus" );
457#endif // BIGVOICE_HAS_CLOUDBUS
458
459 // added 2024-02-19
460 SetMetadataMulti = m_lib.GetSymbol< decltype(bigvoice_SetMetadataMulti ) >("bigvoice_SetMetadataMulti" );
461
462#if BIGVOICE_HAS_WEBSERVER
463 // added 2024-05-23
464 Webserver_SetAppHealth = m_lib.GetSymbol< decltype(bigvoice_Webserver_SetAppHealth ) >("Webserver_SetAppHealth" );
465 Webserver_GetAppHealth = m_lib.GetSymbol< decltype(bigvoice_Webserver_GetAppHealth ) >("Webserver_GetAppHealth" );
466 Webserver_FreeString = m_lib.GetSymbol< decltype(bigvoice_Webserver_FreeString ) >("Webserver_FreeString" );
467 #endif // BIGVOICE_HAS_WEBSERVER
468
469#ifdef _WIN32
470 // added 2025-05-28
471 SetInstanceTracing = m_lib.GetSymbol< decltype(bigvoice_SetInstanceTracing ) >("SetInstanceTracing" );
472 SetInstanceTracingProcessActivity = m_lib.GetSymbol< decltype(bigvoice_SetInstanceTracingProcessActivity) >("SetInstanceTracingProcessActivity");
473#endif // _WIN32
474 } catch (std::runtime_error& ) {
475 // Ignored, handler will take care
476 }
477
478 m_bOK=true;
479 return true;
480 }
487 bool IsOk() const {
488 return m_bOK;
489 }
490
491 };
492
493
494
495 static constexpr const char *process_name = "SOUND4 BIGVOICE.CL";
496 static constexpr const char *process_shortname = "bigvoice";
528
532 namespace helper {
533 #ifdef _WIN32
539 static inline std::string WStringToUTF8(const std::wstring& wstr) {
540 if (wstr.empty()) return {};
541 int size = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), NULL, 0, NULL, NULL);
542 std::string str(size, 0);
543 WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), &str[0], size, NULL, NULL);
544 return str;
545 }
551 static inline std::wstring UTF8ToWString(const std::string& str) {
552 if (str.empty()) return std::wstring();
553 int size = MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), NULL, 0);
554 std::wstring wstr(size, 0);
555 MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), &wstr[0], size);
556 return wstr;
557 }
558 #endif // _WIN32
559
565 template<typename T>
567 };
568 template<>
569 struct SampleFormat<int16_t> {
570 const bigvoice_SampleFormat format = S16_NATIVE;
571 };
572 template<>
573 struct SampleFormat<int32_t> {
574 const bigvoice_SampleFormat format = S32_NATIVE;
575 };
576 template<>
577 struct SampleFormat<float> {
578 const bigvoice_SampleFormat format = F32_NATIVE;
579 };
580
581 // --------------------------------------------------------------
593 static inline void AudioConvertFrom(CDynLib& dynlib, const uint8_t *payload, float *output, size_t nSpl, bigvoice_SampleFormat fmt) {
594 dynlib.AudioConvertFrom(payload, output, nSpl, fmt);
595 }
596
608 static inline void AudioConvertTo(CDynLib& dynlib, const float *input, uint8_t *payload, size_t nSpl, bigvoice_SampleFormat fmt) {
609 dynlib.AudioConvertTo(input, payload, nSpl, fmt);
610 }
611
622 static inline void StereoToMono(CDynLib& dynlib, const float *input, float *output, size_t nFrame) {
623 dynlib.StereoToMono(input, output, nFrame);
624 }
625
636 static inline void MonoToStereo(CDynLib& dynlib, const float *input, float *output, size_t nFrame) {
637 dynlib.MonoToStereo(input, output, nFrame);
638 }
639
651 static inline void StereoToMono_Planar(CDynLib& dynlib, const float *inputL, const float *inputR, float *output, size_t nFrame) {
652 dynlib.StereoToMono_Planar(inputL, inputR, output, nFrame);
653 }
654
666 static inline void MonoToStereo_Planar(CDynLib& dynlib, const float *input, float *outputL, float *outputR, size_t nFrame) {
667 dynlib.MonoToStereo_Planar(input, outputL, outputR, nFrame);
668 }
669
677 static inline void AudioMonoFromLiveStereo(CDynLib& dynlib, const uint8_t *payload, float *output) {
678 dynlib.AudioMonoFromLiveStereo(payload, output);
679 }
680
688 static inline void AudioMonoToLiveStereo(CDynLib& dynlib, const float *input, uint8_t *payload) {
689 dynlib.AudioMonoToLiveStereo(input, payload);
690 }
691
692 }; // namespace helper
693
700 static inline std::string GetVersion(CDynLib& dynlib)
701 {
702 return std::string(dynlib.GetVersion());
703 }
704
716 static inline unsigned int GetChunkSizeInFrames(CDynLib& dynlib)
717 {
718 return dynlib.GetChunkSizeInFrames();
719 }
720
730 static inline std::vector<unsigned int> GetPossibleChunkSizeInFrames(CDynLib& dynlib)
731 {
732 std::vector<unsigned int> list;
733 if (dynlib.GetPossibleChunkSizeInFrames) {
734 for (unsigned int* src=dynlib.GetPossibleChunkSizeInFrames();*src;src++) {
735 list.push_back(*src);
736 }
737 } else {
738 list.push_back(12);
739 }
740 return list;
741 }
742
749 static inline unsigned int GetChannelCount(CDynLib& dynlib)
750 {
751 return dynlib.GetChannelCount();
752 }
753
762 static inline unsigned int GetAudioInputCount(CDynLib& dynlib)
763 {
764 return dynlib.GetAudioInputCount();
765 }
766
775 static inline unsigned int GetAudioOutputCount(CDynLib& dynlib)
776 {
777 return dynlib.GetAudioOutputCount();
778 }
779
788 static inline unsigned int GetSampleRate(CDynLib& dynlib)
789 {
790 return dynlib.GetSampleRate();
791 }
792
800 static inline void SanityCheck(CDynLib& dynlib, bool a_bCheckFrames = true)
801 {
802 // Do some sanity checks
803 if (dynlib.GetSampleRate()!=BIGVOICE_SAMPLE_RATE) {
804 throw std::runtime_error("Bad library sampling rate");
805 }
806 if (a_bCheckFrames && dynlib.GetChunkSizeInFrames()!=ChunkFrames) {
807 throw std::runtime_error("Bad library frame size");
808 }
810 throw std::runtime_error("Bad library channel count");
811 }
813 throw std::runtime_error("Bad library input count");
814 }
816 throw std::runtime_error("Bad library output count");
817 }
818 }
819
827 static inline std::string GetFormatName(CDynLib& dynlib, const SampleFormat fmt)
828 {
829 return std::string(dynlib.GetFormatName(fmt));
830 }
831
839 static inline SampleFormat GetFormatFromName(CDynLib& dynlib, const std::string& name)
840 {
841 return dynlib.GetFormatFromName(name.c_str());
842 }
843
851 static inline unsigned int GetBytesFromFormat(CDynLib& dynlib, const SampleFormat fmt)
852 {
853 return dynlib.GetBytesFromFormat(fmt);
854 }
855
863 using log_cb_t = std::function<void(LogSeverity,const std::string&)>;
864
869 extern "C" {
870 static inline void _log_cb_c(bigvoice_LogSeverity severity, const char *c_msg) {
871 _log_cb(severity, std::string(c_msg));
872 }
873 }
877 static inline void SetLogSeverity(CDynLib& dynlib, LogSeverity severity)
878 {
879 dynlib.SetLogSeverity(severity);
880 }
884 static inline void SetLoggerCallback(CDynLib& dynlib, log_cb_t cb)
885 {
886 _log_cb=cb;
888 }
889
890#if BIGVOICE_HAS_CLOUDBUS
896 class CBus {
897 public:
898 CBus(CDynLib& dynlib)
899 : m_dynlib(dynlib)
900 {
901 if (m_dynlib.NewBus) {
902 m_bus=m_dynlib.NewBus();
903 }
904 }
906 {
907 if (m_bus && m_dynlib.FreeBus) {
908 m_dynlib.FreeBus(m_bus);
909 }
910 m_bus = nullptr;
911 }
912 bigvoice_CBus *Get() const { return m_bus; }
913 private:
914 CDynLib& m_dynlib;
915 bigvoice_CBus *m_bus;
916 };
917#endif // BIGVOICE_HAS_CLOUDBUS
918
925 public:
926 CPresetLoader() = default;
927 virtual ~CPresetLoader() = default;
928
929 virtual bool IsReadOnly() = 0;
930 virtual bool Exists(const std::filesystem::path &name) = 0;
931 virtual bool Remove(const std::filesystem::path &name) = 0;
932 virtual bool Rename(const std::filesystem::path &from, const std::filesystem::path &to) = 0;
933 virtual std::vector<std::filesystem::path> GetAll() = 0;
934 virtual std::string Read(const std::filesystem::path &filename) = 0;
935 virtual bool Write(const std::filesystem::path &filename, const std::string &content) =0;
936 };
938
944 class CInstance {
945 public:
950 : m_dynlib(dynlib)
951 {
952 params = m_dynlib.NewParameters();
953 if (!params) throw std::bad_alloc();
954 }
955 // non-copyable
956 CInstance( const CInstance& ) = delete;
957 CInstance& operator=( const CInstance& ) = delete;
961 virtual ~CInstance()
962 {
963 Stop();
964 if (params) m_dynlib.FreeParameters(params);
965 }
969 bool IsOk() const { return instance!=nullptr; }
979 void SetParam(const std::string& name, const std::string& value)
980 {
981 assert(params);
982 m_dynlib.SetParameter(params, name.c_str(), value.c_str());
983 }
990 std::string GetParam(const std::string& name)
991 {
992 assert(params);
993 auto c_value=m_dynlib.GetParameter(params, name.c_str());
994 std::string ret(c_value);
995 m_dynlib.FreeParameterValue(c_value);
996 return ret;
997 }
998#if BIGVOICE_HAS_CLOUDBUS
1007 void SetBus(const CBus& bus) {
1008 assert(params);
1009 if (m_dynlib.SetInstanceBus) {
1010 m_dynlib.SetInstanceBus(params,bus.Get());
1011 }
1012 }
1013#endif // BIGVOICE_HAS_CLOUDBUS
1014
1025 void SetPresetManager(CPresetLoader *preset_manager)
1026 {
1027 if (!preset_manager) return;
1028 if (!m_dynlib.SetPresetManager) return;
1029 assert(params);
1030 m_dynlib.SetPresetManager(params,
1039 preset_manager->IsReadOnly(),
1040 preset_manager
1041 );
1042 }
1043
1066 bool Create(const std::string& LoginKey, const std::string& RadioName, const std::string& Access_Key_ID, const std::string& Access_Key_Secret, const std::filesystem::path& save_path, int json_port = 0, unsigned int frames_per_chunk=12)
1067 {
1068 assert(!instance);
1069 std::string l_save_path;
1070 if (!save_path.empty()) {
1071 l_save_path = save_path.u8string();
1072 }
1073 if (m_dynlib.InitProcess3) {
1074 instance = m_dynlib.InitProcess3(LoginKey.c_str(), RadioName.c_str(), Access_Key_ID.c_str(), Access_Key_Secret.c_str(), l_save_path.c_str(), params, frames_per_chunk);
1075 } else if (frames_per_chunk!=12) {
1076 return false;
1077 } else {
1078 instance = m_dynlib.InitProcess2(LoginKey.c_str(), RadioName.c_str(), Access_Key_ID.c_str(), Access_Key_Secret.c_str(), l_save_path.c_str(), params);
1079 }
1080 if (!instance) return false;
1081 if (!init_metadata.empty()) {
1082 for (auto&& [key,value]: init_metadata) {
1083 m_dynlib.SetMetadata(instance, key.c_str(), value.c_str());
1084 }
1085 init_metadata.clear();
1086 }
1087 update_thread = std::thread([this, json_port](){
1089 m_dynlib.StartUpdateThread(instance, json_port);
1091 });
1092 int timeout=5000;
1093 #ifdef DEBUG
1094 timeout=60*1000; // For debugger pauses
1095 #endif
1096 if (m_dynlib.WaitUpdateThreadReady(instance, timeout)<0) {
1097 return false;
1098 }
1099 return true;
1100 }
1101
1109 unsigned int GetChunkFrames() {
1110 if (instance && m_dynlib.GetProcessChunkFrames) {
1111 return m_dynlib.GetProcessChunkFrames(instance);
1112 }
1113 return 12;
1114 }
1115
1123 void PresetManager_InformChange(const std::filesystem::path& relative_path, PresetChange_Kind change_kind)
1124 {
1125 if (m_dynlib.PresetManager_InformChange) {
1126 m_dynlib.PresetManager_InformChange(instance, relative_path.c_str(), (bigvoice_PresetChange_Kind) change_kind);
1127 }
1128 }
1129
1141 void SetMetadata(const std::string& key, const char* value)
1142 {
1143 if (m_dynlib.SetMetadata) {
1144 if (instance) {
1145 m_dynlib.SetMetadata(instance, key.c_str(), value);
1146 } else {
1147 init_metadata.push_back( {key, value} );
1148 }
1149 }
1150 }
1151
1152
1162 void SetMetadataMulti(const std::unordered_map<std::string, const char*>& list)
1163 {
1164 if (instance) {
1165 if (m_dynlib.SetMetadataMulti) {
1166 typedef const char* pchar;
1167 pchar* keyvalue=new pchar[2*list.size()+1];
1168 size_t n=0;
1169 for (auto&& [key,value]: list) {
1170 keyvalue[2*n+0]=key.c_str();
1171 keyvalue[2*n+1]=value;
1172 n++;
1173 }
1174 keyvalue[2*n+0]=nullptr;
1175
1176 bigvoice_SetMetadataMulti(instance, keyvalue);
1177
1178 delete[] keyvalue;
1179 } else {
1180 for (auto&& [key,value]: list) {
1181 SetMetadata(key, value);
1182 }
1183 }
1184 } else {
1185 for (auto&& [key,value]: list) {
1186 if (value) {
1187 init_metadata.push_back( {key, value} );
1188 }
1189 }
1190 }
1191 }
1192
1198 std::vector< std::tuple<std::string,std::string> > GetMetadataInfos()
1199 {
1200 std::vector< std::tuple<std::string,std::string> > values;
1201 if (m_dynlib.GetMetadataInfos) {
1202 const char** c_values = m_dynlib.GetMetadataInfos(instance);
1203 if (c_values) {
1204 for (const char** c_value=c_values; *c_value; ) {
1205 std::string key(*c_value);
1206 c_value++;
1207 if (*c_value) {
1208 std::string descr(*c_value);
1209 c_value++;
1210 values.push_back( {key,descr} );
1211 }
1212 }
1213 m_dynlib.FreeMetadataInfos(instance, c_values);
1214 }
1215 }
1216 return values;
1217 }
1218
1222 virtual void OnUpdateThreadStart() {}
1226 virtual void OnUpdateThreadStop() {}
1227
1228#if BIGVOICE_HAS_WEBSERVER
1242 bool StartWebServer(int http_port, int https_port=0)
1243 {
1244 assert(instance);
1245 assert(webserver==SOUND4_INVALID_WEBSERVER_ID);
1246 webserver = m_dynlib.Webserver(http_port,https_port,instance);
1247 if (webserver==SOUND4_INVALID_WEBSERVER_ID) {
1248 return false;
1249 }
1250 int web_status=m_dynlib.Webserver_Status(webserver);
1251 if (http_port && (web_status & SOUND4_WEBSERVER_HTTP_OK) == 0) {
1252 return false;
1253 }
1254 if (https_port && (web_status & SOUND4_WEBSERVER_HTTPS_OK) == 0) {
1255 return false;
1256 }
1257 return true;
1258 }
1259
1267 void StopWebServer(int timeout_ms = 1000)
1268 {
1269 if (webserver != SOUND4_INVALID_WEBSERVER_ID) {
1270 m_dynlib.Webserver_Stop(webserver, timeout_ms);
1271 webserver = SOUND4_INVALID_WEBSERVER_ID;
1272 }
1273 }
1274
1278 void SetWebServerAppHealth(int httpcode, const std::string& contenttype, const std::string& content)
1279 {
1280 assert(instance);
1281 if (!m_dynlib.Webserver_SetAppHealth) return;
1282 m_dynlib.Webserver_SetAppHealth(instance, httpcode, contenttype.c_str(), content.c_str());
1283 }
1287 void GetWebServerAppHealth(int &httpcode, std::string& contenttype, std::string& content)
1288 {
1289 assert(instance);
1290 if (!m_dynlib.Webserver_GetAppHealth) return;
1291 char* c_contenttype=nullptr;
1292 char* c_content=nullptr;
1293 m_dynlib.Webserver_GetAppHealth(instance, &httpcode, &c_contenttype, &c_content);
1294 contenttype=c_contenttype;
1295 content=c_content;
1296 m_dynlib.Webserver_FreeString(c_contenttype);
1297 m_dynlib.Webserver_FreeString(c_content);
1298 }
1299#endif // BIGVOICE_HAS_WEBSERVER
1300
1310 {
1311 if (!instance) return 0;
1312 return m_dynlib.TerminateProcess(instance);
1313 }
1314
1318 void Stop()
1319 {
1320 if (!instance) return;
1321#if BIGVOICE_HAS_WEBSERVER
1322 StopWebServer();
1323#endif // BIGVOICE_HAS_WEBSERVER
1324 if (update_thread.joinable()) {
1325 m_dynlib.StopUpdateThread(instance); // this will exit the update thread
1326 update_thread.join();
1327 }
1328 m_dynlib.ExitProcess(instance);
1329 instance=nullptr;
1330 }
1331
1341 unsigned int GetEstimatedDelay()
1342 {
1343 assert(instance);
1344 return m_dynlib.GetEstimatedDelay(instance);
1345 }
1346
1359 std::array<float,InputSampleSize>& GetBufferIn()
1360 {
1361 assert(instance);
1362 float *buf=m_dynlib.GetBufferIn(instance);
1363 return reinterpret_cast< std::array<float,InputSampleSize>& >(*buf);
1364
1365 }
1377 std::array<float,OutputSampleSize>& GetBufferOut()
1378 {
1379 assert(instance);
1380 float *buf= m_dynlib.GetBufferOut(instance);
1381 return reinterpret_cast< std::array<float,OutputSampleSize>& >(*buf);
1382 }
1387 {
1388 assert(instance);
1389 m_dynlib.ProcessAudio(instance, m_dynlib.GetBufferIn(instance), m_dynlib.GetBufferOut(instance));
1390 }
1402 void ProcessAudio_Planar(float const * const *input, float * const *output)
1403 {
1404 assert(instance);
1405 m_dynlib.ProcessAudio_Planar(instance, input, output);
1406 }
1407
1419 template<typename T>
1420 std::vector<T> ProcessAnyAudio(const std::vector<T> input)
1421 {
1422 assert(instance);
1423 std::vector<T> output;
1424 unsigned int out_offset=0;
1425 unsigned int in_offset=0;
1426 unsigned int todo = input.size();
1427 while (todo>0) {
1428 unsigned int left = AddAudio(&input[in_offset], todo);
1429 unsigned int out_avail = m_dynlib.GetOutputCount(instance);
1430 output.resize(out_offset + out_avail);
1431 GetAudio(&output[out_offset], out_avail);
1432 out_offset+=out_avail;
1433 in_offset += todo-left;
1434 todo=left;
1435 }
1436 return output;
1437 }
1438
1444 class CClient {
1445 public:
1447 : m_dynlib(dynlib)
1448 {
1449 assert(instance);
1450 client=m_dynlib.NewClient(instance);
1451 if (!client) throw std::bad_alloc();
1452 }
1453 // non-copyable
1454 CClient( const CInstance& ) = delete;
1455 CClient& operator=( const CInstance& ) = delete;
1457 {
1458 if (client) {
1459 m_dynlib.DeleteClient(client);
1460 client=nullptr;
1461 }
1462 }
1470 std::string ProcessJson(const std::string &request, bool *NeedSave = nullptr)
1471 {
1472 assert(client);
1473 int need_save=0;
1474 const char *canswer = m_dynlib.ProcessJson(client, request.c_str(), &need_save);
1475 if (!canswer) return {};
1476 std::string answer(canswer);
1477 m_dynlib.FreeJsonAnswer (canswer);
1478 if (NeedSave) {
1479 *NeedSave=(need_save!=0);
1480 }
1481 return answer;
1482 }
1483 private:
1484 CDynLib& m_dynlib;
1485 bigvoice_CClientInstance *client = nullptr;
1486 };
1494 std::shared_ptr<CClient> NewClient()
1495 {
1496 assert(instance);
1497 return std::make_shared<CClient>(instance, m_dynlib);
1498 }
1499
1510 bool SaveState() {
1511 assert(instance);
1512 if (m_dynlib.SaveState(instance)!=0) {
1513 return false;
1514 }
1515 return true;
1516 }
1517#ifdef _WIN32
1524 void SetInstanceTracing(TraceLoggingHProvider tracing_provider, GUID activity_guid = {}) {
1525 if (m_dynlib.SetInstanceTracing) {
1526 m_dynlib.SetInstanceTracing(params, tracing_provider, activity_guid);
1527 }
1528 }
1535 void SetInstanceTracingProcessActivity(GUID activity_guid) {
1536 assert(instance);
1537 if (m_dynlib.SetInstanceTracingProcessActivity) {
1538 m_dynlib.SetInstanceTracingProcessActivity(instance, activity_guid);
1539 }
1540 }
1541#endif // _WIN32
1542 protected:
1543 template<typename T>
1544 unsigned int AddAudio(const T* payload, unsigned int nFrame)
1545 {
1546 assert(instance);
1547 return m_dynlib.AddAudio(instance, reinterpret_cast<const T*>(payload), nFrame, helper::SampleFormat<T>::format);
1548 }
1549 template<typename T>
1550 unsigned int GetAudio(T* payload, unsigned int max_nFrame)
1551 {
1552 assert(instance);
1553 return m_dynlib.GetAudio(instance, reinterpret_cast<T*>(payload), max_nFrame, helper::SampleFormat<T>::format);
1554 }
1555
1556 private:
1557 CDynLib& m_dynlib;
1558 bigvoice_CParameters* params = nullptr;
1559 bigvoice_CInstance* instance = nullptr;
1560 std::thread update_thread;
1561 std::vector< std::pair<std::string,std::string> > init_metadata;
1562#if BIGVOICE_HAS_WEBSERVER
1563 uint64_t webserver = SOUND4_INVALID_WEBSERVER_ID;
1564#endif // BIGVOICE_HAS_WEBSERVER
1565 };
1566
1567}; // namespace dyn
1568}; // namespace bigvoice
1569}; // namespace sound4
1570
1571// bridge C callbacks to CPresetLoader
1572extern "C" {
1573 static char *bigvoice_custom_reader(const fs_char *filename, void* userdata) {
1574 sound4::bigvoice::dyn::CPresetLoader *preset_loader=reinterpret_cast<sound4::bigvoice::dyn::CPresetLoader*>(userdata);
1575 std::string content=preset_loader->Read(filename);
1576 return strdup(content.c_str());
1577 }
1578 static void bigvoice_custom_reader_free(char *content, void* userdata) {
1579 if (!content) return;
1580 free(content);
1581 }
1582 static int bigvoice_custom_writer(const fs_char *filename, const char *content, void* userdata) {
1583 sound4::bigvoice::dyn::CPresetLoader *preset_loader=reinterpret_cast<sound4::bigvoice::dyn::CPresetLoader*>(userdata);
1584 auto res=preset_loader->Write(filename,content);
1585 return res?0:-1;
1586 }
1587 static int bigvoice_custom_exists(const fs_char *filename, void* userdata) {
1588 sound4::bigvoice::dyn::CPresetLoader *preset_loader=reinterpret_cast<sound4::bigvoice::dyn::CPresetLoader*>(userdata);
1589 auto res=preset_loader->Exists(filename);
1590 return res?0:-1;
1591 }
1592 static fs_char** bigvoice_custom_getall(void* userdata) {
1593 sound4::bigvoice::dyn::CPresetLoader *preset_loader=reinterpret_cast<sound4::bigvoice::dyn::CPresetLoader*>(userdata);
1594 auto res=preset_loader->GetAll();
1595 fs_char**all=(fs_char**)malloc((res.size()+1)*sizeof(const fs_char*));
1596 for (size_t n=0;n<res.size();n++) {
1597 all[n]=fs_strdup(res[n].c_str());
1598 }
1599 all[res.size()]=nullptr;
1600 return all;
1601 }
1602 static void bigvoice_custom_getall_free(fs_char** all, void* userdata) {
1603 if (!all) return;
1604 for (fs_char** one=all;*one;one++) {
1605 free(*one);
1606 }
1607 free(all);
1608 }
1609 static int bigvoice_custom_remove(const fs_char *filename, void* userdata) {
1610 sound4::bigvoice::dyn::CPresetLoader *preset_loader=reinterpret_cast<sound4::bigvoice::dyn::CPresetLoader*>(userdata);
1611 auto res=preset_loader->Remove(filename);
1612 return res?0:-1;
1613 }
1614 static int bigvoice_custom_rename(const fs_char *from, const fs_char *to, void* userdata) {
1615 sound4::bigvoice::dyn::CPresetLoader *preset_loader=reinterpret_cast<sound4::bigvoice::dyn::CPresetLoader*>(userdata);
1616 auto res=preset_loader->Rename(from,to);
1617 return res?0:-1;
1618 }
1619
1620};
helper::DynFuncHolder< decltype(bigvoice_FreeParameterValue) > FreeParameterValue
helper::DynFuncHolder< decltype(bigvoice_AudioMonoFromLiveStereo) > AudioMonoFromLiveStereo
helper::DynFuncHolder< decltype(bigvoice_Webserver_FreeString) > Webserver_FreeString
helper::DynFuncHolder< decltype(bigvoice_GetAudio) > GetAudio
helper::DynFuncHolder< decltype(bigvoice_GetSampleRate) > GetSampleRate
helper::DynFuncHolder< decltype(bigvoice_ProcessJson) > ProcessJson
helper::DynFuncHolder< decltype(bigvoice_NewClient) > NewClient
helper::DynFuncHolder< decltype(bigvoice_GetBufferOut) > GetBufferOut
helper::DynFuncHolder< decltype(bigvoice_WaitUpdateThreadReady) > WaitUpdateThreadReady
helper::DynFuncHolder< decltype(bigvoice_AudioMonoToLiveStereo) > AudioMonoToLiveStereo
helper::DynFuncHolder< decltype(bigvoice_Webserver_Stop) > Webserver_Stop
helper::DynFuncHolder< decltype(bigvoice_InitProcess3) > InitProcess3
helper::DynFuncHolder< decltype(bigvoice_GetMaxPacketFrame) > GetMaxPacketFrame
helper::DynFuncHolder< decltype(bigvoice_FreeBus) > FreeBus
helper::DynFuncHolder< decltype(bigvoice_InitProcess) > InitProcess
helper::DynFuncHolder< decltype(bigvoice_GetFormatFromName) > GetFormatFromName
helper::DynFuncHolder< decltype(bigvoice_GetVersion) > GetVersion
helper::DynFuncHolder< decltype(bigvoice_SetParameter) > SetParameter
helper::DynFuncHolder< decltype(bigvoice_NewParameters) > NewParameters
helper::DynFuncHolder< decltype(bigvoice_SetLoggerCallback) > SetLoggerCallback
helper::DynFuncHolder< decltype(bigvoice_SetInstanceBus) > SetInstanceBus
helper::DynFuncHolder< decltype(bigvoice_ProcessAudio_Planar) > ProcessAudio_Planar
helper::DynFuncHolder< decltype(bigvoice_AudioConvertTo) > AudioConvertTo
helper::DynFuncHolder< decltype(bigvoice_Webserver) > Webserver
helper::DynFuncHolder< decltype(bigvoice_ExitProcess) > ExitProcess
helper::DynFuncHolder< decltype(bigvoice_SetLogSeverity) > SetLogSeverity
bool Load(const std::filesystem::path &path={})
Loads the library.
helper::DynFuncHolder< decltype(bigvoice_GetProcessChunkFrames) > GetProcessChunkFrames
helper::DynFuncHolder< decltype(bigvoice_Webserver_tcp) > Webserver_tcp
helper::DynFuncHolder< decltype(bigvoice_Webserver_tcp2) > Webserver_tcp2
helper::DynFuncHolder< decltype(bigvoice_FreeJsonAnswer) > FreeJsonAnswer
helper::DynFuncHolder< decltype(bigvoice_StartUpdateThread) > StartUpdateThread
helper::DynFuncHolder< decltype(bigvoice_InitProcess2) > InitProcess2
helper::DynFuncHolder< decltype(bigvoice_GetAudioOutputCount) > GetAudioOutputCount
helper::DynFuncHolder< decltype(bigvoice_GetOutputCount) > GetOutputCount
helper::DynFuncHolder< decltype(bigvoice_Webserver_Status) > Webserver_Status
helper::DynFuncHolder< decltype(bigvoice_GetBufferIn) > GetBufferIn
helper::DynFuncHolder< decltype(bigvoice_PresetManager_InformChange) > PresetManager_InformChange
helper::DynFuncHolder< decltype(bigvoice_StereoToMono) > StereoToMono
helper::DynFuncHolder< decltype(bigvoice_SetInstanceTracingProcessActivity) > SetInstanceTracingProcessActivity
helper::DynFuncHolder< decltype(bigvoice_StopUpdateThread) > StopUpdateThread
helper::DynFuncHolder< decltype(bigvoice_SetPresetManager) > SetPresetManager
helper::DynFuncHolder< decltype(bigvoice_GetBytesFromFormat) > GetBytesFromFormat
helper::DynFuncHolder< decltype(bigvoice_SaveState) > SaveState
helper::DynFuncHolder< decltype(bigvoice_FreeMetadataInfos) > FreeMetadataInfos
bool IsOk() const
Check if the library was loaded correctly.
helper::DynFuncHolder< decltype(bigvoice_SetMetadata) > SetMetadata
helper::DynFuncHolder< decltype(bigvoice_GetMetadataInfos) > GetMetadataInfos
helper::DynFuncHolder< decltype(bigvoice_AddAudio) > AddAudio
helper::DynFuncHolder< decltype(bigvoice_DeleteClient) > DeleteClient
helper::DynFuncHolder< decltype(bigvoice_ProcessAudio) > ProcessAudio
helper::DynFuncHolder< decltype(bigvoice_AudioConvertFrom) > AudioConvertFrom
helper::DynFuncHolder< decltype(bigvoice_NewBus) > NewBus
helper::DynFuncHolder< decltype(bigvoice_Webserver_GetAppHealth) > Webserver_GetAppHealth
helper::DynFuncHolder< decltype(bigvoice_StereoToMono_Planar) > StereoToMono_Planar
helper::DynFuncHolder< decltype(bigvoice_MonoToStereo) > MonoToStereo
helper::DynFuncHolder< decltype(bigvoice_GetFormatName) > GetFormatName
helper::DynFuncHolder< decltype(bigvoice_MonoToStereo_Planar) > MonoToStereo_Planar
helper::DynFuncHolder< decltype(bigvoice_GetAudioInputCount) > GetAudioInputCount
helper::DynFuncHolder< decltype(bigvoice_AddPadAudio) > AddPadAudio
helper::DynFuncHolder< decltype(bigvoice_SetMetadataMulti) > SetMetadataMulti
helper::DynFuncHolder< decltype(bigvoice_SetInstanceTracing) > SetInstanceTracing
helper::DynFuncHolder< decltype(bigvoice_Webserver_SetAppHealth) > Webserver_SetAppHealth
helper::DynFuncHolder< decltype(bigvoice_GetParameter) > GetParameter
helper::DynFuncHolder< decltype(bigvoice_GetChunkSizeInFrames) > GetChunkSizeInFrames
helper::DynFuncHolder< decltype(bigvoice_TerminateProcess) > TerminateProcess
helper::DynFuncHolder< decltype(bigvoice_FreeParameters) > FreeParameters
helper::DynFuncHolder< decltype(bigvoice_GetPossibleChunkSizeInFrames) > GetPossibleChunkSizeInFrames
helper::DynFuncHolder< decltype(bigvoice_GetEstimatedDelay) > GetEstimatedDelay
helper::DynFuncHolder< decltype(bigvoice_GetChannelCount) > GetChannelCount
std::string ProcessJson(const std::string &request, bool *NeedSave=nullptr)
Process a JSON request and returns the answer.
CClient & operator=(const CInstance &)=delete
CClient(bigvoice_CInstance *instance, CDynLib &dynlib)
void SetMetadataMulti(const std::unordered_map< std::string, const char * > &list)
std::array< float, InputSampleSize > & GetBufferIn()
unsigned int AddAudio(const T *payload, unsigned int nFrame)
void SetWebServerAppHealth(int httpcode, const std::string &contenttype, const std::string &content)
void SetMetadata(const std::string &key, const char *value)
CInstance(const CInstance &)=delete
void GetWebServerAppHealth(int &httpcode, std::string &contenttype, std::string &content)
void SetParam(const std::string &name, const std::string &value)
std::string GetParam(const std::string &name)
CInstance & operator=(const CInstance &)=delete
std::vector< T > ProcessAnyAudio(const std::vector< T > input)
unsigned int GetAudio(T *payload, unsigned int max_nFrame)
bool StartWebServer(int http_port, int https_port=0)
void ProcessAudio_Planar(float const *const *input, float *const *output)
void SetInstanceTracing(TraceLoggingHProvider tracing_provider, GUID activity_guid={})
std::vector< std::tuple< std::string, std::string > > GetMetadataInfos()
void SetPresetManager(CPresetLoader *preset_manager)
std::array< float, OutputSampleSize > & GetBufferOut()
bool Create(const std::string &LoginKey, const std::string &RadioName, const std::string &Access_Key_ID, const std::string &Access_Key_Secret, const std::filesystem::path &save_path, int json_port=0, unsigned int frames_per_chunk=12)
void SetInstanceTracingProcessActivity(GUID activity_guid)
void PresetManager_InformChange(const std::filesystem::path &relative_path, PresetChange_Kind change_kind)
virtual std::string Read(const std::filesystem::path &filename)=0
virtual bool Write(const std::filesystem::path &filename, const std::string &content)=0
virtual std::vector< std::filesystem::path > GetAll()=0
virtual bool Exists(const std::filesystem::path &name)=0
virtual bool Remove(const std::filesystem::path &name)=0
virtual bool Rename(const std::filesystem::path &from, const std::filesystem::path &to)=0
CDynLoader & operator=(CDynLoader const &)=delete
static std::filesystem::path GetThisLibraryPath(void)
DynFuncHolder< T > GetSymbol(const std::string &name)
CDynLoader(const CDynLoader &)=delete
DynFuncHolder< T > GetSymbol_safe(const std::string &name)
bool Load(const std::filesystem::path &dynlib, uint32_t loadflags=LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR|LOAD_LIBRARY_SEARCH_APPLICATION_DIR|LOAD_LIBRARY_SEARCH_USER_DIRS|LOAD_LIBRARY_SEARCH_SYSTEM32)
unsigned int bigvoice_GetOutputCount(struct bigvoice_CInstance *instance)
unsigned int bigvoice_GetAudio(struct bigvoice_CInstance *instance, uint8_t *payload, unsigned int max_nFrame, enum bigvoice_SampleFormat fmt)
unsigned int bigvoice_GetMaxPacketFrame(struct bigvoice_CInstance *instance)
bigvoice_SampleFormat
const char * bigvoice_GetFormatName(const enum bigvoice_SampleFormat fmt)
unsigned int bigvoice_GetBytesFromFormat(const enum bigvoice_SampleFormat fmt)
unsigned int bigvoice_AddPadAudio(struct bigvoice_CInstance *instance)
enum bigvoice_SampleFormat bigvoice_GetFormatFromName(const char *name)
unsigned int bigvoice_AddAudio(struct bigvoice_CInstance *instance, const uint8_t *payload, unsigned int nFrame, enum bigvoice_SampleFormat fmt)
int bigvoice_SaveState(struct bigvoice_CInstance *instance)
void bigvoice_DeleteClient(struct bigvoice_CClientInstance *client)
const char * bigvoice_ProcessJson(struct bigvoice_CClientInstance *client, const char *json_str, int *need_save)
void bigvoice_FreeJsonAnswer(const char *json_str)
struct bigvoice_CClientInstance * bigvoice_NewClient(struct bigvoice_CInstance *instance)
struct bigvoice_CBus * bigvoice_NewBus()
void bigvoice_FreeBus(struct bigvoice_CBus *bus)
void bigvoice_SetInstanceBus(struct bigvoice_CParameters *params, struct bigvoice_CBus *bus)
void bigvoice_AudioConvertTo(const float *input, uint8_t *payload, size_t nSpl, enum bigvoice_SampleFormat fmt)
void bigvoice_AudioConvertFrom(const uint8_t *payload, float *output, size_t nSpl, enum bigvoice_SampleFormat fmt)
void bigvoice_AudioMonoToLiveStereo(const float *input, uint8_t *payload)
void bigvoice_StereoToMono_Planar(const float *inputL, const float *inputR, float *output, size_t nFrame)
void bigvoice_MonoToStereo_Planar(const float *input, float *outputL, float *outputR, size_t nFrame)
void bigvoice_AudioMonoFromLiveStereo(const uint8_t *payload, float *output)
void bigvoice_MonoToStereo(const float *input, float *output, size_t nFrame)
void bigvoice_StereoToMono(const float *input, float *output, size_t nFrame)
void bigvoice_ProcessAudio(struct bigvoice_CInstance *instance, const float *input, float *output)
unsigned int bigvoice_GetEstimatedDelay(struct bigvoice_CInstance *instance)
float * bigvoice_GetBufferOut(struct bigvoice_CInstance *instance)
float * bigvoice_GetBufferIn(struct bigvoice_CInstance *instance)
void bigvoice_ProcessAudio_Planar(struct bigvoice_CInstance *instance, float const *const *input, float *const *output)
#define BIGVOICE_SAMPLE_RATE
#define BIGVOICE_CHANNEL_COUNT
bigvoice_LogSeverity
unsigned int bigvoice_GetAudioInputCount()
unsigned int bigvoice_GetChannelCount()
void bigvoice_SetLoggerCallback(bigvoice_loggerfn logger)
void bigvoice_SetLogSeverity(enum bigvoice_LogSeverity severity)
#define BIGVOICE_AUDIO_OUTPUT_COUNT
unsigned int bigvoice_GetChunkSizeInFrames()
unsigned int bigvoice_GetAudioOutputCount()
#define BIGVOICE_AUDIO_INPUT_COUNT
const char * bigvoice_GetVersion()
#define BIGVOICE_AUDIOFRAME_COUNT
unsigned int bigvoice_GetSampleRate()
unsigned int * bigvoice_GetPossibleChunkSizeInFrames()
void bigvoice_FreeParameterValue(const char *value)
int bigvoice_TerminateProcess(struct bigvoice_CInstance *instance)
struct bigvoice_CInstance * bigvoice_InitProcess3(const char *LoginKey, const char *RadioName, const char *Access_Key_ID, const char *Access_Key_Secret, const char *save_path, const struct bigvoice_CParameters *parameters, unsigned int frames_per_chunk)
void bigvoice_FreeParameters(struct bigvoice_CParameters *params)
void bigvoice_ExitProcess(struct bigvoice_CInstance *instance)
struct bigvoice_CParameters * bigvoice_NewParameters()
unsigned int bigvoice_GetProcessChunkFrames(struct bigvoice_CInstance *instance)
struct bigvoice_CInstance * bigvoice_InitProcess2(const char *LoginKey, const char *RadioName, const char *Access_Key_ID, const char *Access_Key_Secret, const char *save_path, const struct bigvoice_CParameters *parameters)
void bigvoice_SetParameter(struct bigvoice_CParameters *params, const char *name, const char *value)
struct bigvoice_CInstance * bigvoice_InitProcess(const char *LoginKey, const char *RadioName, const char *Access_Key_ID, const char *Access_Key_Secret, const char *save_path)
const char * bigvoice_GetParameter(struct bigvoice_CParameters *params, const char *name)
void bigvoice_FreeMetadataInfos(struct bigvoice_CInstance *instance, const char **infos)
void bigvoice_SetMetadata(struct bigvoice_CInstance *instance, const char *key, const char *value)
const char ** bigvoice_GetMetadataInfos(struct bigvoice_CInstance *instance)
void bigvoice_SetMetadataMulti(struct bigvoice_CInstance *instance, const char **keyvalue)
bigvoice_PresetChange_Kind
void bigvoice_SetPresetManager(struct bigvoice_CParameters *params, bigvoice_storage_reader reader, bigvoice_storage_reader_free, bigvoice_storage_writer writer, bigvoice_storage_exists exists, bigvoice_storage_getall getall, bigvoice_storage_getall_free getall_free, bigvoice_storage_remove remove, bigvoice_storage_rename rename, int IsReadOnly, void *userdata)
void bigvoice_PresetManager_InformChange(struct bigvoice_CInstance *instance, const fs_char *relative_path, enum bigvoice_PresetChange_Kind change_kind)
wchar_t fs_char
void bigvoice_SetInstanceTracingProcessActivity(struct bigvoice_CInstance *instance, GUID activity_guid)
void bigvoice_SetInstanceTracing(struct bigvoice_CParameters *params, TraceLoggingHProvider tracing_provider, GUID activity_guid)
void bigvoice_StopUpdateThread(struct bigvoice_CInstance *instance)
int bigvoice_WaitUpdateThreadReady(struct bigvoice_CInstance *instance, int milliseconds)
void bigvoice_StartUpdateThread(struct bigvoice_CInstance *instance, unsigned int port)
#define SOUND4_WEBSERVER_HTTPS_OK
uint64_t bigvoice_Webserver_tcp(unsigned int listenport, unsigned int listenport_secure, const char *socket_ip, unsigned int socket_port)
uint64_t bigvoice_Webserver(unsigned int listenport, unsigned int listenport_secure, struct bigvoice_CInstance *instance)
int bigvoice_Webserver_Stop(uint64_t id, int timeout_ms)
uint64_t bigvoice_Webserver_tcp2(unsigned int listenport, unsigned int listenport_secure, const char *socket_ip, unsigned int socket_port, const struct bigvoice_CParameters *parameters)
int bigvoice_Webserver_Status(uint64_t id)
void bigvoice_Webserver_SetAppHealth(struct bigvoice_CInstance *instance, int httpcode, const char *contenttype, const char *content)
#define SOUND4_WEBSERVER_HTTP_OK
void bigvoice_Webserver_FreeString(char *str)
#define SOUND4_INVALID_WEBSERVER_ID
void bigvoice_Webserver_GetAppHealth(struct bigvoice_CInstance *instance, int *httpcode, char **contenttype, char **content)
static void StereoToMono(CDynLib &dynlib, const float *input, float *output, size_t nFrame)
static std::wstring UTF8ToWString(const std::string &str)
static std::string WStringToUTF8(const std::wstring &wstr)
static void MonoToStereo_Planar(CDynLib &dynlib, const float *input, float *outputL, float *outputR, size_t nFrame)
static void MonoToStereo(CDynLib &dynlib, const float *input, float *output, size_t nFrame)
static void AudioMonoFromLiveStereo(CDynLib &dynlib, const uint8_t *payload, float *output)
static void StereoToMono_Planar(CDynLib &dynlib, const float *inputL, const float *inputR, float *output, size_t nFrame)
static void AudioMonoToLiveStereo(CDynLib &dynlib, const float *input, uint8_t *payload)
static void AudioConvertFrom(CDynLib &dynlib, const uint8_t *payload, float *output, size_t nSpl, bigvoice_SampleFormat fmt)
static void AudioConvertTo(CDynLib &dynlib, const float *input, uint8_t *payload, size_t nSpl, bigvoice_SampleFormat fmt)
static void SetLogSeverity(CDynLib &dynlib, LogSeverity severity)
static unsigned int GetBytesFromFormat(CDynLib &dynlib, const SampleFormat fmt)
static SampleFormat GetFormatFromName(CDynLib &dynlib, const std::string &name)
static constexpr const char * process_name
static constexpr const char * process_shortname
static void SetLoggerCallback(CDynLib &dynlib, log_cb_t cb)
std::function< void(LogSeverity, const std::string &)> log_cb_t
static void _log_cb_c(bigvoice_LogSeverity severity, const char *c_msg)
static std::string GetFormatName(CDynLib &dynlib, const SampleFormat fmt)
static void SanityCheck(CDynLib &dynlib, bool a_bCheckFrames=true)
static unsigned int GetAudioInputCount()
static std::vector< unsigned int > GetPossibleChunkSizeInFrames()
static unsigned int GetSampleRate()
static unsigned int GetChannelCount()
static unsigned int GetAudioOutputCount()
static unsigned int GetChunkSizeInFrames()
static std::string GetVersion()
@ S32_NATIVE
32-bit signed integer, native
Definition sound4cl.hpp:72
@ F32_NATIVE
32-bit floating-point, native
Definition sound4cl.hpp:73
@ S16_NATIVE
16-bit signed integer, native
Definition sound4cl.hpp:70
@ info
info
Definition sound4cl.hpp:280
C interface for library.
struct _tlgProvider_t const * TraceLoggingHProvider
static int bigvoice_custom_exists(const fs_char *filename, void *userdata)
static int bigvoice_custom_rename(const fs_char *from, const fs_char *to, void *userdata)
static int bigvoice_custom_writer(const fs_char *filename, const char *content, void *userdata)
static fs_char ** bigvoice_custom_getall(void *userdata)
static int bigvoice_custom_remove(const fs_char *filename, void *userdata)
static void bigvoice_custom_reader_free(char *content, void *userdata)
static char * bigvoice_custom_reader(const fs_char *filename, void *userdata)
static void bigvoice_custom_getall_free(fs_char **all, void *userdata)
static int bigvoice_custom_exists(const fs_char *filename, void *userdata)
static int bigvoice_custom_rename(const fs_char *from, const fs_char *to, void *userdata)
static int bigvoice_custom_writer(const fs_char *filename, const char *content, void *userdata)
static fs_char ** bigvoice_custom_getall(void *userdata)
static int bigvoice_custom_remove(const fs_char *filename, void *userdata)
static void bigvoice_custom_reader_free(char *content, void *userdata)
static char * bigvoice_custom_reader(const fs_char *filename, void *userdata)
static void bigvoice_custom_getall_free(fs_char **all, void *userdata)