Beispiel #1
0
PdSynth :: PdSynth(lua_State * L)
    :	synth(5), mPd(NULL) {
    synth.init(L);

    luaav_audio_config config = luaav_audio_config_current();
    void * userdata = this;
    mPd = zg_new_context(config.inchannels, config.outchannels, config.blocksize, config.samplerate, printCallbackFunction, userdata);

    mIns = config.inchannels;
    mOuts = config.outchannels;
    mBlockSize = config.blocksize;

    // create some buffers for PD to use:
    // (Can't use LuaAV signals, because PD wants floats...)
    mInputBuffers = (float *)calloc(mIns * mBlockSize, sizeof(float));
    mOutputBuffers = (float *)calloc(mOuts * mBlockSize, sizeof(float));
}
Beispiel #2
0
int main(int argc, char * const argv[]) {
  const int blockSize = 64;
  const int numInputChannels = 2;
  const int numOutputChannels = 2;
  const float sampleRate = 22050.0f;
  
  // pass directory and filename of the patch to load
  PdContext *context = zg_new_context(numInputChannels, numOutputChannels, blockSize, sampleRate,
      callbackFunction, NULL);
  PdGraph *graph = zg_new_graph(context, "/Users/mhroth/workspace/ZenGarden/test/", "MessageMessageBox.pd");
  if (graph == NULL) {
    zg_delete_context(context);
    return 1;
  }
  
  zg_attach_graph(context, graph);
  
  float *inputBuffers = (float *) calloc(numInputChannels * blockSize, sizeof(float));
  float *outputBuffers = (float *) calloc(numOutputChannels * blockSize, sizeof(float));
  
  timeval start, end;
  gettimeofday(&start, NULL);
  for (int i = 0; i < NUM_ITERATIONS; i++) {
    zg_process(context, inputBuffers, outputBuffers);
  }
  gettimeofday(&end, NULL);
  double elapsedTime = (end.tv_sec - start.tv_sec) * 1000.0; // sec to ms
  elapsedTime += (end.tv_usec - start.tv_usec) / 1000.0; // us to ms
  printf("Runtime is: %i iterations in %f milliseconds == %f iterations/second.\n", NUM_ITERATIONS,
    elapsedTime, ((double) NUM_ITERATIONS)*1000.0/elapsedTime);
  double simulatedTime = ((double) blockSize / (double) sampleRate) * (double) NUM_ITERATIONS * 1000.0; // milliseconds
  printf("Runs in realtime: %s (x%.3f)\n", (simulatedTime >= elapsedTime) ? "YES" : "NO", simulatedTime/elapsedTime);
  
  zg_delete_context(context);
  free(inputBuffers);
  free(outputBuffers);
  
  return 0;
}
Beispiel #3
0
void ofxZenGarden::load(string patchFile, int inputs, int outputs, int samplerate, int bufferSize) {
	patchFile = ofToDataPath(patchFile);
	running = false;

	hasADC = false;
	blockSize = bufferSize;
	numInputChannels = inputs;
	numOutputChannels = outputs;
	sampleRate = samplerate;
	path = patchFile;
	if(inputBuffer!=NULL) delete [] inputBuffer;
	if(outputBuffer!=NULL) delete [] outputBuffer;
	
	outputBuffer = new float[numOutputChannels*blockSize];
	inputBuffer = new float[numInputChannels*blockSize];
	char file[256];
	char dir[512];
	getDirAndFile(patchFile.c_str(), dir, file);
	if(context!=NULL) {
		delete context;
		context = NULL;
	}
	printf("Starting graph with in: %d out: %d sr: %d bs: %d\n", numInputChannels, numOutputChannels, sampleRate, blockSize);
	
	
	context = zg_new_context(numInputChannels, numOutputChannels, blockSize, sampleRate,
										callbackFunction, NULL);
	ZGGraph *graph = zg_new_graph(context, dir, file);
	if (graph == NULL) {
		printf("PdGraph could not be created. Is the filename correct?\n");
		zg_delete_context(context);
		return;
	}
	
	zg_attach_graph(context, graph);
	
	
	
	
	// look through the pd file and see if there's a dac~ in it
	
	
	
	string line;
	ifstream myfile (patchFile.c_str());
	if (myfile.is_open()) {
		while (! myfile.eof() ) {
			getline (myfile,line);
			if(line.find("adc~;")!=-1) {
				hasADC = true;
				break;
			}
		}
		myfile.close();
	}
	
	
	if(hasADC) {
		printf("Has input\n");
	} else {
		printf("No input\n");
	}


	running = true;
}