SOUND4 BIGVOICE.CL Library [1.1.6]
Loading...
Searching...
No Matches
Sample using C interface

C example.

See full example cpp/sound4.bigvoice.cl-pipe.cpp

Sample to create the processing instance

see Process creation/destruction and Update Management

// Setup parameters
// Optional: activate web authentication, set admin password
// This creates the authentication only for a new storage path
bigvoice_SetParameter(params,"ADMIN_USER", "admin");
bigvoice_SetParameter(params,"ADMIN_SECRET", "admin");
// Create the processing instance
pInstance=bigvoice_InitProcess2(pLoginKey,pRadioName,pKeyId,pAccessKey,store_path.c_str(), params);
if (!pInstance) {
std::cerr << "Failed to create the process instance"<< std::endl;
return 1;
}
// Start the update thread, without JSON server (low priority)
std::thread updater([pInstance](){
// will returned when stopped or destroyed
std::cerr << "bigvoice_StartUpdateThread (no json port)" << std::endl;
std::cerr << "bigvoice_StartUpdateThread END" << std::endl;
});
// This is not mandatory, but better be sure we are ready right now
std::cerr << "Waiting update thread" << std::endl;
if (bigvoice_WaitUpdateThreadReady(pInstance, 5000)<0) {
std::cerr << "Timeout to create the process instance"<< std::endl;
}
std::cerr << "Waiting update thread DONE" << std::endl;
#if (BIGVOICE_HAS_WEBSERVER)
// Starts a web server, listening on port http://localhost:8080, https://localhost:8443
std::cerr << "Starting web server" << std::endl;
int listenport= 8080;
int listenport_secure= 8443;
uint64_t webserver= SOUND4_INVALID_WEBSERVER_ID;
if (listenport || listenport_secure) {
webserver = bigvoice_Webserver(listenport,listenport_secure,pInstance);
if (webserver==SOUND4_INVALID_WEBSERVER_ID) {
std::cerr << "Starting web server FAILED" << std::endl;
} else {
int web_status=bigvoice_Webserver_Status(webserver);
if (listenport) {
if (web_status & SOUND4_WEBSERVER_HTTP_OK) {
std::cerr << "Web server listening on port " << listenport;
} else {
std::cerr << "Web server failed to listen on port " << listenport;
}
}
if (listenport_secure) {
if (web_status & SOUND4_WEBSERVER_HTTPS_OK) {
std::cerr << "Web server listening on secure port " << listenport_secure;
} else {
std::cerr << "Web server failed to listen on secure port " << listenport_secure;
}
}
std::cerr << "Starting web server DONE" << std::endl;
}
}
#endif // (BIGVOICE_HAS_WEBSERVER)
// Force load a factory preset now
// Could be used instead of setting a store_path
/*{
bigvoice_CClientInstance *pClient=bigvoice_NewClient(pInstance);
const char *answer=bigvoice_ProcessJson(pClient, "{ \"factoryload\": \"All Programs\" }", NULL);
std::cerr << "Loaded factory preset answer: " << answer<< std::endl;
bigvoice_FreeJsonAnswer(answer);
bigvoice_DeleteClient(pClient);
}*/
void bigvoice_FreeParameters(struct bigvoice_CParameters *params)
struct bigvoice_CParameters * bigvoice_NewParameters()
struct bigvoice_CInstance * bigvoice_InitProcess2(const char *LoginKey, const char *RadioName, const char *Access_Key_ID, const char *Access_Key_Secret, const char *save_path, const struct bigvoice_CParameters *parameters)
void bigvoice_SetParameter(struct bigvoice_CParameters *params, const char *name, const char *value)
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_Status(uint64_t id)
#define SOUND4_WEBSERVER_HTTP_OK
#define SOUND4_INVALID_WEBSERVER_ID

Sample processing loop

see Direct processing

bool stopthread=false;
alignas(64) float audio_in[CHUNK_SIZE*CHANNEL_COUNT];
alignas(64) float audio_out[CHUNK_SIZE*CHANNEL_COUNT];
#if defined(_WIN32) || defined(WIN32)
// Windows: The stdin, stdout, and stderr streams always open in text mode by default
_setmode(_fileno(stdin), _O_BINARY);
_setmode(_fileno(stdout), _O_BINARY);
#endif
while (!stopthread)
{
// Read a chunk from stdin
if (std::fread(&audio_in[0], sizeof(float), CHUNK_SIZE*CHANNEL_COUNT, stdin) != CHUNK_SIZE*CHANNEL_COUNT) {
std::cerr << "ProcessLoop: input stopped"<< std::endl;
stopthread=true;
break;
}
if (stopthread) break;
// Process it
bigvoice_ProcessAudio(pInstance, audio_in, audio_out);
// Write it to stdout
if (fwrite(&audio_out[0], sizeof(float), CHUNK_SIZE*CHANNEL_COUNT, stdout) != CHUNK_SIZE*CHANNEL_COUNT) {
std::cerr << "Failed to write audio output" << std::endl;
stopthread=true;
}
}
void bigvoice_ProcessAudio(struct bigvoice_CInstance *instance, const float *input, float *output)
#define CHANNEL_COUNT
#define CHUNK_SIZE

Sample to stop the processing instance

see Process creation/destruction

#if (BIGVOICE_HAS_WEBSERVER)
// Stopping the webserver
std::cerr << "Stopping web server" << std::endl;
bigvoice_Webserver_Stop(webserver, 1000);
std::cerr << "Stopping web server DONE" << std::endl;
#endif // (BIGVOICE_HAS_WEBSERVER)
// Stopping the processing instance
std::cerr << "Stopping Update thread" << std::endl;
bigvoice_StopUpdateThread(pInstance); // this will exit the update thread
std::cerr << "Stopping Update thread DONE" << std::endl;
updater.join();
void bigvoice_ExitProcess(struct bigvoice_CInstance *instance)
void bigvoice_StopUpdateThread(struct bigvoice_CInstance *instance)
int bigvoice_Webserver_Stop(uint64_t id, int timeout_ms)