int CsoundObj_process(CsoundObj *self, int inNumberFrames, double *inputBuffer, double *outputBuffer) { int result = csoundPerformKsmps(self->csound); if (result == 0) { int outputChannelCount = csoundGetNchnls(self->csound); int inputChannelCount = csoundGetNchnlsInput(self->csound); self->csoundOut = csoundGetSpout(self->csound); self->csoundIn = csoundGetSpin(self->csound); if (self->useAudioInput == 1) { memcpy(self->csoundIn, inputBuffer, sizeof(double) * inNumberFrames); } memcpy(outputBuffer, self->csoundOut, sizeof(double) * inNumberFrames * outputChannelCount); // printf("csoundOut =%f outputBuffer = %f\n", self->csoundOut[0], outputBuffer[0]); } return result; }
void CsoundObject_readCallback(void *inRefCon, UInt32 inNumberFrames, Float32 **audioData) { CsoundObject *self = (CsoundObject *) inRefCon; MYFLT *csoundOut = csoundGetSpout(self->csound); csoundPerformKsmps(self->csound); for (size_t channel = 0; channel < self->channelsCount; ++channel) { cblas_scopy((SInt32)inNumberFrames, &csoundOut[channel], 2, audioData[channel], 1); } }
void CsoundObj_compileCSD(CsoundObj *self, char *filePath, uint32_t samplerate, double controlrate, uint32_t bufferSize) { char samplerateArgument[10] = {0}; char controlrateArgument[10] = {0}; char bufferSizeArgument[10] = {0}; sprintf((char *)&samplerateArgument, "-r %d", samplerate); sprintf((char *)&controlrateArgument, "-k %f", controlrate); sprintf((char *)&bufferSizeArgument, "-b %d", bufferSize); char *argv[5] = { "csound", samplerateArgument, controlrateArgument, bufferSizeArgument, filePath }; printf("File name is %s\n", filePath); int result = csoundCompile(self->csound, 5, argv); if (result == 0) { printf("success\n"); self->csoundIn = csoundGetSpin(self->csound); self->csoundOut = csoundGetSpout(self->csound); self->zerodBFS = csoundGet0dBFS(self->csound); } else { printf("compilation failed\n"); } }
float *CsoundObj_getOutputBuffer(CsoundObj *self) { return csoundGetSpout(self->csound); }
int CsoundPerformanceThread::Perform() { int retval = 0; do { while (firstMessage) { csoundLockMutex(queueLock); do { CsoundPerformanceThreadMessage *msg; // get oldest message msg = (CsoundPerformanceThreadMessage*) firstMessage; if (!msg) break; // unlink from FIFO firstMessage = msg->nxt; if (!msg->nxt) lastMessage = (CsoundPerformanceThreadMessage*) 0; // process and destroy message retval = msg->run(); delete msg; // TODO: This should be moved out of the Perform function } while (!retval); if (paused) csoundWaitThreadLock(pauseLock, (size_t) 0); // mark queue as empty csoundNotifyThreadLock(flushLock); csoundUnlockMutex(queueLock); // if error or end of score, return now if (retval) goto endOfPerf; // if paused, wait until a new message is received, then loop back if (!paused) break; // VL: if this is paused, then it will double lock. csoundWaitThreadLockNoTimeout(pauseLock); csoundNotifyThreadLock(pauseLock); } if(processcallback != NULL) processcallback(cdata); retval = csoundPerformKsmps(csound); if (recordData.running) { MYFLT *spout = csoundGetSpout(csound); int len = csoundGetKsmps(csound) * csoundGetNchnls(csound); if (csoundGet0dBFS(csound) != 1.0) { MYFLT zdbfs = csoundGet0dBFS(csound); MYFLT *modspout = spout; for (int i = 0; i < len; i++) { *modspout /= zdbfs; modspout++; } } int written = csoundWriteCircularBuffer(NULL, recordData.cbuf, spout, len); if (written != len) { csoundMessage(csound, "perfThread record buffer overrun."); } } pthread_cond_signal(&recordData.condvar); // Needs to be outside the if for the case where stop record was requested } while (!retval); endOfPerf: status = retval; csoundCleanup(csound); // delete any pending messages csoundLockMutex(queueLock); { CsoundPerformanceThreadMessage *msg; msg = (CsoundPerformanceThreadMessage*) firstMessage; firstMessage = (CsoundPerformanceThreadMessage*) 0; lastMessage = (CsoundPerformanceThreadMessage*) 0; while (msg) { CsoundPerformanceThreadMessage *nxt = msg->nxt; delete msg; msg = nxt; } } csoundNotifyThreadLock(flushLock); csoundUnlockMutex(queueLock); running = 1; return retval; }