# HG changeset patch # User Giulio Moro # Date 1461100946 -3600 # Node ID da5ce9876fcc78a57c6616507e3a4c18b728406b # Parent ba0b63625146201a9f4b83f28d734bb3242231de Improved basic_button project diff -r ba0b63625146 -r da5ce9876fcc projects/basic_button/render.cpp --- a/projects/basic_button/render.cpp Tue Apr 19 13:46:37 2016 +0100 +++ b/projects/basic_button/render.cpp Tue Apr 19 22:22:26 2016 +0100 @@ -1,4 +1,4 @@ - /* +/* * * Andrew McPherson and Victor Zappi * Queen Mary, University of London @@ -8,6 +8,7 @@ #include #include #include +#include // setup() is called once before the audio rendering starts. // Use it to perform any initialisation and allocation which is dependent @@ -20,10 +21,8 @@ bool setup(BeagleRTContext *context, void *userData) { - for(unsigned int n=0; ndigitalFrames; n++){ - pinModeFrame(context, 0, P8_08, INPUT); - pinModeFrame(context, 0, P8_07, OUTPUT); - } + pinModeFrame(context, 0, P8_08, INPUT); + pinModeFrame(context, 0, P8_07, OUTPUT); return true; } @@ -42,13 +41,14 @@ void render(BeagleRTContext *context, void *userData) { - float sum=0; for(unsigned int n=0; ndigitalFrames; n++){ int status=digitalReadFrame(context, 0, P8_08); //read the value of the button - sum += status; - digitalWriteFrame(context, n, P8_07, status); //write the status to the LED + digitalWriteFrameOnce(context, n, P8_07, status); //write the status to the LED + float out = 0.1 * status * rand() / (float)RAND_MAX * 2 - 1; //generate some noise, gated by the button + for(unsigned int j = 0; j < context->audioChannels; j++){ + audioWriteFrame(context, n, j, out); //write the audio output + } } - rt_printf("status: %f\n", sum); } // cleanup() is called once at the end, after the audio has stopped. @@ -58,3 +58,4 @@ { // Nothing to do here } +