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; }
int PyQcsObject::getNumChannels(int index) { int nchnls = -1; CsoundEngine *e = m_qcs->getEngine(index); if (e != NULL) { CSOUND *cs = e->getCsound(); if (cs != NULL) { nchnls = csoundGetNchnls (cs); } } return nchnls; }
int CsoundObj_getOutputChannelCount(CsoundObj *self) { return csoundGetNchnls(self->csound); }
uint32_t CsoundObj_getNchnls(CsoundObj *self) { return csoundGetNchnls(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; }
CsPerfThreadMsg_Record(CsoundPerformanceThread *pt, std::string filename, int samplebits = 16, int numbufs = 4) : CsoundPerformanceThreadMessage(pt) { this->filename = filename; CsoundPerformanceThreadMessage::lockRecord(); recordData_t *recordData = CsoundPerformanceThreadMessage::getRecordData(); if (recordData->running) { CsoundPerformanceThreadMessage::unlockRecord(); return; } CSOUND * csound = pt_->GetCsound(); if (!csound) { return; } int bufsize = csoundGetOutputBufferSize(csound) * csoundGetNchnls(csound) * numbufs; recordData->cbuf = csoundCreateCircularBuffer(csound, bufsize, sizeof(MYFLT)); if (!recordData->cbuf) { csoundMessage(csound, "Could create recording buffer."); return; } SF_INFO sf_info; sf_info.samplerate = csoundGetSr(csound); sf_info.channels = csoundGetNchnls(csound); switch (samplebits) { case 32: sf_info.format = SF_FORMAT_FLOAT; break; case 24: sf_info.format = SF_FORMAT_PCM_24; break; case 16: default: sf_info.format = SF_FORMAT_PCM_16; break; } sf_info.format |= SF_FORMAT_WAV; recordData->sfile = (void *) sf_open(filename.c_str(), SFM_WRITE, &sf_info); if (!recordData->sfile) { csoundMessage(csound, "Could not open file for recording."); csoundDestroyCircularBuffer(csound, recordData->cbuf); return; } sf_command((SNDFILE *) recordData->sfile, SFC_SET_CLIPPING, NULL, SF_TRUE); recordData->running = true; recordData->thread = csoundCreateThread(recordThread_, (void*) recordData); CsoundPerformanceThreadMessage::unlockRecord(); }