comparison examples/basic_libpd/render.cpp @ 308:1feb9c23ac57 prerelease

Renamed read/write functions to remove the Frame --> e.g. analogWriteFrameOnce -> analogWriteOnce, digitalReadFrame -> digitalRead
author andrewm
date Fri, 27 May 2016 18:21:21 +0100
parents e4392164b458
children 9151fe15c194
comparison
equal deleted inserted replaced
307:ff5f346a293e 308:1feb9c23ac57
113 */ 113 */
114 static int analogChannelsInUse = min(context->analogChannels, gChannelsInUse - context->audioChannels); 114 static int analogChannelsInUse = min(context->analogChannels, gChannelsInUse - context->audioChannels);
115 // rt_printf("channelsInUse: %d, analogChannels in Use: %d\n", gChannelsInUse, analogChannelsInUse); 115 // rt_printf("channelsInUse: %d, analogChannels in Use: %d\n", gChannelsInUse, analogChannelsInUse);
116 for(unsigned int n = 0; n < context->audioFrames; ++n){ //pd buffers are interleaved 116 for(unsigned int n = 0; n < context->audioFrames; ++n){ //pd buffers are interleaved
117 for(unsigned int ch = 0; ch < context->audioChannels; ++ch){ //first two channels are audio 117 for(unsigned int ch = 0; ch < context->audioChannels; ++ch){ //first two channels are audio
118 gInBuf[inW++] = audioReadFrame(context, n, ch); 118 gInBuf[inW++] = audioRead(context, n, ch);
119 } 119 }
120 // then analogs 120 // then analogs
121 // this loop resamples by ZOH, as needed, using m 121 // this loop resamples by ZOH, as needed, using m
122 if(context->analogChannels == 8 ){ //hold the value for two frames 122 if(context->analogChannels == 8 ){ //hold the value for two frames
123 for(int analogCh = 0; analogCh < analogChannelsInUse; ++analogCh){ 123 for(int analogCh = 0; analogCh < analogChannelsInUse; ++analogCh){
124 gInBuf[inW++] = analogReadFrame(context, n/2, analogCh); // n/2 wil be the same for n and n+1 when n is even 124 gInBuf[inW++] = analogRead(context, n/2, analogCh); // n/2 wil be the same for n and n+1 when n is even
125 } 125 }
126 } else if(context->analogChannels == 4){ //write every frame 126 } else if(context->analogChannels == 4){ //write every frame
127 for(int analogCh = 0; analogCh < analogChannelsInUse; ++analogCh){ 127 for(int analogCh = 0; analogCh < analogChannelsInUse; ++analogCh){
128 gInBuf[inW++] = analogReadFrame(context, n, analogCh); 128 gInBuf[inW++] = analogRead(context, n, analogCh);
129 } 129 }
130 } else if(context->analogChannels == 2){ //drop every other frame 130 } else if(context->analogChannels == 2){ //drop every other frame
131 for(int analogCh = 0; analogCh < analogChannelsInUse; ++analogCh){ 131 for(int analogCh = 0; analogCh < analogChannelsInUse; ++analogCh){
132 gInBuf[inW++] = analogReadFrame(context, n*2, analogCh); 132 gInBuf[inW++] = analogRead(context, n*2, analogCh);
133 } 133 }
134 } 134 }
135 if(inW == gBufLength * gChannelsInUse){ 135 if(inW == gBufLength * gChannelsInUse){
136 inW = 0; 136 inW = 0;
137 } 137 }
143 outR = 0; // reset the read pointer. NOTE: hopefully this is needed only the first time 143 outR = 0; // reset the read pointer. NOTE: hopefully this is needed only the first time
144 } 144 }
145 145
146 for(unsigned int n = 0; n < context->audioFrames; n++){ //pd buffers are interleaved 146 for(unsigned int n = 0; n < context->audioFrames; n++){ //pd buffers are interleaved
147 for(unsigned int ch = 0; ch < context->audioChannels; ++ch){ 147 for(unsigned int ch = 0; ch < context->audioChannels; ++ch){
148 audioWriteFrame(context, n, ch, gOutBuf[outR++]); 148 audioWrite(context, n, ch, gOutBuf[outR++]);
149 } 149 }
150 //and analogs 150 //and analogs
151 if(context->analogChannels == 8){ 151 if(context->analogChannels == 8){
152 for(unsigned int analogCh = 0; analogCh < analogChannelsInUse; ++analogCh){ 152 for(unsigned int analogCh = 0; analogCh < analogChannelsInUse; ++analogCh){
153 float analogOut = gOutBuf[outR++]; 153 float analogOut = gOutBuf[outR++];
154 if((n&1) == 0){//write every two frames 154 if((n&1) == 0){//write every two frames
155 analogWriteFrame(context, n/2, analogCh, analogOut); 155 analogWrite(context, n/2, analogCh, analogOut);
156 } else { 156 } else {
157 // discard this sample 157 // discard this sample
158 } 158 }
159 } 159 }
160 } else if(context->analogChannels == 4){ //write every frame 160 } else if(context->analogChannels == 4){ //write every frame
161 for(int analogCh = 0; analogCh < analogChannelsInUse; ++analogCh){ 161 for(int analogCh = 0; analogCh < analogChannelsInUse; ++analogCh){
162 float analogOut = gOutBuf[outR++]; 162 float analogOut = gOutBuf[outR++];
163 analogWriteFrame(context, n, analogCh, analogOut); 163 analogWrite(context, n, analogCh, analogOut);
164 } 164 }
165 } else if(context->analogChannels == 2){ //write twice every frame 165 } else if(context->analogChannels == 2){ //write twice every frame
166 for(unsigned int analogCh = 0; analogCh < analogChannelsInUse; ++analogCh){ 166 for(unsigned int analogCh = 0; analogCh < analogChannelsInUse; ++analogCh){
167 float analogOut = gOutBuf[outR++]; 167 float analogOut = gOutBuf[outR++];
168 analogWriteFrame(context, 2*n, analogCh, analogOut); 168 analogWrite(context, 2*n, analogCh, analogOut);
169 analogWriteFrame(context, 2*n + 1, analogCh, analogOut); 169 analogWrite(context, 2*n + 1, analogCh, analogOut);
170 } 170 }
171 } 171 }
172 if(outR == gBufLength * gChannelsInUse){ 172 if(outR == gBufLength * gChannelsInUse){
173 outR = 0; 173 outR = 0;
174 } 174 }