diff --git a/examples/audio-trough.pd b/examples/audio-trough.pd new file mode 100644 index 0000000..529bd3e --- /dev/null +++ b/examples/audio-trough.pd @@ -0,0 +1,9 @@ +#N canvas 653 457 450 300 12; +#X obj 151 125 adc~ 1 2 3 4 5 6; +#X obj 152 184 dac~ 1 2 3 4 5 6; +#X connect 0 0 1 0; +#X connect 0 1 1 1; +#X connect 0 2 1 2; +#X connect 0 3 1 3; +#X connect 0 4 1 4; +#X connect 0 5 1 5; diff --git a/src/LibPDEngine.cpp b/src/LibPDEngine.cpp index 7f4ee6e..b04fae3 100644 --- a/src/LibPDEngine.cpp +++ b/src/LibPDEngine.cpp @@ -4,7 +4,7 @@ #include using namespace std; -#define BUFFERSIZE 4096 +#define BUFFERSIZE MAX_BUFFER_SIZE * NUM_ROWS void chair_write_patch_to_file(const string &patch, const string &path, const string &name ) { @@ -34,6 +34,7 @@ struct LibPDEngine : ScriptEngine { } // // variables for libpd t_pdinstance *_lpd; + int _pd_block_size = 64; int _sampleRate = 0; int _ticks = 0; float _output[BUFFERSIZE]; @@ -50,27 +51,43 @@ struct LibPDEngine : ScriptEngine { ProcessBlock* block = getProcessBlock(); _sampleRate = block->sampleRate; - + + setBufferSize(_pd_block_size); + setFrameDivider(1); libpd_init(); _lpd = libpd_new_instance(); libpd_set_instance(_lpd); - libpd_init_audio(2, 2, _sampleRate); + libpd_init_audio(NUM_ROWS, NUM_ROWS, _sampleRate); //cout << "_lpd is initialized" << endl; //cout << "num od pd instances: " << libpd_num_instances() << endl; // compute audio [; pd dsp 1( - libpd_start_message(1); // one entry in list + libpd_start_message(1); // one enstry in list libpd_add_float(1.0f); libpd_finish_message("pd", "dsp"); std::string name = "test.pd"; - std::string patch = "#N canvas 333 425 105 153 10;\n" + std::string patch = "#N canvas 653 457 450 300 12;\n" + "#X obj 151 125 adc~ 1 2 3 4 5 6;\n" + "#X obj 152 184 dac~ 1 2 3 4 5 6;\n" + "#X connect 0 0 1 0;\n" + "#X connect 0 1 1 1;\n" + "#X connect 0 2 1 2;\n" + "#X connect 0 3 1 3;\n" + "#X connect 0 4 1 4;\n" + "#X connect 0 5 1 5;"; + + + + + + /*"#N canvas 333 425 105 153 10;\n" "#X obj 32 79 dac~;\n" "#X obj 32 27 adc~;\n" "#X connect 1 0 0 0;\n" - "#X connect 1 1 0 1;"; + "#X connect 1 1 0 1;";*/ //libpd_openfile(patch.c_str(), path.c_str()); @@ -82,26 +99,24 @@ struct LibPDEngine : ScriptEngine { int process() override { // block ProcessBlock* block = getProcessBlock(); - int curr_bufSize = 256; - block->bufferSize = curr_bufSize; - display(std::to_string(curr_bufSize)); - const int nChans = 2; - + display(std::to_string(block->bufferSize)); + // pass samples to/from libpd - _ticks = curr_bufSize / 64; - for (int s = 0; s < curr_bufSize; s++) { - for (int c = 0; c < nChans; c++) { - _input[s*nChans+c] = block->inputs[c][s]; + _ticks = 1;//curr_bufSize / 64; + int rows = NUM_ROWS; + for (int s = 0; s < _pd_block_size; s++) { + for (int r = 0; r < rows; r++) { + _input[s*rows+r] = block->inputs[r][s]; } } libpd_set_instance(_lpd); libpd_process_float(_ticks, _input, _output); - for (int s = 0; s < curr_bufSize; s++) { - for (int c = 0; c < nChans; c++) { - block->outputs[c][s] = _output[s*nChans+c]; + for (int s = 0; s < _pd_block_size; s++) { + for (int r = 0; r < rows; r++) { + block->outputs[r][s] = _output[s*rows+r]; } }