annotate examples/basic_libpd/render.cpp @ 429:8533f7198644 prerelease

Re-added Doxygen
author Giulio Moro <giuliomoro@yahoo.it>
date Thu, 16 Jun 2016 19:21:46 +0100
parents 9dc5a0ccad25
children
rev   line source
giuliomoro@230 1 /*
giuliomoro@230 2 * render.cpp
giuliomoro@230 3 *
giuliomoro@230 4 * Created on: Oct 24, 2014
giuliomoro@230 5 * Author: parallels
giuliomoro@230 6 */
giuliomoro@230 7
giuliomoro@301 8 #include <Bela.h>
giuliomoro@353 9 #include <DigitalChannelManager.h>
giuliomoro@230 10 #include <cmath>
giuliomoro@230 11 #include <I2c_Codec.h>
giuliomoro@230 12 #include <PRU.h>
giuliomoro@230 13 #include <stdio.h>
giuliomoro@230 14 #include "z_libpd.h"
giuliomoro@342 15 #include "s_stuff.h"
giuliomoro@230 16 #include <UdpServer.h>
giuliomoro@324 17 #include <Midi.h>
giuliomoro@345 18 //extern t_sample* sys_soundin;
giuliomoro@345 19 //extern t_sample* sys_soundout;
giuliomoro@345 20 // if you are 100% sure of what value was used to compile libpd/puredata, then
giuliomoro@345 21 // you could #define this instead of getting it at runtime. It has proved to give some 0.3%
giuliomoro@343 22 // performance boost when it is 8 (thanks to vectorize optimizations I guess).
giuliomoro@230 23 int gBufLength;
giuliomoro@230 24
giuliomoro@230 25 float* gInBuf;
giuliomoro@230 26 float* gOutBuf;
giuliomoro@230 27
giuliomoro@230 28 void pdnoteon(int ch, int pitch, int vel) {
giuliomoro@230 29 printf("noteon: %d %d %d\n", ch, pitch, vel);
giuliomoro@230 30 }
giuliomoro@230 31
giuliomoro@301 32 void Bela_printHook(const char *recv){
giuliomoro@230 33 rt_printf("%s", recv);
giuliomoro@230 34 }
giuliomoro@230 35
giuliomoro@340 36 void libpdReadFilesLoop(){
giuliomoro@230 37 while(!gShouldStop){
giuliomoro@337 38 // check for modified sockets/file descriptors
giuliomoro@337 39 // (libpd would normally do this every block WITHIN the audio thread)
giuliomoro@337 40 // not sure if this is thread-safe at the moment
giuliomoro@230 41 libpd_sys_microsleep(0);
giuliomoro@230 42 usleep(1000);
giuliomoro@230 43 }
giuliomoro@230 44 }
giuliomoro@340 45
giuliomoro@325 46 #define PARSE_MIDI
giuliomoro@353 47 static AuxiliaryTask libpdReadFilesTask;
giuliomoro@353 48 static Midi midi;
giuliomoro@353 49 static DigitalChannelManager dcm;
giuliomoro@342 50 //UdpServer udpServer;
giuliomoro@337 51
giuliomoro@345 52 void sendDigitalMessage(bool state, unsigned int delay, void* receiverName){
giuliomoro@345 53 libpd_float((char*)receiverName, (float)state);
giuliomoro@345 54 // rt_printf("%s: %d\n", (char*)receiverName, state);
giuliomoro@345 55 }
giuliomoro@350 56
giuliomoro@352 57 #define LIBPD_DIGITAL_OFFSET 11 // digitals are preceded by 2 audio and 8 analogs (even if using a different number of analogs)
giuliomoro@352 58
giuliomoro@352 59 void Bela_messageHook(const char *source, const char *symbol, int argc, t_atom *argv){
giuliomoro@352 60 if(strcmp(source, "bela_setDigital") == 0){
giuliomoro@352 61 // symbol is the direction, argv[0] is the channel, argv[1] (optional)
giuliomoro@363 62 // is signal("sig" or "~") or message("message", default) rate
giuliomoro@353 63 bool isMessageRate = true; // defaults to message rate
giuliomoro@354 64 bool direction = 0; // initialize it just to avoid the compiler's warning
giuliomoro@354 65 bool disable = false;
giuliomoro@352 66 if(strcmp(symbol, "in") == 0){
giuliomoro@352 67 direction = INPUT;
giuliomoro@352 68 } else if(strcmp(symbol, "out") == 0){
giuliomoro@352 69 direction = OUTPUT;
giuliomoro@354 70 } else if(strcmp(symbol, "disable") == 0){
giuliomoro@354 71 disable = true;
giuliomoro@352 72 } else {
giuliomoro@354 73 return;
giuliomoro@352 74 }
giuliomoro@352 75 if(argc == 0){
giuliomoro@354 76 return;
giuliomoro@352 77 } else if (libpd_is_float(&argv[0]) == false){
giuliomoro@352 78 return;
giuliomoro@352 79 }
giuliomoro@352 80 int channel = libpd_get_float(&argv[0]) - LIBPD_DIGITAL_OFFSET;
giuliomoro@354 81 if(disable == true){
giuliomoro@354 82 dcm.unmanage(channel);
giuliomoro@355 83 return;
giuliomoro@354 84 }
giuliomoro@352 85 if(argc >= 2){
giuliomoro@352 86 t_atom* a = &argv[1];
giuliomoro@352 87 if(libpd_is_symbol(a)){
giuliomoro@352 88 char *s = libpd_get_symbol(a);
giuliomoro@352 89 if(strcmp(s, "~") == 0 || strncmp(s, "sig", 3) == 0){
giuliomoro@353 90 isMessageRate = false;
giuliomoro@352 91 }
giuliomoro@352 92 }
giuliomoro@352 93 }
giuliomoro@354 94 dcm.manage(channel, direction, isMessageRate);
giuliomoro@352 95 }
giuliomoro@352 96 }
giuliomoro@352 97
giuliomoro@350 98 void Bela_floatHook(const char *source, float value){
giuliomoro@350 99 // let's make this as optimized as possible for built-in digital Out parsing
giuliomoro@350 100 // the built-in digital receivers are of the form "bela_digitalOutXX" where XX is between 11 and 26
giuliomoro@350 101 static int prefixLength = 15; // strlen("bela_digitalOut")
giuliomoro@350 102 if(strncmp(source, "bela_digitalOut", prefixLength)==0){
giuliomoro@350 103 if(source[prefixLength] != 0){ //the two ifs are used instead of if(strlen(source) >= prefixLength+2)
giuliomoro@350 104 if(source[prefixLength + 1] != 0){
giuliomoro@357 105 // quickly convert the suffix to integer, assuming they are numbers, avoiding to call atoi
giuliomoro@350 106 int receiver = ((source[prefixLength] - 48) * 10);
giuliomoro@350 107 receiver += (source[prefixLength+1] - 48);
giuliomoro@350 108 unsigned int channel = receiver - 11; // go back to the actual Bela digital channel number
giuliomoro@350 109 if(channel >= 0 && channel < 16){ //16 is the hardcoded value for the number of digital channels
giuliomoro@354 110 dcm.setValue(channel, value);
giuliomoro@350 111 }
giuliomoro@350 112 }
giuliomoro@350 113 }
giuliomoro@350 114 }
giuliomoro@350 115 }
giuliomoro@350 116
giuliomoro@345 117 char receiverNames[16][21]={
giuliomoro@345 118 {"bela_digitalIn11"},{"bela_digitalIn12"},{"bela_digitalIn13"},{"bela_digitalIn14"},{"bela_digitalIn15"},
giuliomoro@345 119 {"bela_digitalIn16"},{"bela_digitalIn17"},{"bela_digitalIn18"},{"bela_digitalIn19"},{"bela_digitalIn20"},
giuliomoro@345 120 {"bela_digitalIn21"},{"bela_digitalIn22"},{"bela_digitalIn23"},{"bela_digitalIn24"},{"bela_digitalIn25"},
giuliomoro@345 121 {"bela_digitalIn26"}
giuliomoro@345 122 };
giuliomoro@345 123
giuliomoro@345 124 static unsigned int analogChannelsInUse;
giuliomoro@345 125 static unsigned int gLibpdBlockSize;
giuliomoro@345 126 static unsigned int gChannelsInUse = 26;
giuliomoro@345 127
giuliomoro@301 128 bool setup(BelaContext *context, void *userData)
giuliomoro@230 129 {
giuliomoro@353 130 dcm.setCallback(sendDigitalMessage);
giuliomoro@345 131 analogChannelsInUse = min(context->analogChannels, gChannelsInUse - context->audioChannels - context->digitalChannels);
giuliomoro@345 132 if(context->digitalChannels > 0){
giuliomoro@345 133 for(unsigned int ch = 0; ch < context->digitalChannels; ++ch){
giuliomoro@353 134 dcm.setCallbackArgument(ch, receiverNames[ch]);
giuliomoro@345 135 }
giuliomoro@345 136 }
giuliomoro@324 137 midi.readFrom(0);
giuliomoro@324 138 midi.writeTo(0);
giuliomoro@325 139 #ifdef PARSE_MIDI
giuliomoro@324 140 midi.enableParser(true);
giuliomoro@325 141 #else
giuliomoro@325 142 midi.enableParser(false);
giuliomoro@325 143 #endif /* PARSE_MIDI */
giuliomoro@345 144 // gChannelsInUse = min((int)(context->analogChannels+context->audioChannels), (int)gChannelsInUse);
giuliomoro@342 145 // udpServer.bindToPort(1234);
giuliomoro@230 146
giuliomoro@340 147 gLibpdBlockSize = libpd_blocksize();
giuliomoro@337 148 // check that we are not running with a blocksize smaller than gLibPdBlockSize
giuliomoro@230 149 // it would still work, but the load would be executed unevenly between calls to render
giuliomoro@340 150 if(context->audioFrames < gLibpdBlockSize){
giuliomoro@340 151 fprintf(stderr, "Error: minimum block size must be %d\n", gLibpdBlockSize);
giuliomoro@230 152 return false;
giuliomoro@230 153 }
giuliomoro@349 154 // set hooks before calling libpd_init
giuliomoro@349 155 libpd_set_printhook(Bela_printHook);
giuliomoro@349 156 libpd_set_floathook(Bela_floatHook);
giuliomoro@352 157 libpd_set_messagehook(Bela_messageHook);
giuliomoro@349 158 libpd_set_noteonhook(pdnoteon);
giuliomoro@340 159 //TODO: add hooks for other midi events and generate MIDI output appropriately
giuliomoro@349 160 libpd_init();
giuliomoro@357 161 //TODO: ideally, we would analyse the ASCII of the patch file and find out which in/outs to use
giuliomoro@230 162 libpd_init_audio(gChannelsInUse, gChannelsInUse, context->audioSampleRate);
giuliomoro@350 163 gInBuf = libpd_get_sys_soundin();
giuliomoro@350 164 gOutBuf = libpd_get_sys_soundout();
giuliomoro@230 165
giuliomoro@230 166 libpd_start_message(1); // one entry in list
giuliomoro@230 167 libpd_add_float(1.0f);
giuliomoro@230 168 libpd_finish_message("pd", "dsp");
giuliomoro@230 169
giuliomoro@340 170 gBufLength = max(gLibpdBlockSize, context->audioFrames);
giuliomoro@230 171
giuliomoro@350 172
giuliomoro@350 173 // bind your receivers here
giuliomoro@350 174 libpd_bind("bela_digitalOut11");
giuliomoro@350 175 libpd_bind("bela_digitalOut12");
giuliomoro@350 176 libpd_bind("bela_digitalOut13");
giuliomoro@350 177 libpd_bind("bela_digitalOut14");
giuliomoro@350 178 libpd_bind("bela_digitalOut15");
giuliomoro@350 179 libpd_bind("bela_digitalOut16");
giuliomoro@350 180 libpd_bind("bela_digitalOut17");
giuliomoro@350 181 libpd_bind("bela_digitalOut18");
giuliomoro@350 182 libpd_bind("bela_digitalOut19");
giuliomoro@350 183 libpd_bind("bela_digitalOut20");
giuliomoro@350 184 libpd_bind("bela_digitalOut21");
giuliomoro@350 185 libpd_bind("bela_digitalOut22");
giuliomoro@350 186 libpd_bind("bela_digitalOut23");
giuliomoro@350 187 libpd_bind("bela_digitalOut24");
giuliomoro@350 188 libpd_bind("bela_digitalOut25");
giuliomoro@350 189 libpd_bind("bela_digitalOut26");
giuliomoro@352 190 libpd_bind("bela_setDigital");
giuliomoro@350 191
giuliomoro@353 192 char file[] = "_main.pd";
giuliomoro@353 193 char folder[] = "./";
giuliomoro@353 194 // open patch [; pd open file folder(
giuliomoro@353 195 libpd_openfile(file, folder);
giuliomoro@340 196 libpdReadFilesTask = Bela_createAuxiliaryTask(libpdReadFilesLoop, 60, "libpdReadFiles");
giuliomoro@340 197 Bela_scheduleAuxiliaryTask(libpdReadFilesTask);
giuliomoro@340 198
giuliomoro@349 199
giuliomoro@230 200 return true;
giuliomoro@230 201 }
giuliomoro@230 202
giuliomoro@230 203 // render() is called regularly at the highest priority by the audio engine.
giuliomoro@230 204 // Input and output are given from the audio hardware and the other
giuliomoro@230 205 // ADCs and DACs (if available). If only audio is available, numMatrixFrames
giuliomoro@230 206 // will be 0.
giuliomoro@345 207
giuliomoro@301 208 void render(BelaContext *context, void *userData)
giuliomoro@230 209 {
giuliomoro@324 210 int num;
giuliomoro@341 211 // the safest thread-safe option to handle MIDI input is to process the MIDI buffer
giuliomoro@341 212 // from the audio thread.
giuliomoro@325 213 #ifdef PARSE_MIDI
giuliomoro@324 214 while((num = midi.getParser()->numAvailableMessages()) > 0){
giuliomoro@324 215 static MidiChannelMessage message;
giuliomoro@324 216 message = midi.getParser()->getNextChannelMessage();
giuliomoro@341 217 //message.prettyPrint(); // use this to print beautified message (channel, data bytes)
giuliomoro@324 218 switch(message.getType()){
giuliomoro@325 219 case kmmNoteOn:
giuliomoro@325 220 {
giuliomoro@324 221 int noteNumber = message.getDataByte(0);
giuliomoro@324 222 int velocity = message.getDataByte(1);
giuliomoro@324 223 int channel = message.getChannel();
giuliomoro@324 224 libpd_noteon(channel, noteNumber, velocity);
giuliomoro@325 225 break;
giuliomoro@324 226 }
giuliomoro@325 227 case kmmNoteOff:
giuliomoro@325 228 {
giuliomoro@325 229 /* PureData does not seem to handle noteoff messages as per the MIDI specs,
giuliomoro@325 230 * so that the noteoff velocity is ignored. Here we convert them to noteon
giuliomoro@325 231 * with a velocity of 0.
giuliomoro@325 232 */
giuliomoro@325 233 int noteNumber = message.getDataByte(0);
giuliomoro@325 234 // int velocity = message.getDataByte(1); // would be ignored by Pd
giuliomoro@325 235 int channel = message.getChannel();
giuliomoro@325 236 libpd_noteon(channel, noteNumber, 0);
giuliomoro@325 237 break;
giuliomoro@324 238 }
giuliomoro@325 239 case kmmControlChange:
giuliomoro@325 240 {
giuliomoro@325 241 int channel = message.getChannel();
giuliomoro@325 242 int controller = message.getDataByte(0);
giuliomoro@325 243 int value = message.getDataByte(1);
giuliomoro@325 244 libpd_controlchange(channel, controller, value);
giuliomoro@325 245 break;
giuliomoro@325 246 }
giuliomoro@325 247 case kmmProgramChange:
giuliomoro@325 248 {
giuliomoro@325 249 int channel = message.getChannel();
giuliomoro@325 250 int program = message.getDataByte(0);
giuliomoro@325 251 libpd_programchange(channel, program);
giuliomoro@325 252 break;
giuliomoro@325 253 }
giuliomoro@325 254 case kmmPolyphonicKeyPressure:
giuliomoro@325 255 {
giuliomoro@325 256 int channel = message.getChannel();
giuliomoro@325 257 int pitch = message.getDataByte(0);
giuliomoro@325 258 int value = message.getDataByte(1);
giuliomoro@325 259 libpd_polyaftertouch(channel, pitch, value);
giuliomoro@325 260 break;
giuliomoro@325 261 }
giuliomoro@325 262 case kmmChannelPressure:
giuliomoro@325 263 {
giuliomoro@325 264 int channel = message.getChannel();
giuliomoro@325 265 int value = message.getDataByte(0);
giuliomoro@325 266 libpd_aftertouch(channel, value);
giuliomoro@325 267 break;
giuliomoro@325 268 }
giuliomoro@325 269 case kmmPitchBend:
giuliomoro@325 270 {
giuliomoro@325 271 int channel = message.getChannel();
giuliomoro@325 272 int value = (message.getDataByte(1) << 7)| message.getDataByte(0);
giuliomoro@325 273 libpd_pitchbend(channel, value);
giuliomoro@325 274 break;
giuliomoro@325 275 }
giuliomoro@337 276 case kmmNone:
giuliomoro@337 277 case kmmAny:
giuliomoro@337 278 break;
giuliomoro@324 279 }
giuliomoro@324 280 }
giuliomoro@325 281 #else
giuliomoro@325 282 int input;
giuliomoro@325 283 while((input = midi.getInput()) >= 0){
giuliomoro@325 284 libpd_midibyte(0, input);
giuliomoro@325 285 }
giuliomoro@325 286 #endif /* PARSE_MIDI */
giuliomoro@340 287
giuliomoro@341 288 static unsigned int numberOfPdBlocksToProcess = gBufLength / gLibpdBlockSize;
giuliomoro@350 289
giuliomoro@350 290 // these are reset at every audio callback. Persistence across audio callbacks
giuliomoro@350 291 // is handled by the core code.
giuliomoro@350 292 // setDataOut = 0;
giuliomoro@350 293 // clearDataOut = 0;
giuliomoro@350 294
giuliomoro@343 295 for(unsigned int tick = 0; tick < numberOfPdBlocksToProcess; ++tick){
giuliomoro@345 296 unsigned int audioFrameBase = gLibpdBlockSize * tick;
giuliomoro@343 297 unsigned int j;
giuliomoro@343 298 unsigned int k;
giuliomoro@343 299 float* p0;
giuliomoro@343 300 float* p1;
giuliomoro@343 301 for (j = 0, p0 = gInBuf; j < gLibpdBlockSize; j++, p0++) {
giuliomoro@343 302 for (k = 0, p1 = p0; k < context->audioChannels; k++, p1 += gLibpdBlockSize) {
giuliomoro@345 303 *p1 = audioRead(context, audioFrameBase + j, k);
giuliomoro@232 304 }
giuliomoro@343 305 }
giuliomoro@343 306 // then analogs
giuliomoro@343 307 // this loop resamples by ZOH, as needed, using m
giuliomoro@343 308 if(context->analogChannels == 8 ){ //hold the value for two frames
giuliomoro@343 309 for (j = 0, p0 = gInBuf; j < gLibpdBlockSize; j++, p0++) {
giuliomoro@343 310 for (k = 0, p1 = p0 + gLibpdBlockSize * context->audioChannels; k < analogChannelsInUse; k++, p1 += gLibpdBlockSize) {
giuliomoro@345 311 unsigned int analogFrame = (audioFrameBase + j) / 2;
giuliomoro@343 312 *p1 = analogRead(context, analogFrame, k);
giuliomoro@341 313 }
giuliomoro@343 314 }
giuliomoro@343 315 } else if(context->analogChannels == 4){ //write every frame
giuliomoro@343 316 for (j = 0, p0 = gInBuf; j < gLibpdBlockSize; j++, p0++) {
giuliomoro@343 317 for (k = 0, p1 = p0 + gLibpdBlockSize * context->audioChannels; k < analogChannelsInUse; k++, p1 += gLibpdBlockSize) {
giuliomoro@345 318 unsigned int analogFrame = audioFrameBase + j;
giuliomoro@343 319 *p1 = analogRead(context, analogFrame, k);
giuliomoro@341 320 }
giuliomoro@343 321 }
giuliomoro@343 322 } else if(context->analogChannels == 2){ //drop every other frame
giuliomoro@343 323 for (j = 0, p0 = gInBuf; j < gLibpdBlockSize; j++, p0++) {
giuliomoro@343 324 for (k = 0, p1 = p0 + gLibpdBlockSize * context->audioChannels; k < analogChannelsInUse; k++, p1 += gLibpdBlockSize) {
giuliomoro@345 325 unsigned int analogFrame = (audioFrameBase + j) * 2;
giuliomoro@343 326 *p1 = analogRead(context, analogFrame, k);
giuliomoro@341 327 }
giuliomoro@232 328 }
giuliomoro@230 329 }
giuliomoro@345 330
giuliomoro@345 331 //then digital
giuliomoro@353 332 // note: in multiple places below we assume that the number of digitals is same as number of audio
giuliomoro@348 333 // digital in at message-rate
giuliomoro@353 334 dcm.processInput(&context->digital[audioFrameBase], gLibpdBlockSize);
giuliomoro@353 335
giuliomoro@348 336 // digital in at signal-rate
giuliomoro@348 337 for (j = 0, p0 = gInBuf; j < gLibpdBlockSize; j++, p0++) {
giuliomoro@353 338 unsigned int digitalFrame = audioFrameBase + j;
giuliomoro@348 339 for (k = 0, p1 = p0 + gLibpdBlockSize * (context->audioChannels + 8);
giuliomoro@348 340 k < 16; ++k, p1 += gLibpdBlockSize) {
giuliomoro@353 341 if(dcm.isSignalRate(k) && dcm.isInput(k)){ // only process input channels that are handled at signal rate
giuliomoro@353 342 *p1 = digitalRead(context, digitalFrame, k);
giuliomoro@353 343 }
giuliomoro@348 344 }
giuliomoro@348 345 }
giuliomoro@345 346
giuliomoro@342 347 libpd_process_sys(); // process the block
giuliomoro@345 348
giuliomoro@348 349 //digital out
giuliomoro@353 350 // digital out at signal-rate
giuliomoro@345 351 for (j = 0, p0 = gOutBuf; j < gLibpdBlockSize; ++j, ++p0) {
giuliomoro@345 352 unsigned int digitalFrame = (audioFrameBase + j);
giuliomoro@345 353 for (k = 0, p1 = p0 + gLibpdBlockSize * (context->audioChannels + 8);
giuliomoro@345 354 k < context->digitalChannels; k++, p1 += gLibpdBlockSize) {
giuliomoro@353 355 if(dcm.isSignalRate(k) && dcm.isOutput(k)){ // only process output channels that are handled at signal rate
giuliomoro@353 356 digitalWriteOnce(context, digitalFrame, k, *p1 > 0.5);
giuliomoro@353 357 }
giuliomoro@345 358 }
giuliomoro@345 359 }
giuliomoro@348 360
giuliomoro@350 361 // digital out at message-rate
giuliomoro@353 362 dcm.processOutput(&context->digital[audioFrameBase], gLibpdBlockSize);
giuliomoro@350 363
giuliomoro@345 364 //audio
giuliomoro@343 365 for (j = 0, p0 = gOutBuf; j < gLibpdBlockSize; j++, p0++) {
giuliomoro@343 366 for (k = 0, p1 = p0; k < context->audioChannels; k++, p1 += gLibpdBlockSize) {
giuliomoro@345 367 audioWrite(context, audioFrameBase + j, k, *p1);
giuliomoro@341 368 }
giuliomoro@343 369 }
giuliomoro@354 370
giuliomoro@345 371 //analog
giuliomoro@343 372 if(context->analogChannels == 8){
giuliomoro@343 373 for (j = 0, p0 = gOutBuf; j < gLibpdBlockSize; j += 2, p0 += 2) { //write every two frames
giuliomoro@345 374 unsigned int analogFrame = (audioFrameBase + j) / 2;
giuliomoro@343 375 for (k = 0, p1 = p0 + gLibpdBlockSize * context->audioChannels; k < analogChannelsInUse; k++, p1 += gLibpdBlockSize) {
giuliomoro@345 376 analogWriteOnce(context, analogFrame, k, *p1);
giuliomoro@341 377 }
giuliomoro@343 378 }
giuliomoro@343 379 } else if(context->analogChannels == 4){ //write every frame
giuliomoro@343 380 for (j = 0, p0 = gOutBuf; j < gLibpdBlockSize; ++j, ++p0) {
giuliomoro@345 381 unsigned int analogFrame = (audioFrameBase + j);
giuliomoro@343 382 for (k = 0, p1 = p0 + gLibpdBlockSize * context->audioChannels; k < analogChannelsInUse; k++, p1 += gLibpdBlockSize) {
giuliomoro@345 383 analogWriteOnce(context, analogFrame, k, *p1);
giuliomoro@341 384 }
giuliomoro@343 385 }
giuliomoro@343 386 } else if(context->analogChannels == 2){ //write every frame twice
giuliomoro@343 387 for (j = 0, p0 = gOutBuf; j < gLibpdBlockSize; j++, p0++) {
giuliomoro@343 388 for (k = 0, p1 = p0 + gLibpdBlockSize * context->audioChannels; k < analogChannelsInUse; k++, p1 += gLibpdBlockSize) {
giuliomoro@345 389 int analogFrame = audioFrameBase * 2 + j * 2;
giuliomoro@345 390 analogWriteOnce(context, analogFrame, k, *p1);
giuliomoro@345 391 analogWriteOnce(context, analogFrame + 1, k, *p1);
giuliomoro@232 392 }
giuliomoro@232 393 }
giuliomoro@230 394 }
giuliomoro@230 395 }
giuliomoro@230 396 }
giuliomoro@232 397
giuliomoro@230 398 // cleanup() is called once at the end, after the audio has stopped.
giuliomoro@230 399 // Release any resources that were allocated in setup().
giuliomoro@230 400
giuliomoro@301 401 void cleanup(BelaContext *context, void *userData)
giuliomoro@230 402 {
giuliomoro@230 403 }