I am making and addon (to nodejs). One of the functions that I have is responsible of doing fast algorithms with audio that arrives. My objective is to do that algorithms in a thread. This is a resume of that function:
void buffering(const FunctionCallbackInfo<v8::Value>& args) {
Isolate* isolate = Isolate::GetCurrent();
HandleScope scope(isolate);
int size = args[1]->NumberValue();
int final_read = args[2]->NumberValue();
int inicio_read = args[3]->NumberValue();
int client_id = args[4]->NumberValue();
Local<Object> bufferObj = args[0]->ToObject();
buf = node::Buffer::Data(bufferObj);
char mini_buf[80000];//char mini_buf[4096];
memcpy(mini_buf, buf, size);
//To implement a thread
int teste_buf = Julius[client_id].Audio_Buffering(mini_buf, size, final_read, inicio_read, client_id);
//(....returns to nodejs...)
}
If the Audio_Buffering
was only executed only one time, I could do in this way:
std::thread t[num__threads];
t[client_id] = std::thread(&SREngineJulius::Audio_Buffering, &Julius[client_id], mini_buf, size, final_read,inicio_read,client_id);
It happens that, this function is executed as long the audio is coming (because of the events in server). So my objective is to put that executions in a thread. Could be the same? If not how can i make that happen?