Пример #1
0
Window::Window()
{
    ap = new audioProcessor();
    ap->setFrameLength(256); // Default vector size for Pd is 64.
                             // We are calling libpd_process_float with 4 * 64 samples in "audiooutput.c".

    // creating our GUI controls
    createPureDataControls("Pure Data Controls");
    createPortaudioControls(tr("Portaudio Controls"));

    QHBoxLayout *layout = new QHBoxLayout;

    layout->addWidget(portaudioControlsGroup);
    layout->addWidget(pureDataControlsGroup);
    setLayout(layout);

    libpd_banghook = (t_libpd_banghook) Window::bangpd;  // binding the function bangpd to receive bangs from our pd patchers
    libpd_printhook = (t_libpd_printhook) Window::printpd; // binding printpd

    libpd_init();
    libpd_init_audio(0, 2, 44100); // 0 inputs, 2 outputs, we should adjust this (also for portaudio) every time we change the input or output device
                                   // and load a corresponding output patch, in this example it is statically set to 2 outputs and 0 inputs

    QString path = QCoreApplication::applicationDirPath();
    libpd_openfile("puredata/stereoout.pd", path.toLatin1());   // loading an output patcher with 2 outputs
    libpd_openfile("puredata/firstpatcher.pd", path.toLatin1());
    libpd_openfile("puredata/secondpatcher.pd", path.toLatin1());   // preloads the playback patchers, dynamically loading patchers seemed a little unstable on os x
    libpd_bind("playfinishedfirst");    // binding the pd patcher send "playfinishedfirst" to our libpd_banghook, libpd_printhook etc..
    libpd_bind("playfinishedsecond");   // same for the send object "playfinishedsecond"

    setWindowTitle(tr("Libpd, Portaudio and Qt Test Project"));
    Window::globalWindow = this; // binding a static window to our window object in order to access our instance from bangpd and printpd
}
Пример #2
0
int main(int argc, char **argv) {
  if (argc < 3) {
    fprintf(stderr, "usage: %s file folder\n", argv[0]);
    return -1;
  }

  // init pd
  int srate = 44100;
  libpd_printhook = (t_libpd_printhook) pdprint;
  libpd_noteonhook = (t_libpd_noteonhook) pdnoteon;
  libpd_init();
  libpd_init_audio(1, 2, srate, 1);
  float inbuf[64], outbuf[128];  // one input channel, two output channels
                                 // block size 64, one tick per buffer

  // compute audio    [; pd dsp 1(
  libpd_start_message();
  libpd_add_float(1.0f);
  libpd_finish_message("pd", "dsp");

  // open patch       [; pd open file folder(
  libpd_openfile(argv[1], argv[2]);

  // now run pd for ten seconds (logical time)
  int i;
  for (i = 0; i < 10 * srate / 64; i++) {
    // fill inbuf here
    libpd_process_float(inbuf, outbuf);
    // use outbuf here
  }

  return 0;
}
Пример #3
0
//--------------------------------------------------------------------
Patch PdBase::openPatch(const std::string& patch, const std::string& path) {
    // [; pd open file folder(
	void* handle = libpd_openfile(patch.c_str(), path.c_str());
	if(handle == NULL) {
		return Patch(); // return empty Patch
	}
	int dollarZero = libpd_getdollarzero(handle);
	return Patch(handle, dollarZero, patch, path);
}
Пример #4
0
int portAudio::initPortAudio() {
   
    //the *hook functions deal with receiving messages from Pd, see https://github.com/libpd/libpd/wiki/libpd
    libpd_set_printhook(pdprint);
    //libpd_set_noteonhook(pdnoteon);
    
    //libpd_set_floathook(pdfloat);
    libpd_init();


    libpd_init_audio(2, 2, this->getSampleRate()); //one channel in, one channel out
    
    // compute audio    [; pd dsp 1(
    libpd_start_message(1); // one entry in list
    libpd_add_float(1.0f);
    libpd_finish_message("pd", "dsp");
    
    // open patch       [; pd open file folder(, the handle is a void*
    handle = libpd_openfile("latido.pd","../../Source");
    
    //pass a number to pd, myMessage is a pd receive
    libpd_float("myMessage", 10011);
    
    for (int i = 0; i < this->getBlockSize(); i++) {
        //intialize buffer, this is probably unnecessary
        theBuffer.outbuf[i] = 0;
    }
   
    /* Initialize portaudio library before making any other calls. */
    err = Pa_Initialize();
    if( err != paNoError )
        this->sendError(err);
    
    /* Open an portaudio I/O stream. */
    err = Pa_OpenDefaultStream( &stream,
                               1,          /* input channels */
                               2,          /* output channels */
                               paFloat32,  /* 32 bit floating point output */
                               portAudio::getSampleRate(),
                               portAudio::getBlockSize(),        /* frames per buffer */
                               portAudio::paCallback,
                               &theBuffer );
    if( err != paNoError )
        this->sendError(err);
    
    err = Pa_StartStream( stream );
    if( err != paNoError )
        this->sendError(err);
    
    return err;
    
}
Пример #5
0
JNIEXPORT jlong JNICALL Java_org_puredata_core_PdBase_openFile
(JNIEnv *env, jclass cls, jstring jpatch, jstring jdir) {
  if (!jpatch || !jdir) return 0;
  const char *cpatch = (char *) (*env)->GetStringUTFChars(env, jpatch, NULL);
  const char *cdir = (char *) (*env)->GetStringUTFChars(env, jdir, NULL);
  pthread_mutex_lock(&mutex);
  jlong ptr = (jlong) libpd_openfile(cpatch, cdir);
  pthread_mutex_unlock(&mutex);
  (*env)->ReleaseStringUTFChars(env, jpatch, cpatch);
  (*env)->ReleaseStringUTFChars(env, jdir, cdir);
  return ptr;
  // very naughty, returning a pointer to Java
  // using long integer in case we're on a 64bit CPU
}
Пример #6
0
// =====================
// = INITIALIZE LIB PD =
// =====================
void initLibPd() {
    // init the pd engine
    libpd_init();
    libpd_init_audio(2, 2, sampleRate); //nInputs, nOutputs, sampleRate

    // send compute audio 1 message to pd
    libpd_start_message(1);
    libpd_add_float(1.0f);
    libpd_finish_message("pd", "dsp");

    // load the patch
    patchFile = libpd_openfile( (char*)filename.c_str(), (char*)directory.c_str() );
    if (patchFile == NULL) {
        std::cout << "Could not open patch";
        exit(1);
    }
}
Пример #7
0
int main(int argc, char **argv) {
    if (argc < 3) {
    fprintf(stderr, "usage: %s file folder\n", argv[0]);
    return -1;
    }

    // init pd
    int srate = 44100, foo;
    libpd_set_printhook((t_libpd_printhook)pdprint);
    libpd_set_noteonhook((t_libpd_noteonhook)pdnoteon);
    libpd_init();
    libpd_init_audio(1, 2, srate);

    // compute audio    [; pd dsp 1(
    libpd_start_message(1); // one entry in list
    libpd_add_float(1.0f);
    libpd_finish_message("pd", "dsp");

    // open patch       [; pd open file folder(
    void *file = libpd_openfile(argv[1], argv[2]);

    // now run pd
    for (foo = 0; foo < 2; foo++)  /* note: doesn't yet work the second time */
    {
        printf("running nogui for 1000 ticks...\n");

        runawhile(1);

        printf("starting gui..\n");
        if (libpd_start_gui("../../../pure-data/"))
            printf("gui startup failed\n");

        printf("running for 2000 more ticks...\n");
        runawhile(2);

        libpd_stop_gui();
    }

    printf("Closing and exiting\n");
    libpd_closefile(file);

    return 0;
}
Пример #8
0
// =====================
// = INITIALIZE LIB PD =
// =====================
void initLibPd(){
	 // The Jack server only seems to run fine at 256 samples per frame and libpd only processess samples
	 // in chunks (ticks) of n*64 samples at a time. We need to set the ticksPerBuffer to 4.


	 // init the pd engine
	 libpd_init();
	 libpd_init_audio(2, 2, sampleRate, 4); //nInputs, nOutputs, sampleRate, ticksPerBuffer
	 
	 // send compute audio 1 message to pd
	 libpd_start_message(1);
	 libpd_add_float(1.0f);
	 libpd_finish_message("pd", "dsp");
	 
	 // load the patch
	 patchFile = libpd_openfile( (char*)filename.c_str(), (char*)directory.c_str() );
	 if (patchFile == NULL) {
			std::cout << "Could not open patch";
			exit(1);
	 }
}
Пример #9
0
int main(int argc, char **argv) {
  t_pdinstance *pd1 = pdinstance_new(), *pd2 = pdinstance_new();
  if (argc < 3) {
    fprintf(stderr, "usage: %s file folder\n", argv[0]);
    return -1;
  }
  
  int srate = 44100;
    // maybe these two calls should be available per-instnace somehow:
  libpd_set_printhook(pdprint);   
  libpd_set_noteonhook(pdnoteon);
    /* set a "current" instance before libpd_init() or else Pd will make
    an unnecessary third "default" instance. */
  pd_setinstance(pd1);
  libpd_init();
    /* ... here we'd sure like to be able to have number of channels be
    per-nstance.  The sample rate is still global within Pd but we might
    also consider relaxing that restrction. */
  libpd_init_audio(1, 2, srate);

  float inbuf[64], outbuf[128];  // one input channel, two output channels
                                 // block size 64, one tick per buffer

  pd_setinstance(pd1);  // talk to first pd instance 

  // compute audio    [; pd dsp 1(
  libpd_start_message(1); // one entry in list
  libpd_add_float(1.0f);
  libpd_finish_message("pd", "dsp");

  // open patch       [; pd open file folder(
  libpd_openfile(argv[1], argv[2]);

  pd_setinstance(pd2);

  // compute audio    [; pd dsp 1(
  libpd_start_message(1); // one entry in list
  libpd_add_float(1.0f);
  libpd_finish_message("pd", "dsp");

  // open patch       [; pd open file folder(
  libpd_openfile(argv[1], argv[2]);

    /* the following two messages can be sent without setting the pd nstance
    and anyhow the symbols are global so they may affect multiple instances.
    However, if the messages change anyhing in the pd instacne structure
    (DSP state; current time; list of all canvases n our instance) those
    changes will apply to the current Pd nstance, so the earlier messages,
    for instance, were sensitive to which was the current one. 
    
    Note also that I'm using the fact that $0 is set to 1003, 1004, ...
    as patches are opened -it would be better to opent the patches with 
    settable $1, etc parameters to libpd_openfile().  */
    
  // [; pd frequency 1 (
  libpd_start_message(1); // one entry in list
  libpd_add_float(1.0f);
  libpd_finish_message("1003-frequency", "float");

  // [; pd frequency 1 (
  libpd_start_message(1); // one entry in list
  libpd_add_float(2.0f);
  libpd_finish_message("1004-frequency", "float");

  // now run pd for ten seconds (logical time)
  int i, j;
  for (i = 0; i < 3; i++) {
    // fill inbuf here
    pd_setinstance(pd1);
    libpd_process_float(1, inbuf, outbuf);
    if (i < 2)
    {
        for (j = 0; j < 8; j++)
            printf("%f ", outbuf[j]);
        printf("\n");
    }
    pd_setinstance(pd2);
    libpd_process_float(1, inbuf, outbuf);
    if (i < 2)
    {
        for (j = 0; j < 8; j++)
            printf("%f ", outbuf[j]);
        printf("\n");
    }
  }

  return 0;
}