コード例 #1
0
ファイル: pdtest.c プロジェクト: LuaAV/LuaAV
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_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_start_message();
  libpd_add_symbol(argv[1]);
  libpd_add_symbol(argv[2]);
  libpd_finish_message("pd", "open");

  // 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;
}
コード例 #2
0
ファイル: PdBase.cpp プロジェクト: senemezgi/ofxPd
void PdBase::closePatch(const std::string& patch) {
	// [; pd-name menuclose 1(
	string patchname = (string) "pd-"+patch;
	libpd_start_message(PdContext::instance().maxMsgLen);
	libpd_add_float(1.0f);
	libpd_finish_message(patchname.c_str(), "menuclose");
}
コード例 #3
0
ファイル: z_jni_shared.c プロジェクト: AtelasLeo/libpd
JNIEXPORT jint JNICALL Java_org_puredata_core_PdBase_finishMessage
(JNIEnv *env, jclass cls, jstring jrecv, jstring jmsg) {
  if (!jrecv || !jmsg) return -10;
  const char *crecv = (char *) (*env)->GetStringUTFChars(env, jrecv, NULL);
  const char *cmsg = (char *) (*env)->GetStringUTFChars(env, jmsg, NULL);
  pthread_mutex_lock(&mutex);
  jint err = libpd_finish_message(crecv, cmsg);
  pthread_mutex_unlock(&mutex);
  (*env)->ReleaseStringUTFChars(env, jrecv, crecv);
  (*env)->ReleaseStringUTFChars(env, jmsg, cmsg);
  return err;
}
コード例 #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
ファイル: window.cpp プロジェクト: funkerresch/audioappdemo
void Window::startStopAudio(bool startStop)
{
   if(startStop)
   {
       qDebug() << "Start";
       libpd_start_message(1);
       libpd_add_float(1.0f);
       libpd_finish_message("pd", "dsp"); //start dsp
       ap->startAudio();
       startStopButton->setText(tr("Stop Audio"));
       startStopButton->setChecked(true);
   }
   else
   {
       qDebug() << "Stop";
       libpd_start_message(1);
       libpd_add_float(0.0f);
       libpd_finish_message("pd", "dsp"); //stop dsp
       ap->stopAudio();
       startStopButton->setText(tr("Start Audio"));
       startStopButton->setChecked(false);
   }
}
コード例 #6
0
ファイル: main.cpp プロジェクト: wimmuskee/XookyNabox
// =====================
// = 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
ファイル: PdBase.cpp プロジェクト: senemezgi/ofxPd
void PdBase::finishMessage(const std::string& dest, const std::string& msg) {

    PdContext& context = PdContext::instance();

	if(!context.bMsgInProgress) {
    	cerr << "Pd: Can not finish message, message not in progress" << endl;
		return;
	}
	
    if(context.msgType != MSG) {
        cerr << "Pd: Can not finish message, midi byte stream in progress" << endl;
		return;
    }
    
    libpd_finish_message(dest.c_str(), msg.c_str());
	
	context.bMsgInProgress = false;
    context.curMsgLen = 0;
}
コード例 #8
0
ファイル: guitest.c プロジェクト: millerpuckette/libpd
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;
}
コード例 #9
0
ファイル: main.cpp プロジェクト: rvega/XookyNabox
// =====================
// = 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);
	 }
}
コード例 #10
0
ファイル: PdBase.cpp プロジェクト: senemezgi/ofxPd
void PdBase::PdContext::computeAudio(bool state) {
	// [; pd dsp $1(
	libpd_start_message(1);
	libpd_add_float((float) state);
	libpd_finish_message("pd", "dsp");
}
コード例 #11
0
ファイル: pdtest_multi.c プロジェクト: kwh23/LearingPDiOS
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;
}