22 #include <stringapiset.h>
25 #define fs_strdup wcsdup
27 #pragma warning(disable : 4996)
31 #define fs_strdup strdup
106 if (wstr.empty())
return {};
107 int size = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (
int)wstr.size(), NULL, 0, NULL, NULL);
108 std::string str(size, 0);
109 WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (
int)wstr.size(), &str[0], size, NULL, NULL);
118 if (str.empty())
return std::wstring();
119 int size = MultiByteToWideChar(CP_UTF8, 0, &str[0], (
int)str.size(), NULL, 0);
120 std::wstring wstr(size, 0);
121 MultiByteToWideChar(CP_UTF8, 0, &str[0], (
int)str.size(), &wstr[0], size);
185 static inline void StereoToMono(
const float *input,
float *output,
size_t nFrame) {
198 static inline void MonoToStereo(
const float *input,
float *output,
size_t nFrame) {
212 static inline void StereoToMono_Planar(
const float *inputL,
const float *inputR,
float *output,
size_t nFrame) {
226 static inline void MonoToStereo_Planar(
const float *input,
float *outputL,
float *outputR,
size_t nFrame) {
287 std::vector<unsigned int> list;
289 list.push_back(*src);
349 throw std::runtime_error(
"Bad library sampling rate");
352 throw std::runtime_error(
"Bad library frame size");
355 throw std::runtime_error(
"Bad library channel count");
358 throw std::runtime_error(
"Bad library input count");
361 throw std::runtime_error(
"Bad library output count");
413 _log_cb(severity, std::string(c_msg));
432#if BIGVOICE_HAS_CLOUDBUS
464 virtual bool Exists(
const std::filesystem::path &name) = 0;
465 virtual bool Remove(
const std::filesystem::path &name) = 0;
466 virtual bool Rename(
const std::filesystem::path &from,
const std::filesystem::path &to) = 0;
467 virtual std::vector<std::filesystem::path>
GetAll() = 0;
468 virtual std::string
Read(
const std::filesystem::path &filename) = 0;
469 virtual bool Write(
const std::filesystem::path &filename,
const std::string &content) =0;
486 if (!params)
throw std::bad_alloc();
502 bool IsOk()
const {
return instance!=
nullptr; }
512 void SetParam(
const std::string& name,
const std::string& value)
527 std::string ret(c_value);
532#if BIGVOICE_HAS_CLOUDBUS
559 if (!preset_manager)
return;
597 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)
600 std::string l_save_path;
601 if (!save_path.empty()) {
602 l_save_path = save_path.u8string();
604 instance =
bigvoice_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);
605 if (!instance)
return false;
606 if (!init_metadata.empty()) {
607 for (
auto&& [key,value]: init_metadata) {
610 init_metadata.clear();
612 update_thread = std::thread([
this, json_port](){
669 init_metadata.push_back( {key, value} );
685 typedef const char* pchar;
686 pchar* keyvalue=
new pchar[2*list.size()+1];
688 for (
auto&& [key,value]: list) {
689 keyvalue[2*n+0]=key.c_str();
690 keyvalue[2*n+1]=value;
693 keyvalue[2*n+0]=
nullptr;
699 for (
auto&& [key,value]: list) {
701 init_metadata.push_back( {key, value} );
714 std::vector< std::tuple<std::string,std::string> > values;
717 for (
const char** c_value=c_values; *c_value; ) {
718 std::string key(*c_value);
721 std::string descr(*c_value);
723 values.push_back( {key,descr} );
738 std::vector<AuxiliaryOutputInfos> values;
742 auto c_info=*c_value;
745 .description = c_info->description ,
746 .sample_rate = c_info->sample_rate ,
747 .channel_count = c_info->channel_count,
748 .buffer = c_info->buffer ,
768#if BIGVOICE_HAS_WEBSERVER
829 char* c_contenttype=
nullptr;
830 char* c_content=
nullptr;
832 contenttype=c_contenttype;
849 if (!instance)
return 0;
858 if (!instance)
return;
859#if BIGVOICE_HAS_WEBSERVER
862 if (update_thread.joinable()) {
864 update_thread.join();
901 return reinterpret_cast< std::array<float,InputSampleSize>&
>(*buf);
919 return reinterpret_cast< std::array<float,OutputSampleSize>&
>(*buf);
961 std::vector<T> output;
962 unsigned int out_offset=0;
963 unsigned int in_offset=0;
964 unsigned int todo = input.size();
966 unsigned int left =
AddAudio(&input[in_offset], todo);
968 output.resize(out_offset + out_avail);
969 GetAudio(&output[out_offset], out_avail);
970 out_offset+=out_avail;
971 in_offset += todo-left;
988 if (!client)
throw std::bad_alloc();
1007 std::string
ProcessJson(
const std::string &request,
bool *NeedSave =
nullptr)
1012 if (!canswer)
return {};
1013 std::string answer(canswer);
1016 *NeedSave=(need_save!=0);
1033 return std::make_shared<CClient>(instance);
1075 template<
typename T>
1076 unsigned int AddAudio(
const T* payload,
unsigned int nFrame)
1081 template<
typename T>
1082 unsigned int GetAudio(T* payload,
unsigned int max_nFrame)
1091 std::thread update_thread;
1092 std::vector< std::pair<std::string,std::string> > init_metadata;
1093#if BIGVOICE_HAS_WEBSERVER
1105 std::string content=preset_loader->
Read(filename);
1106 return strdup(content.c_str());
1109 if (!content)
return;
1114 auto res=preset_loader->
Write(filename,content);
1119 auto res=preset_loader->
Exists(filename);
1124 auto res=preset_loader->
GetAll();
1126 for (
size_t n=0;n<res.size();n++) {
1127 all[n]=fs_strdup(res[n].c_str());
1129 all[res.size()]=
nullptr;
1134 for (
fs_char** one=all;*one;one++) {
1141 auto res=preset_loader->
Remove(filename);
1146 auto res=preset_loader->
Rename(from,to);
bigvoice_CBus * Get() const
CClient(bigvoice_CInstance *instance)
std::string ProcessJson(const std::string &request, bool *NeedSave=nullptr)
Process a JSON request and returns the answer.
CClient & operator=(const CInstance &)=delete
CClient(const CInstance &)=delete
void SetBus(const CBus &bus)
void SetInstanceTracing(TraceLoggingHProvider tracing_provider, GUID activity_guid={})
void SetMetadataMulti(const std::unordered_map< std::string, const char * > &list)
virtual void OnUpdateThreadStart()
void GetWebServerAppHealth(int &httpcode, std::string &contenttype, std::string &content)
std::string GetParam(const std::string &name)
std::vector< AuxiliaryOutputInfos > GetAuxiliaryAudioOutputInfos()
std::array< float, OutputSampleSize > & GetBufferOut()
void PresetManager_InformChange(const std::filesystem::path &relative_path, PresetChange_Kind change_kind)
unsigned int GetChunkFrames()
void SetInstanceTracingProcessActivity(GUID activity_guid)
unsigned int GetEstimatedDelay()
std::vector< T > ProcessAnyAudio(const std::vector< T > input)
void ProcessAudio_Planar(float const *const *input, float *const *output)
unsigned int AddAudio(const T *payload, unsigned int nFrame)
virtual void OnUpdateThreadStop()
void StopWebServer(int timeout_ms=1000)
CInstance & operator=(const CInstance &)=delete
void SetPresetManager(CPresetLoader *preset_manager)
unsigned int GetAudio(T *payload, unsigned int max_nFrame)
bool StartWebServer(int http_port, int https_port=0)
void SetMetadata(const std::string &key, const char *value)
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 SetWebServerAppHealth(int httpcode, const std::string &contenttype, const std::string &content)
std::vector< std::tuple< std::string, std::string > > GetMetadataInfos()
void ActivateAuxiliaryAudioID(const std::string &id)
CInstance(const CInstance &)=delete
std::array< float, InputSampleSize > & GetBufferIn()
std::shared_ptr< CClient > NewClient()
void SetParam(const std::string &name, const std::string &value)
Custom preset handler helper.
virtual ~CPresetLoader()=default
virtual bool Write(const std::filesystem::path &filename, const std::string &content)=0
virtual bool IsReadOnly()=0
virtual bool Exists(const std::filesystem::path &name)=0
virtual bool Rename(const std::filesystem::path &from, const std::filesystem::path &to)=0
virtual bool Remove(const std::filesystem::path &name)=0
virtual std::vector< std::filesystem::path > GetAll()=0
virtual std::string Read(const std::filesystem::path &filename)=0
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)
const char * bigvoice_GetFormatName(const enum bigvoice_SampleFormat fmt)
unsigned int bigvoice_GetBytesFromFormat(const enum bigvoice_SampleFormat fmt)
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)
struct SOUND4_AuxiliaryOutputInfos ** bigvoice_GetAuxiliaryAudioOutputInfos(struct bigvoice_CInstance *instance)
int bigvoice_ActivateAuxiliaryAudioID(struct bigvoice_CInstance *instance, const char *id)
void bigvoice_FreeAuxiliaryAudioInfos(struct SOUND4_AuxiliaryOutputInfos **infos)
int bigvoice_SaveState(struct bigvoice_CInstance *instance)
void bigvoice_DeleteClient(struct bigvoice_CClientInstance *client)
const char * bigvoice_ProcessJson(struct bigvoice_CClientInstance *client, const char *json_str, int *need_save)
void bigvoice_FreeJsonAnswer(const char *json_str)
struct bigvoice_CClientInstance * bigvoice_NewClient(struct bigvoice_CInstance *instance)
struct bigvoice_CBus * bigvoice_NewBus()
void bigvoice_FreeBus(struct bigvoice_CBus *bus)
void bigvoice_SetInstanceBus(struct bigvoice_CParameters *params, struct bigvoice_CBus *bus)
void bigvoice_AudioConvertTo(const float *input, uint8_t *payload, size_t nSpl, enum bigvoice_SampleFormat fmt)
void bigvoice_AudioConvertFrom(const uint8_t *payload, float *output, size_t nSpl, enum bigvoice_SampleFormat fmt)
void bigvoice_AudioMonoToLiveStereo(const float *input, uint8_t *payload)
void bigvoice_StereoToMono_Planar(const float *inputL, const float *inputR, float *output, size_t nFrame)
void bigvoice_MonoToStereo_Planar(const float *input, float *outputL, float *outputR, size_t nFrame)
void bigvoice_AudioMonoFromLiveStereo(const uint8_t *payload, float *output)
void bigvoice_MonoToStereo(const float *input, float *output, size_t nFrame)
void bigvoice_StereoToMono(const float *input, float *output, size_t nFrame)
void bigvoice_ProcessAudio(struct bigvoice_CInstance *instance, const float *input, float *output)
unsigned int bigvoice_GetEstimatedDelay(struct bigvoice_CInstance *instance)
float * bigvoice_GetBufferOut(struct bigvoice_CInstance *instance)
float * bigvoice_GetBufferIn(struct bigvoice_CInstance *instance)
void bigvoice_ProcessAudio_Planar(struct bigvoice_CInstance *instance, float const *const *input, float *const *output)
#define BIGVOICE_SAMPLE_RATE
#define BIGVOICE_CHANNEL_COUNT
unsigned int bigvoice_GetAudioInputCount()
unsigned int bigvoice_GetChannelCount()
void bigvoice_SetLoggerCallback(bigvoice_loggerfn logger)
void bigvoice_SetLogSeverity(enum bigvoice_LogSeverity severity)
#define BIGVOICE_AUDIO_OUTPUT_COUNT
unsigned int bigvoice_GetChunkSizeInFrames()
unsigned int bigvoice_GetAudioOutputCount()
#define BIGVOICE_AUDIO_INPUT_COUNT
const char * bigvoice_GetVersion()
#define BIGVOICE_AUDIOFRAME_COUNT
unsigned int bigvoice_GetSampleRate()
unsigned int * bigvoice_GetPossibleChunkSizeInFrames()
void bigvoice_FreeParameterValue(const char *value)
int bigvoice_TerminateProcess(struct bigvoice_CInstance *instance)
struct bigvoice_CInstance * bigvoice_InitProcess3(const char *LoginKey, const char *RadioName, const char *Access_Key_ID, const char *Access_Key_Secret, const char *save_path, const struct bigvoice_CParameters *parameters, unsigned int frames_per_chunk)
void bigvoice_FreeParameters(struct bigvoice_CParameters *params)
void bigvoice_ExitProcess(struct bigvoice_CInstance *instance)
struct bigvoice_CParameters * bigvoice_NewParameters()
unsigned int bigvoice_GetProcessChunkFrames(struct bigvoice_CInstance *instance)
void bigvoice_SetParameter(struct bigvoice_CParameters *params, const char *name, const char *value)
const char * bigvoice_GetParameter(struct bigvoice_CParameters *params, const char *name)
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)
void bigvoice_SetInstanceTracingProcessActivity(struct bigvoice_CInstance *instance, GUID activity_guid)
void bigvoice_SetInstanceTracing(struct bigvoice_CParameters *params, TraceLoggingHProvider tracing_provider, GUID activity_guid)
void bigvoice_StopUpdateThread(struct bigvoice_CInstance *instance)
int bigvoice_WaitUpdateThreadReady(struct bigvoice_CInstance *instance, int milliseconds)
void bigvoice_StartUpdateThread(struct bigvoice_CInstance *instance, unsigned int port)
#define SOUND4_WEBSERVER_HTTPS_OK
uint64_t bigvoice_Webserver(unsigned int listenport, unsigned int listenport_secure, struct bigvoice_CInstance *instance)
int bigvoice_Webserver_Stop(uint64_t id, int timeout_ms)
int bigvoice_Webserver_Status(uint64_t id)
void bigvoice_Webserver_SetAppHealth(struct bigvoice_CInstance *instance, int httpcode, const char *contenttype, const char *content)
#define SOUND4_WEBSERVER_HTTP_OK
void bigvoice_Webserver_FreeString(char *str)
#define SOUND4_INVALID_WEBSERVER_ID
void bigvoice_Webserver_GetAppHealth(struct bigvoice_CInstance *instance, int *httpcode, char **contenttype, char **content)
static std::wstring UTF8ToWString(const std::string &str)
static void MonoToStereo_Planar(const float *input, float *outputL, float *outputR, size_t nFrame)
static void AudioConvertFrom(const uint8_t *payload, float *output, size_t nSpl, bigvoice_SampleFormat fmt)
static void MonoToStereo(const float *input, float *output, size_t nFrame)
static void StereoToMono(const float *input, float *output, size_t nFrame)
static void StereoToMono_Planar(const float *inputL, const float *inputR, float *output, size_t nFrame)
static std::string WStringToUTF8(const std::wstring &wstr)
static void AudioMonoToLiveStereo(const float *input, uint8_t *payload)
static void AudioMonoFromLiveStereo(const uint8_t *payload, float *output)
static void AudioConvertTo(const float *input, uint8_t *payload, size_t nSpl, bigvoice_SampleFormat fmt)
static unsigned int GetAudioInputCount()
static std::vector< unsigned int > GetPossibleChunkSizeInFrames()
const size_t OutputChannels
static std::string GetFormatName(const SampleFormat fmt)
static SampleFormat GetFormatFromName(const std::string &name)
std::function< void(LogSeverity, const std::string &)> log_cb_t
static void SetLogSeverity(LogSeverity severity)
const size_t OutputSampleSize
static void SanityCheck(bool a_bCheckFrames=true)
static unsigned int GetSampleRate()
static constexpr const char * process_name
const size_t InputChannels
const size_t InputSampleSize
static unsigned int GetChannelCount()
static unsigned int GetAudioOutputCount()
static void SetLoggerCallback(log_cb_t cb)
static unsigned int GetChunkSizeInFrames()
static unsigned int GetBytesFromFormat(const SampleFormat fmt)
static constexpr const char * process_shortname
static std::string GetVersion()
static void _log_cb_c(bigvoice_LogSeverity severity, const char *c_msg)
@ S32_NATIVE
32-bit signed integer, native
@ F32_NATIVE
32-bit floating-point, native
@ S16_NATIVE
16-bit signed integer, native
struct _tlgProvider_t const * TraceLoggingHProvider
static int bigvoice_custom_exists(const fs_char *filename, void *userdata)
static int bigvoice_custom_rename(const fs_char *from, const fs_char *to, void *userdata)
static int bigvoice_custom_writer(const fs_char *filename, const char *content, void *userdata)
static fs_char ** bigvoice_custom_getall(void *userdata)
static int bigvoice_custom_remove(const fs_char *filename, void *userdata)
static void bigvoice_custom_reader_free(char *content, void *userdata)
static char * bigvoice_custom_reader(const fs_char *filename, void *userdata)
static void bigvoice_custom_getall_free(fs_char **all, void *userdata)
const float * buffer
The output buffer of the output. See sound4::bigvoice::CInstance::ProcessAudio for format.
std::string description
The description of the output.
std::string id
The ID of the output (fixed across versions)
unsigned int channel_count
The number of channels of this output.
unsigned int sample_rate
The sampling rate of this output.