SOUND4 BIGVOICE.CL Library [0.9.8]
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  bool IsOk() const { return m_ptr!=NULL; }
93  operator T* () const { return reinterpret_cast<T*>(m_ptr); }
94  };
95 
100  class CDynLoader {
101  private:
102  DynLib_t m_lib {};
103  public:
104  CDynLoader() = default;
105  CDynLoader(CDynLoader&&) = default;
106  // No copy allowed
107  CDynLoader(const CDynLoader&) = delete;
108  CDynLoader& operator=(CDynLoader const&) = delete;
109  operator bool() const {
110  return (m_lib!=NULL);
111  }
112  bool IsOk() const {
113  return (m_lib!=NULL);
114  }
115  #ifdef __unix__
116  void Close() {
117  if (IsOk()) {
118  dlclose(m_lib);
119  m_lib=NULL;
120  }
121  }
122  bool Load(const std::filesystem::path& dynlib)
123  {
124  Close();
125  m_lib=dlopen(dynlib.c_str(), RTLD_NOW|RTLD_LOCAL);
126  return IsOk();
127  }
128  template <typename T>
129  DynFuncHolder<T> GetSymbol(const std::string& name) {
130  auto ptr=dlsym(m_lib, name.c_str());
131  if (!ptr) {
132  throw std::runtime_error("Missing function in library");
133  }
134  return DynFuncHolder<T>(ptr);
135  }
136  static fs_char *GetThisLibraryPath(void) {
137  static Dl_info info;
138  if (! dladdr((void *) GetThisLibraryPath, & info)) return NULL;
139  return realpath(info.dli_fname, NULL);
140  }
141  #else
142  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)
143  {
144  Close();
145  m_lib=LoadLibraryExW(dynlib.c_str(), NULL, loadflags);
146  return IsOk();
147  }
148  void Close() {
149  if (IsOk()) {
150  // NOTE: On Windows, FreeLibrary may create a lot of troubles, should use FreeLibraryAndExitThread but...
151  // So define SOUND4_CALL_FREELIBRARY before including this file if you really want to unload the library dynamically
152  #if defined(SOUND4_CALL_FREELIBRARYANDEXITTHREAD)
153  FreeLibraryAndExitThread(m_lib, 0);
154  #elif defined(SOUND4_CALL_FREELIBRARY)
155  FreeLibrary(m_lib);
156  #endif // SOUND4_CALL_FREELIBRARY
157  m_lib=NULL;
158  }
159  }
160  template <typename T>
161  DynFuncHolder<T> GetSymbol(const std::string& name) {
162  auto ptr=GetProcAddress(m_lib, name.c_str());
163  if (!ptr) {
164  throw std::runtime_error("Missing function in library");
165  }
166  return DynFuncHolder<T>(ptr);
167  }
168  static fs_char *GetThisLibraryPath(void) {
169  static wchar_t path[MAX_PATH]={};
170  HMODULE hm = NULL;
171  if (GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
172  GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
173  (LPCWSTR) &GetThisLibraryPath, &hm))
174  {
175  if (GetModuleFileNameW(hm, path, MAX_PATH) == 0) {
176  }
177  }
178  return path;
179  }
180  #endif
181  virtual ~CDynLoader() {
182  Close();
183  }
184  }; // class CDynLoader
185  }; // namespace helper
186 
193  class CDynLib {
194  private:
195  helper::CDynLoader m_lib;
196  bool m_bOK = false;
197  public:
198  CDynLib() = default;
199 
200  // All those wrapped functions have the same signature as there C bigvoice_XXX
245 #if BIGVOICE_HAS_WEBSERVER
251 #endif // BIGVOICE_HAS_WEBSERVER
252 
253  // added 2023-03-22
256 
257  // added 2023-05-22
261 
262  // added 2023-06-20
265 
266  // added 2023-09-21
270 
271 #if BIGVOICE_HAS_CLOUDBUS
272  // added 2023-06-26
276 #endif // BIGVOICE_HAS_CLOUDBUS
277 
285  bool Load(const std::filesystem::path& path = std::filesystem::current_path()) {
286  std::string filename;
287  #ifdef __unix__
288  filename="libsound4.bigvoice.cl.so";
289  #else
290  filename="sound4.bigvoice.cl.dll";
291  #endif
292  auto p = path;
293  p.append(filename);
294  m_lib.Load(p.native());
295  if (!m_lib.IsOk()) {
296  // Search in the same directory this code is in
298  p.append(filename);
299  m_lib.Load(p.native());
300  if (!m_lib.IsOk()) {
301  return false;
302  }
303  }
304  // Load all C functions
305  try {
306  GetVersion = m_lib.GetSymbol< decltype(bigvoice_GetVersion ) >("bigvoice_GetVersion" );
307  GetChunkSizeInFrames = m_lib.GetSymbol< decltype(bigvoice_GetChunkSizeInFrames ) >("bigvoice_GetChunkSizeInFrames" );
308  GetChannelCount = m_lib.GetSymbol< decltype(bigvoice_GetChannelCount ) >("bigvoice_GetChannelCount" );
309  GetAudioInputCount = m_lib.GetSymbol< decltype(bigvoice_GetAudioInputCount ) >("bigvoice_GetAudioInputCount" );
310  GetAudioOutputCount = m_lib.GetSymbol< decltype(bigvoice_GetAudioOutputCount ) >("bigvoice_GetAudioOutputCount" );
311  GetSampleRate = m_lib.GetSymbol< decltype(bigvoice_GetSampleRate ) >("bigvoice_GetSampleRate" );
312  SetLoggerCallback = m_lib.GetSymbol< decltype(bigvoice_SetLoggerCallback ) >("bigvoice_SetLoggerCallback" );
313  SetLogSeverity = m_lib.GetSymbol< decltype(bigvoice_SetLogSeverity ) >("bigvoice_SetLogSeverity" );
314  NewParameters = m_lib.GetSymbol< decltype(bigvoice_NewParameters ) >("bigvoice_NewParameters" );
315  FreeParameters = m_lib.GetSymbol< decltype(bigvoice_FreeParameters ) >("bigvoice_FreeParameters" );
316  SetParameter = m_lib.GetSymbol< decltype(bigvoice_SetParameter ) >("bigvoice_SetParameter" );
317  GetParameter = m_lib.GetSymbol< decltype(bigvoice_GetParameter ) >("bigvoice_GetParameter" );
318  FreeParameterValue = m_lib.GetSymbol< decltype(bigvoice_FreeParameterValue ) >("bigvoice_FreeParameterValue" );
319  InitProcess = m_lib.GetSymbol< decltype(bigvoice_InitProcess ) >("bigvoice_InitProcess" );
320  InitProcess2 = m_lib.GetSymbol< decltype(bigvoice_InitProcess2 ) >("bigvoice_InitProcess2" );
321  TerminateProcess = m_lib.GetSymbol< decltype(bigvoice_TerminateProcess ) >("bigvoice_TerminateProcess" );
322  ExitProcess = m_lib.GetSymbol< decltype(bigvoice_ExitProcess ) >("bigvoice_ExitProcess" );
323  StartUpdateThread = m_lib.GetSymbol< decltype(bigvoice_StartUpdateThread ) >("bigvoice_StartUpdateThread" );
324  StopUpdateThread = m_lib.GetSymbol< decltype(bigvoice_StopUpdateThread ) >("bigvoice_StopUpdateThread" );
325  WaitUpdateThreadReady = m_lib.GetSymbol< decltype(bigvoice_WaitUpdateThreadReady ) >("bigvoice_WaitUpdateThreadReady" );
326  ProcessAudio = m_lib.GetSymbol< decltype(bigvoice_ProcessAudio ) >("bigvoice_ProcessAudio" );
327  ProcessAudio_Planar = m_lib.GetSymbol< decltype(bigvoice_ProcessAudio_Planar ) >("bigvoice_ProcessAudio_Planar" );
328  GetBufferIn = m_lib.GetSymbol< decltype(bigvoice_GetBufferIn ) >("bigvoice_GetBufferIn" );
329  GetBufferOut = m_lib.GetSymbol< decltype(bigvoice_GetBufferOut ) >("bigvoice_GetBufferOut" );
330  GetEstimatedDelay = m_lib.GetSymbol< decltype(bigvoice_GetEstimatedDelay ) >("bigvoice_GetEstimatedDelay" );
331  GetFormatName = m_lib.GetSymbol< decltype(bigvoice_GetFormatName ) >("bigvoice_GetFormatName" );
332  GetFormatFromName = m_lib.GetSymbol< decltype(bigvoice_GetFormatFromName ) >("bigvoice_GetFormatFromName" );
333  GetBytesFromFormat = m_lib.GetSymbol< decltype(bigvoice_GetBytesFromFormat ) >("bigvoice_GetBytesFromFormat" );
334  GetMaxPacketFrame = m_lib.GetSymbol< decltype(bigvoice_GetMaxPacketFrame ) >("bigvoice_GetMaxPacketFrame" );
335  AddAudio = m_lib.GetSymbol< decltype(bigvoice_AddAudio ) >("bigvoice_AddAudio" );
336  AddPadAudio = m_lib.GetSymbol< decltype(bigvoice_AddPadAudio ) >("bigvoice_AddPadAudio" );
337  GetOutputCount = m_lib.GetSymbol< decltype(bigvoice_GetOutputCount ) >("bigvoice_GetOutputCount" );
338  GetAudio = m_lib.GetSymbol< decltype(bigvoice_GetAudio ) >("bigvoice_GetAudio" );
339  AudioConvertFrom = m_lib.GetSymbol< decltype(bigvoice_AudioConvertFrom ) >("bigvoice_AudioConvertFrom" );
340  AudioConvertTo = m_lib.GetSymbol< decltype(bigvoice_AudioConvertTo ) >("bigvoice_AudioConvertTo" );
341  StereoToMono = m_lib.GetSymbol< decltype(bigvoice_StereoToMono ) >("bigvoice_StereoToMono" );
342  MonoToStereo = m_lib.GetSymbol< decltype(bigvoice_MonoToStereo ) >("bigvoice_MonoToStereo" );
343  AudioMonoFromLiveStereo = m_lib.GetSymbol< decltype(bigvoice_AudioMonoFromLiveStereo) >("bigvoice_AudioMonoFromLiveStereo");
344  AudioMonoToLiveStereo = m_lib.GetSymbol< decltype(bigvoice_AudioMonoToLiveStereo ) >("bigvoice_AudioMonoToLiveStereo" );
345  NewClient = m_lib.GetSymbol< decltype(bigvoice_NewClient ) >("bigvoice_NewClient" );
346  DeleteClient = m_lib.GetSymbol< decltype(bigvoice_DeleteClient ) >("bigvoice_DeleteClient" );
347  ProcessJson = m_lib.GetSymbol< decltype(bigvoice_ProcessJson ) >("bigvoice_ProcessJson" );
348  FreeJsonAnswer = m_lib.GetSymbol< decltype(bigvoice_FreeJsonAnswer ) >("bigvoice_FreeJsonAnswer" );
349  SaveState = m_lib.GetSymbol< decltype(bigvoice_SaveState ) >("bigvoice_SaveState" );
350 #if BIGVOICE_HAS_WEBSERVER
351  Webserver_tcp = m_lib.GetSymbol< decltype(bigvoice_Webserver_tcp ) >("bigvoice_Webserver_tcp" );
352  Webserver_tcp2 = m_lib.GetSymbol< decltype(bigvoice_Webserver_tcp2 ) >("bigvoice_Webserver_tcp2" );
353  Webserver = m_lib.GetSymbol< decltype(bigvoice_Webserver ) >("bigvoice_Webserver" );
354  Webserver_Stop = m_lib.GetSymbol< decltype(bigvoice_Webserver_Stop ) >("bigvoice_Webserver_Stop" );
355  Webserver_Status = m_lib.GetSymbol< decltype(bigvoice_Webserver_Status ) >("bigvoice_Webserver_Status" );
356 #endif // BIGVOICE_HAS_WEBSERVER
357 
358  // added 2023-03-22
359  StereoToMono_Planar = m_lib.GetSymbol< decltype(bigvoice_StereoToMono_Planar ) >("bigvoice_StereoToMono_Planar" );
360  MonoToStereo_Planar = m_lib.GetSymbol< decltype(bigvoice_MonoToStereo_Planar ) >("bigvoice_MonoToStereo_Planar" );
361 
362  } catch (std::runtime_error& ) {
363  return false;
364  }
365  // C functions allowed to be missing
366  try {
367  // added 2023-05-22
368  SetMetadata = m_lib.GetSymbol< decltype(bigvoice_SetMetadata ) >("bigvoice_SetMetadata" );
369  GetMetadataInfos = m_lib.GetSymbol< decltype(bigvoice_GetMetadataInfos ) >("bigvoice_GetMetadataInfos" );
370  FreeMetadataInfos = m_lib.GetSymbol< decltype(bigvoice_FreeMetadataInfos ) >("bigvoice_FreeMetadataInfos" );
371  // added 2023-06-20
372  SetPresetManager = m_lib.GetSymbol< decltype(bigvoice_SetPresetManager ) >("bigvoice_SetPresetManager" );
373  PresetManager_InformChange = m_lib.GetSymbol< decltype(bigvoice_PresetManager_InformChange ) >("bigvoice_PresetManager_InformChange" );
374 
375  // added 2023-09-21
376  GetPossibleChunkSizeInFrames = m_lib.GetSymbol< decltype(bigvoice_GetPossibleChunkSizeInFrames ) >("bigvoice_GetPossibleChunkSizeInFrames" );
377  GetProcessChunkFrames = m_lib.GetSymbol< decltype(bigvoice_GetProcessChunkFrames ) >("bigvoice_GetProcessChunkFrames" );
378  InitProcess3 = m_lib.GetSymbol< decltype(bigvoice_InitProcess3 ) >("bigvoice_InitProcess3" );
379 
380 #if BIGVOICE_HAS_CLOUDBUS
381  // added 2023-06-26
382  NewBus = m_lib.GetSymbol< decltype(bigvoice_NewBus ) >("bigvoice_NewBus" );
383  FreeBus = m_lib.GetSymbol< decltype(bigvoice_FreeBus ) >("bigvoice_FreeBus" );
384  SetInstanceBus = m_lib.GetSymbol< decltype(bigvoice_SetInstanceBus ) >("bigvoice_SetInstanceBus" );
385 #endif // BIGVOICE_HAS_CLOUDBUS
386  } catch (std::runtime_error& ) {
387  // Ignored, handler will take care
388  }
389 
390  m_bOK=true;
391  return true;
392  }
399  bool IsOk() const {
400  return m_bOK;
401  }
402 
403  };
404 
405 
406 
407  static constexpr const char *process_name = "SOUND4 BIGVOICE.CL";
408  static constexpr const char *process_shortname = "bigvoice";
434 
438  namespace helper {
439  #ifdef _WIN32
445  static inline std::string WStringToUTF8(const std::wstring& wstr) {
446  if (wstr.empty()) return {};
447  int size = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), NULL, 0, NULL, NULL);
448  std::string str(size, 0);
449  WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), &str[0], size, NULL, NULL);
450  return str;
451  }
457  static inline std::wstring UTF8ToWString(const std::string& str) {
458  if (str.empty()) return std::wstring();
459  int size = MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), NULL, 0);
460  std::wstring wstr(size, 0);
461  MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), &wstr[0], size);
462  return wstr;
463  }
464  #endif // _WIN32
465 
471  template<typename T>
472  struct SampleFormat {
473  };
474  template<>
475  struct SampleFormat<int16_t> {
477  };
478  template<>
479  struct SampleFormat<int32_t> {
481  };
482  template<>
483  struct SampleFormat<float> {
485  };
486 
487 
492  static inline void AudioConvertFrom(CDynLib& dynlib, const uint8_t *payload, float *output, size_t nSpl, bigvoice_SampleFormat fmt) {
493  dynlib.AudioConvertFrom(payload, output, nSpl, fmt);
494  }
495  static inline void AudioConvertTo(CDynLib& dynlib, const float *input, uint8_t *payload, size_t nSpl, bigvoice_SampleFormat fmt) {
496  dynlib.AudioConvertTo(input, payload, nSpl, fmt);
497  }
498  static inline void StereoToMono(CDynLib& dynlib, const float *input, float *output, size_t nSpl) {
499  dynlib.StereoToMono(input, output, nSpl);
500  }
501  static inline void MonoToStereo(CDynLib& dynlib, const float *input, float *output, size_t nSpl) {
502  dynlib.MonoToStereo(input, output, nSpl);
503  }
504  static inline void StereoToMono_Planar(CDynLib& dynlib, const float *inputL, const float *inputR, float *output, size_t nSpl) {
505  dynlib.StereoToMono_Planar(inputL, inputR, output, nSpl);
506  }
507  static inline void MonoToStereo_Planar(CDynLib& dynlib, const float *input, float *outputL, float *outputR, size_t nSpl) {
508  dynlib.MonoToStereo_Planar(input, outputL, outputR, nSpl);
509  }
510  static inline void AudioMonoFromLiveStereo(CDynLib& dynlib, const uint8_t *payload, float *output) {
511  dynlib.AudioMonoFromLiveStereo(payload, output);
512  }
513  static inline void AudioMonoToLiveStereo(CDynLib& dynlib, const float *input, uint8_t *payload) {
514  dynlib.AudioMonoToLiveStereo(input, payload);
515  }
516 
517  }; // namespace helper
518 
524  static inline std::string GetVersion(CDynLib& dynlib)
525  {
526  return std::string(dynlib.GetVersion());
527  }
528 
539  static inline unsigned int GetChunkSizeInFrames(CDynLib& dynlib)
540  {
541  return dynlib.GetChunkSizeInFrames();
542  }
543 
552  static inline std::vector<unsigned int> GetPossibleChunkSizeInFrames(CDynLib& dynlib)
553  {
554  std::vector<unsigned int> list;
555  if (dynlib.GetPossibleChunkSizeInFrames) {
556  for (unsigned int* src=dynlib.GetPossibleChunkSizeInFrames();*src;src++) {
557  list.push_back(*src);
558  }
559  } else {
560  list.push_back(12);
561  }
562  return list;
563  }
564 
572  static inline unsigned int GetChannelCount(CDynLib& dynlib)
573  {
574  return dynlib.GetChannelCount();
575  }
576 
585  static inline unsigned int GetAudioInputCount(CDynLib& dynlib)
586  {
587  return dynlib.GetAudioInputCount();
588  }
589 
598  static inline unsigned int GetAudioOutputCount(CDynLib& dynlib)
599  {
600  return dynlib.GetAudioOutputCount();
601  }
602 
610  static inline unsigned int GetSampleRate(CDynLib& dynlib)
611  {
612  return dynlib.GetSampleRate();
613  }
614 
620  static inline void SanityCheck(CDynLib& dynlib, bool a_bCheckFrames = true)
621  {
622  // Do some sanity checks
623  if (dynlib.GetSampleRate()!=BIGVOICE_SAMPLE_RATE) {
624  throw std::runtime_error("Bad library sampling rate");
625  }
626  if (a_bCheckFrames && dynlib.GetChunkSizeInFrames()!=ChunkFrames) {
627  throw std::runtime_error("Bad library frame size");
628  }
629  if (dynlib.GetChannelCount()!=BIGVOICE_CHANNEL_COUNT) {
630  throw std::runtime_error("Bad library channel count");
631  }
632  if (dynlib.GetAudioInputCount()!=BIGVOICE_AUDIO_INPUT_COUNT) {
633  throw std::runtime_error("Bad library input count");
634  }
635  if (dynlib.GetAudioOutputCount()!=BIGVOICE_AUDIO_OUTPUT_COUNT) {
636  throw std::runtime_error("Bad library output count");
637  }
638  }
639 
646  static inline std::string GetFormatName(CDynLib& dynlib, const SampleFormat fmt)
647  {
648  return std::string(dynlib.GetFormatName(fmt));
649  }
650 
657  static inline SampleFormat GetFormatFromName(CDynLib& dynlib, const std::string& name)
658  {
659  return dynlib.GetFormatFromName(name.c_str());
660  }
661 
668  static inline unsigned int GetBytesFromFormat(CDynLib& dynlib, const SampleFormat fmt)
669  {
670  return dynlib.GetBytesFromFormat(fmt);
671  }
672 
680  using log_cb_t = std::function<void(LogSeverity,const std::string&)>;
681 
685  static log_cb_t _log_cb;
686  extern "C" {
687  static inline void _log_cb_c(bigvoice_LogSeverity severity, const char *c_msg) {
688  _log_cb(severity, std::string(c_msg));
689  }
690  }
694  static inline void SetLogSeverity(CDynLib& dynlib, LogSeverity severity)
695  {
696  dynlib.SetLogSeverity(severity);
697  }
701  static inline void SetLoggerCallback(CDynLib& dynlib, log_cb_t cb)
702  {
703  _log_cb=cb;
704  dynlib.SetLoggerCallback(&_log_cb_c);
705  }
706 
707 #if BIGVOICE_HAS_CLOUDBUS
708  class CBus {
709  public:
710  CBus(CDynLib& dynlib)
711  : m_dynlib(dynlib)
712  {
713  if (m_dynlib.NewBus) {
714  m_bus=m_dynlib.NewBus();
715  }
716  }
718  {
719  if (m_bus && m_dynlib.FreeBus) {
720  m_dynlib.FreeBus(m_bus);
721  }
722  m_bus = nullptr;
723  }
724  bigvoice_CBus *Get() const { return m_bus; }
725  private:
726  CDynLib& m_dynlib;
727  bigvoice_CBus *m_bus;
728  };
729 #endif // BIGVOICE_HAS_CLOUDBUS
730 
736  public:
737  CPresetLoader() = default;
738  virtual ~CPresetLoader() = default;
739 
740  virtual bool IsReadOnly() = 0;
741  virtual bool Exists(const std::filesystem::path &name) = 0;
742  virtual bool Remove(const std::filesystem::path &name) = 0;
743  virtual bool Rename(const std::filesystem::path &from, const std::filesystem::path &to) = 0;
744  virtual std::vector<std::filesystem::path> GetAll() = 0;
745  virtual std::string Read(const std::filesystem::path &filename) = 0;
746  virtual bool Write(const std::filesystem::path &filename, const std::string &content) =0;
747  };
749 
753  class CInstance {
754  public:
759  : m_dynlib(dynlib)
760  {
761  params = m_dynlib.NewParameters();
762  if (!params) throw std::bad_alloc();
763  }
764  // non-copyable
765  CInstance( const CInstance& ) = delete;
766  CInstance& operator=( const CInstance& ) = delete;
771  {
772  Stop();
773  if (params) m_dynlib.FreeParameters(params);
774  }
778  bool IsOk() const { return instance!=nullptr; }
786  void SetParam(const std::string& name, const std::string& value)
787  {
788  assert(params);
789  m_dynlib.SetParameter(params, name.c_str(), value.c_str());
790  }
796  std::string GetParam(const std::string& name)
797  {
798  assert(params);
799  auto c_value=m_dynlib.GetParameter(params, name.c_str());
800  std::string ret(c_value);
801  m_dynlib.FreeParameterValue(c_value);
802  return ret;
803  }
804 #if BIGVOICE_HAS_CLOUDBUS
808  void SetBus(const CBus& bus) {
809  assert(params);
810  if (m_dynlib.SetInstanceBus) {
811  m_dynlib.SetInstanceBus(params,bus.Get());
812  }
813  }
814 #endif // BIGVOICE_HAS_CLOUDBUS
815 
825  void SetPresetManager(CPresetLoader *preset_manager)
826  {
827  if (!preset_manager) return;
828  if (!m_dynlib.SetPresetManager) return;
829  assert(params);
830  m_dynlib.SetPresetManager(params,
831  bigvoice_custom_reader,
832  bigvoice_custom_reader_free,
833  bigvoice_custom_writer,
834  bigvoice_custom_exists,
835  bigvoice_custom_getall,
836  bigvoice_custom_getall_free,
837  bigvoice_custom_remove,
838  bigvoice_custom_rename,
839  preset_manager->IsReadOnly(),
840  preset_manager
841  );
842  }
843 
858  bool Create(const std::string& LoginKey, const std::string& RadioName, const std::string& AWS_Access_ID, const std::string& AWS_Access_Secret, const std::filesystem::path& save_path, int json_port = 0, unsigned int frames_per_chunk=12)
859  {
860  assert(!instance);
861  std::string l_save_path;
862  if (!save_path.empty()) {
863  l_save_path = save_path.u8string();
864  }
865  if (m_dynlib.InitProcess3) {
866  instance = m_dynlib.InitProcess3(LoginKey.c_str(), RadioName.c_str(), AWS_Access_ID.c_str(), AWS_Access_Secret.c_str(), l_save_path.c_str(), params, frames_per_chunk);
867  } else if (frames_per_chunk!=12) {
868  return false;
869  } else {
870  instance = m_dynlib.InitProcess2(LoginKey.c_str(), RadioName.c_str(), AWS_Access_ID.c_str(), AWS_Access_Secret.c_str(), l_save_path.c_str(), params);
871  }
872  if (!instance) return false;
873  if (!init_metadata.empty()) {
874  for (auto&& [key,value]: init_metadata) {
875  m_dynlib.SetMetadata(instance, key.c_str(), value.c_str());
876  }
877  init_metadata.clear();
878  }
879  update_thread = std::thread([this, json_port](){
881  m_dynlib.StartUpdateThread(instance, json_port);
883  });
884  int timeout=5000;
885  #ifdef DEBUG
886  timeout=60*1000; // For debugger pauses
887  #endif
888  if (m_dynlib.WaitUpdateThreadReady(instance, timeout)<0) {
889  return false;
890  }
891  return true;
892  }
893 
901  unsigned int GetChunkFrames() {
902  if (instance && m_dynlib.GetProcessChunkFrames) {
903  return m_dynlib.GetProcessChunkFrames(instance);
904  }
905  return 12;
906  }
907 
915  void PresetManager_InformChange(const std::filesystem::path& relative_path, PresetChange_Kind change_kind)
916  {
917  if (m_dynlib.PresetManager_InformChange) {
918  m_dynlib.PresetManager_InformChange(instance, relative_path.c_str(), (bigvoice_PresetChange_Kind) change_kind);
919  }
920  }
921 
933  void SetMetadata(const std::string& key, const char* value)
934  {
935  if (m_dynlib.SetMetadata) {
936  if (instance) {
937  m_dynlib.SetMetadata(instance, key.c_str(), value);
938  } else {
939  init_metadata.push_back( {key, value} );
940  }
941  }
942  }
943 
949  std::vector< std::tuple<std::string,std::string> > GetMetadataInfos()
950  {
951  std::vector< std::tuple<std::string,std::string> > values;
952  if (m_dynlib.GetMetadataInfos) {
953  const char** c_values = m_dynlib.GetMetadataInfos(instance);
954  if (c_values) {
955  for (const char** c_value=c_values; *c_value; ) {
956  std::string key(*c_value);
957  c_value++;
958  if (*c_value) {
959  std::string descr(*c_value);
960  c_value++;
961  values.push_back( {key,descr} );
962  }
963  }
964  m_dynlib.FreeMetadataInfos(instance, c_values);
965  }
966  }
967  return values;
968  }
969 
970  // Can be overloaded, called at start of UpdateThread in the thread
971  virtual void OnUpdateThreadStart() {}
972  // Can be overloaded to call at end of UpdateThread in the thread
973  virtual void OnUpdateThreadStop() {}
974 
975 #if BIGVOICE_HAS_WEBSERVER
981  bool StartWebServer(int http_port, int https_port=0)
982  {
983  assert(instance);
984  assert(webserver==SOUND4_INVALID_WEBSERVER_ID);
985  webserver = m_dynlib.Webserver(http_port,https_port,instance);
986  if (webserver==SOUND4_INVALID_WEBSERVER_ID) {
987  return false;
988  }
989  int web_status=m_dynlib.Webserver_Status(webserver);
990  if (http_port && (web_status & SOUND4_WEBSERVER_HTTP_OK) == 0) {
991  return false;
992  }
993  if (https_port && (web_status & SOUND4_WEBSERVER_HTTPS_OK) == 0) {
994  return false;
995  }
996  return true;
997  }
1004  {
1005  if (webserver != SOUND4_INVALID_WEBSERVER_ID) {
1006  m_dynlib.Webserver_Stop(webserver, 1000);
1007  webserver = SOUND4_INVALID_WEBSERVER_ID;
1008  }
1009  }
1010 #endif // BIGVOICE_HAS_WEBSERVER
1011 
1019  {
1020  if (!instance) return 0;
1021  return m_dynlib.TerminateProcess(instance);
1022  }
1023 
1029  void Stop()
1030  {
1031  if (!instance) return;
1032 #if BIGVOICE_HAS_WEBSERVER
1033  StopWebServer();
1034 #endif // BIGVOICE_HAS_WEBSERVER
1035  if (update_thread.joinable()) {
1036  m_dynlib.StopUpdateThread(instance); // this will exit the update thread
1037  update_thread.join();
1038  }
1039  m_dynlib.ExitProcess(instance);
1040  instance=nullptr;
1041  }
1042 
1048  unsigned int GetEstimatedDelay()
1049  {
1050  assert(instance);
1051  return m_dynlib.GetEstimatedDelay(instance);
1052  }
1053 
1064  std::array<float,InputSampleSize>& GetBufferIn()
1065  {
1066  assert(instance);
1067  float *buf=m_dynlib.GetBufferIn(instance);
1068  return reinterpret_cast< std::array<float,InputSampleSize>& >(*buf);
1069 
1070  }
1081  std::array<float,OutputSampleSize>& GetBufferOut()
1082  {
1083  assert(instance);
1084  float *buf= m_dynlib.GetBufferOut(instance);
1085  return reinterpret_cast< std::array<float,OutputSampleSize>& >(*buf);
1086  }
1093  {
1094  assert(instance);
1095  m_dynlib.ProcessAudio(instance, m_dynlib.GetBufferIn(instance), m_dynlib.GetBufferOut(instance));
1096  }
1110  // void ProcessAudio_Planar(const std::array< const std::array<const float,ChunkFrames>, InputChannels>& input, std::array< std::array<float,ChunkFrames>, OutputChannels>& output)
1111  void ProcessAudio_Planar(float const * const *input, float * const *output)
1112  {
1113  assert(instance);
1114  m_dynlib.ProcessAudio_Planar(instance, input, output);
1115  }
1116 
1128  template<typename T>
1129  std::vector<T> ProcessAnyAudio(const std::vector<T> input)
1130  {
1131  assert(instance);
1132  std::vector<T> output;
1133  unsigned int out_offset=0;
1134  unsigned int in_offset=0;
1135  unsigned int todo = input.size();
1136  while (todo>0) {
1137  unsigned int left = AddAudio(&input[in_offset], todo);
1138  unsigned int out_avail = m_dynlib.GetOutputCount(instance);
1139  output.resize(out_offset + out_avail);
1140  GetAudio(&output[out_offset], out_avail);
1141  out_offset+=out_avail;
1142  in_offset += todo-left;
1143  todo=left;
1144  }
1145  return output;
1146  }
1147 
1153  class CClient {
1154  public:
1155  CClient(bigvoice_CInstance* instance, CDynLib& dynlib)
1156  : m_dynlib(dynlib)
1157  {
1158  assert(instance);
1159  client=m_dynlib.NewClient(instance);
1160  if (!client) throw std::bad_alloc();
1161  }
1162  // non-copyable
1163  CClient( const CInstance& ) = delete;
1164  CClient& operator=( const CInstance& ) = delete;
1166  {
1167  if (client) {
1168  m_dynlib.DeleteClient(client);
1169  client=nullptr;
1170  }
1171  }
1179  std::string ProcessJson(const std::string &request, bool *NeedSave = nullptr)
1180  {
1181  assert(client);
1182  int need_save=0;
1183  const char *canswer = m_dynlib.ProcessJson(client, request.c_str(), &need_save);
1184  if (!canswer) return {};
1185  std::string answer(canswer);
1186  m_dynlib.FreeJsonAnswer (canswer);
1187  if (NeedSave) {
1188  *NeedSave=(need_save!=0);
1189  }
1190  return answer;
1191  }
1192  private:
1193  CDynLib& m_dynlib;
1194  bigvoice_CClientInstance *client = nullptr;
1195  };
1203  std::shared_ptr<CClient> NewClient()
1204  {
1205  assert(instance);
1206  return std::make_shared<CClient>(instance, m_dynlib);
1207  }
1208 
1209  protected:
1210  template<typename T>
1211  unsigned int AddAudio(const T* payload, unsigned int nFrame)
1212  {
1213  assert(instance);
1214  return m_dynlib.AddAudio(instance, reinterpret_cast<const T*>(payload), nFrame, helper::SampleFormat<T>::format);
1215  }
1216  template<typename T>
1217  unsigned int GetAudio(T* payload, unsigned int max_nFrame)
1218  {
1219  assert(instance);
1220  return m_dynlib.GetAudio(instance, reinterpret_cast<T*>(payload), max_nFrame, helper::SampleFormat<T>::format);
1221  }
1222 
1223  private:
1224  CDynLib& m_dynlib;
1225  bigvoice_CParameters* params = nullptr;
1226  bigvoice_CInstance* instance = nullptr;
1227  std::thread update_thread;
1228  std::vector< std::pair<std::string,std::string> > init_metadata;
1229 #if BIGVOICE_HAS_WEBSERVER
1230  uint64_t webserver = SOUND4_INVALID_WEBSERVER_ID;
1231 #endif // BIGVOICE_HAS_WEBSERVER
1232  };
1233 
1234 }; // namespace dyn
1235 }; // namespace bigvoice
1236 }; // namespace sound4
1237 
1238 
1239 // bridge C callbacks to CPresetLoader
1240 extern "C" {
1241  static char *bigvoice_custom_reader(const fs_char *filename, void* userdata) {
1242  sound4::bigvoice::dyn::CPresetLoader *preset_loader=reinterpret_cast<sound4::bigvoice::dyn::CPresetLoader*>(userdata);
1243  std::string content=preset_loader->Read(filename);
1244  return strdup(content.c_str());
1245  }
1246  static void bigvoice_custom_reader_free(char *content, void* userdata) {
1247  if (!content) return;
1248  free(content);
1249  }
1250  static int bigvoice_custom_writer(const fs_char *filename, const char *content, void* userdata) {
1251  sound4::bigvoice::dyn::CPresetLoader *preset_loader=reinterpret_cast<sound4::bigvoice::dyn::CPresetLoader*>(userdata);
1252  auto res=preset_loader->Write(filename,content);
1253  return res?0:-1;
1254  }
1255  static int bigvoice_custom_exists(const fs_char *filename, void* userdata) {
1256  sound4::bigvoice::dyn::CPresetLoader *preset_loader=reinterpret_cast<sound4::bigvoice::dyn::CPresetLoader*>(userdata);
1257  auto res=preset_loader->Exists(filename);
1258  return res?0:-1;
1259  }
1260  static fs_char** bigvoice_custom_getall(void* userdata) {
1261  sound4::bigvoice::dyn::CPresetLoader *preset_loader=reinterpret_cast<sound4::bigvoice::dyn::CPresetLoader*>(userdata);
1262  auto res=preset_loader->GetAll();
1263  fs_char**all=(fs_char**)malloc((res.size()+1)*sizeof(const fs_char*));
1264  for (size_t n=0;n<res.size();n++) {
1265  all[n]=fs_strdup(res[n].c_str());
1266  }
1267  all[res.size()]=nullptr;
1268  return all;
1269  }
1270  static void bigvoice_custom_getall_free(fs_char** all, void* userdata) {
1271  if (!all) return;
1272  for (fs_char** one=all;*one;one++) {
1273  free(*one);
1274  }
1275  free(all);
1276  }
1277  static int bigvoice_custom_remove(const fs_char *filename, void* userdata) {
1278  sound4::bigvoice::dyn::CPresetLoader *preset_loader=reinterpret_cast<sound4::bigvoice::dyn::CPresetLoader*>(userdata);
1279  auto res=preset_loader->Remove(filename);
1280  return res?0:-1;
1281  }
1282  static int bigvoice_custom_rename(const fs_char *from, const fs_char *to, void* userdata) {
1283  sound4::bigvoice::dyn::CPresetLoader *preset_loader=reinterpret_cast<sound4::bigvoice::dyn::CPresetLoader*>(userdata);
1284  auto res=preset_loader->Rename(from,to);
1285  return res?0:-1;
1286  }
1287 
1288 };
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
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
bool Load(const std::filesystem::path &path=std::filesystem::current_path())
Loads the library.
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_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
std::shared_ptr< CClient > NewClient()
unsigned int AddAudio(const T *payload, unsigned int nFrame)
std::array< float, InputSampleSize > & GetBufferIn()
bool Create(const std::string &LoginKey, const std::string &RadioName, const std::string &AWS_Access_ID, const std::string &AWS_Access_Secret, const std::filesystem::path &save_path, int json_port=0, unsigned int frames_per_chunk=12)
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)
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
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)
struct bigvoice_CInstance * bigvoice_InitProcess2(const char *LoginKey, const char *RadioName, const char *AWS_Access_ID, const char *AWS_Access_Secret, const char *save_path, const struct bigvoice_CParameters *parameters)
struct bigvoice_CInstance * bigvoice_InitProcess(const char *LoginKey, const char *RadioName, const char *AWS_Access_ID, const char *AWS_Access_Secret, const char *save_path)
int bigvoice_TerminateProcess(struct bigvoice_CInstance *instance)
void bigvoice_FreeParameters(struct bigvoice_CParameters *params)
void bigvoice_ExitProcess(struct bigvoice_CInstance *instance)
struct bigvoice_CInstance * bigvoice_InitProcess3(const char *LoginKey, const char *RadioName, const char *AWS_Access_ID, const char *AWS_Access_Secret, const char *save_path, const struct bigvoice_CParameters *parameters, unsigned int frames_per_chunk)
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)
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)
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
C interface for library.
#define fs_strdup
helper for OS dependant file name copy