SOUND4 BIGVOICE.CL Library [1.1.13]
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
331 // added 2025-05-28
336
344 bool Load(const std::filesystem::path& path = {}) {
345 std::string filename;
346 #if defined(__APPLE__)
347 filename="libsound4.bigvoice.cl.dylib";
348 #elif defined(__unix__)
349 filename="libsound4.bigvoice.cl.so";
350 #else
351 filename="sound4.bigvoice.cl.dll";
352 #endif
353 m_lib.Close();
354 // If a path is given, use it directly and do not try other path
355 if (!path.empty() && !m_lib.Load(path / filename)) {
356 return false;
357 } else if (!m_lib.IsOk()) {
358 auto thisdir=helper::CDynLoader::GetThisLibraryPath().parent_path();
359 #ifndef _WIN32
360 // Linux: if in a bin directory, try ../lib first
361 if (!m_lib.IsOk() && thisdir.filename()=="bin") {
362 auto libdir = thisdir.parent_path() / "lib";
363 m_lib.Load(libdir / filename);
364 }
365 #endif // !_WIN32
366 if (!m_lib.IsOk()) {
367 // Search in the same directory this code is in
368 m_lib.Load(thisdir / filename);
369 }
370 if (!m_lib.IsOk()) {
371 // Try current path
372 std::error_code ec;
373 auto p = std::filesystem::current_path(ec);
374 if (!ec) {
375 m_lib.Load(p / filename);
376 }
377 }
378 if (!m_lib.IsOk()) {
379 return false;
380 }
381 }
382 // Load all C functions
383 try {
384 GetVersion = m_lib.GetSymbol< decltype(bigvoice_GetVersion ) >("bigvoice_GetVersion" );
385 GetChunkSizeInFrames = m_lib.GetSymbol< decltype(bigvoice_GetChunkSizeInFrames ) >("bigvoice_GetChunkSizeInFrames" );
386 GetChannelCount = m_lib.GetSymbol< decltype(bigvoice_GetChannelCount ) >("bigvoice_GetChannelCount" );
387 GetAudioInputCount = m_lib.GetSymbol< decltype(bigvoice_GetAudioInputCount ) >("bigvoice_GetAudioInputCount" );
388 GetAudioOutputCount = m_lib.GetSymbol< decltype(bigvoice_GetAudioOutputCount ) >("bigvoice_GetAudioOutputCount" );
389 GetSampleRate = m_lib.GetSymbol< decltype(bigvoice_GetSampleRate ) >("bigvoice_GetSampleRate" );
390 SetLoggerCallback = m_lib.GetSymbol< decltype(bigvoice_SetLoggerCallback ) >("bigvoice_SetLoggerCallback" );
391 SetLogSeverity = m_lib.GetSymbol< decltype(bigvoice_SetLogSeverity ) >("bigvoice_SetLogSeverity" );
392 NewParameters = m_lib.GetSymbol< decltype(bigvoice_NewParameters ) >("bigvoice_NewParameters" );
393 FreeParameters = m_lib.GetSymbol< decltype(bigvoice_FreeParameters ) >("bigvoice_FreeParameters" );
394 SetParameter = m_lib.GetSymbol< decltype(bigvoice_SetParameter ) >("bigvoice_SetParameter" );
395 GetParameter = m_lib.GetSymbol< decltype(bigvoice_GetParameter ) >("bigvoice_GetParameter" );
396 FreeParameterValue = m_lib.GetSymbol< decltype(bigvoice_FreeParameterValue ) >("bigvoice_FreeParameterValue" );
397 InitProcess = m_lib.GetSymbol< decltype(bigvoice_InitProcess ) >("bigvoice_InitProcess" );
398 InitProcess2 = m_lib.GetSymbol< decltype(bigvoice_InitProcess2 ) >("bigvoice_InitProcess2" );
399 TerminateProcess = m_lib.GetSymbol< decltype(bigvoice_TerminateProcess ) >("bigvoice_TerminateProcess" );
400 ExitProcess = m_lib.GetSymbol< decltype(bigvoice_ExitProcess ) >("bigvoice_ExitProcess" );
401 StartUpdateThread = m_lib.GetSymbol< decltype(bigvoice_StartUpdateThread ) >("bigvoice_StartUpdateThread" );
402 StopUpdateThread = m_lib.GetSymbol< decltype(bigvoice_StopUpdateThread ) >("bigvoice_StopUpdateThread" );
403 WaitUpdateThreadReady = m_lib.GetSymbol< decltype(bigvoice_WaitUpdateThreadReady ) >("bigvoice_WaitUpdateThreadReady" );
404 ProcessAudio = m_lib.GetSymbol< decltype(bigvoice_ProcessAudio ) >("bigvoice_ProcessAudio" );
405 ProcessAudio_Planar = m_lib.GetSymbol< decltype(bigvoice_ProcessAudio_Planar ) >("bigvoice_ProcessAudio_Planar" );
406 GetBufferIn = m_lib.GetSymbol< decltype(bigvoice_GetBufferIn ) >("bigvoice_GetBufferIn" );
407 GetBufferOut = m_lib.GetSymbol< decltype(bigvoice_GetBufferOut ) >("bigvoice_GetBufferOut" );
408 GetEstimatedDelay = m_lib.GetSymbol< decltype(bigvoice_GetEstimatedDelay ) >("bigvoice_GetEstimatedDelay" );
409 GetFormatName = m_lib.GetSymbol< decltype(bigvoice_GetFormatName ) >("bigvoice_GetFormatName" );
410 GetFormatFromName = m_lib.GetSymbol< decltype(bigvoice_GetFormatFromName ) >("bigvoice_GetFormatFromName" );
411 GetBytesFromFormat = m_lib.GetSymbol< decltype(bigvoice_GetBytesFromFormat ) >("bigvoice_GetBytesFromFormat" );
412 GetMaxPacketFrame = m_lib.GetSymbol< decltype(bigvoice_GetMaxPacketFrame ) >("bigvoice_GetMaxPacketFrame" );
413 AddAudio = m_lib.GetSymbol< decltype(bigvoice_AddAudio ) >("bigvoice_AddAudio" );
414 AddPadAudio = m_lib.GetSymbol< decltype(bigvoice_AddPadAudio ) >("bigvoice_AddPadAudio" );
415 GetOutputCount = m_lib.GetSymbol< decltype(bigvoice_GetOutputCount ) >("bigvoice_GetOutputCount" );
416 GetAudio = m_lib.GetSymbol< decltype(bigvoice_GetAudio ) >("bigvoice_GetAudio" );
417 AudioConvertFrom = m_lib.GetSymbol< decltype(bigvoice_AudioConvertFrom ) >("bigvoice_AudioConvertFrom" );
418 AudioConvertTo = m_lib.GetSymbol< decltype(bigvoice_AudioConvertTo ) >("bigvoice_AudioConvertTo" );
419 StereoToMono = m_lib.GetSymbol< decltype(bigvoice_StereoToMono ) >("bigvoice_StereoToMono" );
420 MonoToStereo = m_lib.GetSymbol< decltype(bigvoice_MonoToStereo ) >("bigvoice_MonoToStereo" );
421 AudioMonoFromLiveStereo = m_lib.GetSymbol< decltype(bigvoice_AudioMonoFromLiveStereo) >("bigvoice_AudioMonoFromLiveStereo");
422 AudioMonoToLiveStereo = m_lib.GetSymbol< decltype(bigvoice_AudioMonoToLiveStereo ) >("bigvoice_AudioMonoToLiveStereo" );
423 NewClient = m_lib.GetSymbol< decltype(bigvoice_NewClient ) >("bigvoice_NewClient" );
424 DeleteClient = m_lib.GetSymbol< decltype(bigvoice_DeleteClient ) >("bigvoice_DeleteClient" );
425 ProcessJson = m_lib.GetSymbol< decltype(bigvoice_ProcessJson ) >("bigvoice_ProcessJson" );
426 FreeJsonAnswer = m_lib.GetSymbol< decltype(bigvoice_FreeJsonAnswer ) >("bigvoice_FreeJsonAnswer" );
427 SaveState = m_lib.GetSymbol< decltype(bigvoice_SaveState ) >("bigvoice_SaveState" );
428#if BIGVOICE_HAS_WEBSERVER
429 Webserver_tcp = m_lib.GetSymbol< decltype(bigvoice_Webserver_tcp ) >("bigvoice_Webserver_tcp" );
430 Webserver_tcp2 = m_lib.GetSymbol< decltype(bigvoice_Webserver_tcp2 ) >("bigvoice_Webserver_tcp2" );
431 Webserver = m_lib.GetSymbol< decltype(bigvoice_Webserver ) >("bigvoice_Webserver" );
432 Webserver_Stop = m_lib.GetSymbol< decltype(bigvoice_Webserver_Stop ) >("bigvoice_Webserver_Stop" );
433 Webserver_Status = m_lib.GetSymbol< decltype(bigvoice_Webserver_Status ) >("bigvoice_Webserver_Status" );
434#endif // BIGVOICE_HAS_WEBSERVER
435
436 // added 2023-03-22
437 StereoToMono_Planar = m_lib.GetSymbol< decltype(bigvoice_StereoToMono_Planar ) >("bigvoice_StereoToMono_Planar" );
438 MonoToStereo_Planar = m_lib.GetSymbol< decltype(bigvoice_MonoToStereo_Planar ) >("bigvoice_MonoToStereo_Planar" );
439
440 } catch (std::runtime_error& ) {
441 return false;
442 }
443 // C functions allowed to be missing
444 try {
445 // added 2023-05-22
446 SetMetadata = m_lib.GetSymbol< decltype(bigvoice_SetMetadata ) >("bigvoice_SetMetadata" );
447 GetMetadataInfos = m_lib.GetSymbol< decltype(bigvoice_GetMetadataInfos ) >("bigvoice_GetMetadataInfos" );
448 FreeMetadataInfos = m_lib.GetSymbol< decltype(bigvoice_FreeMetadataInfos ) >("bigvoice_FreeMetadataInfos" );
449 // added 2023-06-20
450 SetPresetManager = m_lib.GetSymbol< decltype(bigvoice_SetPresetManager ) >("bigvoice_SetPresetManager" );
451 PresetManager_InformChange = m_lib.GetSymbol< decltype(bigvoice_PresetManager_InformChange ) >("bigvoice_PresetManager_InformChange" );
452
453 // added 2023-09-21
454 GetPossibleChunkSizeInFrames = m_lib.GetSymbol< decltype(bigvoice_GetPossibleChunkSizeInFrames ) >("bigvoice_GetPossibleChunkSizeInFrames" );
455 GetProcessChunkFrames = m_lib.GetSymbol< decltype(bigvoice_GetProcessChunkFrames ) >("bigvoice_GetProcessChunkFrames" );
456 InitProcess3 = m_lib.GetSymbol< decltype(bigvoice_InitProcess3 ) >("bigvoice_InitProcess3" );
457
458#if BIGVOICE_HAS_CLOUDBUS
459 // added 2023-06-26
460 NewBus = m_lib.GetSymbol< decltype(bigvoice_NewBus ) >("bigvoice_NewBus" );
461 FreeBus = m_lib.GetSymbol< decltype(bigvoice_FreeBus ) >("bigvoice_FreeBus" );
462 SetInstanceBus = m_lib.GetSymbol< decltype(bigvoice_SetInstanceBus ) >("bigvoice_SetInstanceBus" );
463#endif // BIGVOICE_HAS_CLOUDBUS
464
465 // added 2024-02-19
466 SetMetadataMulti = m_lib.GetSymbol< decltype(bigvoice_SetMetadataMulti ) >("bigvoice_SetMetadataMulti" );
467
468#if BIGVOICE_HAS_WEBSERVER
469 // added 2024-05-23
470 Webserver_SetAppHealth = m_lib.GetSymbol< decltype(bigvoice_Webserver_SetAppHealth ) >("Webserver_SetAppHealth" );
471 Webserver_GetAppHealth = m_lib.GetSymbol< decltype(bigvoice_Webserver_GetAppHealth ) >("Webserver_GetAppHealth" );
472 Webserver_FreeString = m_lib.GetSymbol< decltype(bigvoice_Webserver_FreeString ) >("Webserver_FreeString" );
473 #endif // BIGVOICE_HAS_WEBSERVER
474
475#ifdef _WIN32
476 // added 2025-05-28
477 SetInstanceTracing = m_lib.GetSymbol< decltype(bigvoice_SetInstanceTracing ) >("SetInstanceTracing" );
478 SetInstanceTracingProcessActivity = m_lib.GetSymbol< decltype(bigvoice_SetInstanceTracingProcessActivity) >("SetInstanceTracingProcessActivity");
479#endif // _WIN32
480
481 // added 2025-05-28
482 GetAudioConverter = m_lib.GetSymbol< decltype(bigvoice_GetAudioConverter ) >("GetAudioConverter" );
483 FreeAudioConverter = m_lib.GetSymbol< decltype(bigvoice_FreeAudioConverter ) >("FreeAudioConverter" );
484 AudioConverter_From = m_lib.GetSymbol< decltype(bigvoice_AudioConverter_From ) >("AudioConverter_From" );
485 AudioConverter_To = m_lib.GetSymbol< decltype(bigvoice_AudioConverter_To ) >("AudioConverter_To" );
486
487 } catch (std::runtime_error& ) {
488 // Ignored, handler will take care
489 }
490
491 m_bOK=true;
492 return true;
493 }
500 bool IsOk() const {
501 return m_bOK;
502 }
503
504 };
505
506
507
508 static constexpr const char *process_name = "SOUND4 BIGVOICE.CL";
509 static constexpr const char *process_shortname = "bigvoice";
541
545 namespace helper {
546 #ifdef _WIN32
552 static inline std::string WStringToUTF8(const std::wstring& wstr) {
553 if (wstr.empty()) return {};
554 int size = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), NULL, 0, NULL, NULL);
555 std::string str(size, 0);
556 WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), &str[0], size, NULL, NULL);
557 return str;
558 }
564 static inline std::wstring UTF8ToWString(const std::string& str) {
565 if (str.empty()) return std::wstring();
566 int size = MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), NULL, 0);
567 std::wstring wstr(size, 0);
568 MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), &wstr[0], size);
569 return wstr;
570 }
571 #endif // _WIN32
572
578 template<typename T>
580 };
581 template<>
582 struct SampleFormat<int16_t> {
583 const bigvoice_SampleFormat format = S16_NATIVE;
584 };
585 template<>
586 struct SampleFormat<int32_t> {
587 const bigvoice_SampleFormat format = S32_NATIVE;
588 };
589 template<>
590 struct SampleFormat<float> {
591 const bigvoice_SampleFormat format = F32_NATIVE;
592 };
593
594 // --------------------------------------------------------------
606 static inline void AudioConvertFrom(CDynLib& dynlib, const uint8_t *payload, float *output, size_t nSpl, bigvoice_SampleFormat fmt) {
607 dynlib.AudioConvertFrom(payload, output, nSpl, fmt);
608 }
609
621 static inline void AudioConvertTo(CDynLib& dynlib, const float *input, uint8_t *payload, size_t nSpl, bigvoice_SampleFormat fmt) {
622 dynlib.AudioConvertTo(input, payload, nSpl, fmt);
623 }
624
635 static inline void StereoToMono(CDynLib& dynlib, const float *input, float *output, size_t nFrame) {
636 dynlib.StereoToMono(input, output, nFrame);
637 }
638
649 static inline void MonoToStereo(CDynLib& dynlib, const float *input, float *output, size_t nFrame) {
650 dynlib.MonoToStereo(input, output, nFrame);
651 }
652
664 static inline void StereoToMono_Planar(CDynLib& dynlib, const float *inputL, const float *inputR, float *output, size_t nFrame) {
665 dynlib.StereoToMono_Planar(inputL, inputR, output, nFrame);
666 }
667
679 static inline void MonoToStereo_Planar(CDynLib& dynlib, const float *input, float *outputL, float *outputR, size_t nFrame) {
680 dynlib.MonoToStereo_Planar(input, outputL, outputR, nFrame);
681 }
682
690 static inline void AudioMonoFromLiveStereo(CDynLib& dynlib, const uint8_t *payload, float *output) {
691 dynlib.AudioMonoFromLiveStereo(payload, output);
692 }
693
701 static inline void AudioMonoToLiveStereo(CDynLib& dynlib, const float *input, uint8_t *payload) {
702 dynlib.AudioMonoToLiveStereo(input, payload);
703 }
704
705 }; // namespace helper
706
713 static inline std::string GetVersion(CDynLib& dynlib)
714 {
715 return std::string(dynlib.GetVersion());
716 }
717
729 static inline unsigned int GetChunkSizeInFrames(CDynLib& dynlib)
730 {
731 return dynlib.GetChunkSizeInFrames();
732 }
733
743 static inline std::vector<unsigned int> GetPossibleChunkSizeInFrames(CDynLib& dynlib)
744 {
745 std::vector<unsigned int> list;
746 if (dynlib.GetPossibleChunkSizeInFrames) {
747 for (unsigned int* src=dynlib.GetPossibleChunkSizeInFrames();*src;src++) {
748 list.push_back(*src);
749 }
750 } else {
751 list.push_back(12);
752 }
753 return list;
754 }
755
762 static inline unsigned int GetChannelCount(CDynLib& dynlib)
763 {
764 return dynlib.GetChannelCount();
765 }
766
775 static inline unsigned int GetAudioInputCount(CDynLib& dynlib)
776 {
777 return dynlib.GetAudioInputCount();
778 }
779
788 static inline unsigned int GetAudioOutputCount(CDynLib& dynlib)
789 {
790 return dynlib.GetAudioOutputCount();
791 }
792
801 static inline unsigned int GetSampleRate(CDynLib& dynlib)
802 {
803 return dynlib.GetSampleRate();
804 }
805
813 static inline void SanityCheck(CDynLib& dynlib, bool a_bCheckFrames = true)
814 {
815 // Do some sanity checks
816 if (dynlib.GetSampleRate()!=BIGVOICE_SAMPLE_RATE) {
817 throw std::runtime_error("Bad library sampling rate");
818 }
819 if (a_bCheckFrames && dynlib.GetChunkSizeInFrames()!=ChunkFrames) {
820 throw std::runtime_error("Bad library frame size");
821 }
823 throw std::runtime_error("Bad library channel count");
824 }
826 throw std::runtime_error("Bad library input count");
827 }
829 throw std::runtime_error("Bad library output count");
830 }
831 }
832
840 static inline std::string GetFormatName(CDynLib& dynlib, const SampleFormat fmt)
841 {
842 return std::string(dynlib.GetFormatName(fmt));
843 }
844
852 static inline SampleFormat GetFormatFromName(CDynLib& dynlib, const std::string& name)
853 {
854 return dynlib.GetFormatFromName(name.c_str());
855 }
856
864 static inline unsigned int GetBytesFromFormat(CDynLib& dynlib, const SampleFormat fmt)
865 {
866 return dynlib.GetBytesFromFormat(fmt);
867 }
868
876 using log_cb_t = std::function<void(LogSeverity,const std::string&)>;
877
882 extern "C" {
883 static inline void _log_cb_c(bigvoice_LogSeverity severity, const char *c_msg) {
884 _log_cb(severity, std::string(c_msg));
885 }
886 }
890 static inline void SetLogSeverity(CDynLib& dynlib, LogSeverity severity)
891 {
892 dynlib.SetLogSeverity(severity);
893 }
897 static inline void SetLoggerCallback(CDynLib& dynlib, log_cb_t cb)
898 {
899 _log_cb=cb;
901 }
902
903#if BIGVOICE_HAS_CLOUDBUS
909 class CBus {
910 public:
911 CBus(CDynLib& dynlib)
912 : m_dynlib(dynlib)
913 {
914 if (m_dynlib.NewBus) {
915 m_bus=m_dynlib.NewBus();
916 }
917 }
919 {
920 if (m_bus && m_dynlib.FreeBus) {
921 m_dynlib.FreeBus(m_bus);
922 }
923 m_bus = nullptr;
924 }
925 bigvoice_CBus *Get() const { return m_bus; }
926 private:
927 CDynLib& m_dynlib;
928 bigvoice_CBus *m_bus;
929 };
930#endif // BIGVOICE_HAS_CLOUDBUS
931
938 public:
939 CPresetLoader() = default;
940 virtual ~CPresetLoader() = default;
941
942 virtual bool IsReadOnly() = 0;
943 virtual bool Exists(const std::filesystem::path &name) = 0;
944 virtual bool Remove(const std::filesystem::path &name) = 0;
945 virtual bool Rename(const std::filesystem::path &from, const std::filesystem::path &to) = 0;
946 virtual std::vector<std::filesystem::path> GetAll() = 0;
947 virtual std::string Read(const std::filesystem::path &filename) = 0;
948 virtual bool Write(const std::filesystem::path &filename, const std::string &content) =0;
949 };
951
957 class CInstance {
958 public:
963 : m_dynlib(dynlib)
964 {
965 params = m_dynlib.NewParameters();
966 if (!params) throw std::bad_alloc();
967 }
968 // non-copyable
969 CInstance( const CInstance& ) = delete;
970 CInstance& operator=( const CInstance& ) = delete;
974 virtual ~CInstance()
975 {
976 Stop();
977 if (params) m_dynlib.FreeParameters(params);
978 }
982 bool IsOk() const { return instance!=nullptr; }
992 void SetParam(const std::string& name, const std::string& value)
993 {
994 assert(params);
995 m_dynlib.SetParameter(params, name.c_str(), value.c_str());
996 }
1003 std::string GetParam(const std::string& name)
1004 {
1005 assert(params);
1006 auto c_value=m_dynlib.GetParameter(params, name.c_str());
1007 std::string ret(c_value);
1008 m_dynlib.FreeParameterValue(c_value);
1009 return ret;
1010 }
1011#if BIGVOICE_HAS_CLOUDBUS
1020 void SetBus(const CBus& bus) {
1021 assert(params);
1022 if (m_dynlib.SetInstanceBus) {
1023 m_dynlib.SetInstanceBus(params,bus.Get());
1024 }
1025 }
1026#endif // BIGVOICE_HAS_CLOUDBUS
1027
1038 void SetPresetManager(CPresetLoader *preset_manager)
1039 {
1040 if (!preset_manager) return;
1041 if (!m_dynlib.SetPresetManager) return;
1042 assert(params);
1043 m_dynlib.SetPresetManager(params,
1052 preset_manager->IsReadOnly(),
1053 preset_manager
1054 );
1055 }
1056
1079 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)
1080 {
1081 assert(!instance);
1082 std::string l_save_path;
1083 if (!save_path.empty()) {
1084 #if (__cplusplus<202002L)
1085 l_save_path = save_path.u8string();
1086 #else // C++20
1087 l_save_path = (const char*)save_path.u8string().c_str();
1088 #endif // C++20
1089 }
1090 if (m_dynlib.InitProcess3) {
1091 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);
1092 } else if (frames_per_chunk!=12) {
1093 return false;
1094 } else {
1095 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);
1096 }
1097 if (!instance) return false;
1098 if (!init_metadata.empty()) {
1099 for (auto&& [key,value]: init_metadata) {
1100 m_dynlib.SetMetadata(instance, key.c_str(), value.c_str());
1101 }
1102 init_metadata.clear();
1103 }
1104 update_thread = std::thread([this, json_port](){
1106 m_dynlib.StartUpdateThread(instance, json_port);
1108 });
1109 int timeout=5000;
1110 #ifdef DEBUG
1111 timeout=60*1000; // For debugger pauses
1112 #endif
1113 if (m_dynlib.WaitUpdateThreadReady(instance, timeout)<0) {
1114 return false;
1115 }
1116 return true;
1117 }
1118
1126 unsigned int GetChunkFrames() {
1127 if (instance && m_dynlib.GetProcessChunkFrames) {
1128 return m_dynlib.GetProcessChunkFrames(instance);
1129 }
1130 return 12;
1131 }
1132
1140 void PresetManager_InformChange(const std::filesystem::path& relative_path, PresetChange_Kind change_kind)
1141 {
1142 if (m_dynlib.PresetManager_InformChange) {
1143 m_dynlib.PresetManager_InformChange(instance, relative_path.c_str(), (bigvoice_PresetChange_Kind) change_kind);
1144 }
1145 }
1146
1158 void SetMetadata(const std::string& key, const char* value)
1159 {
1160 if (m_dynlib.SetMetadata) {
1161 if (instance) {
1162 m_dynlib.SetMetadata(instance, key.c_str(), value);
1163 } else {
1164 init_metadata.push_back( {key, value} );
1165 }
1166 }
1167 }
1168
1169
1179 void SetMetadataMulti(const std::unordered_map<std::string, const char*>& list)
1180 {
1181 if (instance) {
1182 if (m_dynlib.SetMetadataMulti) {
1183 typedef const char* pchar;
1184 pchar* keyvalue=new pchar[2*list.size()+1];
1185 size_t n=0;
1186 for (auto&& [key,value]: list) {
1187 keyvalue[2*n+0]=key.c_str();
1188 keyvalue[2*n+1]=value;
1189 n++;
1190 }
1191 keyvalue[2*n+0]=nullptr;
1192
1193 bigvoice_SetMetadataMulti(instance, keyvalue);
1194
1195 delete[] keyvalue;
1196 } else {
1197 for (auto&& [key,value]: list) {
1198 SetMetadata(key, value);
1199 }
1200 }
1201 } else {
1202 for (auto&& [key,value]: list) {
1203 if (value) {
1204 init_metadata.push_back( {key, value} );
1205 }
1206 }
1207 }
1208 }
1209
1215 std::vector< std::tuple<std::string,std::string> > GetMetadataInfos()
1216 {
1217 std::vector< std::tuple<std::string,std::string> > values;
1218 if (m_dynlib.GetMetadataInfos) {
1219 const char** c_values = m_dynlib.GetMetadataInfos(instance);
1220 if (c_values) {
1221 for (const char** c_value=c_values; *c_value; ) {
1222 std::string key(*c_value);
1223 c_value++;
1224 if (*c_value) {
1225 std::string descr(*c_value);
1226 c_value++;
1227 values.push_back( {key,descr} );
1228 }
1229 }
1230 m_dynlib.FreeMetadataInfos(instance, c_values);
1231 }
1232 }
1233 return values;
1234 }
1235
1239 virtual void OnUpdateThreadStart() {}
1243 virtual void OnUpdateThreadStop() {}
1244
1245#if BIGVOICE_HAS_WEBSERVER
1259 bool StartWebServer(int http_port, int https_port=0)
1260 {
1261 assert(instance);
1262 assert(webserver==SOUND4_INVALID_WEBSERVER_ID);
1263 webserver = m_dynlib.Webserver(http_port,https_port,instance);
1264 if (webserver==SOUND4_INVALID_WEBSERVER_ID) {
1265 return false;
1266 }
1267 int web_status=m_dynlib.Webserver_Status(webserver);
1268 if (http_port && (web_status & SOUND4_WEBSERVER_HTTP_OK) == 0) {
1269 return false;
1270 }
1271 if (https_port && (web_status & SOUND4_WEBSERVER_HTTPS_OK) == 0) {
1272 return false;
1273 }
1274 return true;
1275 }
1276
1284 void StopWebServer(int timeout_ms = 1000)
1285 {
1286 if (webserver != SOUND4_INVALID_WEBSERVER_ID) {
1287 m_dynlib.Webserver_Stop(webserver, timeout_ms);
1288 webserver = SOUND4_INVALID_WEBSERVER_ID;
1289 }
1290 }
1291
1295 void SetWebServerAppHealth(int httpcode, const std::string& contenttype, const std::string& content)
1296 {
1297 assert(instance);
1298 if (!m_dynlib.Webserver_SetAppHealth) return;
1299 m_dynlib.Webserver_SetAppHealth(instance, httpcode, contenttype.c_str(), content.c_str());
1300 }
1304 void GetWebServerAppHealth(int &httpcode, std::string& contenttype, std::string& content)
1305 {
1306 assert(instance);
1307 if (!m_dynlib.Webserver_GetAppHealth) return;
1308 char* c_contenttype=nullptr;
1309 char* c_content=nullptr;
1310 m_dynlib.Webserver_GetAppHealth(instance, &httpcode, &c_contenttype, &c_content);
1311 contenttype=c_contenttype;
1312 content=c_content;
1313 m_dynlib.Webserver_FreeString(c_contenttype);
1314 m_dynlib.Webserver_FreeString(c_content);
1315 }
1316#endif // BIGVOICE_HAS_WEBSERVER
1317
1327 {
1328 if (!instance) return 0;
1329 return m_dynlib.TerminateProcess(instance);
1330 }
1331
1335 void Stop()
1336 {
1337 if (!instance) return;
1338#if BIGVOICE_HAS_WEBSERVER
1339 StopWebServer();
1340#endif // BIGVOICE_HAS_WEBSERVER
1341 if (update_thread.joinable()) {
1342 m_dynlib.StopUpdateThread(instance); // this will exit the update thread
1343 update_thread.join();
1344 }
1345 m_dynlib.ExitProcess(instance);
1346 instance=nullptr;
1347 }
1348
1358 unsigned int GetEstimatedDelay()
1359 {
1360 assert(instance);
1361 return m_dynlib.GetEstimatedDelay(instance);
1362 }
1363
1376 std::array<float,InputSampleSize>& GetBufferIn()
1377 {
1378 assert(instance);
1379 float *buf=m_dynlib.GetBufferIn(instance);
1380 return reinterpret_cast< std::array<float,InputSampleSize>& >(*buf);
1381
1382 }
1394 std::array<float,OutputSampleSize>& GetBufferOut()
1395 {
1396 assert(instance);
1397 float *buf= m_dynlib.GetBufferOut(instance);
1398 return reinterpret_cast< std::array<float,OutputSampleSize>& >(*buf);
1399 }
1404 {
1405 assert(instance);
1406 m_dynlib.ProcessAudio(instance, m_dynlib.GetBufferIn(instance), m_dynlib.GetBufferOut(instance));
1407 }
1419 void ProcessAudio_Planar(float const * const *input, float * const *output)
1420 {
1421 assert(instance);
1422 m_dynlib.ProcessAudio_Planar(instance, input, output);
1423 }
1424
1436 template<typename T>
1437 std::vector<T> ProcessAnyAudio(const std::vector<T> input)
1438 {
1439 assert(instance);
1440 std::vector<T> output;
1441 unsigned int out_offset=0;
1442 unsigned int in_offset=0;
1443 unsigned int todo = input.size();
1444 while (todo>0) {
1445 unsigned int left = AddAudio(&input[in_offset], todo);
1446 unsigned int out_avail = m_dynlib.GetOutputCount(instance);
1447 output.resize(out_offset + out_avail);
1448 GetAudio(&output[out_offset], out_avail);
1449 out_offset+=out_avail;
1450 in_offset += todo-left;
1451 todo=left;
1452 }
1453 return output;
1454 }
1455
1461 class CClient {
1462 public:
1464 : m_dynlib(dynlib)
1465 {
1466 assert(instance);
1467 client=m_dynlib.NewClient(instance);
1468 if (!client) throw std::bad_alloc();
1469 }
1470 // non-copyable
1471 CClient( const CInstance& ) = delete;
1472 CClient& operator=( const CInstance& ) = delete;
1474 {
1475 if (client) {
1476 m_dynlib.DeleteClient(client);
1477 client=nullptr;
1478 }
1479 }
1487 std::string ProcessJson(const std::string &request, bool *NeedSave = nullptr)
1488 {
1489 assert(client);
1490 int need_save=0;
1491 const char *canswer = m_dynlib.ProcessJson(client, request.c_str(), &need_save);
1492 if (!canswer) return {};
1493 std::string answer(canswer);
1494 m_dynlib.FreeJsonAnswer (canswer);
1495 if (NeedSave) {
1496 *NeedSave=(need_save!=0);
1497 }
1498 return answer;
1499 }
1500 private:
1501 CDynLib& m_dynlib;
1502 bigvoice_CClientInstance *client = nullptr;
1503 };
1511 std::shared_ptr<CClient> NewClient()
1512 {
1513 assert(instance);
1514 return std::make_shared<CClient>(instance, m_dynlib);
1515 }
1516
1527 bool SaveState() {
1528 assert(instance);
1529 if (m_dynlib.SaveState(instance)!=0) {
1530 return false;
1531 }
1532 return true;
1533 }
1534#ifdef _WIN32
1541 void SetInstanceTracing(TraceLoggingHProvider tracing_provider, GUID activity_guid = {}) {
1542 if (m_dynlib.SetInstanceTracing) {
1543 m_dynlib.SetInstanceTracing(params, tracing_provider, activity_guid);
1544 }
1545 }
1552 void SetInstanceTracingProcessActivity(GUID activity_guid) {
1553 assert(instance);
1554 if (m_dynlib.SetInstanceTracingProcessActivity) {
1555 m_dynlib.SetInstanceTracingProcessActivity(instance, activity_guid);
1556 }
1557 }
1558#endif // _WIN32
1559 protected:
1560 template<typename T>
1561 unsigned int AddAudio(const T* payload, unsigned int nFrame)
1562 {
1563 assert(instance);
1564 return m_dynlib.AddAudio(instance, reinterpret_cast<const T*>(payload), nFrame, helper::SampleFormat<T>::format);
1565 }
1566 template<typename T>
1567 unsigned int GetAudio(T* payload, unsigned int max_nFrame)
1568 {
1569 assert(instance);
1570 return m_dynlib.GetAudio(instance, reinterpret_cast<T*>(payload), max_nFrame, helper::SampleFormat<T>::format);
1571 }
1572
1573 private:
1574 CDynLib& m_dynlib;
1575 bigvoice_CParameters* params = nullptr;
1576 bigvoice_CInstance* instance = nullptr;
1577 std::thread update_thread;
1578 std::vector< std::pair<std::string,std::string> > init_metadata;
1579#if BIGVOICE_HAS_WEBSERVER
1580 uint64_t webserver = SOUND4_INVALID_WEBSERVER_ID;
1581#endif // BIGVOICE_HAS_WEBSERVER
1582 };
1583
1591 public:
1598 : m_dynlib(dynlib)
1599 { }
1600
1605 {
1606 Delete();
1607 }
1608
1624 bool Configure(SampleFormat fmt, size_t nFrame, size_t payl_ch, size_t payl_ch_offset, bigvoice_ConverterTargetMode target_mode)
1625 {
1626 Delete();
1627 if (m_dynlib.GetAudioConverter)
1628 m_cvt = m_dynlib.GetAudioConverter((bigvoice_SampleFormat)fmt, nFrame, payl_ch, payl_ch_offset, target_mode);
1629 return IsOK();
1630 }
1631 void Delete()
1632 {
1633 if (m_cvt && m_dynlib.FreeAudioConverter) {
1634 m_dynlib.FreeAudioConverter(m_cvt);
1635 }
1636 m_cvt = nullptr;
1637 }
1638 bool IsOK() const { return (m_cvt!=nullptr); }
1639
1648 void ConvertFrom(const uint8_t *payload, float *output)
1649 { m_dynlib.AudioConverter_From(m_cvt, payload, output); }
1650
1659 void ConvertTo(const float *input, uint8_t *payload)
1660 { m_dynlib.AudioConverter_To(m_cvt, input, payload); }
1661
1662 private:
1663 CDynLib& m_dynlib;
1664 bigvoice_CAudioConverter *m_cvt = nullptr;
1665 };
1666
1667}; // namespace dyn
1668}; // namespace bigvoice
1669}; // namespace sound4
1670
1671// bridge C callbacks to CPresetLoader
1672extern "C" {
1673 static char *bigvoice_custom_reader(const fs_char *filename, void* userdata) {
1674 sound4::bigvoice::dyn::CPresetLoader *preset_loader=reinterpret_cast<sound4::bigvoice::dyn::CPresetLoader*>(userdata);
1675 std::string content=preset_loader->Read(filename);
1676 return strdup(content.c_str());
1677 }
1678 static void bigvoice_custom_reader_free(char *content, void* userdata) {
1679 if (!content) return;
1680 free(content);
1681 }
1682 static int bigvoice_custom_writer(const fs_char *filename, const char *content, void* userdata) {
1683 sound4::bigvoice::dyn::CPresetLoader *preset_loader=reinterpret_cast<sound4::bigvoice::dyn::CPresetLoader*>(userdata);
1684 auto res=preset_loader->Write(filename,content);
1685 return res?0:-1;
1686 }
1687 static int bigvoice_custom_exists(const fs_char *filename, void* userdata) {
1688 sound4::bigvoice::dyn::CPresetLoader *preset_loader=reinterpret_cast<sound4::bigvoice::dyn::CPresetLoader*>(userdata);
1689 auto res=preset_loader->Exists(filename);
1690 return res?0:-1;
1691 }
1692 static fs_char** bigvoice_custom_getall(void* userdata) {
1693 sound4::bigvoice::dyn::CPresetLoader *preset_loader=reinterpret_cast<sound4::bigvoice::dyn::CPresetLoader*>(userdata);
1694 auto res=preset_loader->GetAll();
1695 fs_char**all=(fs_char**)malloc((res.size()+1)*sizeof(const fs_char*));
1696 for (size_t n=0;n<res.size();n++) {
1697 all[n]=fs_strdup(res[n].c_str());
1698 }
1699 all[res.size()]=nullptr;
1700 return all;
1701 }
1702 static void bigvoice_custom_getall_free(fs_char** all, void* userdata) {
1703 if (!all) return;
1704 for (fs_char** one=all;*one;one++) {
1705 free(*one);
1706 }
1707 free(all);
1708 }
1709 static int bigvoice_custom_remove(const fs_char *filename, void* userdata) {
1710 sound4::bigvoice::dyn::CPresetLoader *preset_loader=reinterpret_cast<sound4::bigvoice::dyn::CPresetLoader*>(userdata);
1711 auto res=preset_loader->Remove(filename);
1712 return res?0:-1;
1713 }
1714 static int bigvoice_custom_rename(const fs_char *from, const fs_char *to, void* userdata) {
1715 sound4::bigvoice::dyn::CPresetLoader *preset_loader=reinterpret_cast<sound4::bigvoice::dyn::CPresetLoader*>(userdata);
1716 auto res=preset_loader->Rename(from,to);
1717 return res?0:-1;
1718 }
1719
1720};
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)
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: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)