SOUND4 x1.CLOUD Library [1.5.6]
Loading...
Searching...
No Matches
Sample using C interface

C example.

See full example cpp/sound4.x1.cloud-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
cloudx1_SetParameter(params,"ADMIN_USER", "admin");
cloudx1_SetParameter(params,"ADMIN_SECRET", "admin");
// Create the processing instance
pInstance=cloudx1_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 << "cloudx1_StartUpdateThread (no json port)" << std::endl;
std::cerr << "cloudx1_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 (cloudx1_WaitUpdateThreadReady(pInstance, 5000)<0) {
std::cerr << "Timeout to create the process instance"<< std::endl;
}
std::cerr << "Waiting update thread DONE" << std::endl;
#if (CLOUDX1_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 = cloudx1_Webserver(listenport,listenport_secure,pInstance);
if (webserver==SOUND4_INVALID_WEBSERVER_ID) {
std::cerr << "Starting web server FAILED" << std::endl;
} else {
int web_status=cloudx1_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 // (CLOUDX1_HAS_WEBSERVER)
// Force load a factory preset now
// Could be used instead of setting a store_path
/*{
cloudx1_CClientInstance *pClient=cloudx1_NewClient(pInstance);
const char *answer=cloudx1_ProcessJson(pClient, "{ \"factoryload\": \"All Programs\" }", NULL);
std::cerr << "Loaded factory preset answer: " << answer<< std::endl;
cloudx1_FreeJsonAnswer(answer);
cloudx1_DeleteClient(pClient);
}*/
void cloudx1_FreeParameters(struct cloudx1_CParameters *params)
void cloudx1_SetParameter(struct cloudx1_CParameters *params, const char *name, const char *value)
struct cloudx1_CParameters * cloudx1_NewParameters()
struct cloudx1_CInstance * cloudx1_InitProcess2(const char *LoginKey, const char *RadioName, const char *Access_Key_ID, const char *Access_Key_Secret, const char *save_path, const struct cloudx1_CParameters *parameters)
void cloudx1_StartUpdateThread(struct cloudx1_CInstance *instance, unsigned int port)
int cloudx1_WaitUpdateThreadReady(struct cloudx1_CInstance *instance, int milliseconds)
#define SOUND4_WEBSERVER_HTTPS_OK
uint64_t cloudx1_Webserver(unsigned int listenport, unsigned int listenport_secure, struct cloudx1_CInstance *instance)
int cloudx1_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
cloudx1_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 cloudx1_ProcessAudio(struct cloudx1_CInstance *instance, const float *input, float *output)
#define CHANNEL_COUNT
#define CHUNK_SIZE

Sample to stop the processing instance

see Process creation/destruction

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