Mercurial > hg > beaglert
comparison examples/04-Audio/measure-noisefloor/render.cpp @ 544:cdabbaf3a252 prerelease
Updated Audio examples for audioOutChannels etc.
author | Robert Jack <robert.h.jack@gmail.com> |
---|---|
date | Fri, 24 Jun 2016 13:32:07 +0100 |
parents | 8fcfbfb32aa0 |
children |
comparison
equal
deleted
inserted
replaced
543:8f8809c77dda | 544:cdabbaf3a252 |
---|---|
47 // | 47 // |
48 // Return true on success; returning false halts the program. | 48 // Return true on success; returning false halts the program. |
49 | 49 |
50 bool setup(BelaContext *context, void *userData) | 50 bool setup(BelaContext *context, void *userData) |
51 { | 51 { |
52 | |
53 // Check that we have the same number of inputs and outputs. | |
54 if(context->audioInChannels != context->audioOutChannels || | |
55 context->analogInChannels != context-> analogOutChannels){ | |
56 printf("Error: for this project, you need the same number of input and output channels.\n"); | |
57 return false; | |
58 } | |
59 | |
52 // Clear the filter data structures | 60 // Clear the filter data structures |
53 for(int i = 0; i < 10; i++) { | 61 for(int i = 0; i < 10; i++) { |
54 gReadBufferPointers[i] = gWriteBufferPointers[i] = 0; | 62 gReadBufferPointers[i] = gWriteBufferPointers[i] = 0; |
55 gBuffers0[i] = new float[gBufferSize]; | 63 gBuffers0[i] = new float[gBufferSize]; |
56 gBuffers1[i] = new float[gBufferSize]; | 64 gBuffers1[i] = new float[gBufferSize]; |
76 { | 84 { |
77 bool bufferIsFull = false; // Whether at least one buffer has filled | 85 bool bufferIsFull = false; // Whether at least one buffer has filled |
78 | 86 |
79 for(unsigned int n = 0; n < context->audioFrames; n++) { | 87 for(unsigned int n = 0; n < context->audioFrames; n++) { |
80 // Store audio inputs in buffer | 88 // Store audio inputs in buffer |
81 for(unsigned int ch = 0; ch < context->audioChannels; ch++) { | 89 for(unsigned int ch = 0; ch < context->audioOutChannels; ch++) { |
82 if(gWriteBufferPointers[ch] < gBufferSize) { | 90 if(gWriteBufferPointers[ch] < gBufferSize) { |
83 gWriteBuffers[ch][gWriteBufferPointers[ch]] = | 91 gWriteBuffers[ch][gWriteBufferPointers[ch]] = |
84 context->audioIn[n * context->audioChannels + ch]; | 92 context->audioIn[n * context->audioOutChannels + ch]; |
85 gWriteBufferPointers[ch]++; | 93 gWriteBufferPointers[ch]++; |
86 if(gWriteBufferPointers[ch] >= gBufferSize) | 94 if(gWriteBufferPointers[ch] >= gBufferSize) |
87 bufferIsFull = true; | 95 bufferIsFull = true; |
88 } | 96 } |
89 } | 97 } |
90 } | 98 } |
91 | 99 |
92 if(context->analogChannels != 0) { | 100 if(context->analogOutChannels != 0) { |
93 for(unsigned int n = 0; n < context->analogFrames; n++) { | 101 for(unsigned int n = 0; n < context->analogFrames; n++) { |
94 // Store analog inputs in buffer, starting at channel 2 | 102 // Store analog inputs in buffer, starting at channel 2 |
95 for(unsigned int ch = 0; ch < context->analogChannels; ch++) { | 103 for(unsigned int ch = 0; ch < context->analogOutChannels; ch++) { |
96 if(gWriteBufferPointers[ch + 2] < gBufferSize) { | 104 if(gWriteBufferPointers[ch + 2] < gBufferSize) { |
97 gWriteBuffers[ch + 2][gWriteBufferPointers[ch + 2]] = | 105 gWriteBuffers[ch + 2][gWriteBufferPointers[ch + 2]] = |
98 context->analogIn[n * context->analogChannels + ch]; | 106 context->analogIn[n * context->analogOutChannels + ch]; |
99 gWriteBufferPointers[ch + 2]++; | 107 gWriteBufferPointers[ch + 2]++; |
100 if(gWriteBufferPointers[ch + 2] >= gBufferSize) | 108 if(gWriteBufferPointers[ch + 2] >= gBufferSize) |
101 bufferIsFull = true; | 109 bufferIsFull = true; |
102 } | 110 } |
103 | 111 |
104 // Set all analog outputs to halfway point so they can be more | 112 // Set all analog outputs to halfway point so they can be more |
105 // easily measured for noise | 113 // easily measured for noise |
106 context->analogOut[n * context->analogChannels + ch] = 0.5; | 114 context->analogOut[n * context->analogOutChannels + ch] = 0.5; |
107 } | 115 } |
108 } | 116 } |
109 } | 117 } |
110 | 118 |
111 | 119 |