Esempio n. 1
0
File: pdtest.c Progetto: 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;
}
Esempio n. 2
0
/// init the pd instance
bool PdBase::PdContext::init(const int numInChannels, const int numOutChannels, const int sampleRate) {
    
	// attach callbacks
	libpd_printhook = (t_libpd_printhook) _print;
	
	libpd_banghook = (t_libpd_banghook) _bang;
	libpd_floathook = (t_libpd_floathook) _float;
	libpd_symbolhook = (t_libpd_symbolhook) _symbol;
	libpd_listhook = (t_libpd_listhook) _list;
	libpd_messagehook = (t_libpd_messagehook) _message;
	
	libpd_noteonhook = (t_libpd_noteonhook) _noteon;
	libpd_controlchangehook = (t_libpd_controlchangehook) _controlchange;
	libpd_programchangehook = (t_libpd_programchangehook) _programchange;
	libpd_pitchbendhook = (t_libpd_pitchbendhook) _pitchbend;
	libpd_aftertouchhook = (t_libpd_aftertouchhook) _aftertouch;
	libpd_polyaftertouchhook = (t_libpd_polyaftertouchhook) _polyaftertouch;
	
	libpd_midibytehook = (t_libpd_midibytehook) _midibyte;
    
    // init pd
	libpd_init();
	if(libpd_init_audio(numInChannels, numOutChannels, sampleRate) != 0) {
		return false;
	}
    bInited = true;

    return bInited;
}
Esempio n. 3
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
}
Esempio n. 4
0
int libpd_sync_init_audio(
    int input_channels, int output_channels, int sample_rate) {
  pthread_mutex_lock(&mutex);
  int err = libpd_init_audio(input_channels, output_channels, sample_rate);
  pthread_mutex_unlock(&mutex);
  return err;
}
Esempio 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;
    
}
Esempio n. 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);
    }
}
Esempio n. 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;
}
Esempio n. 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);
	 }
}
/// init the pd instance
bool PdBase::PdContext::init(const int numInChannels, const int numOutChannels, const int sampleRate) {

    // attach callbacks
	libpd_printhook = (t_libpd_printhook) libpd_print_concatenator;
    libpd_concatenated_printhook = (t_libpd_printhook) _print;

    libpd_banghook = (t_libpd_banghook) _bang;
    libpd_floathook = (t_libpd_floathook) _float;
    libpd_symbolhook = (t_libpd_symbolhook) _symbol;
    libpd_listhook = (t_libpd_listhook) _list;
    libpd_messagehook = (t_libpd_messagehook) _message;

    libpd_noteonhook = (t_libpd_noteonhook) _noteon;
    libpd_controlchangehook = (t_libpd_controlchangehook) _controlchange;
    libpd_programchangehook = (t_libpd_programchangehook) _programchange;
    libpd_pitchbendhook = (t_libpd_pitchbendhook) _pitchbend;
    libpd_aftertouchhook = (t_libpd_aftertouchhook) _aftertouch;
    libpd_polyaftertouchhook = (t_libpd_polyaftertouchhook) _polyaftertouch;

    libpd_midibytehook = (t_libpd_midibytehook) _midibyte;

    // init libpd, should only be called once!
	if(!bLibPDInited) {
		libpd_init();
		bLibPDInited = true;
	}
	// init audio
    if(libpd_init_audio(numInChannels, numOutChannels, sampleRate) != 0) {
        return false;
    }
    bInited = true;

    messages.clear();

    return bInited;
}
Esempio n. 10
0
/// init the pd instance
bool PdBase::PdContext::init(const int numInChannels, const int numOutChannels, const int sampleRate) {

    // attach callbacks
	libpd_set_printhook(libpd_print_concatenator);
    libpd_set_concatenated_printhook(_print);

    libpd_set_banghook(_bang);
    libpd_set_floathook(_float);
    libpd_set_symbolhook(_symbol);
    libpd_set_listhook(_list);
    libpd_set_messagehook(_message);

    libpd_set_noteonhook(_noteon);
    libpd_set_controlchangehook(_controlchange);
    libpd_set_programchangehook(_programchange);
    libpd_set_pitchbendhook(_pitchbend);
    libpd_set_aftertouchhook(_aftertouch);
    libpd_set_polyaftertouchhook(_polyaftertouch);

    libpd_set_midibytehook(_midibyte);

    // init libpd, should only be called once!
	if(!bLibPDInited) {
		libpd_init();
		bLibPDInited = true;
	}
	// init audio
    if(libpd_init_audio(numInChannels, numOutChannels, sampleRate) != 0) {
        return false;
    }
    bInited = true;

    messages.clear();

    return bInited;
}
Esempio n. 11
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;
}