comparison scripts/hvresources/render.cpp @ 166:e6558ce09884

- Cleaned up default heavy render.cpp file
author chnrx <chris.heinrichs@gmail.com>
date Thu, 03 Dec 2015 17:15:10 +0000
parents 5bcf04234f80
children 3b8a28edae41
comparison
equal deleted inserted replaced
165:30dade7bc2bc 166:e6558ce09884
13 13
14 #include <BeagleRT.h> 14 #include <BeagleRT.h>
15 #include <cmath> 15 #include <cmath>
16 #include "../include/Utilities.h" 16 #include "../include/Utilities.h"
17 #include "Heavy_bbb.h" 17 #include "Heavy_bbb.h"
18
19 // #include "I2c_TouchKey.h"
20
21 // #include "../include/UdpServer.h"
22 // #include "../include/UdpClient.h"
23 // #include <iostream>
24 // #include <fstream>
25 // #include "../include/ReceiveAudioThread.h"
26
27 // #include "../include/render.h"
28 // #include <arm_neon.h>
29 // #include <time.h>
30 // #include <sndfile.h>
31
32 // #include "../include/RTAudio.h"
33 // #include <rtdk.h>
34
35 18
36 /* 19 /*
37 * HEAVY CONTEXT & BUFFERS 20 * HEAVY CONTEXT & BUFFERS
38 */ 21 */
39 22
62 } 45 }
63 46
64 } 47 }
65 48
66 /* 49 /*
67 * RENDER INITIALISATION, LOOP & CLEANUP 50 * SETUP, RENDER LOOP & CLEANUP
68 */ 51 */
69 52
70
71 // bool initialise_render(int numMatrixChannels, int numAudioChannels,
72 // int numMatrixFramesPerPeriod,
73 // int numAudioFramesPerPeriod,
74 // float matrixSampleRate, float audioSampleRate,
75 // void *userData)
76 // {
77 bool setup(BeagleRTContext *context, void *userData) { 53 bool setup(BeagleRTContext *context, void *userData) {
78 54
79 /* HEAVY */ 55 /* HEAVY */
80 56
81 gHeavyContext = hv_bbb_new(context->audioSampleRate); 57 gHeavyContext = hv_bbb_new(context->audioSampleRate);
82 58
83 gHvInputChannels = hv_getNumInputChannels(gHeavyContext); 59 gHvInputChannels = hv_getNumInputChannels(gHeavyContext);
84 gHvOutputChannels = hv_getNumOutputChannels(gHeavyContext); 60 gHvOutputChannels = hv_getNumOutputChannels(gHeavyContext);
85 61
86 // srand ( time(NULL) );
87
88 rt_printf("Starting Heavy context with %d input channels and %d output channels\n", 62 rt_printf("Starting Heavy context with %d input channels and %d output channels\n",
89 gHvInputChannels, gHvOutputChannels); 63 gHvInputChannels, gHvOutputChannels);
90 64
91 if(gHvInputChannels != 0) { 65 if(gHvInputChannels != 0) {
92 gHvInputBuffers = (float *)calloc(gHvInputChannels * context->audioFrames,sizeof(float)); 66 gHvInputBuffers = (float *)calloc(gHvInputChannels * context->audioFrames,sizeof(float));
93 //memset(gHvInputBuffers,0,gHvInputChannels * numAudioFramesPerPeriod * sizeof(float));
94 } 67 }
95 if(gHvOutputChannels != 0) { 68 if(gHvOutputChannels != 0) {
96 gHvOutputBuffers = (float *)calloc(gHvOutputChannels * context->audioFrames,sizeof(float)); 69 gHvOutputBuffers = (float *)calloc(gHvOutputChannels * context->audioFrames,sizeof(float));
97 } 70 }
98 71
105 78
106 return true; 79 return true;
107 } 80 }
108 81
109 82
110 // void render(int numMatrixFrames, int numAudioFrames, float *audioIn, float *audioOut,
111 // uint16_t *matrixIn, uint16_t *matrixOut)
112 // {
113 void render(BeagleRTContext *context, void *userData) 83 void render(BeagleRTContext *context, void *userData)
114 { 84 {
115 // use this for thread management
116 // if(gCount == 0) {
117 // } else {
118 // }
119 // gCount++;
120 85
121 // De-interleave the data 86 // De-interleave the data
122 if(gHvInputBuffers != NULL) { 87 if(gHvInputBuffers != NULL) {
123 for(int n = 0; n < context->audioFrames; n++) { 88 for(int n = 0; n < context->audioFrames; n++) {
124 for(int ch = 0; ch < gHvInputChannels; ch++) { 89 for(int ch = 0; ch < gHvInputChannels; ch++) {
155 // THESE ARE SENSOR OUTPUT 'CHANNELS' USED FOR ROUTING 120 // THESE ARE SENSOR OUTPUT 'CHANNELS' USED FOR ROUTING
156 // they are the content of the 'sensor output' dac~ channels 121 // they are the content of the 'sensor output' dac~ channels
157 } else { 122 } else {
158 if(ch >= context->audioChannels) { 123 if(ch >= context->audioChannels) {
159 int m = n/2; 124 int m = n/2;
160 // float mOut = (float)gHvOutputBuffers[ch*numAudioFrames + n];
161 // mOut = constrain(mOut,0.0,1.0);
162 context->analogOut[m * context->analogFrames + (ch-context->audioChannels)] = constrain(gHvOutputBuffers[ch*context->audioFrames + n],0.0,1.0); 125 context->analogOut[m * context->analogFrames + (ch-context->audioChannels)] = constrain(gHvOutputBuffers[ch*context->audioFrames + n],0.0,1.0);
163 } else { 126 } else {
164 context->audioOut[n * context->audioChannels + ch] = gHvOutputBuffers[ch * context->audioFrames + n]; 127 context->audioOut[n * context->audioChannels + ch] = gHvOutputBuffers[ch * context->audioFrames + n];
165 } 128 }
166 } 129 }