SOUND4 BIGVOICE.CL Library [1.1.5]
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#else // !_WIN32
45 #define fs_strdup strdup
46#endif // !_WIN32
47
48// bridge C callbacks to CPresetLoader
49extern "C" {
50 static char *bigvoice_custom_reader(const fs_char *filename, void* userdata);
51 static void bigvoice_custom_reader_free(char *content, void* userdata);
52 static int bigvoice_custom_writer(const fs_char *filename, const char *content, void* userdata);
53 static int bigvoice_custom_exists(const fs_char *filename, void* userdata);
54 static fs_char** bigvoice_custom_getall(void* userdata);
55 static void bigvoice_custom_getall_free(fs_char** all, void* userdata);
56 static int bigvoice_custom_remove(const fs_char *filename, void* userdata);
57 static int bigvoice_custom_rename(const fs_char *from, const fs_char *to, void* userdata);
58};
59
63namespace sound4 {
67namespace bigvoice {
71namespace dyn {
72
76 namespace helper {
77 // Storage definition, depending on OS
78 #if UNIXLIKE
79 using DynLib_t = void *;
80 using DynFunc_t = void *;
81 #else
82 using DynLib_t = HMODULE;
83 using DynFunc_t = FARPROC;
84 #endif
85
91 template <typename T>
93 private:
94 DynFunc_t m_ptr = NULL;
95 public:
96 DynFuncHolder() = default;
97 DynFuncHolder(DynFunc_t a_ptr) : m_ptr(a_ptr) {}
98 operator bool() const { return (m_ptr!=NULL); }
99 bool IsOk() const { return m_ptr!=NULL; }
100 operator T* () const { return reinterpret_cast<T*>(m_ptr); }
101 };
102
108 private:
109 DynLib_t m_lib {};
110 public:
111 CDynLoader() = default;
112 CDynLoader(CDynLoader&&) = default;
113 // No copy allowed
114 CDynLoader(const CDynLoader&) = delete;
115 CDynLoader& operator=(CDynLoader const&) = delete;
116 operator bool() const {
117 return (m_lib!=NULL);
118 }
119 bool IsOk() const {
120 return (m_lib!=NULL);
121 }
122 #if UNIXLIKE
123 void Close() {
124 if (IsOk()) {
125 #ifndef __SANITIZE_ADDRESS__ // avoid unloading to keep call stack
126 dlclose(m_lib);
127 #endif // __SANITIZE_ADDRESS__
128 m_lib=NULL;
129 }
130 }
131 bool Load(const std::filesystem::path& dynlib)
132 {
133 Close();
134 m_lib=dlopen(dynlib.c_str(), RTLD_NOW|RTLD_LOCAL);
135 return IsOk();
136 }
137 template <typename T>
138 DynFuncHolder<T> GetSymbol(const std::string& name) {
139 auto ptr=dlsym(m_lib, name.c_str());
140 if (!ptr) {
141 throw std::runtime_error("Missing function in library");
142 }
143 return DynFuncHolder<T>(ptr);
144 }
145 template <typename T>
146 DynFuncHolder<T> GetSymbol_safe(const std::string& name) {
147 auto ptr=dlsym(m_lib, name.c_str());
148 return DynFuncHolder<T>(ptr);
149 }
150 static std::filesystem::path GetThisLibraryPath(void) {
151 static Dl_info info;
152 if (! dladdr((void *) GetThisLibraryPath, & info)) return {};
153 auto rp=realpath(info.dli_fname, NULL);
154 std::filesystem::path p(rp);
155 free(rp);
156 return p;
157 }
158 #else
165 void Close() {
166 if (IsOk()) {
167 // NOTE: On Windows, FreeLibrary may create a lot of troubles, should use FreeLibraryAndExitThread but...
168 // So define SOUND4_CALL_FREELIBRARY before including this file if you really want to unload the library dynamically
169 #if defined(SOUND4_CALL_FREELIBRARYANDEXITTHREAD)
170 FreeLibraryAndExitThread(m_lib, 0);
171 #elif defined(SOUND4_CALL_FREELIBRARY)
172 FreeLibrary(m_lib);
173 #endif // SOUND4_CALL_FREELIBRARY
174 m_lib=NULL;
175 }
176 }
177 template <typename T>
178 DynFuncHolder<T> GetSymbol(const std::string& name) {
179 auto ptr=GetProcAddress(m_lib, name.c_str());
180 if (!ptr) {
181 throw std::runtime_error("Missing function in library");
182 }
183 return DynFuncHolder<T>(ptr);
184 }
185 template <typename T>
186 DynFuncHolder<T> GetSymbol_safe(const std::string& name) {
187 auto ptr=GetProcAddress(m_lib, name.c_str());
188 return DynFuncHolder<T>(ptr);
189 }
190 static std::filesystem::path GetThisLibraryPath(void) {
191 static wchar_t path[MAX_PATH]={};
192 HMODULE hm = NULL;
196 {
197 if (GetModuleFileNameW(hm, path, MAX_PATH) > 0) {
198 return std::filesystem::path(path);
199 }
200 }
201 return {};
202 }
203 #endif
204 virtual ~CDynLoader() {
205 Close();
206 }
207 }; // class CDynLoader
208 }; // namespace helper
209
216 class CDynLib {
217 private:
218 helper::CDynLoader m_lib;
219 bool m_bOK = false;
220 public:
221 CDynLib() = default;
222
223 // All those wrapped functions have the same signature as there C bigvoice_XXX
268#if BIGVOICE_HAS_WEBSERVER
274#endif // BIGVOICE_HAS_WEBSERVER
275
276 // added 2023-03-22
279
280 // added 2023-05-22
284
285 // added 2023-06-20
288
289 // added 2023-09-21
293
294#if BIGVOICE_HAS_CLOUDBUS
295 // added 2023-06-26
299#endif // BIGVOICE_HAS_CLOUDBUS
300
301 // added 2024-02-19
303
304#if BIGVOICE_HAS_WEBSERVER
305 // added 2024-05-23
309#endif // BIGVOICE_HAS_WEBSERVER
310
318 bool Load(const std::filesystem::path& path = {}) {
319 std::string filename;
320 #if defined(__APPLE__)
321 filename="libsound4.bigvoice.cl.dylib";
322 #elif defined(__unix__)
323 filename="libsound4.bigvoice.cl.so";
324 #else
325 filename="sound4.bigvoice.cl.dll";
326 #endif
327 m_lib.Close();
328 // If a path is given, use it directly and do not try other path
329 if (!path.empty() && !m_lib.Load(path / filename)) {
330 return false;
331 } else if (!m_lib.IsOk()) {
332 auto thisdir=helper::CDynLoader::GetThisLibraryPath().parent_path();
333 #ifndef _WIN32
334 // Linux: if in a bin directory, try ../lib first
335 if (!m_lib.IsOk() && thisdir.filename()=="bin") {
336 auto libdir = thisdir.parent_path() / "lib";
337 m_lib.Load(libdir / filename);
338 }
339 #endif // !_WIN32
340 if (!m_lib.IsOk()) {
341 // Search in the same directory this code is in
342 m_lib.Load(thisdir / filename);
343 }
344 if (!m_lib.IsOk()) {
345 // Try current path
346 std::error_code ec;
347 auto p = std::filesystem::current_path(ec);
348 if (!ec) {
349 m_lib.Load(p / filename);
350 }
351 }
352 if (!m_lib.IsOk()) {
353 return false;
354 }
355 }
356 // Load all C functions
357 try {
358 GetVersion = m_lib.GetSymbol< decltype(bigvoice_GetVersion ) >("bigvoice_GetVersion" );
359 GetChunkSizeInFrames = m_lib.GetSymbol< decltype(bigvoice_GetChunkSizeInFrames ) >("bigvoice_GetChunkSizeInFrames" );
360 GetChannelCount = m_lib.GetSymbol< decltype(bigvoice_GetChannelCount ) >("bigvoice_GetChannelCount" );
361 GetAudioInputCount = m_lib.GetSymbol< decltype(bigvoice_GetAudioInputCount ) >("bigvoice_GetAudioInputCount" );
362 GetAudioOutputCount = m_lib.GetSymbol< decltype(bigvoice_GetAudioOutputCount ) >("bigvoice_GetAudioOutputCount" );
363 GetSampleRate = m_lib.GetSymbol< decltype(bigvoice_GetSampleRate ) >("bigvoice_GetSampleRate" );
364 SetLoggerCallback = m_lib.GetSymbol< decltype(bigvoice_SetLoggerCallback ) >("bigvoice_SetLoggerCallback" );
365 SetLogSeverity = m_lib.GetSymbol< decltype(bigvoice_SetLogSeverity ) >("bigvoice_SetLogSeverity" );
366 NewParameters = m_lib.GetSymbol< decltype(bigvoice_NewParameters ) >("bigvoice_NewParameters" );
367 FreeParameters = m_lib.GetSymbol< decltype(bigvoice_FreeParameters ) >("bigvoice_FreeParameters" );
368 SetParameter = m_lib.GetSymbol< decltype(bigvoice_SetParameter ) >("bigvoice_SetParameter" );
369 GetParameter = m_lib.GetSymbol< decltype(bigvoice_GetParameter ) >("bigvoice_GetParameter" );
370 FreeParameterValue = m_lib.GetSymbol< decltype(bigvoice_FreeParameterValue ) >("bigvoice_FreeParameterValue" );
371 InitProcess = m_lib.GetSymbol< decltype(bigvoice_InitProcess ) >("bigvoice_InitProcess" );
372 InitProcess2 = m_lib.GetSymbol< decltype(bigvoice_InitProcess2 ) >("bigvoice_InitProcess2" );
373 TerminateProcess = m_lib.GetSymbol< decltype(bigvoice_TerminateProcess ) >("bigvoice_TerminateProcess" );
374 ExitProcess = m_lib.GetSymbol< decltype(bigvoice_ExitProcess ) >("bigvoice_ExitProcess" );
375 StartUpdateThread = m_lib.GetSymbol< decltype(bigvoice_StartUpdateThread ) >("bigvoice_StartUpdateThread" );
376 StopUpdateThread = m_lib.GetSymbol< decltype(bigvoice_StopUpdateThread ) >("bigvoice_StopUpdateThread" );
377 WaitUpdateThreadReady = m_lib.GetSymbol< decltype(bigvoice_WaitUpdateThreadReady ) >("bigvoice_WaitUpdateThreadReady" );
378 ProcessAudio = m_lib.GetSymbol< decltype(bigvoice_ProcessAudio ) >("bigvoice_ProcessAudio" );
379 ProcessAudio_Planar = m_lib.GetSymbol< decltype(bigvoice_ProcessAudio_Planar ) >("bigvoice_ProcessAudio_Planar" );
380 GetBufferIn = m_lib.GetSymbol< decltype(bigvoice_GetBufferIn ) >("bigvoice_GetBufferIn" );
381 GetBufferOut = m_lib.GetSymbol< decltype(bigvoice_GetBufferOut ) >("bigvoice_GetBufferOut" );
382 GetEstimatedDelay = m_lib.GetSymbol< decltype(bigvoice_GetEstimatedDelay ) >("bigvoice_GetEstimatedDelay" );
383 GetFormatName = m_lib.GetSymbol< decltype(bigvoice_GetFormatName ) >("bigvoice_GetFormatName" );
384 GetFormatFromName = m_lib.GetSymbol< decltype(bigvoice_GetFormatFromName ) >("bigvoice_GetFormatFromName" );
385 GetBytesFromFormat = m_lib.GetSymbol< decltype(bigvoice_GetBytesFromFormat ) >("bigvoice_GetBytesFromFormat" );
386 GetMaxPacketFrame = m_lib.GetSymbol< decltype(bigvoice_GetMaxPacketFrame ) >("bigvoice_GetMaxPacketFrame" );
387 AddAudio = m_lib.GetSymbol< decltype(bigvoice_AddAudio ) >("bigvoice_AddAudio" );
388 AddPadAudio = m_lib.GetSymbol< decltype(bigvoice_AddPadAudio ) >("bigvoice_AddPadAudio" );
389 GetOutputCount = m_lib.GetSymbol< decltype(bigvoice_GetOutputCount ) >("bigvoice_GetOutputCount" );
390 GetAudio = m_lib.GetSymbol< decltype(bigvoice_GetAudio ) >("bigvoice_GetAudio" );
391 AudioConvertFrom = m_lib.GetSymbol< decltype(bigvoice_AudioConvertFrom ) >("bigvoice_AudioConvertFrom" );
392 AudioConvertTo = m_lib.GetSymbol< decltype(bigvoice_AudioConvertTo ) >("bigvoice_AudioConvertTo" );
393 StereoToMono = m_lib.GetSymbol< decltype(bigvoice_StereoToMono ) >("bigvoice_StereoToMono" );
394 MonoToStereo = m_lib.GetSymbol< decltype(bigvoice_MonoToStereo ) >("bigvoice_MonoToStereo" );
395 AudioMonoFromLiveStereo = m_lib.GetSymbol< decltype(bigvoice_AudioMonoFromLiveStereo) >("bigvoice_AudioMonoFromLiveStereo");
396 AudioMonoToLiveStereo = m_lib.GetSymbol< decltype(bigvoice_AudioMonoToLiveStereo ) >("bigvoice_AudioMonoToLiveStereo" );
397 NewClient = m_lib.GetSymbol< decltype(bigvoice_NewClient ) >("bigvoice_NewClient" );
398 DeleteClient = m_lib.GetSymbol< decltype(bigvoice_DeleteClient ) >("bigvoice_DeleteClient" );
399 ProcessJson = m_lib.GetSymbol< decltype(bigvoice_ProcessJson ) >("bigvoice_ProcessJson" );
400 FreeJsonAnswer = m_lib.GetSymbol< decltype(bigvoice_FreeJsonAnswer ) >("bigvoice_FreeJsonAnswer" );
401 SaveState = m_lib.GetSymbol< decltype(bigvoice_SaveState ) >("bigvoice_SaveState" );
402#if BIGVOICE_HAS_WEBSERVER
403 Webserver_tcp = m_lib.GetSymbol< decltype(bigvoice_Webserver_tcp ) >("bigvoice_Webserver_tcp" );
404 Webserver_tcp2 = m_lib.GetSymbol< decltype(bigvoice_Webserver_tcp2 ) >("bigvoice_Webserver_tcp2" );
405 Webserver = m_lib.GetSymbol< decltype(bigvoice_Webserver ) >("bigvoice_Webserver" );
406 Webserver_Stop = m_lib.GetSymbol< decltype(bigvoice_Webserver_Stop ) >("bigvoice_Webserver_Stop" );
407 Webserver_Status = m_lib.GetSymbol< decltype(bigvoice_Webserver_Status ) >("bigvoice_Webserver_Status" );
408#endif // BIGVOICE_HAS_WEBSERVER
409
410 // added 2023-03-22
411 StereoToMono_Planar = m_lib.GetSymbol< decltype(bigvoice_StereoToMono_Planar ) >("bigvoice_StereoToMono_Planar" );
412 MonoToStereo_Planar = m_lib.GetSymbol< decltype(bigvoice_MonoToStereo_Planar ) >("bigvoice_MonoToStereo_Planar" );
413
414 } catch (std::runtime_error& ) {
415 return false;
416 }
417 // C functions allowed to be missing
418 try {
419 // added 2023-05-22
420 SetMetadata = m_lib.GetSymbol< decltype(bigvoice_SetMetadata ) >("bigvoice_SetMetadata" );
421 GetMetadataInfos = m_lib.GetSymbol< decltype(bigvoice_GetMetadataInfos ) >("bigvoice_GetMetadataInfos" );
422 FreeMetadataInfos = m_lib.GetSymbol< decltype(bigvoice_FreeMetadataInfos ) >("bigvoice_FreeMetadataInfos" );
423 // added 2023-06-20
424 SetPresetManager = m_lib.GetSymbol< decltype(bigvoice_SetPresetManager ) >("bigvoice_SetPresetManager" );
425 PresetManager_InformChange = m_lib.GetSymbol< decltype(bigvoice_PresetManager_InformChange ) >("bigvoice_PresetManager_InformChange" );
426
427 // added 2023-09-21
428 GetPossibleChunkSizeInFrames = m_lib.GetSymbol< decltype(bigvoice_GetPossibleChunkSizeInFrames ) >("bigvoice_GetPossibleChunkSizeInFrames" );
429 GetProcessChunkFrames = m_lib.GetSymbol< decltype(bigvoice_GetProcessChunkFrames ) >("bigvoice_GetProcessChunkFrames" );
430 InitProcess3 = m_lib.GetSymbol< decltype(bigvoice_InitProcess3 ) >("bigvoice_InitProcess3" );
431
432#if BIGVOICE_HAS_CLOUDBUS
433 // added 2023-06-26
434 NewBus = m_lib.GetSymbol< decltype(bigvoice_NewBus ) >("bigvoice_NewBus" );
435 FreeBus = m_lib.GetSymbol< decltype(bigvoice_FreeBus ) >("bigvoice_FreeBus" );
436 SetInstanceBus = m_lib.GetSymbol< decltype(bigvoice_SetInstanceBus ) >("bigvoice_SetInstanceBus" );
437#endif // BIGVOICE_HAS_CLOUDBUS
438
439 // added 2024-02-19
440 SetMetadataMulti = m_lib.GetSymbol< decltype(bigvoice_SetMetadataMulti ) >("bigvoice_SetMetadataMulti" );
441
442#if BIGVOICE_HAS_WEBSERVER
443 // added 2024-05-23
444 Webserver_SetAppHealth = m_lib.GetSymbol< decltype(bigvoice_Webserver_SetAppHealth ) >("Webserver_SetAppHealth" );
445 Webserver_GetAppHealth = m_lib.GetSymbol< decltype(bigvoice_Webserver_GetAppHealth ) >("Webserver_GetAppHealth" );
446 Webserver_FreeString = m_lib.GetSymbol< decltype(bigvoice_Webserver_FreeString ) >("Webserver_FreeString" );
447#endif // BIGVOICE_HAS_WEBSERVER
448
449 } catch (std::runtime_error& ) {
450 // Ignored, handler will take care
451 }
452
453 m_bOK=true;
454 return true;
455 }
462 bool IsOk() const {
463 return m_bOK;
464 }
465
466 };
467
468
469
470 static constexpr const char *process_name = "SOUND4 BIGVOICE.CL";
471 static constexpr const char *process_shortname = "bigvoice";
497
501 namespace helper {
502 #ifdef _WIN32
508 static inline std::string WStringToUTF8(const std::wstring& wstr) {
509 if (wstr.empty()) return {};
510 int size = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), NULL, 0, NULL, NULL);
511 std::string str(size, 0);
512 WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), &str[0], size, NULL, NULL);
513 return str;
514 }
520 static inline std::wstring UTF8ToWString(const std::string& str) {
521 if (str.empty()) return std::wstring();
522 int size = MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), NULL, 0);
523 std::wstring wstr(size, 0);
524 MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), &wstr[0], size);
525 return wstr;
526 }
527 #endif // _WIN32
528
534 template<typename T>
536 };
537 template<>
541 template<>
545 template<>
548 };
549
550
555 static inline void AudioConvertFrom(CDynLib& dynlib, const uint8_t *payload, float *output, size_t nSpl, bigvoice_SampleFormat fmt) {
556 dynlib.AudioConvertFrom(payload, output, nSpl, fmt);
557 }
558 static inline void AudioConvertTo(CDynLib& dynlib, const float *input, uint8_t *payload, size_t nSpl, bigvoice_SampleFormat fmt) {
559 dynlib.AudioConvertTo(input, payload, nSpl, fmt);
560 }
561 static inline void StereoToMono(CDynLib& dynlib, const float *input, float *output, size_t nSpl) {
562 dynlib.StereoToMono(input, output, nSpl);
563 }
564 static inline void MonoToStereo(CDynLib& dynlib, const float *input, float *output, size_t nSpl) {
565 dynlib.MonoToStereo(input, output, nSpl);
566 }
567 static inline void StereoToMono_Planar(CDynLib& dynlib, const float *inputL, const float *inputR, float *output, size_t nSpl) {
568 dynlib.StereoToMono_Planar(inputL, inputR, output, nSpl);
569 }
570 static inline void MonoToStereo_Planar(CDynLib& dynlib, const float *input, float *outputL, float *outputR, size_t nSpl) {
571 dynlib.MonoToStereo_Planar(input, outputL, outputR, nSpl);
572 }
573 static inline void AudioMonoFromLiveStereo(CDynLib& dynlib, const uint8_t *payload, float *output) {
574 dynlib.AudioMonoFromLiveStereo(payload, output);
575 }
576 static inline void AudioMonoToLiveStereo(CDynLib& dynlib, const float *input, uint8_t *payload) {
577 dynlib.AudioMonoToLiveStereo(input, payload);
578 }
579
580 }; // namespace helper
581
587 static inline std::string GetVersion(CDynLib& dynlib)
588 {
589 return std::string(dynlib.GetVersion());
590 }
591
602 static inline unsigned int GetChunkSizeInFrames(CDynLib& dynlib)
603 {
604 return dynlib.GetChunkSizeInFrames();
605 }
606
615 static inline std::vector<unsigned int> GetPossibleChunkSizeInFrames(CDynLib& dynlib)
616 {
617 std::vector<unsigned int> list;
618 if (dynlib.GetPossibleChunkSizeInFrames) {
619 for (unsigned int* src=dynlib.GetPossibleChunkSizeInFrames();*src;src++) {
620 list.push_back(*src);
621 }
622 } else {
623 list.push_back(12);
624 }
625 return list;
626 }
627
635 static inline unsigned int GetChannelCount(CDynLib& dynlib)
636 {
637 return dynlib.GetChannelCount();
638 }
639
648 static inline unsigned int GetAudioInputCount(CDynLib& dynlib)
649 {
650 return dynlib.GetAudioInputCount();
651 }
652
661 static inline unsigned int GetAudioOutputCount(CDynLib& dynlib)
662 {
663 return dynlib.GetAudioOutputCount();
664 }
665
673 static inline unsigned int GetSampleRate(CDynLib& dynlib)
674 {
675 return dynlib.GetSampleRate();
676 }
677
683 static inline void SanityCheck(CDynLib& dynlib, bool a_bCheckFrames = true)
684 {
685 // Do some sanity checks
686 if (dynlib.GetSampleRate()!=BIGVOICE_SAMPLE_RATE) {
687 throw std::runtime_error("Bad library sampling rate");
688 }
689 if (a_bCheckFrames && dynlib.GetChunkSizeInFrames()!=ChunkFrames) {
690 throw std::runtime_error("Bad library frame size");
691 }
692 if (dynlib.GetChannelCount()!=BIGVOICE_CHANNEL_COUNT) {
693 throw std::runtime_error("Bad library channel count");
694 }
695 if (dynlib.GetAudioInputCount()!=BIGVOICE_AUDIO_INPUT_COUNT) {
696 throw std::runtime_error("Bad library input count");
697 }
698 if (dynlib.GetAudioOutputCount()!=BIGVOICE_AUDIO_OUTPUT_COUNT) {
699 throw std::runtime_error("Bad library output count");
700 }
701 }
702
709 static inline std::string GetFormatName(CDynLib& dynlib, const SampleFormat fmt)
710 {
711 return std::string(dynlib.GetFormatName(fmt));
712 }
713
720 static inline SampleFormat GetFormatFromName(CDynLib& dynlib, const std::string& name)
721 {
722 return dynlib.GetFormatFromName(name.c_str());
723 }
724
731 static inline unsigned int GetBytesFromFormat(CDynLib& dynlib, const SampleFormat fmt)
732 {
733 return dynlib.GetBytesFromFormat(fmt);
734 }
735
743 using log_cb_t = std::function<void(LogSeverity,const std::string&)>;
744
748 static log_cb_t _log_cb;
749 extern "C" {
750 static inline void _log_cb_c(bigvoice_LogSeverity severity, const char *c_msg) {
751 _log_cb(severity, std::string(c_msg));
752 }
753 }
757 static inline void SetLogSeverity(CDynLib& dynlib, LogSeverity severity)
758 {
759 dynlib.SetLogSeverity(severity);
760 }
764 static inline void SetLoggerCallback(CDynLib& dynlib, log_cb_t cb)
765 {
766 _log_cb=cb;
767 dynlib.SetLoggerCallback(&_log_cb_c);
768 }
769
770#if BIGVOICE_HAS_CLOUDBUS
771 class CBus {
772 public:
773 CBus(CDynLib& dynlib)
774 : m_dynlib(dynlib)
775 {
776 if (m_dynlib.NewBus) {
777 m_bus=m_dynlib.NewBus();
778 }
779 }
781 {
782 if (m_bus && m_dynlib.FreeBus) {
783 m_dynlib.FreeBus(m_bus);
784 }
785 m_bus = nullptr;
786 }
787 bigvoice_CBus *Get() const { return m_bus; }
788 private:
789 CDynLib& m_dynlib;
790 bigvoice_CBus *m_bus;
791 };
792#endif // BIGVOICE_HAS_CLOUDBUS
793
799 public:
800 CPresetLoader() = default;
801 virtual ~CPresetLoader() = default;
802
803 virtual bool IsReadOnly() = 0;
804 virtual bool Exists(const std::filesystem::path &name) = 0;
805 virtual bool Remove(const std::filesystem::path &name) = 0;
806 virtual bool Rename(const std::filesystem::path &from, const std::filesystem::path &to) = 0;
807 virtual std::vector<std::filesystem::path> GetAll() = 0;
808 virtual std::string Read(const std::filesystem::path &filename) = 0;
809 virtual bool Write(const std::filesystem::path &filename, const std::string &content) =0;
810 };
812
816 class CInstance {
817 public:
822 : m_dynlib(dynlib)
823 {
824 params = m_dynlib.NewParameters();
825 if (!params) throw std::bad_alloc();
826 }
827 // non-copyable
828 CInstance( const CInstance& ) = delete;
829 CInstance& operator=( const CInstance& ) = delete;
833 virtual ~CInstance()
834 {
835 Stop();
836 if (params) m_dynlib.FreeParameters(params);
837 }
841 bool IsOk() const { return instance!=nullptr; }
849 void SetParam(const std::string& name, const std::string& value)
850 {
851 assert(params);
852 m_dynlib.SetParameter(params, name.c_str(), value.c_str());
853 }
859 std::string GetParam(const std::string& name)
860 {
861 assert(params);
862 auto c_value=m_dynlib.GetParameter(params, name.c_str());
863 std::string ret(c_value);
864 m_dynlib.FreeParameterValue(c_value);
865 return ret;
866 }
867#if BIGVOICE_HAS_CLOUDBUS
871 void SetBus(const CBus& bus) {
872 assert(params);
873 if (m_dynlib.SetInstanceBus) {
874 m_dynlib.SetInstanceBus(params,bus.Get());
875 }
876 }
877#endif // BIGVOICE_HAS_CLOUDBUS
878
888 void SetPresetManager(CPresetLoader *preset_manager)
889 {
890 if (!preset_manager) return;
891 if (!m_dynlib.SetPresetManager) return;
892 assert(params);
893 m_dynlib.SetPresetManager(params,
894 bigvoice_custom_reader,
895 bigvoice_custom_reader_free,
896 bigvoice_custom_writer,
897 bigvoice_custom_exists,
898 bigvoice_custom_getall,
899 bigvoice_custom_getall_free,
900 bigvoice_custom_remove,
901 bigvoice_custom_rename,
902 preset_manager->IsReadOnly(),
903 preset_manager
904 );
905 }
906
921 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)
922 {
923 assert(!instance);
924 std::string l_save_path;
925 if (!save_path.empty()) {
926 l_save_path = save_path.u8string();
927 }
928 if (m_dynlib.InitProcess3) {
929 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);
930 } else if (frames_per_chunk!=12) {
931 return false;
932 } else {
933 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);
934 }
935 if (!instance) return false;
936 if (!init_metadata.empty()) {
937 for (auto&& [key,value]: init_metadata) {
938 m_dynlib.SetMetadata(instance, key.c_str(), value.c_str());
939 }
940 init_metadata.clear();
941 }
942 update_thread = std::thread([this, json_port](){
944 m_dynlib.StartUpdateThread(instance, json_port);
946 });
947 int timeout=5000;
948 #ifdef DEBUG
949 timeout=60*1000; // For debugger pauses
950 #endif
951 if (m_dynlib.WaitUpdateThreadReady(instance, timeout)<0) {
952 return false;
953 }
954 return true;
955 }
956
964 unsigned int GetChunkFrames() {
965 if (instance && m_dynlib.GetProcessChunkFrames) {
966 return m_dynlib.GetProcessChunkFrames(instance);
967 }
968 return 12;
969 }
970
978 void PresetManager_InformChange(const std::filesystem::path& relative_path, PresetChange_Kind change_kind)
979 {
980 if (m_dynlib.PresetManager_InformChange) {
981 m_dynlib.PresetManager_InformChange(instance, relative_path.c_str(), (bigvoice_PresetChange_Kind) change_kind);
982 }
983 }
984
996 void SetMetadata(const std::string& key, const char* value)
997 {
998 if (m_dynlib.SetMetadata) {
999 if (instance) {
1000 m_dynlib.SetMetadata(instance, key.c_str(), value);
1001 } else {
1002 init_metadata.push_back( {key, value} );
1003 }
1004 }
1005 }
1006
1007
1017 void SetMetadataMulti(const std::unordered_map<std::string, const char*>& list)
1018 {
1019 if (instance) {
1020 if (m_dynlib.SetMetadataMulti) {
1021 typedef const char* pchar;
1022 pchar* keyvalue=new pchar[2*list.size()+1];
1023 size_t n=0;
1024 for (auto&& [key,value]: list) {
1025 keyvalue[2*n+0]=key.c_str();
1026 keyvalue[2*n+1]=value;
1027 n++;
1028 }
1029 keyvalue[2*n+0]=nullptr;
1030
1031 bigvoice_SetMetadataMulti(instance, keyvalue);
1032
1033 delete[] keyvalue;
1034 } else {
1035 for (auto&& [key,value]: list) {
1036 SetMetadata(key, value);
1037 }
1038 }
1039 } else {
1040 for (auto&& [key,value]: list) {
1041 if (value) {
1042 init_metadata.push_back( {key, value} );
1043 }
1044 }
1045 }
1046 }
1047
1053 std::vector< std::tuple<std::string,std::string> > GetMetadataInfos()
1054 {
1055 std::vector< std::tuple<std::string,std::string> > values;
1056 if (m_dynlib.GetMetadataInfos) {
1057 const char** c_values = m_dynlib.GetMetadataInfos(instance);
1058 if (c_values) {
1059 for (const char** c_value=c_values; *c_value; ) {
1060 std::string key(*c_value);
1061 c_value++;
1062 if (*c_value) {
1063 std::string descr(*c_value);
1064 c_value++;
1065 values.push_back( {key,descr} );
1066 }
1067 }
1068 m_dynlib.FreeMetadataInfos(instance, c_values);
1069 }
1070 }
1071 return values;
1072 }
1073
1074 // Can be overloaded, called at start of UpdateThread in the thread
1075 virtual void OnUpdateThreadStart() {}
1076 // Can be overloaded to call at end of UpdateThread in the thread
1077 virtual void OnUpdateThreadStop() {}
1078
1079#if BIGVOICE_HAS_WEBSERVER
1085 bool StartWebServer(int http_port, int https_port=0)
1086 {
1087 assert(instance);
1088 assert(webserver==SOUND4_INVALID_WEBSERVER_ID);
1089 webserver = m_dynlib.Webserver(http_port,https_port,instance);
1090 if (webserver==SOUND4_INVALID_WEBSERVER_ID) {
1091 return false;
1092 }
1093 int web_status=m_dynlib.Webserver_Status(webserver);
1094 if (http_port && (web_status & SOUND4_WEBSERVER_HTTP_OK) == 0) {
1095 return false;
1096 }
1097 if (https_port && (web_status & SOUND4_WEBSERVER_HTTPS_OK) == 0) {
1098 return false;
1099 }
1100 return true;
1101 }
1108 {
1109 if (webserver != SOUND4_INVALID_WEBSERVER_ID) {
1110 m_dynlib.Webserver_Stop(webserver, 1000);
1111 webserver = SOUND4_INVALID_WEBSERVER_ID;
1112 }
1113 }
1114
1118 void SetWebServerAppHealth(int httpcode, const std::string& contenttype, const std::string& content)
1119 {
1120 assert(instance);
1121 if (!m_dynlib.Webserver_SetAppHealth) return;
1122 m_dynlib.Webserver_SetAppHealth(instance, httpcode, contenttype.c_str(), content.c_str());
1123 }
1127 void GetWebServerAppHealth(int &httpcode, std::string& contenttype, std::string& content)
1128 {
1129 assert(instance);
1130 if (!m_dynlib.Webserver_GetAppHealth) return;
1131 char* c_contenttype=nullptr;
1132 char* c_content=nullptr;
1133 m_dynlib.Webserver_GetAppHealth(instance, &httpcode, &c_contenttype, &c_content);
1134 contenttype=c_contenttype;
1135 content=c_content;
1136 m_dynlib.Webserver_FreeString(c_contenttype);
1137 m_dynlib.Webserver_FreeString(c_content);
1138 }
1139#endif // BIGVOICE_HAS_WEBSERVER
1140
1148 {
1149 if (!instance) return 0;
1150 return m_dynlib.TerminateProcess(instance);
1151 }
1152
1158 void Stop()
1159 {
1160 if (!instance) return;
1161#if BIGVOICE_HAS_WEBSERVER
1162 StopWebServer();
1163#endif // BIGVOICE_HAS_WEBSERVER
1164 if (update_thread.joinable()) {
1165 m_dynlib.StopUpdateThread(instance); // this will exit the update thread
1166 update_thread.join();
1167 }
1168 m_dynlib.ExitProcess(instance);
1169 instance=nullptr;
1170 }
1171
1177 unsigned int GetEstimatedDelay()
1178 {
1179 assert(instance);
1180 return m_dynlib.GetEstimatedDelay(instance);
1181 }
1182
1193 std::array<float,InputSampleSize>& GetBufferIn()
1194 {
1195 assert(instance);
1196 float *buf=m_dynlib.GetBufferIn(instance);
1197 return reinterpret_cast< std::array<float,InputSampleSize>& >(*buf);
1198
1199 }
1210 std::array<float,OutputSampleSize>& GetBufferOut()
1211 {
1212 assert(instance);
1213 float *buf= m_dynlib.GetBufferOut(instance);
1214 return reinterpret_cast< std::array<float,OutputSampleSize>& >(*buf);
1215 }
1222 {
1223 assert(instance);
1224 m_dynlib.ProcessAudio(instance, m_dynlib.GetBufferIn(instance), m_dynlib.GetBufferOut(instance));
1225 }
1239 // void ProcessAudio_Planar(const std::array< const std::array<const float,ChunkFrames>, InputChannels>& input, std::array< std::array<float,ChunkFrames>, OutputChannels>& output)
1240 void ProcessAudio_Planar(float const * const *input, float * const *output)
1241 {
1242 assert(instance);
1243 m_dynlib.ProcessAudio_Planar(instance, input, output);
1244 }
1245
1257 template<typename T>
1258 std::vector<T> ProcessAnyAudio(const std::vector<T> input)
1259 {
1260 assert(instance);
1261 std::vector<T> output;
1262 unsigned int out_offset=0;
1263 unsigned int in_offset=0;
1264 unsigned int todo = input.size();
1265 while (todo>0) {
1266 unsigned int left = AddAudio(&input[in_offset], todo);
1267 unsigned int out_avail = m_dynlib.GetOutputCount(instance);
1268 output.resize(out_offset + out_avail);
1269 GetAudio(&output[out_offset], out_avail);
1270 out_offset+=out_avail;
1271 in_offset += todo-left;
1272 todo=left;
1273 }
1274 return output;
1275 }
1276
1282 class CClient {
1283 public:
1285 : m_dynlib(dynlib)
1286 {
1287 assert(instance);
1288 client=m_dynlib.NewClient(instance);
1289 if (!client) throw std::bad_alloc();
1290 }
1291 // non-copyable
1292 CClient( const CInstance& ) = delete;
1293 CClient& operator=( const CInstance& ) = delete;
1295 {
1296 if (client) {
1297 m_dynlib.DeleteClient(client);
1298 client=nullptr;
1299 }
1300 }
1308 std::string ProcessJson(const std::string &request, bool *NeedSave = nullptr)
1309 {
1310 assert(client);
1311 int need_save=0;
1312 const char *canswer = m_dynlib.ProcessJson(client, request.c_str(), &need_save);
1313 if (!canswer) return {};
1314 std::string answer(canswer);
1315 m_dynlib.FreeJsonAnswer (canswer);
1316 if (NeedSave) {
1317 *NeedSave=(need_save!=0);
1318 }
1319 return answer;
1320 }
1321 private:
1322 CDynLib& m_dynlib;
1323 bigvoice_CClientInstance *client = nullptr;
1324 };
1332 std::shared_ptr<CClient> NewClient()
1333 {
1334 assert(instance);
1335 return std::make_shared<CClient>(instance, m_dynlib);
1336 }
1337
1338 protected:
1339 template<typename T>
1340 unsigned int AddAudio(const T* payload, unsigned int nFrame)
1341 {
1342 assert(instance);
1343 return m_dynlib.AddAudio(instance, reinterpret_cast<const T*>(payload), nFrame, helper::SampleFormat<T>::format);
1344 }
1345 template<typename T>
1346 unsigned int GetAudio(T* payload, unsigned int max_nFrame)
1347 {
1348 assert(instance);
1349 return m_dynlib.GetAudio(instance, reinterpret_cast<T*>(payload), max_nFrame, helper::SampleFormat<T>::format);
1350 }
1351
1352 private:
1353 CDynLib& m_dynlib;
1354 bigvoice_CParameters* params = nullptr;
1355 bigvoice_CInstance* instance = nullptr;
1356 std::thread update_thread;
1357 std::vector< std::pair<std::string,std::string> > init_metadata;
1358#if BIGVOICE_HAS_WEBSERVER
1359 uint64_t webserver = SOUND4_INVALID_WEBSERVER_ID;
1360#endif // BIGVOICE_HAS_WEBSERVER
1361 };
1362
1363}; // namespace dyn
1364}; // namespace bigvoice
1365}; // namespace sound4
1366
1367
1368// bridge C callbacks to CPresetLoader
1369extern "C" {
1370 static char *bigvoice_custom_reader(const fs_char *filename, void* userdata) {
1371 sound4::bigvoice::dyn::CPresetLoader *preset_loader=reinterpret_cast<sound4::bigvoice::dyn::CPresetLoader*>(userdata);
1372 std::string content=preset_loader->Read(filename);
1373 return strdup(content.c_str());
1374 }
1375 static void bigvoice_custom_reader_free(char *content, void* userdata) {
1376 if (!content) return;
1377 free(content);
1378 }
1379 static int bigvoice_custom_writer(const fs_char *filename, const char *content, void* userdata) {
1380 sound4::bigvoice::dyn::CPresetLoader *preset_loader=reinterpret_cast<sound4::bigvoice::dyn::CPresetLoader*>(userdata);
1381 auto res=preset_loader->Write(filename,content);
1382 return res?0:-1;
1383 }
1384 static int bigvoice_custom_exists(const fs_char *filename, void* userdata) {
1385 sound4::bigvoice::dyn::CPresetLoader *preset_loader=reinterpret_cast<sound4::bigvoice::dyn::CPresetLoader*>(userdata);
1386 auto res=preset_loader->Exists(filename);
1387 return res?0:-1;
1388 }
1389 static fs_char** bigvoice_custom_getall(void* userdata) {
1390 sound4::bigvoice::dyn::CPresetLoader *preset_loader=reinterpret_cast<sound4::bigvoice::dyn::CPresetLoader*>(userdata);
1391 auto res=preset_loader->GetAll();
1392 fs_char**all=(fs_char**)malloc((res.size()+1)*sizeof(const fs_char*));
1393 for (size_t n=0;n<res.size();n++) {
1394 all[n]=fs_strdup(res[n].c_str());
1395 }
1396 all[res.size()]=nullptr;
1397 return all;
1398 }
1399 static void bigvoice_custom_getall_free(fs_char** all, void* userdata) {
1400 if (!all) return;
1401 for (fs_char** one=all;*one;one++) {
1402 free(*one);
1403 }
1404 free(all);
1405 }
1406 static int bigvoice_custom_remove(const fs_char *filename, void* userdata) {
1407 sound4::bigvoice::dyn::CPresetLoader *preset_loader=reinterpret_cast<sound4::bigvoice::dyn::CPresetLoader*>(userdata);
1408 auto res=preset_loader->Remove(filename);
1409 return res?0:-1;
1410 }
1411 static int bigvoice_custom_rename(const fs_char *from, const fs_char *to, void* userdata) {
1412 sound4::bigvoice::dyn::CPresetLoader *preset_loader=reinterpret_cast<sound4::bigvoice::dyn::CPresetLoader*>(userdata);
1413 auto res=preset_loader->Rename(from,to);
1414 return res?0:-1;
1415 }
1416
1417};
helper::DynFuncHolder< decltype(bigvoice_FreeParameterValue) > FreeParameterValue
helper::DynFuncHolder< decltype(bigvoice_AudioMonoFromLiveStereo) > AudioMonoFromLiveStereo
helper::DynFuncHolder< decltype(bigvoice_Webserver_FreeString) > Webserver_FreeString
helper::DynFuncHolder< decltype(bigvoice_GetAudio) > GetAudio
helper::DynFuncHolder< decltype(bigvoice_GetSampleRate) > GetSampleRate
helper::DynFuncHolder< decltype(bigvoice_ProcessJson) > ProcessJson
helper::DynFuncHolder< decltype(bigvoice_NewClient) > NewClient
helper::DynFuncHolder< decltype(bigvoice_GetBufferOut) > GetBufferOut
helper::DynFuncHolder< decltype(bigvoice_WaitUpdateThreadReady) > WaitUpdateThreadReady
helper::DynFuncHolder< decltype(bigvoice_AudioMonoToLiveStereo) > AudioMonoToLiveStereo
helper::DynFuncHolder< decltype(bigvoice_Webserver_Stop) > Webserver_Stop
helper::DynFuncHolder< decltype(bigvoice_InitProcess3) > InitProcess3
helper::DynFuncHolder< decltype(bigvoice_GetMaxPacketFrame) > GetMaxPacketFrame
helper::DynFuncHolder< decltype(bigvoice_FreeBus) > FreeBus
helper::DynFuncHolder< decltype(bigvoice_InitProcess) > InitProcess
helper::DynFuncHolder< decltype(bigvoice_GetFormatFromName) > GetFormatFromName
helper::DynFuncHolder< decltype(bigvoice_GetVersion) > GetVersion
helper::DynFuncHolder< decltype(bigvoice_SetParameter) > SetParameter
helper::DynFuncHolder< decltype(bigvoice_NewParameters) > NewParameters
helper::DynFuncHolder< decltype(bigvoice_SetLoggerCallback) > SetLoggerCallback
helper::DynFuncHolder< decltype(bigvoice_SetInstanceBus) > SetInstanceBus
helper::DynFuncHolder< decltype(bigvoice_ProcessAudio_Planar) > ProcessAudio_Planar
helper::DynFuncHolder< decltype(bigvoice_AudioConvertTo) > AudioConvertTo
helper::DynFuncHolder< decltype(bigvoice_Webserver) > Webserver
helper::DynFuncHolder< decltype(bigvoice_ExitProcess) > ExitProcess
helper::DynFuncHolder< decltype(bigvoice_SetLogSeverity) > SetLogSeverity
bool Load(const std::filesystem::path &path={})
Loads the library.
helper::DynFuncHolder< decltype(bigvoice_GetProcessChunkFrames) > GetProcessChunkFrames
helper::DynFuncHolder< decltype(bigvoice_Webserver_tcp) > Webserver_tcp
helper::DynFuncHolder< decltype(bigvoice_Webserver_tcp2) > Webserver_tcp2
helper::DynFuncHolder< decltype(bigvoice_FreeJsonAnswer) > FreeJsonAnswer
helper::DynFuncHolder< decltype(bigvoice_StartUpdateThread) > StartUpdateThread
helper::DynFuncHolder< decltype(bigvoice_InitProcess2) > InitProcess2
helper::DynFuncHolder< decltype(bigvoice_GetAudioOutputCount) > GetAudioOutputCount
helper::DynFuncHolder< decltype(bigvoice_GetOutputCount) > GetOutputCount
helper::DynFuncHolder< decltype(bigvoice_Webserver_Status) > Webserver_Status
helper::DynFuncHolder< decltype(bigvoice_GetBufferIn) > GetBufferIn
helper::DynFuncHolder< decltype(bigvoice_PresetManager_InformChange) > PresetManager_InformChange
helper::DynFuncHolder< decltype(bigvoice_StereoToMono) > StereoToMono
helper::DynFuncHolder< decltype(bigvoice_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_Webserver_SetAppHealth) > Webserver_SetAppHealth
helper::DynFuncHolder< decltype(bigvoice_GetParameter) > GetParameter
helper::DynFuncHolder< decltype(bigvoice_GetChunkSizeInFrames) > GetChunkSizeInFrames
helper::DynFuncHolder< decltype(bigvoice_TerminateProcess) > TerminateProcess
helper::DynFuncHolder< decltype(bigvoice_FreeParameters) > FreeParameters
helper::DynFuncHolder< decltype(bigvoice_GetPossibleChunkSizeInFrames) > GetPossibleChunkSizeInFrames
helper::DynFuncHolder< decltype(bigvoice_GetEstimatedDelay) > GetEstimatedDelay
helper::DynFuncHolder< decltype(bigvoice_GetChannelCount) > GetChannelCount
std::string ProcessJson(const std::string &request, bool *NeedSave=nullptr)
Process a JSON request and returns the answer.
CClient & operator=(const CInstance &)=delete
CClient(bigvoice_CInstance *instance, CDynLib &dynlib)
void SetMetadataMulti(const std::unordered_map< std::string, const char * > &list)
std::array< float, InputSampleSize > & GetBufferIn()
unsigned int AddAudio(const T *payload, unsigned int nFrame)
void SetWebServerAppHealth(int httpcode, const std::string &contenttype, const std::string &content)
void SetMetadata(const std::string &key, const char *value)
CInstance(const CInstance &)=delete
void GetWebServerAppHealth(int &httpcode, std::string &contenttype, std::string &content)
void SetParam(const std::string &name, const std::string &value)
std::string GetParam(const std::string &name)
CInstance & operator=(const CInstance &)=delete
std::vector< T > ProcessAnyAudio(const std::vector< T > input)
unsigned int GetAudio(T *payload, unsigned int max_nFrame)
bool StartWebServer(int http_port, int https_port=0)
void ProcessAudio_Planar(float const *const *input, float *const *output)
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 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)
@ F32_NATIVE
32-bit floating-point, native
@ S16_NATIVE
16-bit signed integer, native
@ S32_NATIVE
32-bit signed integer, native
int bigvoice_SaveState(struct bigvoice_CInstance *instance)
void bigvoice_DeleteClient(struct bigvoice_CClientInstance *client)
const char * bigvoice_ProcessJson(struct bigvoice_CClientInstance *client, const char *json_str, int *need_save)
void bigvoice_FreeJsonAnswer(const char *json_str)
struct bigvoice_CClientInstance * bigvoice_NewClient(struct bigvoice_CInstance *instance)
struct bigvoice_CBus * bigvoice_NewBus()
void bigvoice_FreeBus(struct bigvoice_CBus *bus)
void bigvoice_SetInstanceBus(struct bigvoice_CParameters *params, struct bigvoice_CBus *bus)
void bigvoice_AudioConvertTo(const float *input, uint8_t *payload, size_t nSpl, enum bigvoice_SampleFormat fmt)
void bigvoice_AudioConvertFrom(const uint8_t *payload, float *output, size_t nSpl, enum bigvoice_SampleFormat fmt)
void bigvoice_AudioMonoToLiveStereo(const float *input, uint8_t *payload)
void bigvoice_StereoToMono_Planar(const float *inputL, const float *inputR, float *output, size_t nFrame)
void bigvoice_MonoToStereo_Planar(const float *input, float *outputL, float *outputR, size_t nFrame)
void bigvoice_AudioMonoFromLiveStereo(const uint8_t *payload, float *output)
void bigvoice_MonoToStereo(const float *input, float *output, size_t nFrame)
void bigvoice_StereoToMono(const float *input, float *output, size_t nFrame)
void bigvoice_ProcessAudio(struct bigvoice_CInstance *instance, const float *input, float *output)
unsigned int bigvoice_GetEstimatedDelay(struct bigvoice_CInstance *instance)
float * bigvoice_GetBufferOut(struct bigvoice_CInstance *instance)
float * bigvoice_GetBufferIn(struct bigvoice_CInstance *instance)
void bigvoice_ProcessAudio_Planar(struct bigvoice_CInstance *instance, float const *const *input, float *const *output)
#define BIGVOICE_SAMPLE_RATE
#define BIGVOICE_CHANNEL_COUNT
bigvoice_LogSeverity
unsigned int bigvoice_GetAudioInputCount()
unsigned int bigvoice_GetChannelCount()
void bigvoice_SetLoggerCallback(bigvoice_loggerfn logger)
void bigvoice_SetLogSeverity(enum bigvoice_LogSeverity severity)
#define BIGVOICE_AUDIO_OUTPUT_COUNT
unsigned int bigvoice_GetChunkSizeInFrames()
unsigned int bigvoice_GetAudioOutputCount()
#define BIGVOICE_AUDIO_INPUT_COUNT
const char * bigvoice_GetVersion()
#define BIGVOICE_AUDIOFRAME_COUNT
unsigned int bigvoice_GetSampleRate()
unsigned int * bigvoice_GetPossibleChunkSizeInFrames()
void bigvoice_FreeParameterValue(const char *value)
int bigvoice_TerminateProcess(struct bigvoice_CInstance *instance)
struct bigvoice_CInstance * bigvoice_InitProcess3(const char *LoginKey, const char *RadioName, const char *Access_Key_ID, const char *Access_Key_Secret, const char *save_path, const struct bigvoice_CParameters *parameters, unsigned int frames_per_chunk)
void bigvoice_FreeParameters(struct bigvoice_CParameters *params)
void bigvoice_ExitProcess(struct bigvoice_CInstance *instance)
struct bigvoice_CParameters * bigvoice_NewParameters()
unsigned int bigvoice_GetProcessChunkFrames(struct bigvoice_CInstance *instance)
struct bigvoice_CInstance * bigvoice_InitProcess2(const char *LoginKey, const char *RadioName, const char *Access_Key_ID, const char *Access_Key_Secret, const char *save_path, const struct bigvoice_CParameters *parameters)
void bigvoice_SetParameter(struct bigvoice_CParameters *params, const char *name, const char *value)
struct bigvoice_CInstance * bigvoice_InitProcess(const char *LoginKey, const char *RadioName, const char *Access_Key_ID, const char *Access_Key_Secret, const char *save_path)
const char * bigvoice_GetParameter(struct bigvoice_CParameters *params, const char *name)
void bigvoice_FreeMetadataInfos(struct bigvoice_CInstance *instance, const char **infos)
void bigvoice_SetMetadata(struct bigvoice_CInstance *instance, const char *key, const char *value)
const char ** bigvoice_GetMetadataInfos(struct bigvoice_CInstance *instance)
void bigvoice_SetMetadataMulti(struct bigvoice_CInstance *instance, const char **keyvalue)
bigvoice_PresetChange_Kind
void bigvoice_SetPresetManager(struct bigvoice_CParameters *params, bigvoice_storage_reader reader, bigvoice_storage_reader_free, bigvoice_storage_writer writer, bigvoice_storage_exists exists, bigvoice_storage_getall getall, bigvoice_storage_getall_free getall_free, bigvoice_storage_remove remove, bigvoice_storage_rename rename, int IsReadOnly, void *userdata)
void bigvoice_PresetManager_InformChange(struct bigvoice_CInstance *instance, const fs_char *relative_path, enum bigvoice_PresetChange_Kind change_kind)
wchar_t fs_char
void bigvoice_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)
std::function< void(LogSeverity, const std::string &)> log_cb_t
bigvoice_SampleFormat SampleFormat
const LogSeverity info
Definition sound4cl.hpp:248
std::function< void(LogSeverity, const std::string &)> log_cb_t
Definition sound4cl.hpp:258
C interface for library.
#define fs_strdup
helper for OS dependant file name copy