Mercurial > hg > beaglert
comparison examples/basic_libpd/render.cpp @ 338:1802f99cd77f prerelease
Initial support for thread-safe libpd (stil missing updated libpd binary), untested
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Sun, 05 Jun 2016 21:46:44 +0100 |
parents | 5e2780bfbfed |
children | 69d86429a1cf |
comparison
equal
deleted
inserted
replaced
337:5e2780bfbfed | 338:1802f99cd77f |
---|---|
10 #include <Utilities.h> | 10 #include <Utilities.h> |
11 #include <I2c_Codec.h> | 11 #include <I2c_Codec.h> |
12 #include <PRU.h> | 12 #include <PRU.h> |
13 #include <stdio.h> | 13 #include <stdio.h> |
14 #include "z_libpd.h" | 14 #include "z_libpd.h" |
15 #include "z_queued.h" | |
15 #include <UdpServer.h> | 16 #include <UdpServer.h> |
16 #include <Midi.h> | 17 #include <Midi.h> |
17 | 18 |
18 | 19 |
19 // setup() is called once before the audio rendering starts. | 20 // setup() is called once before the audio rendering starts. |
73 if(context->audioFrames < gLibPdBlockSize){ | 74 if(context->audioFrames < gLibPdBlockSize){ |
74 fprintf(stderr, "Error: minimum block size must be %d\n", gLibPdBlockSize); | 75 fprintf(stderr, "Error: minimum block size must be %d\n", gLibPdBlockSize); |
75 return false; | 76 return false; |
76 } | 77 } |
77 // init pd | 78 // init pd |
78 libpd_set_printhook(Bela_printHook); // set this before calling libpd_init | 79 libpd_set_queued_printhook(Bela_printHook); // set this before calling libpd_init |
79 libpd_set_noteonhook(pdnoteon); | 80 libpd_set_queued_noteonhook(pdnoteon); |
80 libpd_init(); | 81 libpd_queued_init(); |
81 //TODO: analyse the ASCII of the patch file and find the in/outs to use | 82 //TODO: analyse the ASCII of the patch file and find the in/outs to use |
82 libpd_init_audio(gChannelsInUse, gChannelsInUse, context->audioSampleRate); | 83 libpd_init_audio(gChannelsInUse, gChannelsInUse, context->audioSampleRate); |
83 | 84 |
84 libpd_start_message(1); // one entry in list | 85 libpd_start_message(1); // one entry in list |
85 libpd_add_float(1.0f); | 86 libpd_add_float(1.0f); |
218 } | 219 } |
219 } | 220 } |
220 // rt_printf("inW %d\n", inW); | 221 // rt_printf("inW %d\n", inW); |
221 if(inW == 0){ //if the buffer is full, process it | 222 if(inW == 0){ //if the buffer is full, process it |
222 static int numberOfPdBlocksToProcess = gBufLength/gLibPdBlockSize; | 223 static int numberOfPdBlocksToProcess = gBufLength/gLibPdBlockSize; |
224 // TODO: see if we can rewrite libpd_process_float so that it takes a buffer | |
225 // of interleaved channels of arbitrary length channels rather than a series of | |
226 // stacked buffers of size gLibPdBlockSize as it currently does. | |
223 libpd_process_float(numberOfPdBlocksToProcess, gInBuf, gOutBuf); | 227 libpd_process_float(numberOfPdBlocksToProcess, gInBuf, gOutBuf); |
224 outR = 0; // reset the read pointer. NOTE: hopefully this is needed only the first time | 228 outR = 0; // reset the read pointer. NOTE: hopefully this is needed only the first time |
225 } | 229 } |
226 | 230 |
227 for(unsigned int n = 0; n < context->audioFrames; n++){ //pd buffers are interleaved | 231 for(unsigned int n = 0; n < context->audioFrames; n++){ //pd buffers are interleaved |
261 // cleanup() is called once at the end, after the audio has stopped. | 265 // cleanup() is called once at the end, after the audio has stopped. |
262 // Release any resources that were allocated in setup(). | 266 // Release any resources that were allocated in setup(). |
263 | 267 |
264 void cleanup(BelaContext *context, void *userData) | 268 void cleanup(BelaContext *context, void *userData) |
265 { | 269 { |
270 libpd_queued_release(); | |
266 free(gInBuf); | 271 free(gInBuf); |
267 free(gOutBuf); | 272 free(gOutBuf); |
268 } | 273 } |