SOUND4 BIGVOICE.CL Library [1.1.15]
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&& other) noexcept : m_lib(other.m_lib) { other.m_lib = NULL; }
120 CDynLoader& operator=(CDynLoader&& other) noexcept {
121 if (this != &other) { Close(); m_lib = other.m_lib; other.m_lib = NULL; }
122 return *this;
123 }
124 // No copy allowed
125 CDynLoader(const CDynLoader&) = delete;
126 CDynLoader& operator=(CDynLoader const&) = delete;
127 operator bool() const {
128 return (m_lib!=NULL);
129 }
130 bool IsOk() const {
131 return (m_lib!=NULL);
132 }
133 #if UNIXLIKE
134 void Close() {
135 if (IsOk()) {
136 #ifndef __SANITIZE_ADDRESS__ // avoid unloading to keep call stack
137 dlclose(m_lib);
138 #endif // __SANITIZE_ADDRESS__
139 m_lib=NULL;
140 }
141 }
142 bool Load(const std::filesystem::path& dynlib)
143 {
144 Close();
145 m_lib=dlopen(dynlib.c_str(), RTLD_NOW|RTLD_LOCAL);
146 return IsOk();
147 }
148 template <typename T>
149 DynFuncHolder<T> GetSymbol(const std::string& name) {
150 auto ptr=dlsym(m_lib, name.c_str());
151 if (!ptr) {
152 throw std::runtime_error("Missing function in library");
153 }
154 return DynFuncHolder<T>(ptr);
155 }
156 template <typename T>
157 DynFuncHolder<T> GetSymbol_safe(const std::string& name) {
158 auto ptr=dlsym(m_lib, name.c_str());
159 return DynFuncHolder<T>(ptr);
160 }
161 static std::filesystem::path GetThisLibraryPath(void) {
162 static Dl_info info;
163 if (! dladdr((void *) GetThisLibraryPath, & info)) return {};
164 auto rp=realpath(info.dli_fname, NULL);
165 if (!rp) {
166 #if defined(__unix__)
167 rp=realpath("/proc/self/exe", NULL);
168 #elif defined(__APPLE__)
169 // How to solve this for Apple ?
170 #endif
171 }
172 std::filesystem::path p(rp);
173 free(rp);
174 return p;
175 }
176 #else
183 void Close() {
184 if (IsOk()) {
185 // NOTE: On Windows, FreeLibrary may create a lot of troubles, should use FreeLibraryAndExitThread but...
186 // So define SOUND4_CALL_FREELIBRARY before including this file if you really want to unload the library dynamically
187 #if defined(SOUND4_CALL_FREELIBRARYANDEXITTHREAD)
188 FreeLibraryAndExitThread(m_lib, 0);
189 #elif defined(SOUND4_CALL_FREELIBRARY)
190 FreeLibrary(m_lib);
191 #endif // SOUND4_CALL_FREELIBRARY
192 m_lib=NULL;
193 }
194 }
195 template <typename T>
196 DynFuncHolder<T> GetSymbol(const std::string& name) {
197 auto ptr=GetProcAddress(m_lib, name.c_str());
198 if (!ptr) {
199 throw std::runtime_error("Missing function in library");
200 }
201 return DynFuncHolder<T>(ptr);
202 }
203 template <typename T>
204 DynFuncHolder<T> GetSymbol_safe(const std::string& name) {
205 auto ptr=GetProcAddress(m_lib, name.c_str());
206 return DynFuncHolder<T>(ptr);
207 }
208 static std::filesystem::path GetThisLibraryPath(void) {
209 static wchar_t path[MAX_PATH]={};
210 HMODULE hm = NULL;
214 {
215 if (GetModuleFileNameW(hm, path, MAX_PATH) > 0) {
216 return std::filesystem::path(path);
217 }
218 }
219 return {};
220 }
221 #endif
222 virtual ~CDynLoader() {
223 Close();
224 }
225 }; // class CDynLoader
226 }; // namespace helper
227
234 class CDynLib {
235 private:
236 helper::CDynLoader m_lib;
237 bool m_bOK = false;
238 public:
239 CDynLib() = default;
240
241 // All those wrapped functions have the same signature as there C bigvoice_XXX
286#if BIGVOICE_HAS_WEBSERVER
292#endif // BIGVOICE_HAS_WEBSERVER
293
294 // added 2023-03-22
297
298 // added 2023-05-22
302
303 // added 2023-06-20
306
307 // added 2023-09-21
311
312#if BIGVOICE_HAS_CLOUDBUS
313 // added 2023-06-26
317#endif // BIGVOICE_HAS_CLOUDBUS
318
319 // added 2024-02-19
321
322#if BIGVOICE_HAS_WEBSERVER
323 // added 2024-05-23
327#endif // BIGVOICE_HAS_WEBSERVER
328
329#ifdef _WIN32
330 // added 2025-05-28
333#endif // _WIN32
334
335 // added 2025-05-28
340
348 bool Load(const std::filesystem::path& path = {}) {
349 std::string filename;
350 #if defined(__APPLE__)
351 filename="libsound4.bigvoice.cl.dylib";
352 #elif defined(__unix__)
353 filename="libsound4.bigvoice.cl.so";
354 #else
355 filename="sound4.bigvoice.cl.dll";
356 #endif
357 m_lib.Close();
358 // If a path is given, use it directly and do not try other path
359 if (!path.empty() && !m_lib.Load(path / filename)) {
360 return false;
361 } else if (!m_lib.IsOk()) {
362 auto thisdir=helper::CDynLoader::GetThisLibraryPath().parent_path();
363 #ifndef _WIN32
364 // Linux: if in a bin directory, try ../lib first
365 if (!m_lib.IsOk() && thisdir.filename()=="bin") {
366 auto libdir = thisdir.parent_path() / "lib";
367 m_lib.Load(libdir / filename);
368 }
369 #endif // !_WIN32
370 if (!m_lib.IsOk()) {
371 // Search in the same directory this code is in
372 m_lib.Load(thisdir / filename);
373 }
374 if (!m_lib.IsOk()) {
375 // Try current path
376 std::error_code ec;
377 auto p = std::filesystem::current_path(ec);
378 if (!ec) {
379 m_lib.Load(p / filename);
380 }
381 }
382 if (!m_lib.IsOk()) {
383 return false;
384 }
385 }
386 // Load all C functions
387 try {
388 GetVersion = m_lib.GetSymbol< decltype(bigvoice_GetVersion ) >("bigvoice_GetVersion" );
389 GetChunkSizeInFrames = m_lib.GetSymbol< decltype(bigvoice_GetChunkSizeInFrames ) >("bigvoice_GetChunkSizeInFrames" );
390 GetChannelCount = m_lib.GetSymbol< decltype(bigvoice_GetChannelCount ) >("bigvoice_GetChannelCount" );
391 GetAudioInputCount = m_lib.GetSymbol< decltype(bigvoice_GetAudioInputCount ) >("bigvoice_GetAudioInputCount" );
392 GetAudioOutputCount = m_lib.GetSymbol< decltype(bigvoice_GetAudioOutputCount ) >("bigvoice_GetAudioOutputCount" );
393 GetSampleRate = m_lib.GetSymbol< decltype(bigvoice_GetSampleRate ) >("bigvoice_GetSampleRate" );
394 SetLoggerCallback = m_lib.GetSymbol< decltype(bigvoice_SetLoggerCallback ) >("bigvoice_SetLoggerCallback" );
395 SetLogSeverity = m_lib.GetSymbol< decltype(bigvoice_SetLogSeverity ) >("bigvoice_SetLogSeverity" );
396 NewParameters = m_lib.GetSymbol< decltype(bigvoice_NewParameters ) >("bigvoice_NewParameters" );
397 FreeParameters = m_lib.GetSymbol< decltype(bigvoice_FreeParameters ) >("bigvoice_FreeParameters" );
398 SetParameter = m_lib.GetSymbol< decltype(bigvoice_SetParameter ) >("bigvoice_SetParameter" );
399 GetParameter = m_lib.GetSymbol< decltype(bigvoice_GetParameter ) >("bigvoice_GetParameter" );
400 FreeParameterValue = m_lib.GetSymbol< decltype(bigvoice_FreeParameterValue ) >("bigvoice_FreeParameterValue" );
401 InitProcess = m_lib.GetSymbol< decltype(bigvoice_InitProcess ) >("bigvoice_InitProcess" );
402 InitProcess2 = m_lib.GetSymbol< decltype(bigvoice_InitProcess2 ) >("bigvoice_InitProcess2" );
403 TerminateProcess = m_lib.GetSymbol< decltype(bigvoice_TerminateProcess ) >("bigvoice_TerminateProcess" );
404 ExitProcess = m_lib.GetSymbol< decltype(bigvoice_ExitProcess ) >("bigvoice_ExitProcess" );
405 StartUpdateThread = m_lib.GetSymbol< decltype(bigvoice_StartUpdateThread ) >("bigvoice_StartUpdateThread" );
406 StopUpdateThread = m_lib.GetSymbol< decltype(bigvoice_StopUpdateThread ) >("bigvoice_StopUpdateThread" );
407 WaitUpdateThreadReady = m_lib.GetSymbol< decltype(bigvoice_WaitUpdateThreadReady ) >("bigvoice_WaitUpdateThreadReady" );
408 ProcessAudio = m_lib.GetSymbol< decltype(bigvoice_ProcessAudio ) >("bigvoice_ProcessAudio" );
409 ProcessAudio_Planar = m_lib.GetSymbol< decltype(bigvoice_ProcessAudio_Planar ) >("bigvoice_ProcessAudio_Planar" );
410 GetBufferIn = m_lib.GetSymbol< decltype(bigvoice_GetBufferIn ) >("bigvoice_GetBufferIn" );
411 GetBufferOut = m_lib.GetSymbol< decltype(bigvoice_GetBufferOut ) >("bigvoice_GetBufferOut" );
412 GetEstimatedDelay = m_lib.GetSymbol< decltype(bigvoice_GetEstimatedDelay ) >("bigvoice_GetEstimatedDelay" );
413 GetFormatName = m_lib.GetSymbol< decltype(bigvoice_GetFormatName ) >("bigvoice_GetFormatName" );
414 GetFormatFromName = m_lib.GetSymbol< decltype(bigvoice_GetFormatFromName ) >("bigvoice_GetFormatFromName" );
415 GetBytesFromFormat = m_lib.GetSymbol< decltype(bigvoice_GetBytesFromFormat ) >("bigvoice_GetBytesFromFormat" );
416 GetMaxPacketFrame = m_lib.GetSymbol< decltype(bigvoice_GetMaxPacketFrame ) >("bigvoice_GetMaxPacketFrame" );
417 AddAudio = m_lib.GetSymbol< decltype(bigvoice_AddAudio ) >("bigvoice_AddAudio" );
418 AddPadAudio = m_lib.GetSymbol< decltype(bigvoice_AddPadAudio ) >("bigvoice_AddPadAudio" );
419 GetOutputCount = m_lib.GetSymbol< decltype(bigvoice_GetOutputCount ) >("bigvoice_GetOutputCount" );
420 GetAudio = m_lib.GetSymbol< decltype(bigvoice_GetAudio ) >("bigvoice_GetAudio" );
421 AudioConvertFrom = m_lib.GetSymbol< decltype(bigvoice_AudioConvertFrom ) >("bigvoice_AudioConvertFrom" );
422 AudioConvertTo = m_lib.GetSymbol< decltype(bigvoice_AudioConvertTo ) >("bigvoice_AudioConvertTo" );
423 StereoToMono = m_lib.GetSymbol< decltype(bigvoice_StereoToMono ) >("bigvoice_StereoToMono" );
424 MonoToStereo = m_lib.GetSymbol< decltype(bigvoice_MonoToStereo ) >("bigvoice_MonoToStereo" );
425 AudioMonoFromLiveStereo = m_lib.GetSymbol< decltype(bigvoice_AudioMonoFromLiveStereo) >("bigvoice_AudioMonoFromLiveStereo");
426 AudioMonoToLiveStereo = m_lib.GetSymbol< decltype(bigvoice_AudioMonoToLiveStereo ) >("bigvoice_AudioMonoToLiveStereo" );
427 NewClient = m_lib.GetSymbol< decltype(bigvoice_NewClient ) >("bigvoice_NewClient" );
428 DeleteClient = m_lib.GetSymbol< decltype(bigvoice_DeleteClient ) >("bigvoice_DeleteClient" );
429 ProcessJson = m_lib.GetSymbol< decltype(bigvoice_ProcessJson ) >("bigvoice_ProcessJson" );
430 FreeJsonAnswer = m_lib.GetSymbol< decltype(bigvoice_FreeJsonAnswer ) >("bigvoice_FreeJsonAnswer" );
431 SaveState = m_lib.GetSymbol< decltype(bigvoice_SaveState ) >("bigvoice_SaveState" );
432#if BIGVOICE_HAS_WEBSERVER
433 Webserver_tcp = m_lib.GetSymbol< decltype(bigvoice_Webserver_tcp ) >("bigvoice_Webserver_tcp" );
434 Webserver_tcp2 = m_lib.GetSymbol< decltype(bigvoice_Webserver_tcp2 ) >("bigvoice_Webserver_tcp2" );
435 Webserver = m_lib.GetSymbol< decltype(bigvoice_Webserver ) >("bigvoice_Webserver" );
436 Webserver_Stop = m_lib.GetSymbol< decltype(bigvoice_Webserver_Stop ) >("bigvoice_Webserver_Stop" );
437 Webserver_Status = m_lib.GetSymbol< decltype(bigvoice_Webserver_Status ) >("bigvoice_Webserver_Status" );
438#endif // BIGVOICE_HAS_WEBSERVER
439
440 // added 2023-03-22
441 StereoToMono_Planar = m_lib.GetSymbol< decltype(bigvoice_StereoToMono_Planar ) >("bigvoice_StereoToMono_Planar" );
442 MonoToStereo_Planar = m_lib.GetSymbol< decltype(bigvoice_MonoToStereo_Planar ) >("bigvoice_MonoToStereo_Planar" );
443
444 } catch (std::runtime_error& ) {
445 return false;
446 }
447 // C functions allowed to be missing
448 try {
449 // added 2023-05-22
450 SetMetadata = m_lib.GetSymbol< decltype(bigvoice_SetMetadata ) >("bigvoice_SetMetadata" );
451 GetMetadataInfos = m_lib.GetSymbol< decltype(bigvoice_GetMetadataInfos ) >("bigvoice_GetMetadataInfos" );
452 FreeMetadataInfos = m_lib.GetSymbol< decltype(bigvoice_FreeMetadataInfos ) >("bigvoice_FreeMetadataInfos" );
453 // added 2023-06-20
454 SetPresetManager = m_lib.GetSymbol< decltype(bigvoice_SetPresetManager ) >("bigvoice_SetPresetManager" );
455 PresetManager_InformChange = m_lib.GetSymbol< decltype(bigvoice_PresetManager_InformChange ) >("bigvoice_PresetManager_InformChange" );
456
457 // added 2023-09-21
458 GetPossibleChunkSizeInFrames = m_lib.GetSymbol< decltype(bigvoice_GetPossibleChunkSizeInFrames ) >("bigvoice_GetPossibleChunkSizeInFrames" );
459 GetProcessChunkFrames = m_lib.GetSymbol< decltype(bigvoice_GetProcessChunkFrames ) >("bigvoice_GetProcessChunkFrames" );
460 InitProcess3 = m_lib.GetSymbol< decltype(bigvoice_InitProcess3 ) >("bigvoice_InitProcess3" );
461
462#if BIGVOICE_HAS_CLOUDBUS
463 // added 2023-06-26
464 NewBus = m_lib.GetSymbol< decltype(bigvoice_NewBus ) >("bigvoice_NewBus" );
465 FreeBus = m_lib.GetSymbol< decltype(bigvoice_FreeBus ) >("bigvoice_FreeBus" );
466 SetInstanceBus = m_lib.GetSymbol< decltype(bigvoice_SetInstanceBus ) >("bigvoice_SetInstanceBus" );
467#endif // BIGVOICE_HAS_CLOUDBUS
468
469 // added 2024-02-19
470 SetMetadataMulti = m_lib.GetSymbol< decltype(bigvoice_SetMetadataMulti ) >("bigvoice_SetMetadataMulti" );
471
472#if BIGVOICE_HAS_WEBSERVER
473 // added 2024-05-23
474 Webserver_SetAppHealth = m_lib.GetSymbol< decltype(bigvoice_Webserver_SetAppHealth ) >("Webserver_SetAppHealth" );
475 Webserver_GetAppHealth = m_lib.GetSymbol< decltype(bigvoice_Webserver_GetAppHealth ) >("Webserver_GetAppHealth" );
476 Webserver_FreeString = m_lib.GetSymbol< decltype(bigvoice_Webserver_FreeString ) >("Webserver_FreeString" );
477 #endif // BIGVOICE_HAS_WEBSERVER
478
479#ifdef _WIN32
480 // added 2025-05-28
481 SetInstanceTracing = m_lib.GetSymbol< decltype(bigvoice_SetInstanceTracing ) >("SetInstanceTracing" );
482 SetInstanceTracingProcessActivity = m_lib.GetSymbol< decltype(bigvoice_SetInstanceTracingProcessActivity) >("SetInstanceTracingProcessActivity");
483#endif // _WIN32
484
485 // added 2025-05-28
486 GetAudioConverter = m_lib.GetSymbol< decltype(bigvoice_GetAudioConverter ) >("GetAudioConverter" );
487 FreeAudioConverter = m_lib.GetSymbol< decltype(bigvoice_FreeAudioConverter ) >("FreeAudioConverter" );
488 AudioConverter_From = m_lib.GetSymbol< decltype(bigvoice_AudioConverter_From ) >("AudioConverter_From" );
489 AudioConverter_To = m_lib.GetSymbol< decltype(bigvoice_AudioConverter_To ) >("AudioConverter_To" );
490
491 } catch (std::runtime_error& ) {
492 // Ignored, handler will take care
493 }
494
495 m_bOK=true;
496 return true;
497 }
504 bool IsOk() const {
505 return m_bOK;
506 }
507
508 };
509
510
511
512 static constexpr const char *process_name = "SOUND4 BIGVOICE.CL";
513 static constexpr const char *process_shortname = "bigvoice";
545
549 namespace helper {
550 #ifdef _WIN32
556 static inline std::string WStringToUTF8(const std::wstring& wstr) {
557 if (wstr.empty()) return {};
558 int size = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), NULL, 0, NULL, NULL);
559 std::string str(size, 0);
560 WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), &str[0], size, NULL, NULL);
561 return str;
562 }
568 static inline std::wstring UTF8ToWString(const std::string& str) {
569 if (str.empty()) return std::wstring();
570 int size = MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), NULL, 0);
571 std::wstring wstr(size, 0);
572 MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), &wstr[0], size);
573 return wstr;
574 }
575 #endif // _WIN32
576
582 template<typename T>
584 };
585 template<>
586 struct SampleFormat<int16_t> {
587 const bigvoice_SampleFormat format = S16_NATIVE;
588 };
589 template<>
590 struct SampleFormat<int32_t> {
591 const bigvoice_SampleFormat format = S32_NATIVE;
592 };
593 template<>
594 struct SampleFormat<float> {
595 const bigvoice_SampleFormat format = F32_NATIVE;
596 };
597
598 // --------------------------------------------------------------
610 static inline void AudioConvertFrom(CDynLib& dynlib, const uint8_t *payload, float *output, size_t nSpl, bigvoice_SampleFormat fmt) {
611 dynlib.AudioConvertFrom(payload, output, nSpl, fmt);
612 }
613
625 static inline void AudioConvertTo(CDynLib& dynlib, const float *input, uint8_t *payload, size_t nSpl, bigvoice_SampleFormat fmt) {
626 dynlib.AudioConvertTo(input, payload, nSpl, fmt);
627 }
628
639 static inline void StereoToMono(CDynLib& dynlib, const float *input, float *output, size_t nFrame) {
640 dynlib.StereoToMono(input, output, nFrame);
641 }
642
653 static inline void MonoToStereo(CDynLib& dynlib, const float *input, float *output, size_t nFrame) {
654 dynlib.MonoToStereo(input, output, nFrame);
655 }
656
668 static inline void StereoToMono_Planar(CDynLib& dynlib, const float *inputL, const float *inputR, float *output, size_t nFrame) {
669 dynlib.StereoToMono_Planar(inputL, inputR, output, nFrame);
670 }
671
683 static inline void MonoToStereo_Planar(CDynLib& dynlib, const float *input, float *outputL, float *outputR, size_t nFrame) {
684 dynlib.MonoToStereo_Planar(input, outputL, outputR, nFrame);
685 }
686
694 static inline void AudioMonoFromLiveStereo(CDynLib& dynlib, const uint8_t *payload, float *output) {
695 dynlib.AudioMonoFromLiveStereo(payload, output);
696 }
697
705 static inline void AudioMonoToLiveStereo(CDynLib& dynlib, const float *input, uint8_t *payload) {
706 dynlib.AudioMonoToLiveStereo(input, payload);
707 }
708
709 }; // namespace helper
710
717 static inline std::string GetVersion(CDynLib& dynlib)
718 {
719 return std::string(dynlib.GetVersion());
720 }
721
733 static inline unsigned int GetChunkSizeInFrames(CDynLib& dynlib)
734 {
735 return dynlib.GetChunkSizeInFrames();
736 }
737
747 static inline std::vector<unsigned int> GetPossibleChunkSizeInFrames(CDynLib& dynlib)
748 {
749 std::vector<unsigned int> list;
750 if (dynlib.GetPossibleChunkSizeInFrames) {
751 for (unsigned int* src=dynlib.GetPossibleChunkSizeInFrames();*src;src++) {
752 list.push_back(*src);
753 }
754 } else {
755 list.push_back(12);
756 }
757 return list;
758 }
759
766 static inline unsigned int GetChannelCount(CDynLib& dynlib)
767 {
768 return dynlib.GetChannelCount();
769 }
770
779 static inline unsigned int GetAudioInputCount(CDynLib& dynlib)
780 {
781 return dynlib.GetAudioInputCount();
782 }
783
792 static inline unsigned int GetAudioOutputCount(CDynLib& dynlib)
793 {
794 return dynlib.GetAudioOutputCount();
795 }
796
805 static inline unsigned int GetSampleRate(CDynLib& dynlib)
806 {
807 return dynlib.GetSampleRate();
808 }
809
817 static inline void SanityCheck(CDynLib& dynlib, bool a_bCheckFrames = true)
818 {
819 // Do some sanity checks
820 if (dynlib.GetSampleRate()!=BIGVOICE_SAMPLE_RATE) {
821 throw std::runtime_error("Bad library sampling rate");
822 }
823 if (a_bCheckFrames && dynlib.GetChunkSizeInFrames()!=ChunkFrames) {
824 throw std::runtime_error("Bad library frame size");
825 }
827 throw std::runtime_error("Bad library channel count");
828 }
830 throw std::runtime_error("Bad library input count");
831 }
833 throw std::runtime_error("Bad library output count");
834 }
835 }
836
844 static inline std::string GetFormatName(CDynLib& dynlib, const SampleFormat fmt)
845 {
846 return std::string(dynlib.GetFormatName(fmt));
847 }
848
856 static inline SampleFormat GetFormatFromName(CDynLib& dynlib, const std::string& name)
857 {
858 return dynlib.GetFormatFromName(name.c_str());
859 }
860
868 static inline unsigned int GetBytesFromFormat(CDynLib& dynlib, const SampleFormat fmt)
869 {
870 return dynlib.GetBytesFromFormat(fmt);
871 }
872
880 using log_cb_t = std::function<void(LogSeverity,const std::string&)>;
881
886 extern "C" {
887 static inline void _log_cb_c(bigvoice_LogSeverity severity, const char *c_msg) {
888 _log_cb(severity, std::string(c_msg));
889 }
890 }
894 static inline void SetLogSeverity(CDynLib& dynlib, LogSeverity severity)
895 {
896 dynlib.SetLogSeverity(severity);
897 }
901 static inline void SetLoggerCallback(CDynLib& dynlib, log_cb_t cb)
902 {
903 _log_cb=cb;
905 }
906
907#if BIGVOICE_HAS_CLOUDBUS
913 class CBus {
914 public:
915 CBus(CDynLib& dynlib)
916 : m_dynlib(dynlib)
917 {
918 if (m_dynlib.NewBus) {
919 m_bus=m_dynlib.NewBus();
920 }
921 }
923 {
924 if (m_bus && m_dynlib.FreeBus) {
925 m_dynlib.FreeBus(m_bus);
926 }
927 m_bus = nullptr;
928 }
929 bigvoice_CBus *Get() const { return m_bus; }
930 private:
931 CDynLib& m_dynlib;
932 bigvoice_CBus *m_bus;
933 };
934#endif // BIGVOICE_HAS_CLOUDBUS
935
942 public:
943 CPresetLoader() = default;
944 virtual ~CPresetLoader() = default;
945
946 virtual bool IsReadOnly() = 0;
947 virtual bool Exists(const std::filesystem::path &name) = 0;
948 virtual bool Remove(const std::filesystem::path &name) = 0;
949 virtual bool Rename(const std::filesystem::path &from, const std::filesystem::path &to) = 0;
950 virtual std::vector<std::filesystem::path> GetAll() = 0;
951 virtual std::string Read(const std::filesystem::path &filename) = 0;
952 virtual bool Write(const std::filesystem::path &filename, const std::string &content) =0;
953 };
955
961 class CInstance {
962 public:
967 : m_dynlib(dynlib)
968 {
969 params = m_dynlib.NewParameters();
970 if (!params) throw std::bad_alloc();
971 }
972 // non-copyable
973 CInstance( const CInstance& ) = delete;
974 CInstance& operator=( const CInstance& ) = delete;
978 virtual ~CInstance()
979 {
980 Stop();
981 if (params) m_dynlib.FreeParameters(params);
982 }
986 bool IsOk() const { return instance!=nullptr; }
996 void SetParam(const std::string& name, const std::string& value)
997 {
998 assert(params);
999 m_dynlib.SetParameter(params, name.c_str(), value.c_str());
1000 }
1007 std::string GetParam(const std::string& name)
1008 {
1009 assert(params);
1010 auto c_value=m_dynlib.GetParameter(params, name.c_str());
1011 std::string ret(c_value);
1012 m_dynlib.FreeParameterValue(c_value);
1013 return ret;
1014 }
1015#if BIGVOICE_HAS_CLOUDBUS
1024 void SetBus(const CBus& bus) {
1025 assert(params);
1026 if (m_dynlib.SetInstanceBus) {
1027 m_dynlib.SetInstanceBus(params,bus.Get());
1028 }
1029 }
1030#endif // BIGVOICE_HAS_CLOUDBUS
1031
1042 void SetPresetManager(CPresetLoader *preset_manager)
1043 {
1044 if (!preset_manager) return;
1045 if (!m_dynlib.SetPresetManager) return;
1046 assert(params);
1047 m_dynlib.SetPresetManager(params,
1056 preset_manager->IsReadOnly(),
1057 preset_manager
1058 );
1059 }
1060
1083 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)
1084 {
1085 assert(!instance);
1086 std::string l_save_path;
1087 if (!save_path.empty()) {
1088 #if (__cplusplus<202002L)
1089 l_save_path = save_path.u8string();
1090 #else // C++20
1091 l_save_path = (const char*)save_path.u8string().c_str();
1092 #endif // C++20
1093 }
1094 if (m_dynlib.InitProcess3) {
1095 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);
1096 } else if (frames_per_chunk!=12) {
1097 return false;
1098 } else {
1099 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);
1100 }
1101 if (!instance) return false;
1102 if (!init_metadata.empty()) {
1103 for (auto&& [key,value]: init_metadata) {
1104 m_dynlib.SetMetadata(instance, key.c_str(), value.c_str());
1105 }
1106 init_metadata.clear();
1107 }
1108 update_thread = std::thread([this, json_port](){
1110 m_dynlib.StartUpdateThread(instance, json_port);
1112 });
1113 int timeout=5000;
1114 #ifdef DEBUG
1115 timeout=60*1000; // For debugger pauses
1116 #endif
1117 if (m_dynlib.WaitUpdateThreadReady(instance, timeout)<0) {
1118 return false;
1119 }
1120 return true;
1121 }
1122
1130 unsigned int GetChunkFrames() {
1131 if (instance && m_dynlib.GetProcessChunkFrames) {
1132 return m_dynlib.GetProcessChunkFrames(instance);
1133 }
1134 return 12;
1135 }
1136
1144 void PresetManager_InformChange(const std::filesystem::path& relative_path, PresetChange_Kind change_kind)
1145 {
1146 if (m_dynlib.PresetManager_InformChange) {
1147 m_dynlib.PresetManager_InformChange(instance, relative_path.c_str(), (bigvoice_PresetChange_Kind) change_kind);
1148 }
1149 }
1150
1162 void SetMetadata(const std::string& key, const char* value)
1163 {
1164 if (m_dynlib.SetMetadata) {
1165 if (instance) {
1166 m_dynlib.SetMetadata(instance, key.c_str(), value);
1167 } else {
1168 init_metadata.push_back( {key, value} );
1169 }
1170 }
1171 }
1172
1173
1183 void SetMetadataMulti(const std::unordered_map<std::string, const char*>& list)
1184 {
1185 if (instance) {
1186 if (m_dynlib.SetMetadataMulti) {
1187 typedef const char* pchar;
1188 pchar* keyvalue=new pchar[2*list.size()+1];
1189 size_t n=0;
1190 for (auto&& [key,value]: list) {
1191 keyvalue[2*n+0]=key.c_str();
1192 keyvalue[2*n+1]=value;
1193 n++;
1194 }
1195 keyvalue[2*n+0]=nullptr;
1196
1197 bigvoice_SetMetadataMulti(instance, keyvalue);
1198
1199 delete[] keyvalue;
1200 } else {
1201 for (auto&& [key,value]: list) {
1202 SetMetadata(key, value);
1203 }
1204 }
1205 } else {
1206 for (auto&& [key,value]: list) {
1207 if (value) {
1208 init_metadata.push_back( {key, value} );
1209 }
1210 }
1211 }
1212 }
1213
1219 std::vector< std::tuple<std::string,std::string> > GetMetadataInfos()
1220 {
1221 std::vector< std::tuple<std::string,std::string> > values;
1222 if (m_dynlib.GetMetadataInfos) {
1223 const char** c_values = m_dynlib.GetMetadataInfos(instance);
1224 if (c_values) {
1225 for (const char** c_value=c_values; *c_value; ) {
1226 std::string key(*c_value);
1227 c_value++;
1228 if (*c_value) {
1229 std::string descr(*c_value);
1230 c_value++;
1231 values.push_back( {key,descr} );
1232 }
1233 }
1234 m_dynlib.FreeMetadataInfos(instance, c_values);
1235 }
1236 }
1237 return values;
1238 }
1239
1243 virtual void OnUpdateThreadStart() {}
1247 virtual void OnUpdateThreadStop() {}
1248
1249#if BIGVOICE_HAS_WEBSERVER
1263 bool StartWebServer(int http_port, int https_port=0)
1264 {
1265 assert(instance);
1266 assert(webserver==SOUND4_INVALID_WEBSERVER_ID);
1267 webserver = m_dynlib.Webserver(http_port,https_port,instance);
1268 if (webserver==SOUND4_INVALID_WEBSERVER_ID) {
1269 return false;
1270 }
1271 int web_status=m_dynlib.Webserver_Status(webserver);
1272 if (http_port && (web_status & SOUND4_WEBSERVER_HTTP_OK) == 0) {
1273 return false;
1274 }
1275 if (https_port && (web_status & SOUND4_WEBSERVER_HTTPS_OK) == 0) {
1276 return false;
1277 }
1278 return true;
1279 }
1280
1288 void StopWebServer(int timeout_ms = 1000)
1289 {
1290 if (webserver != SOUND4_INVALID_WEBSERVER_ID) {
1291 m_dynlib.Webserver_Stop(webserver, timeout_ms);
1292 webserver = SOUND4_INVALID_WEBSERVER_ID;
1293 }
1294 }
1295
1299 void SetWebServerAppHealth(int httpcode, const std::string& contenttype, const std::string& content)
1300 {
1301 assert(instance);
1302 if (!m_dynlib.Webserver_SetAppHealth) return;
1303 m_dynlib.Webserver_SetAppHealth(instance, httpcode, contenttype.c_str(), content.c_str());
1304 }
1308 void GetWebServerAppHealth(int &httpcode, std::string& contenttype, std::string& content)
1309 {
1310 assert(instance);
1311 if (!m_dynlib.Webserver_GetAppHealth) return;
1312 char* c_contenttype=nullptr;
1313 char* c_content=nullptr;
1314 m_dynlib.Webserver_GetAppHealth(instance, &httpcode, &c_contenttype, &c_content);
1315 contenttype=c_contenttype;
1316 content=c_content;
1317 m_dynlib.Webserver_FreeString(c_contenttype);
1318 m_dynlib.Webserver_FreeString(c_content);
1319 }
1320#endif // BIGVOICE_HAS_WEBSERVER
1321
1331 {
1332 if (!instance) return 0;
1333 return m_dynlib.TerminateProcess(instance);
1334 }
1335
1339 void Stop()
1340 {
1341 if (!instance) return;
1342#if BIGVOICE_HAS_WEBSERVER
1343 StopWebServer();
1344#endif // BIGVOICE_HAS_WEBSERVER
1345 if (update_thread.joinable()) {
1346 m_dynlib.StopUpdateThread(instance); // this will exit the update thread
1347 update_thread.join();
1348 }
1349 m_dynlib.ExitProcess(instance);
1350 instance=nullptr;
1351 }
1352
1362 unsigned int GetEstimatedDelay()
1363 {
1364 assert(instance);
1365 return m_dynlib.GetEstimatedDelay(instance);
1366 }
1367
1380 std::array<float,InputSampleSize>& GetBufferIn()
1381 {
1382 assert(instance);
1383 float *buf=m_dynlib.GetBufferIn(instance);
1384 return reinterpret_cast< std::array<float,InputSampleSize>& >(*buf);
1385
1386 }
1398 std::array<float,OutputSampleSize>& GetBufferOut()
1399 {
1400 assert(instance);
1401 float *buf= m_dynlib.GetBufferOut(instance);
1402 return reinterpret_cast< std::array<float,OutputSampleSize>& >(*buf);
1403 }
1408 {
1409 assert(instance);
1410 m_dynlib.ProcessAudio(instance, m_dynlib.GetBufferIn(instance), m_dynlib.GetBufferOut(instance));
1411 }
1423 void ProcessAudio_Planar(float const * const *input, float * const *output)
1424 {
1425 assert(instance);
1426 m_dynlib.ProcessAudio_Planar(instance, input, output);
1427 }
1428
1440 template<typename T>
1441 std::vector<T> ProcessAnyAudio(const std::vector<T> input)
1442 {
1443 assert(instance);
1444 std::vector<T> output;
1445 unsigned int out_offset=0;
1446 unsigned int in_offset=0;
1447 unsigned int todo = input.size();
1448 while (todo>0) {
1449 unsigned int left = AddAudio(&input[in_offset], todo);
1450 unsigned int out_avail = m_dynlib.GetOutputCount(instance);
1451 output.resize(out_offset + out_avail);
1452 GetAudio(&output[out_offset], out_avail);
1453 out_offset+=out_avail;
1454 in_offset += todo-left;
1455 todo=left;
1456 }
1457 return output;
1458 }
1459
1465 class CClient {
1466 public:
1468 : m_dynlib(dynlib)
1469 {
1470 assert(instance);
1471 client=m_dynlib.NewClient(instance);
1472 if (!client) throw std::bad_alloc();
1473 }
1474 // non-copyable
1475 CClient( const CInstance& ) = delete;
1476 CClient& operator=( const CInstance& ) = delete;
1478 {
1479 if (client) {
1480 m_dynlib.DeleteClient(client);
1481 client=nullptr;
1482 }
1483 }
1491 std::string ProcessJson(const std::string &request, bool *NeedSave = nullptr)
1492 {
1493 assert(client);
1494 int need_save=0;
1495 const char *canswer = m_dynlib.ProcessJson(client, request.c_str(), &need_save);
1496 if (!canswer) return {};
1497 std::string answer(canswer);
1498 m_dynlib.FreeJsonAnswer (canswer);
1499 if (NeedSave) {
1500 *NeedSave=(need_save!=0);
1501 }
1502 return answer;
1503 }
1504 private:
1505 CDynLib& m_dynlib;
1506 bigvoice_CClientInstance *client = nullptr;
1507 };
1515 std::shared_ptr<CClient> NewClient()
1516 {
1517 assert(instance);
1518 return std::make_shared<CClient>(instance, m_dynlib);
1519 }
1520
1531 bool SaveState() {
1532 assert(instance);
1533 if (m_dynlib.SaveState(instance)!=0) {
1534 return false;
1535 }
1536 return true;
1537 }
1538#ifdef _WIN32
1545 void SetInstanceTracing(TraceLoggingHProvider tracing_provider, GUID activity_guid = {}) {
1546 if (m_dynlib.SetInstanceTracing) {
1547 m_dynlib.SetInstanceTracing(params, tracing_provider, activity_guid);
1548 }
1549 }
1556 void SetInstanceTracingProcessActivity(GUID activity_guid) {
1557 assert(instance);
1558 if (m_dynlib.SetInstanceTracingProcessActivity) {
1559 m_dynlib.SetInstanceTracingProcessActivity(instance, activity_guid);
1560 }
1561 }
1562#endif // _WIN32
1563 protected:
1564 template<typename T>
1565 unsigned int AddAudio(const T* payload, unsigned int nFrame)
1566 {
1567 assert(instance);
1568 return m_dynlib.AddAudio(instance, reinterpret_cast<const T*>(payload), nFrame, helper::SampleFormat<T>::format);
1569 }
1570 template<typename T>
1571 unsigned int GetAudio(T* payload, unsigned int max_nFrame)
1572 {
1573 assert(instance);
1574 return m_dynlib.GetAudio(instance, reinterpret_cast<T*>(payload), max_nFrame, helper::SampleFormat<T>::format);
1575 }
1576
1577 private:
1578 CDynLib& m_dynlib;
1579 bigvoice_CParameters* params = nullptr;
1580 bigvoice_CInstance* instance = nullptr;
1581 std::thread update_thread;
1582 std::vector< std::pair<std::string,std::string> > init_metadata;
1583#if BIGVOICE_HAS_WEBSERVER
1584 uint64_t webserver = SOUND4_INVALID_WEBSERVER_ID;
1585#endif // BIGVOICE_HAS_WEBSERVER
1586 };
1587
1595 public:
1602 : m_dynlib(dynlib)
1603 { }
1604
1609 {
1610 Delete();
1611 }
1612
1628 bool Configure(SampleFormat fmt, size_t nFrame, size_t payl_ch, size_t payl_ch_offset, bigvoice_ConverterTargetMode target_mode)
1629 {
1630 Delete();
1631 if (m_dynlib.GetAudioConverter)
1632 m_cvt = m_dynlib.GetAudioConverter((bigvoice_SampleFormat)fmt, nFrame, payl_ch, payl_ch_offset, target_mode);
1633 return IsOK();
1634 }
1635 void Delete()
1636 {
1637 if (m_cvt && m_dynlib.FreeAudioConverter) {
1638 m_dynlib.FreeAudioConverter(m_cvt);
1639 }
1640 m_cvt = nullptr;
1641 }
1642 bool IsOK() const { return (m_cvt!=nullptr); }
1643
1652 void ConvertFrom(const uint8_t *payload, float *output)
1653 { m_dynlib.AudioConverter_From(m_cvt, payload, output); }
1654
1663 void ConvertTo(const float *input, uint8_t *payload)
1664 { m_dynlib.AudioConverter_To(m_cvt, input, payload); }
1665
1666 private:
1667 CDynLib& m_dynlib;
1668 bigvoice_CAudioConverter *m_cvt = nullptr;
1669 };
1670
1671}; // namespace dyn
1672}; // namespace bigvoice
1673}; // namespace sound4
1674
1675// bridge C callbacks to CPresetLoader
1676extern "C" {
1677 static char *bigvoice_custom_reader(const fs_char *filename, void* userdata) {
1678 sound4::bigvoice::dyn::CPresetLoader *preset_loader=reinterpret_cast<sound4::bigvoice::dyn::CPresetLoader*>(userdata);
1679 std::string content=preset_loader->Read(filename);
1680 return strdup(content.c_str());
1681 }
1682 static void bigvoice_custom_reader_free(char *content, void* userdata) {
1683 if (!content) return;
1684 free(content);
1685 }
1686 static int bigvoice_custom_writer(const fs_char *filename, const char *content, void* userdata) {
1687 sound4::bigvoice::dyn::CPresetLoader *preset_loader=reinterpret_cast<sound4::bigvoice::dyn::CPresetLoader*>(userdata);
1688 auto res=preset_loader->Write(filename,content);
1689 return res?0:-1;
1690 }
1691 static int bigvoice_custom_exists(const fs_char *filename, void* userdata) {
1692 sound4::bigvoice::dyn::CPresetLoader *preset_loader=reinterpret_cast<sound4::bigvoice::dyn::CPresetLoader*>(userdata);
1693 auto res=preset_loader->Exists(filename);
1694 return res?0:-1;
1695 }
1696 static fs_char** bigvoice_custom_getall(void* userdata) {
1697 sound4::bigvoice::dyn::CPresetLoader *preset_loader=reinterpret_cast<sound4::bigvoice::dyn::CPresetLoader*>(userdata);
1698 auto res=preset_loader->GetAll();
1699 fs_char**all=(fs_char**)malloc((res.size()+1)*sizeof(const fs_char*));
1700 for (size_t n=0;n<res.size();n++) {
1701 all[n]=fs_strdup(res[n].c_str());
1702 }
1703 all[res.size()]=nullptr;
1704 return all;
1705 }
1706 static void bigvoice_custom_getall_free(fs_char** all, void* userdata) {
1707 if (!all) return;
1708 for (fs_char** one=all;*one;one++) {
1709 free(*one);
1710 }
1711 free(all);
1712 }
1713 static int bigvoice_custom_remove(const fs_char *filename, void* userdata) {
1714 sound4::bigvoice::dyn::CPresetLoader *preset_loader=reinterpret_cast<sound4::bigvoice::dyn::CPresetLoader*>(userdata);
1715 auto res=preset_loader->Remove(filename);
1716 return res?0:-1;
1717 }
1718 static int bigvoice_custom_rename(const fs_char *from, const fs_char *to, void* userdata) {
1719 sound4::bigvoice::dyn::CPresetLoader *preset_loader=reinterpret_cast<sound4::bigvoice::dyn::CPresetLoader*>(userdata);
1720 auto res=preset_loader->Rename(from,to);
1721 return res?0:-1;
1722 }
1723
1724};
virtual ~CAudioConverter()
Destroy the CAudioConverter object.
CAudioConverter(CDynLib &dynlib)
Construct a new empty CAudioConverter object.
bool Configure(SampleFormat fmt, size_t nFrame, size_t payl_ch, size_t payl_ch_offset, bigvoice_ConverterTargetMode target_mode)
void ConvertFrom(const uint8_t *payload, float *output)
void ConvertTo(const float *input, uint8_t *payload)
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_AudioConverter_From) > AudioConverter_From
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_AudioConverter_To) > AudioConverter_To
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_FreeAudioConverter) > FreeAudioConverter
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_GetAudioConverter) > GetAudioConverter
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)
CDynLoader & operator=(CDynLoader &&other) noexcept
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_AudioConverter_To(struct bigvoice_CAudioConverter *converter, const float *input, uint8_t *payload)
void bigvoice_FreeAudioConverter(struct bigvoice_CAudioConverter *converter)
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_AudioConverter_From(struct bigvoice_CAudioConverter *converter, const uint8_t *payload, float *output)
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)
bigvoice_ConverterTargetMode
struct bigvoice_CAudioConverter * bigvoice_GetAudioConverter(enum bigvoice_SampleFormat fmt, size_t nFrame, size_t payl_ch, size_t payl_ch_offset, enum bigvoice_ConverterTargetMode target_mode)
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:284
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)