SOUND4 BIGVOICE.CL Library [1.0.3]
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 #ifdef __unix__
21  #include <dlfcn.h>
22 #elif defined(_WIN32)
23  #include <libloaderapi.h>
24 #else
25  #error "Unsupported OS"
26 #endif
27 
28 // Needed to have function declarations
29 #include "sound4.bigvoice.cl.h"
30 
31 
32 #ifdef _WIN32
33  #include <stringapiset.h>
34  #include <wchar.h>
36  #define fs_strdup wcsdup
37 #else // !_WIN32
39  #define fs_strdup strdup
40 #endif // !_WIN32
41 
42 // bridge C callbacks to CPresetLoader
43 extern "C" {
44  static char *bigvoice_custom_reader(const fs_char *filename, void* userdata);
45  static void bigvoice_custom_reader_free(char *content, void* userdata);
46  static int bigvoice_custom_writer(const fs_char *filename, const char *content, void* userdata);
47  static int bigvoice_custom_exists(const fs_char *filename, void* userdata);
48  static fs_char** bigvoice_custom_getall(void* userdata);
49  static void bigvoice_custom_getall_free(fs_char** all, void* userdata);
50  static int bigvoice_custom_remove(const fs_char *filename, void* userdata);
51  static int bigvoice_custom_rename(const fs_char *from, const fs_char *to, void* userdata);
52 };
53 
57 namespace sound4 {
61 namespace bigvoice {
65 namespace dyn {
66 
70  namespace helper {
71  // Storage definition, depending on OS
72  #ifdef __unix__
73  using DynLib_t = void *;
74  using DynFunc_t = void *;
75  #else
76  using DynLib_t = HMODULE;
77  using DynFunc_t = FARPROC;
78  #endif
79 
85  template <typename T>
86  class DynFuncHolder {
87  private:
88  DynFunc_t m_ptr = NULL;
89  public:
90  DynFuncHolder() = default;
91  DynFuncHolder(DynFunc_t a_ptr) : m_ptr(a_ptr) {}
92  operator bool() const { return (m_ptr!=NULL); }
93  bool IsOk() const { return m_ptr!=NULL; }
94  operator T* () const { return reinterpret_cast<T*>(m_ptr); }
95  };
96 
101  class CDynLoader {
102  private:
103  DynLib_t m_lib {};
104  public:
105  CDynLoader() = default;
106  CDynLoader(CDynLoader&&) = default;
107  // No copy allowed
108  CDynLoader(const CDynLoader&) = delete;
109  CDynLoader& operator=(CDynLoader const&) = delete;
110  operator bool() const {
111  return (m_lib!=NULL);
112  }
113  bool IsOk() const {
114  return (m_lib!=NULL);
115  }
116  #ifdef __unix__
117  void Close() {
118  if (IsOk()) {
119  #ifndef __SANITIZE_ADDRESS__ // avoid unloading to keep call stack
120  dlclose(m_lib);
121  #endif // __SANITIZE_ADDRESS__
122  m_lib=NULL;
123  }
124  }
125  bool Load(const std::filesystem::path& dynlib)
126  {
127  Close();
128  m_lib=dlopen(dynlib.c_str(), RTLD_NOW|RTLD_LOCAL);
129  return IsOk();
130  }
131  template <typename T>
132  DynFuncHolder<T> GetSymbol(const std::string& name) {
133  auto ptr=dlsym(m_lib, name.c_str());
134  if (!ptr) {
135  throw std::runtime_error("Missing function in library");
136  }
137  return DynFuncHolder<T>(ptr);
138  }
139  template <typename T>
140  DynFuncHolder<T> GetSymbol_safe(const std::string& name) {
141  auto ptr=dlsym(m_lib, name.c_str());
142  return DynFuncHolder<T>(ptr);
143  }
144  static std::filesystem::path GetThisLibraryPath(void) {
145  static Dl_info info;
146  if (! dladdr((void *) GetThisLibraryPath, & info)) return {};
147  auto rp=realpath(info.dli_fname, NULL);
148  std::filesystem::path p(rp);
149  free(rp);
150  return p;
151  }
152  #else
153  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)
154  {
155  Close();
156  m_lib=LoadLibraryExW(dynlib.c_str(), NULL, loadflags);
157  return IsOk();
158  }
159  void Close() {
160  if (IsOk()) {
161  // NOTE: On Windows, FreeLibrary may create a lot of troubles, should use FreeLibraryAndExitThread but...
162  // So define SOUND4_CALL_FREELIBRARY before including this file if you really want to unload the library dynamically
163  #if defined(SOUND4_CALL_FREELIBRARYANDEXITTHREAD)
164  FreeLibraryAndExitThread(m_lib, 0);
165  #elif defined(SOUND4_CALL_FREELIBRARY)
166  FreeLibrary(m_lib);
167  #endif // SOUND4_CALL_FREELIBRARY
168  m_lib=NULL;
169  }
170  }
171  template <typename T>
172  DynFuncHolder<T> GetSymbol(const std::string& name) {
173  auto ptr=GetProcAddress(m_lib, name.c_str());
174  if (!ptr) {
175  throw std::runtime_error("Missing function in library");
176  }
177  return DynFuncHolder<T>(ptr);
178  }
179  template <typename T>
180  DynFuncHolder<T> GetSymbol_safe(const std::string& name) {
181  auto ptr=GetProcAddress(m_lib, name.c_str());
182  return DynFuncHolder<T>(ptr);
183  }
184  static std::filesystem::path GetThisLibraryPath(void) {
185  static wchar_t path[MAX_PATH]={};
186  HMODULE hm = NULL;
187  if (GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
188  GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
189  (LPCWSTR) &GetThisLibraryPath, &hm))
190  {
191  if (GetModuleFileNameW(hm, path, MAX_PATH) > 0) {
192  return std::filesystem::path(path);
193  }
194  }
195  return {};
196  }
197  #endif
198  virtual ~CDynLoader() {
199  Close();
200  }
201  }; // class CDynLoader
202  }; // namespace helper
203 
210  class CDynLib {
211  private:
212  helper::CDynLoader m_lib;
213  bool m_bOK = false;
214  public:
215  CDynLib() = default;
216 
217  // All those wrapped functions have the same signature as there C bigvoice_XXX
262 #if BIGVOICE_HAS_WEBSERVER
268 #endif // BIGVOICE_HAS_WEBSERVER
269 
270  // added 2023-03-22
273 
274  // added 2023-05-22
278 
279  // added 2023-06-20
282 
283  // added 2023-09-21
287 
288 #if BIGVOICE_HAS_CLOUDBUS
289  // added 2023-06-26
293 #endif // BIGVOICE_HAS_CLOUDBUS
294 
295  // added 2024-02-19
297 
305  bool Load(const std::filesystem::path& path = {}) {
306  std::string filename;
307  #ifdef __unix__
308  filename="libsound4.bigvoice.cl.so";
309  #else
310  filename="sound4.bigvoice.cl.dll";
311  #endif
312  m_lib.Close();
313  // If a path is given, use it directly and do not try other path
314  if (!path.empty() && !m_lib.Load(path / filename)) {
315  return false;
316  } else if (!m_lib.IsOk()) {
317  auto thisdir=helper::CDynLoader::GetThisLibraryPath().parent_path();
318  #ifndef _WIN32
319  // Linux: if in a bin directory, try ../lib first
320  if (!m_lib.IsOk() && thisdir.filename()=="bin") {
321  auto libdir = thisdir.parent_path() / "lib";
322  m_lib.Load(libdir / filename);
323  }
324  #endif // !_WIN32
325  if (!m_lib.IsOk()) {
326  // Search in the same directory this code is in
327  m_lib.Load(thisdir / filename);
328  }
329  if (!m_lib.IsOk()) {
330  // Try current path
331  m_lib.Load(std::filesystem::current_path() / filename);
332  }
333  if (!m_lib.IsOk()) {
334  return false;
335  }
336  }
337  // Load all C functions
338  try {
339  GetVersion = m_lib.GetSymbol< decltype(bigvoice_GetVersion ) >("bigvoice_GetVersion" );
340  GetChunkSizeInFrames = m_lib.GetSymbol< decltype(bigvoice_GetChunkSizeInFrames ) >("bigvoice_GetChunkSizeInFrames" );
341  GetChannelCount = m_lib.GetSymbol< decltype(bigvoice_GetChannelCount ) >("bigvoice_GetChannelCount" );
342  GetAudioInputCount = m_lib.GetSymbol< decltype(bigvoice_GetAudioInputCount ) >("bigvoice_GetAudioInputCount" );
343  GetAudioOutputCount = m_lib.GetSymbol< decltype(bigvoice_GetAudioOutputCount ) >("bigvoice_GetAudioOutputCount" );
344  GetSampleRate = m_lib.GetSymbol< decltype(bigvoice_GetSampleRate ) >("bigvoice_GetSampleRate" );
345  SetLoggerCallback = m_lib.GetSymbol< decltype(bigvoice_SetLoggerCallback ) >("bigvoice_SetLoggerCallback" );
346  SetLogSeverity = m_lib.GetSymbol< decltype(bigvoice_SetLogSeverity ) >("bigvoice_SetLogSeverity" );
347  NewParameters = m_lib.GetSymbol< decltype(bigvoice_NewParameters ) >("bigvoice_NewParameters" );
348  FreeParameters = m_lib.GetSymbol< decltype(bigvoice_FreeParameters ) >("bigvoice_FreeParameters" );
349  SetParameter = m_lib.GetSymbol< decltype(bigvoice_SetParameter ) >("bigvoice_SetParameter" );
350  GetParameter = m_lib.GetSymbol< decltype(bigvoice_GetParameter ) >("bigvoice_GetParameter" );
351  FreeParameterValue = m_lib.GetSymbol< decltype(bigvoice_FreeParameterValue ) >("bigvoice_FreeParameterValue" );
352  InitProcess = m_lib.GetSymbol< decltype(bigvoice_InitProcess ) >("bigvoice_InitProcess" );
353  InitProcess2 = m_lib.GetSymbol< decltype(bigvoice_InitProcess2 ) >("bigvoice_InitProcess2" );
354  TerminateProcess = m_lib.GetSymbol< decltype(bigvoice_TerminateProcess ) >("bigvoice_TerminateProcess" );
355  ExitProcess = m_lib.GetSymbol< decltype(bigvoice_ExitProcess ) >("bigvoice_ExitProcess" );
356  StartUpdateThread = m_lib.GetSymbol< decltype(bigvoice_StartUpdateThread ) >("bigvoice_StartUpdateThread" );
357  StopUpdateThread = m_lib.GetSymbol< decltype(bigvoice_StopUpdateThread ) >("bigvoice_StopUpdateThread" );
358  WaitUpdateThreadReady = m_lib.GetSymbol< decltype(bigvoice_WaitUpdateThreadReady ) >("bigvoice_WaitUpdateThreadReady" );
359  ProcessAudio = m_lib.GetSymbol< decltype(bigvoice_ProcessAudio ) >("bigvoice_ProcessAudio" );
360  ProcessAudio_Planar = m_lib.GetSymbol< decltype(bigvoice_ProcessAudio_Planar ) >("bigvoice_ProcessAudio_Planar" );
361  GetBufferIn = m_lib.GetSymbol< decltype(bigvoice_GetBufferIn ) >("bigvoice_GetBufferIn" );
362  GetBufferOut = m_lib.GetSymbol< decltype(bigvoice_GetBufferOut ) >("bigvoice_GetBufferOut" );
363  GetEstimatedDelay = m_lib.GetSymbol< decltype(bigvoice_GetEstimatedDelay ) >("bigvoice_GetEstimatedDelay" );
364  GetFormatName = m_lib.GetSymbol< decltype(bigvoice_GetFormatName ) >("bigvoice_GetFormatName" );
365  GetFormatFromName = m_lib.GetSymbol< decltype(bigvoice_GetFormatFromName ) >("bigvoice_GetFormatFromName" );
366  GetBytesFromFormat = m_lib.GetSymbol< decltype(bigvoice_GetBytesFromFormat ) >("bigvoice_GetBytesFromFormat" );
367  GetMaxPacketFrame = m_lib.GetSymbol< decltype(bigvoice_GetMaxPacketFrame ) >("bigvoice_GetMaxPacketFrame" );
368  AddAudio = m_lib.GetSymbol< decltype(bigvoice_AddAudio ) >("bigvoice_AddAudio" );
369  AddPadAudio = m_lib.GetSymbol< decltype(bigvoice_AddPadAudio ) >("bigvoice_AddPadAudio" );
370  GetOutputCount = m_lib.GetSymbol< decltype(bigvoice_GetOutputCount ) >("bigvoice_GetOutputCount" );
371  GetAudio = m_lib.GetSymbol< decltype(bigvoice_GetAudio ) >("bigvoice_GetAudio" );
372  AudioConvertFrom = m_lib.GetSymbol< decltype(bigvoice_AudioConvertFrom ) >("bigvoice_AudioConvertFrom" );
373  AudioConvertTo = m_lib.GetSymbol< decltype(bigvoice_AudioConvertTo ) >("bigvoice_AudioConvertTo" );
374  StereoToMono = m_lib.GetSymbol< decltype(bigvoice_StereoToMono ) >("bigvoice_StereoToMono" );
375  MonoToStereo = m_lib.GetSymbol< decltype(bigvoice_MonoToStereo ) >("bigvoice_MonoToStereo" );
376  AudioMonoFromLiveStereo = m_lib.GetSymbol< decltype(bigvoice_AudioMonoFromLiveStereo) >("bigvoice_AudioMonoFromLiveStereo");
377  AudioMonoToLiveStereo = m_lib.GetSymbol< decltype(bigvoice_AudioMonoToLiveStereo ) >("bigvoice_AudioMonoToLiveStereo" );
378  NewClient = m_lib.GetSymbol< decltype(bigvoice_NewClient ) >("bigvoice_NewClient" );
379  DeleteClient = m_lib.GetSymbol< decltype(bigvoice_DeleteClient ) >("bigvoice_DeleteClient" );
380  ProcessJson = m_lib.GetSymbol< decltype(bigvoice_ProcessJson ) >("bigvoice_ProcessJson" );
381  FreeJsonAnswer = m_lib.GetSymbol< decltype(bigvoice_FreeJsonAnswer ) >("bigvoice_FreeJsonAnswer" );
382  SaveState = m_lib.GetSymbol< decltype(bigvoice_SaveState ) >("bigvoice_SaveState" );
383 #if BIGVOICE_HAS_WEBSERVER
384  Webserver_tcp = m_lib.GetSymbol< decltype(bigvoice_Webserver_tcp ) >("bigvoice_Webserver_tcp" );
385  Webserver_tcp2 = m_lib.GetSymbol< decltype(bigvoice_Webserver_tcp2 ) >("bigvoice_Webserver_tcp2" );
386  Webserver = m_lib.GetSymbol< decltype(bigvoice_Webserver ) >("bigvoice_Webserver" );
387  Webserver_Stop = m_lib.GetSymbol< decltype(bigvoice_Webserver_Stop ) >("bigvoice_Webserver_Stop" );
388  Webserver_Status = m_lib.GetSymbol< decltype(bigvoice_Webserver_Status ) >("bigvoice_Webserver_Status" );
389 #endif // BIGVOICE_HAS_WEBSERVER
390 
391  // added 2023-03-22
392  StereoToMono_Planar = m_lib.GetSymbol< decltype(bigvoice_StereoToMono_Planar ) >("bigvoice_StereoToMono_Planar" );
393  MonoToStereo_Planar = m_lib.GetSymbol< decltype(bigvoice_MonoToStereo_Planar ) >("bigvoice_MonoToStereo_Planar" );
394 
395  } catch (std::runtime_error& ) {
396  return false;
397  }
398  // C functions allowed to be missing
399  try {
400  // added 2023-05-22
401  SetMetadata = m_lib.GetSymbol< decltype(bigvoice_SetMetadata ) >("bigvoice_SetMetadata" );
402  GetMetadataInfos = m_lib.GetSymbol< decltype(bigvoice_GetMetadataInfos ) >("bigvoice_GetMetadataInfos" );
403  FreeMetadataInfos = m_lib.GetSymbol< decltype(bigvoice_FreeMetadataInfos ) >("bigvoice_FreeMetadataInfos" );
404  // added 2023-06-20
405  SetPresetManager = m_lib.GetSymbol< decltype(bigvoice_SetPresetManager ) >("bigvoice_SetPresetManager" );
406  PresetManager_InformChange = m_lib.GetSymbol< decltype(bigvoice_PresetManager_InformChange ) >("bigvoice_PresetManager_InformChange" );
407 
408  // added 2023-09-21
409  GetPossibleChunkSizeInFrames = m_lib.GetSymbol< decltype(bigvoice_GetPossibleChunkSizeInFrames ) >("bigvoice_GetPossibleChunkSizeInFrames" );
410  GetProcessChunkFrames = m_lib.GetSymbol< decltype(bigvoice_GetProcessChunkFrames ) >("bigvoice_GetProcessChunkFrames" );
411  InitProcess3 = m_lib.GetSymbol< decltype(bigvoice_InitProcess3 ) >("bigvoice_InitProcess3" );
412 
413 #if BIGVOICE_HAS_CLOUDBUS
414  // added 2023-06-26
415  NewBus = m_lib.GetSymbol< decltype(bigvoice_NewBus ) >("bigvoice_NewBus" );
416  FreeBus = m_lib.GetSymbol< decltype(bigvoice_FreeBus ) >("bigvoice_FreeBus" );
417  SetInstanceBus = m_lib.GetSymbol< decltype(bigvoice_SetInstanceBus ) >("bigvoice_SetInstanceBus" );
418 #endif // BIGVOICE_HAS_CLOUDBUS
419 
420  // added 2024-02-19
421  SetMetadataMulti = m_lib.GetSymbol< decltype(bigvoice_SetMetadataMulti ) >("bigvoice_SetMetadataMulti" );
422 
423  } catch (std::runtime_error& ) {
424  // Ignored, handler will take care
425  }
426 
427  m_bOK=true;
428  return true;
429  }
436  bool IsOk() const {
437  return m_bOK;
438  }
439 
440  };
441 
442 
443 
444  static constexpr const char *process_name = "SOUND4 BIGVOICE.CL";
445  static constexpr const char *process_shortname = "bigvoice";
471 
475  namespace helper {
476  #ifdef _WIN32
482  static inline std::string WStringToUTF8(const std::wstring& wstr) {
483  if (wstr.empty()) return {};
484  int size = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), NULL, 0, NULL, NULL);
485  std::string str(size, 0);
486  WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), &str[0], size, NULL, NULL);
487  return str;
488  }
494  static inline std::wstring UTF8ToWString(const std::string& str) {
495  if (str.empty()) return std::wstring();
496  int size = MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), NULL, 0);
497  std::wstring wstr(size, 0);
498  MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), &wstr[0], size);
499  return wstr;
500  }
501  #endif // _WIN32
502 
508  template<typename T>
509  struct SampleFormat {
510  };
511  template<>
512  struct SampleFormat<int16_t> {
514  };
515  template<>
516  struct SampleFormat<int32_t> {
518  };
519  template<>
520  struct SampleFormat<float> {
522  };
523 
524 
529  static inline void AudioConvertFrom(CDynLib& dynlib, const uint8_t *payload, float *output, size_t nSpl, bigvoice_SampleFormat fmt) {
530  dynlib.AudioConvertFrom(payload, output, nSpl, fmt);
531  }
532  static inline void AudioConvertTo(CDynLib& dynlib, const float *input, uint8_t *payload, size_t nSpl, bigvoice_SampleFormat fmt) {
533  dynlib.AudioConvertTo(input, payload, nSpl, fmt);
534  }
535  static inline void StereoToMono(CDynLib& dynlib, const float *input, float *output, size_t nSpl) {
536  dynlib.StereoToMono(input, output, nSpl);
537  }
538  static inline void MonoToStereo(CDynLib& dynlib, const float *input, float *output, size_t nSpl) {
539  dynlib.MonoToStereo(input, output, nSpl);
540  }
541  static inline void StereoToMono_Planar(CDynLib& dynlib, const float *inputL, const float *inputR, float *output, size_t nSpl) {
542  dynlib.StereoToMono_Planar(inputL, inputR, output, nSpl);
543  }
544  static inline void MonoToStereo_Planar(CDynLib& dynlib, const float *input, float *outputL, float *outputR, size_t nSpl) {
545  dynlib.MonoToStereo_Planar(input, outputL, outputR, nSpl);
546  }
547  static inline void AudioMonoFromLiveStereo(CDynLib& dynlib, const uint8_t *payload, float *output) {
548  dynlib.AudioMonoFromLiveStereo(payload, output);
549  }
550  static inline void AudioMonoToLiveStereo(CDynLib& dynlib, const float *input, uint8_t *payload) {
551  dynlib.AudioMonoToLiveStereo(input, payload);
552  }
553 
554  }; // namespace helper
555 
561  static inline std::string GetVersion(CDynLib& dynlib)
562  {
563  return std::string(dynlib.GetVersion());
564  }
565 
576  static inline unsigned int GetChunkSizeInFrames(CDynLib& dynlib)
577  {
578  return dynlib.GetChunkSizeInFrames();
579  }
580 
589  static inline std::vector<unsigned int> GetPossibleChunkSizeInFrames(CDynLib& dynlib)
590  {
591  std::vector<unsigned int> list;
592  if (dynlib.GetPossibleChunkSizeInFrames) {
593  for (unsigned int* src=dynlib.GetPossibleChunkSizeInFrames();*src;src++) {
594  list.push_back(*src);
595  }
596  } else {
597  list.push_back(12);
598  }
599  return list;
600  }
601 
609  static inline unsigned int GetChannelCount(CDynLib& dynlib)
610  {
611  return dynlib.GetChannelCount();
612  }
613 
622  static inline unsigned int GetAudioInputCount(CDynLib& dynlib)
623  {
624  return dynlib.GetAudioInputCount();
625  }
626 
635  static inline unsigned int GetAudioOutputCount(CDynLib& dynlib)
636  {
637  return dynlib.GetAudioOutputCount();
638  }
639 
647  static inline unsigned int GetSampleRate(CDynLib& dynlib)
648  {
649  return dynlib.GetSampleRate();
650  }
651 
657  static inline void SanityCheck(CDynLib& dynlib, bool a_bCheckFrames = true)
658  {
659  // Do some sanity checks
660  if (dynlib.GetSampleRate()!=BIGVOICE_SAMPLE_RATE) {
661  throw std::runtime_error("Bad library sampling rate");
662  }
663  if (a_bCheckFrames && dynlib.GetChunkSizeInFrames()!=ChunkFrames) {
664  throw std::runtime_error("Bad library frame size");
665  }
666  if (dynlib.GetChannelCount()!=BIGVOICE_CHANNEL_COUNT) {
667  throw std::runtime_error("Bad library channel count");
668  }
669  if (dynlib.GetAudioInputCount()!=BIGVOICE_AUDIO_INPUT_COUNT) {
670  throw std::runtime_error("Bad library input count");
671  }
672  if (dynlib.GetAudioOutputCount()!=BIGVOICE_AUDIO_OUTPUT_COUNT) {
673  throw std::runtime_error("Bad library output count");
674  }
675  }
676 
683  static inline std::string GetFormatName(CDynLib& dynlib, const SampleFormat fmt)
684  {
685  return std::string(dynlib.GetFormatName(fmt));
686  }
687 
694  static inline SampleFormat GetFormatFromName(CDynLib& dynlib, const std::string& name)
695  {
696  return dynlib.GetFormatFromName(name.c_str());
697  }
698 
705  static inline unsigned int GetBytesFromFormat(CDynLib& dynlib, const SampleFormat fmt)
706  {
707  return dynlib.GetBytesFromFormat(fmt);
708  }
709 
717  using log_cb_t = std::function<void(LogSeverity,const std::string&)>;
718 
722  static log_cb_t _log_cb;
723  extern "C" {
724  static inline void _log_cb_c(bigvoice_LogSeverity severity, const char *c_msg) {
725  _log_cb(severity, std::string(c_msg));
726  }
727  }
731  static inline void SetLogSeverity(CDynLib& dynlib, LogSeverity severity)
732  {
733  dynlib.SetLogSeverity(severity);
734  }
738  static inline void SetLoggerCallback(CDynLib& dynlib, log_cb_t cb)
739  {
740  _log_cb=cb;
741  dynlib.SetLoggerCallback(&_log_cb_c);
742  }
743 
744 #if BIGVOICE_HAS_CLOUDBUS
745  class CBus {
746  public:
747  CBus(CDynLib& dynlib)
748  : m_dynlib(dynlib)
749  {
750  if (m_dynlib.NewBus) {
751  m_bus=m_dynlib.NewBus();
752  }
753  }
755  {
756  if (m_bus && m_dynlib.FreeBus) {
757  m_dynlib.FreeBus(m_bus);
758  }
759  m_bus = nullptr;
760  }
761  bigvoice_CBus *Get() const { return m_bus; }
762  private:
763  CDynLib& m_dynlib;
764  bigvoice_CBus *m_bus;
765  };
766 #endif // BIGVOICE_HAS_CLOUDBUS
767 
773  public:
774  CPresetLoader() = default;
775  virtual ~CPresetLoader() = default;
776 
777  virtual bool IsReadOnly() = 0;
778  virtual bool Exists(const std::filesystem::path &name) = 0;
779  virtual bool Remove(const std::filesystem::path &name) = 0;
780  virtual bool Rename(const std::filesystem::path &from, const std::filesystem::path &to) = 0;
781  virtual std::vector<std::filesystem::path> GetAll() = 0;
782  virtual std::string Read(const std::filesystem::path &filename) = 0;
783  virtual bool Write(const std::filesystem::path &filename, const std::string &content) =0;
784  };
786 
790  class CInstance {
791  public:
796  : m_dynlib(dynlib)
797  {
798  params = m_dynlib.NewParameters();
799  if (!params) throw std::bad_alloc();
800  }
801  // non-copyable
802  CInstance( const CInstance& ) = delete;
803  CInstance& operator=( const CInstance& ) = delete;
808  {
809  Stop();
810  if (params) m_dynlib.FreeParameters(params);
811  }
815  bool IsOk() const { return instance!=nullptr; }
823  void SetParam(const std::string& name, const std::string& value)
824  {
825  assert(params);
826  m_dynlib.SetParameter(params, name.c_str(), value.c_str());
827  }
833  std::string GetParam(const std::string& name)
834  {
835  assert(params);
836  auto c_value=m_dynlib.GetParameter(params, name.c_str());
837  std::string ret(c_value);
838  m_dynlib.FreeParameterValue(c_value);
839  return ret;
840  }
841 #if BIGVOICE_HAS_CLOUDBUS
845  void SetBus(const CBus& bus) {
846  assert(params);
847  if (m_dynlib.SetInstanceBus) {
848  m_dynlib.SetInstanceBus(params,bus.Get());
849  }
850  }
851 #endif // BIGVOICE_HAS_CLOUDBUS
852 
862  void SetPresetManager(CPresetLoader *preset_manager)
863  {
864  if (!preset_manager) return;
865  if (!m_dynlib.SetPresetManager) return;
866  assert(params);
867  m_dynlib.SetPresetManager(params,
868  bigvoice_custom_reader,
869  bigvoice_custom_reader_free,
870  bigvoice_custom_writer,
871  bigvoice_custom_exists,
872  bigvoice_custom_getall,
873  bigvoice_custom_getall_free,
874  bigvoice_custom_remove,
875  bigvoice_custom_rename,
876  preset_manager->IsReadOnly(),
877  preset_manager
878  );
879  }
880 
895  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)
896  {
897  assert(!instance);
898  std::string l_save_path;
899  if (!save_path.empty()) {
900  l_save_path = save_path.u8string();
901  }
902  if (m_dynlib.InitProcess3) {
903  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);
904  } else if (frames_per_chunk!=12) {
905  return false;
906  } else {
907  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);
908  }
909  if (!instance) return false;
910  if (!init_metadata.empty()) {
911  for (auto&& [key,value]: init_metadata) {
912  m_dynlib.SetMetadata(instance, key.c_str(), value.c_str());
913  }
914  init_metadata.clear();
915  }
916  update_thread = std::thread([this, json_port](){
918  m_dynlib.StartUpdateThread(instance, json_port);
920  });
921  int timeout=5000;
922  #ifdef DEBUG
923  timeout=60*1000; // For debugger pauses
924  #endif
925  if (m_dynlib.WaitUpdateThreadReady(instance, timeout)<0) {
926  return false;
927  }
928  return true;
929  }
930 
938  unsigned int GetChunkFrames() {
939  if (instance && m_dynlib.GetProcessChunkFrames) {
940  return m_dynlib.GetProcessChunkFrames(instance);
941  }
942  return 12;
943  }
944 
952  void PresetManager_InformChange(const std::filesystem::path& relative_path, PresetChange_Kind change_kind)
953  {
954  if (m_dynlib.PresetManager_InformChange) {
955  m_dynlib.PresetManager_InformChange(instance, relative_path.c_str(), (bigvoice_PresetChange_Kind) change_kind);
956  }
957  }
958 
970  void SetMetadata(const std::string& key, const char* value)
971  {
972  if (m_dynlib.SetMetadata) {
973  if (instance) {
974  m_dynlib.SetMetadata(instance, key.c_str(), value);
975  } else {
976  init_metadata.push_back( {key, value} );
977  }
978  }
979  }
980 
981 
991  void SetMetadataMulti(const std::unordered_map<std::string, const char*>& list)
992  {
993  if (instance) {
994  if (m_dynlib.SetMetadataMulti) {
995  typedef const char* pchar;
996  pchar* keyvalue=new pchar[2*list.size()+1];
997  size_t n=0;
998  for (auto&& [key,value]: list) {
999  keyvalue[2*n+0]=key.c_str();
1000  keyvalue[2*n+1]=value;
1001  n++;
1002  }
1003  keyvalue[2*n+0]=nullptr;
1004 
1005  bigvoice_SetMetadataMulti(instance, keyvalue);
1006 
1007  delete[] keyvalue;
1008  } else {
1009  for (auto&& [key,value]: list) {
1010  SetMetadata(key, value);
1011  }
1012  }
1013  } else {
1014  for (auto&& [key,value]: list) {
1015  if (value) {
1016  init_metadata.push_back( {key, value} );
1017  }
1018  }
1019  }
1020  }
1021 
1027  std::vector< std::tuple<std::string,std::string> > GetMetadataInfos()
1028  {
1029  std::vector< std::tuple<std::string,std::string> > values;
1030  if (m_dynlib.GetMetadataInfos) {
1031  const char** c_values = m_dynlib.GetMetadataInfos(instance);
1032  if (c_values) {
1033  for (const char** c_value=c_values; *c_value; ) {
1034  std::string key(*c_value);
1035  c_value++;
1036  if (*c_value) {
1037  std::string descr(*c_value);
1038  c_value++;
1039  values.push_back( {key,descr} );
1040  }
1041  }
1042  m_dynlib.FreeMetadataInfos(instance, c_values);
1043  }
1044  }
1045  return values;
1046  }
1047 
1048  // Can be overloaded, called at start of UpdateThread in the thread
1049  virtual void OnUpdateThreadStart() {}
1050  // Can be overloaded to call at end of UpdateThread in the thread
1051  virtual void OnUpdateThreadStop() {}
1052 
1053 #if BIGVOICE_HAS_WEBSERVER
1059  bool StartWebServer(int http_port, int https_port=0)
1060  {
1061  assert(instance);
1062  assert(webserver==SOUND4_INVALID_WEBSERVER_ID);
1063  webserver = m_dynlib.Webserver(http_port,https_port,instance);
1064  if (webserver==SOUND4_INVALID_WEBSERVER_ID) {
1065  return false;
1066  }
1067  int web_status=m_dynlib.Webserver_Status(webserver);
1068  if (http_port && (web_status & SOUND4_WEBSERVER_HTTP_OK) == 0) {
1069  return false;
1070  }
1071  if (https_port && (web_status & SOUND4_WEBSERVER_HTTPS_OK) == 0) {
1072  return false;
1073  }
1074  return true;
1075  }
1082  {
1083  if (webserver != SOUND4_INVALID_WEBSERVER_ID) {
1084  m_dynlib.Webserver_Stop(webserver, 1000);
1085  webserver = SOUND4_INVALID_WEBSERVER_ID;
1086  }
1087  }
1088 #endif // BIGVOICE_HAS_WEBSERVER
1089 
1097  {
1098  if (!instance) return 0;
1099  return m_dynlib.TerminateProcess(instance);
1100  }
1101 
1107  void Stop()
1108  {
1109  if (!instance) return;
1110 #if BIGVOICE_HAS_WEBSERVER
1111  StopWebServer();
1112 #endif // BIGVOICE_HAS_WEBSERVER
1113  if (update_thread.joinable()) {
1114  m_dynlib.StopUpdateThread(instance); // this will exit the update thread
1115  update_thread.join();
1116  }
1117  m_dynlib.ExitProcess(instance);
1118  instance=nullptr;
1119  }
1120 
1126  unsigned int GetEstimatedDelay()
1127  {
1128  assert(instance);
1129  return m_dynlib.GetEstimatedDelay(instance);
1130  }
1131 
1142  std::array<float,InputSampleSize>& GetBufferIn()
1143  {
1144  assert(instance);
1145  float *buf=m_dynlib.GetBufferIn(instance);
1146  return reinterpret_cast< std::array<float,InputSampleSize>& >(*buf);
1147 
1148  }
1159  std::array<float,OutputSampleSize>& GetBufferOut()
1160  {
1161  assert(instance);
1162  float *buf= m_dynlib.GetBufferOut(instance);
1163  return reinterpret_cast< std::array<float,OutputSampleSize>& >(*buf);
1164  }
1171  {
1172  assert(instance);
1173  m_dynlib.ProcessAudio(instance, m_dynlib.GetBufferIn(instance), m_dynlib.GetBufferOut(instance));
1174  }
1188  // void ProcessAudio_Planar(const std::array< const std::array<const float,ChunkFrames>, InputChannels>& input, std::array< std::array<float,ChunkFrames>, OutputChannels>& output)
1189  void ProcessAudio_Planar(float const * const *input, float * const *output)
1190  {
1191  assert(instance);
1192  m_dynlib.ProcessAudio_Planar(instance, input, output);
1193  }
1194 
1206  template<typename T>
1207  std::vector<T> ProcessAnyAudio(const std::vector<T> input)
1208  {
1209  assert(instance);
1210  std::vector<T> output;
1211  unsigned int out_offset=0;
1212  unsigned int in_offset=0;
1213  unsigned int todo = input.size();
1214  while (todo>0) {
1215  unsigned int left = AddAudio(&input[in_offset], todo);
1216  unsigned int out_avail = m_dynlib.GetOutputCount(instance);
1217  output.resize(out_offset + out_avail);
1218  GetAudio(&output[out_offset], out_avail);
1219  out_offset+=out_avail;
1220  in_offset += todo-left;
1221  todo=left;
1222  }
1223  return output;
1224  }
1225 
1231  class CClient {
1232  public:
1233  CClient(bigvoice_CInstance* instance, CDynLib& dynlib)
1234  : m_dynlib(dynlib)
1235  {
1236  assert(instance);
1237  client=m_dynlib.NewClient(instance);
1238  if (!client) throw std::bad_alloc();
1239  }
1240  // non-copyable
1241  CClient( const CInstance& ) = delete;
1242  CClient& operator=( const CInstance& ) = delete;
1244  {
1245  if (client) {
1246  m_dynlib.DeleteClient(client);
1247  client=nullptr;
1248  }
1249  }
1257  std::string ProcessJson(const std::string &request, bool *NeedSave = nullptr)
1258  {
1259  assert(client);
1260  int need_save=0;
1261  const char *canswer = m_dynlib.ProcessJson(client, request.c_str(), &need_save);
1262  if (!canswer) return {};
1263  std::string answer(canswer);
1264  m_dynlib.FreeJsonAnswer (canswer);
1265  if (NeedSave) {
1266  *NeedSave=(need_save!=0);
1267  }
1268  return answer;
1269  }
1270  private:
1271  CDynLib& m_dynlib;
1272  bigvoice_CClientInstance *client = nullptr;
1273  };
1281  std::shared_ptr<CClient> NewClient()
1282  {
1283  assert(instance);
1284  return std::make_shared<CClient>(instance, m_dynlib);
1285  }
1286 
1287  protected:
1288  template<typename T>
1289  unsigned int AddAudio(const T* payload, unsigned int nFrame)
1290  {
1291  assert(instance);
1292  return m_dynlib.AddAudio(instance, reinterpret_cast<const T*>(payload), nFrame, helper::SampleFormat<T>::format);
1293  }
1294  template<typename T>
1295  unsigned int GetAudio(T* payload, unsigned int max_nFrame)
1296  {
1297  assert(instance);
1298  return m_dynlib.GetAudio(instance, reinterpret_cast<T*>(payload), max_nFrame, helper::SampleFormat<T>::format);
1299  }
1300 
1301  private:
1302  CDynLib& m_dynlib;
1303  bigvoice_CParameters* params = nullptr;
1304  bigvoice_CInstance* instance = nullptr;
1305  std::thread update_thread;
1306  std::vector< std::pair<std::string,std::string> > init_metadata;
1307 #if BIGVOICE_HAS_WEBSERVER
1308  uint64_t webserver = SOUND4_INVALID_WEBSERVER_ID;
1309 #endif // BIGVOICE_HAS_WEBSERVER
1310  };
1311 
1312 }; // namespace dyn
1313 }; // namespace bigvoice
1314 }; // namespace sound4
1315 
1316 
1317 // bridge C callbacks to CPresetLoader
1318 extern "C" {
1319  static char *bigvoice_custom_reader(const fs_char *filename, void* userdata) {
1320  sound4::bigvoice::dyn::CPresetLoader *preset_loader=reinterpret_cast<sound4::bigvoice::dyn::CPresetLoader*>(userdata);
1321  std::string content=preset_loader->Read(filename);
1322  return strdup(content.c_str());
1323  }
1324  static void bigvoice_custom_reader_free(char *content, void* userdata) {
1325  if (!content) return;
1326  free(content);
1327  }
1328  static int bigvoice_custom_writer(const fs_char *filename, const char *content, void* userdata) {
1329  sound4::bigvoice::dyn::CPresetLoader *preset_loader=reinterpret_cast<sound4::bigvoice::dyn::CPresetLoader*>(userdata);
1330  auto res=preset_loader->Write(filename,content);
1331  return res?0:-1;
1332  }
1333  static int bigvoice_custom_exists(const fs_char *filename, void* userdata) {
1334  sound4::bigvoice::dyn::CPresetLoader *preset_loader=reinterpret_cast<sound4::bigvoice::dyn::CPresetLoader*>(userdata);
1335  auto res=preset_loader->Exists(filename);
1336  return res?0:-1;
1337  }
1338  static fs_char** bigvoice_custom_getall(void* userdata) {
1339  sound4::bigvoice::dyn::CPresetLoader *preset_loader=reinterpret_cast<sound4::bigvoice::dyn::CPresetLoader*>(userdata);
1340  auto res=preset_loader->GetAll();
1341  fs_char**all=(fs_char**)malloc((res.size()+1)*sizeof(const fs_char*));
1342  for (size_t n=0;n<res.size();n++) {
1343  all[n]=fs_strdup(res[n].c_str());
1344  }
1345  all[res.size()]=nullptr;
1346  return all;
1347  }
1348  static void bigvoice_custom_getall_free(fs_char** all, void* userdata) {
1349  if (!all) return;
1350  for (fs_char** one=all;*one;one++) {
1351  free(*one);
1352  }
1353  free(all);
1354  }
1355  static int bigvoice_custom_remove(const fs_char *filename, void* userdata) {
1356  sound4::bigvoice::dyn::CPresetLoader *preset_loader=reinterpret_cast<sound4::bigvoice::dyn::CPresetLoader*>(userdata);
1357  auto res=preset_loader->Remove(filename);
1358  return res?0:-1;
1359  }
1360  static int bigvoice_custom_rename(const fs_char *from, const fs_char *to, void* userdata) {
1361  sound4::bigvoice::dyn::CPresetLoader *preset_loader=reinterpret_cast<sound4::bigvoice::dyn::CPresetLoader*>(userdata);
1362  auto res=preset_loader->Rename(from,to);
1363  return res?0:-1;
1364  }
1365 
1366 };
helper::DynFuncHolder< decltype(bigvoice_FreeParameterValue) > FreeParameterValue
helper::DynFuncHolder< decltype(bigvoice_AudioMonoFromLiveStereo) > AudioMonoFromLiveStereo
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_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_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(bigvoice_CInstance *instance, CDynLib &dynlib)
CClient & operator=(const CInstance &)=delete
void SetMetadataMulti(const std::unordered_map< std::string, const char * > &list)
std::shared_ptr< CClient > NewClient()
unsigned int AddAudio(const T *payload, unsigned int nFrame)
std::array< float, InputSampleSize > & GetBufferIn()
void SetMetadata(const std::string &key, const char *value)
CInstance(const CInstance &)=delete
std::vector< T > ProcessAnyAudio(const std::vector< T > input)
void SetParam(const std::string &name, const std::string &value)
std::vector< std::tuple< std::string, std::string > > GetMetadataInfos()
std::string GetParam(const std::string &name)
std::array< float, OutputSampleSize > & GetBufferOut()
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)
CInstance & operator=(const CInstance &)=delete
void SetPresetManager(CPresetLoader *preset_manager)
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
DynFuncHolder< T > GetSymbol_safe(const std::string &name)
CDynLoader & operator=(CDynLoader const &)=delete
static std::filesystem::path GetThisLibraryPath(void)
DynFuncHolder< T > GetSymbol(const std::string &name)
CDynLoader(const CDynLoader &)=delete
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)
void bigvoice_ProcessAudio_Planar(struct bigvoice_CInstance *instance, float const *const *input, float *const *output)
float * bigvoice_GetBufferIn(struct bigvoice_CInstance *instance)
#define BIGVOICE_SAMPLE_RATE
#define BIGVOICE_CHANNEL_COUNT
const char * bigvoice_GetVersion()
bigvoice_LogSeverity
unsigned int * bigvoice_GetPossibleChunkSizeInFrames()
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
#define BIGVOICE_AUDIOFRAME_COUNT
unsigned int bigvoice_GetSampleRate()
void bigvoice_FreeParameterValue(const char *value)
int bigvoice_TerminateProcess(struct bigvoice_CInstance *instance)
void bigvoice_FreeParameters(struct bigvoice_CParameters *params)
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)
void bigvoice_ExitProcess(struct bigvoice_CInstance *instance)
unsigned int bigvoice_GetProcessChunkFrames(struct bigvoice_CInstance *instance)
const char * bigvoice_GetParameter(struct bigvoice_CParameters *params, const char *name)
struct bigvoice_CParameters * bigvoice_NewParameters()
void bigvoice_SetParameter(struct bigvoice_CParameters *params, const char *name, const char *value)
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)
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_FreeMetadataInfos(struct bigvoice_CInstance *instance, const char **infos)
void bigvoice_SetMetadata(struct bigvoice_CInstance *instance, const char *key, const char *value)
void bigvoice_SetMetadataMulti(struct bigvoice_CInstance *instance, const char **keyvalue)
const char ** bigvoice_GetMetadataInfos(struct bigvoice_CInstance *instance)
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)
#define SOUND4_WEBSERVER_HTTP_OK
#define SOUND4_INVALID_WEBSERVER_ID
std::function< void(LogSeverity, const std::string &)> log_cb_t
bigvoice_SampleFormat SampleFormat
const LogSeverity info
Definition: sound4cl.hpp:242
std::function< void(LogSeverity, const std::string &)> log_cb_t
Definition: sound4cl.hpp:252
C interface for library.
#define fs_strdup
helper for OS dependant file name copy