Mercurial > hg > beaglert
comparison examples/basic_libpd/render.cpp @ 349:6e454ebd9cc4 prerelease
Removed libpd_queued
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Wed, 08 Jun 2016 01:55:25 +0100 |
parents | db1e024858b0 |
children | ebaeffa5d493 |
comparison
equal
deleted
inserted
replaced
348:db1e024858b0 | 349:6e454ebd9cc4 |
---|---|
11 #include <Utilities.h> | 11 #include <Utilities.h> |
12 #include <I2c_Codec.h> | 12 #include <I2c_Codec.h> |
13 #include <PRU.h> | 13 #include <PRU.h> |
14 #include <stdio.h> | 14 #include <stdio.h> |
15 #include "z_libpd.h" | 15 #include "z_libpd.h" |
16 #include "z_queued.h" | |
17 #include "s_stuff.h" | 16 #include "s_stuff.h" |
18 #include <UdpServer.h> | 17 #include <UdpServer.h> |
19 #include <Midi.h> | 18 #include <Midi.h> |
20 //extern t_sample* sys_soundin; | 19 //extern t_sample* sys_soundin; |
21 //extern t_sample* sys_soundout; | 20 //extern t_sample* sys_soundout; |
45 } | 44 } |
46 } | 45 } |
47 | 46 |
48 #define PARSE_MIDI | 47 #define PARSE_MIDI |
49 AuxiliaryTask libpdReadFilesTask; | 48 AuxiliaryTask libpdReadFilesTask; |
50 AuxiliaryTask libpdProcessMessageQueueTask; | |
51 AuxiliaryTask libpdProcessMidiQueueTask; | |
52 Midi midi; | 49 Midi midi; |
53 //UdpServer udpServer; | 50 //UdpServer udpServer; |
54 | 51 |
55 void sendDigitalMessage(bool state, unsigned int delay, void* receiverName){ | 52 void sendDigitalMessage(bool state, unsigned int delay, void* receiverName){ |
56 libpd_float((char*)receiverName, (float)state); | 53 libpd_float((char*)receiverName, (float)state); |
94 // it would still work, but the load would be executed unevenly between calls to render | 91 // it would still work, but the load would be executed unevenly between calls to render |
95 if(context->audioFrames < gLibpdBlockSize){ | 92 if(context->audioFrames < gLibpdBlockSize){ |
96 fprintf(stderr, "Error: minimum block size must be %d\n", gLibpdBlockSize); | 93 fprintf(stderr, "Error: minimum block size must be %d\n", gLibpdBlockSize); |
97 return false; | 94 return false; |
98 } | 95 } |
99 // init pd | 96 // set hooks before calling libpd_init |
100 libpd_set_queued_printhook(Bela_printHook); // set this before calling libpd_init | 97 libpd_set_printhook(Bela_printHook); |
101 libpd_set_queued_noteonhook(pdnoteon); | 98 libpd_set_floathook(Bela_floatHook); |
99 libpd_set_noteonhook(pdnoteon); | |
102 //TODO: add hooks for other midi events and generate MIDI output appropriately | 100 //TODO: add hooks for other midi events and generate MIDI output appropriately |
103 libpd_queued_init(); | 101 libpd_init(); |
104 //TODO: ideally, we would analyse the ASCII of the patch file and find the in/outs to use | 102 //TODO: ideally, we would analyse the ASCII of the patch file and find the in/outs to use |
105 libpd_init_audio(gChannelsInUse, gChannelsInUse, context->audioSampleRate); | 103 libpd_init_audio(gChannelsInUse, gChannelsInUse, context->audioSampleRate); |
106 | 104 |
107 libpd_start_message(1); // one entry in list | 105 libpd_start_message(1); // one entry in list |
108 libpd_add_float(1.0f); | 106 libpd_add_float(1.0f); |
117 gInBuf = libpd_get_sys_soundin(); | 115 gInBuf = libpd_get_sys_soundin(); |
118 gOutBuf = libpd_get_sys_soundout(); | 116 gOutBuf = libpd_get_sys_soundout(); |
119 libpdReadFilesTask = Bela_createAuxiliaryTask(libpdReadFilesLoop, 60, "libpdReadFiles"); | 117 libpdReadFilesTask = Bela_createAuxiliaryTask(libpdReadFilesLoop, 60, "libpdReadFiles"); |
120 Bela_scheduleAuxiliaryTask(libpdReadFilesTask); | 118 Bela_scheduleAuxiliaryTask(libpdReadFilesTask); |
121 | 119 |
122 // Higher priority for the midi queue and lower priority for the message queue. Adjust to taste | 120 |
123 libpdProcessMidiQueueTask = Bela_createAuxiliaryTask(libpd_queued_receive_midi_messages, 80, "libpdProcessMidiQueue"); | |
124 libpdProcessMessageQueueTask = Bela_createAuxiliaryTask(libpd_queued_receive_pd_messages, 70, "libpdProcessMessageQueue"); | |
125 return true; | 121 return true; |
126 } | 122 } |
127 | 123 |
128 // render() is called regularly at the highest priority by the audio engine. | 124 // render() is called regularly at the highest priority by the audio engine. |
129 // Input and output are given from the audio hardware and the other | 125 // Input and output are given from the audio hardware and the other |
208 while((input = midi.getInput()) >= 0){ | 204 while((input = midi.getInput()) >= 0){ |
209 libpd_midibyte(0, input); | 205 libpd_midibyte(0, input); |
210 } | 206 } |
211 #endif /* PARSE_MIDI */ | 207 #endif /* PARSE_MIDI */ |
212 | 208 |
213 /* | |
214 * NOTE: if you are only using audio (or only analogs) and you are using interleaved buffers | |
215 * and the blocksize of Bela is the same as gLibPdBlockSize, then you probably | |
216 * do not need the for loops before and after libpd_process_float, so you can save quite some | |
217 * memory operations. | |
218 */ | |
219 static unsigned int numberOfPdBlocksToProcess = gBufLength / gLibpdBlockSize; | 209 static unsigned int numberOfPdBlocksToProcess = gBufLength / gLibpdBlockSize; |
220 for(unsigned int tick = 0; tick < numberOfPdBlocksToProcess; ++tick){ | 210 for(unsigned int tick = 0; tick < numberOfPdBlocksToProcess; ++tick){ |
221 unsigned int audioFrameBase = gLibpdBlockSize * tick; | 211 unsigned int audioFrameBase = gLibpdBlockSize * tick; |
222 unsigned int j; | 212 unsigned int j; |
223 unsigned int k; | 213 unsigned int k; |
317 analogWriteOnce(context, analogFrame + 1, k, *p1); | 307 analogWriteOnce(context, analogFrame + 1, k, *p1); |
318 } | 308 } |
319 } | 309 } |
320 } | 310 } |
321 } | 311 } |
322 Bela_scheduleAuxiliaryTask(libpdProcessMidiQueueTask); | |
323 Bela_scheduleAuxiliaryTask(libpdProcessMessageQueueTask); | |
324 } | 312 } |
325 | 313 |
326 // cleanup() is called once at the end, after the audio has stopped. | 314 // cleanup() is called once at the end, after the audio has stopped. |
327 // Release any resources that were allocated in setup(). | 315 // Release any resources that were allocated in setup(). |
328 | 316 |
329 void cleanup(BelaContext *context, void *userData) | 317 void cleanup(BelaContext *context, void *userData) |
330 { | 318 { |
331 libpd_queued_release(); | |
332 delete[] dtm; | 319 delete[] dtm; |
333 } | 320 } |