Ejemplo n.º 1
0
Archivo: pdtest.c Proyecto: 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;
}
Ejemplo n.º 2
0
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");
}
Ejemplo n.º 3
0
void PdBase::sendMessage(const std::string& dest, const std::string& msg, const List& list) {

    PdContext& context = PdContext::instance();

    if(context.bMsgInProgress) {
        cerr << "Pd: Can not send message, message in progress" << endl;
        return;
    }

    _LOCK();
    libpd_start_message(list.len());
    _UNLOCK();

    context.bMsgInProgress = true;

    // step through list
    for(int i = 0; i < list.len(); ++i) {
        if(list.isFloat(i))
            addFloat(list.getFloat(i));
        else if(list.isSymbol(i))
            addSymbol(list.getSymbol(i));
    }

    finishMessage(dest, msg);
}
Ejemplo n.º 4
0
/* this is called instead of sys_main() to start things */
void libpd_init(void) {
  signal(SIGFPE, SIG_IGN);
  libpd_start_message(32); // allocate array for message assembly
  //printf ( "%p\n", &libpd_printhook );
  sys_printhook = (t_printhook) libpd_printhook;
  sys_soundin = NULL;
  sys_soundout = NULL;
  // are all these settings necessary?
  sys_schedblocksize = DEFDACBLKSIZE;
  sys_externalschedlib = 0;
  sys_printtostderr = 0;
  sys_usestdpath = 0; // don't use pd_extrapath, only sys_searchpath
  sys_debuglevel = 0;
  sys_verbose = 0;
  sys_noloadbang = 0;
  sys_nogui = 1;
  sys_hipriority = 0;
  sys_nmidiin = 0;
  sys_nmidiout = 0;
  sys_time = 0;
  pd_init();
  libpdreceive_setup();
  sys_set_audio_api(API_DUMMY);
  sys_searchpath = NULL;
}
Ejemplo n.º 5
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;
    
}
Ejemplo n.º 6
0
//----------------------------------------------------------
void PdBase::startMessage() {
	
    PdContext& context = PdContext::instance();
    
	if(context.bMsgInProgress) {
    	cerr << "Pd: Can not start message, message in progress" << endl;
		return;
	}
	
	libpd_start_message(context.maxMsgLen);
	
	context.bMsgInProgress = true;
    context.msgType = MSG;
}
Ejemplo n.º 7
0
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);
   }
}
Ejemplo n.º 8
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);
    }
}
Ejemplo n.º 9
0
/* this is called instead of sys_main() to start things */
int libpd_init(void) {
  static int initialized = 0;
  if (initialized) return -1; // only allow init once (for now)
  initialized = 1;
  signal(SIGFPE, SIG_IGN);
  libpd_start_message(32); // allocate array for message assembly
  sys_printhook = (t_printhook) libpd_printhook;
  sys_soundin = NULL;
  sys_soundout = NULL;
  // are all these settings necessary?
  sys_schedblocksize = DEFDACBLKSIZE;
  sys_externalschedlib = 0;
  sys_printtostderr = 0;
  sys_usestdpath = 0; // don't use pd_extrapath, only sys_searchpath
  sys_debuglevel = 0;
  sys_verbose = 0;
  sys_noloadbang = 0;
  sys_nogui = 1;
  sys_hipriority = 0;
  sys_nmidiin = 0;
  sys_nmidiout = 0;
  sys_init_fdpoll();
#ifdef HAVE_SCHED_TICK_ARG
  sys_time = 0;
#endif
  pd_init();
  libpdreceive_setup();
  sys_set_audio_api(API_DUMMY);
  sys_searchpath = NULL;
	
#ifdef LIBPD_EXTRA
  bob_tilde_setup();
  bonk_tilde_setup();
  choice_setup();
  expr_setup();
  fiddle_tilde_setup();
  loop_tilde_setup();
  lrshift_tilde_setup();
  pique_setup();
  sigmund_tilde_setup();
  stdout_setup();
#endif
	
	return 0;
}
Ejemplo n.º 10
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;
}
Ejemplo n.º 11
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);
	 }
}
Ejemplo n.º 12
0
void PdBase::PdContext::computeAudio(bool state) {
	// [; pd dsp $1(
	libpd_start_message(1);
	libpd_add_float((float) state);
	libpd_finish_message("pd", "dsp");
}
Ejemplo n.º 13
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;
}
Ejemplo n.º 14
0
JNIEXPORT jint JNICALL Java_org_puredata_core_PdBase_startMessage
(JNIEnv *env, jclass cls, jint length) {
  return libpd_start_message(length);
}