ERIS CORE

◆ render()

void FASTRUN AppCQT::render ( )
inlineprotectedvirtual

render loop

Reimplemented from AppBaseClass.

Definition at line 170 of file appCQT.h.

170  {
171  if (!is_active || draw == NULL) return;
172  update_calls++;
173  #ifdef TX_PERIODIC_FFT
174  if (fft_buffer_serial_transmit_elapsed > TX_PERIOD && Serial.availableForWrite() > 5900){
175  if(sci==NULL) return;
179  sci->printf(F("S 512"));
180  for(int i = 0; i < 512; i+=1){
181  //transmitt low range then high range
182  //if(Serial.availableForWrite() < 1000){delayMicroseconds(10000);}
183  if(fft_buffer_select_for_serial_transmit == 0) sci->printf(F(",%d"),(int)(100.0*fft2->output[i]));
184  if(fft_buffer_select_for_serial_transmit == 1) sci->printf(F(",%d"),(int)(100.0*fft->output[i]));
185  //if ((i % 127)==0) Serial.flush();
186  }
187  sci->println("");
188  }
191  {
193  sci->println(F("S FIN")); // end of series data
194  }
195  sci->sendLZ4Message();
196  }
197  }
198  #endif
199  if (cqt_serial_transmit_elapsed > TX_CQT_PERIOD){
201  for (uint16_t i=0;i < osc_bank_size;i++){
202  if (oscBank[i].cqtBin < high_range) sci->printf(F("CQT_L %d,%s,%.0f,%.0f,%.2f,%.3f,%.3f\n"),oscBank[i].cqtBin,note_name[oscBank[i].cqtBin],oscBank[i].peakFrequency,note_freq[oscBank[i].cqtBin],oscBank[i].phase,oscBank[i].avgValueFast,oscBank[i].avgValueSlow*1000.0,oscBank[i].transientValue*100.0);
203  if (oscBank[i].cqtBin >= high_range) sci->printf(F("CQT_H %d,%s,%.0f,%.0f,%.2f,%.3f,%.3f\n"),oscBank[i].cqtBin,note_name[oscBank[i].cqtBin],oscBank[i].peakFrequency,note_freq[oscBank[i].cqtBin],oscBank[i].phase,oscBank[i].avgValueFast,oscBank[i].avgValueSlow*1000.0,oscBank[i].transientValue*100.0);
204  }
205  sci->printf(F("CQT_EOF\n"));
206  sci->sendLZ4Message();
207  }
208  //Serial.flush();
210  }
211 
215  if (draw == NULL) return;
216  if (has_pop) draw->fillRoundRect(x,y,w,h,3,CL(0x07,0x00,0x10));
217  //draw the scale lines
218  draw->setFont(Arial_8);
219  draw->setTextColor(ILI9341_DARKGREY);
220  for(uint8_t i=1;i < 18; i++){
221  draw->drawLine(x,y + (h - (log1p((0.1 * i))) * h),x+w,y + (h - (log1p((0.1 * i))) * h),ILI9341_DARKCYAN);
222  if (has_pop){
223  draw->setCursor(x + i * 17,y+ (h - (log1p((0.1 * i))) * h) - 9);
224  if (i < 17) draw->print((log1p((0.1 * i))));
225  }
226  }
227 
228  //draw the cqt bins
229  const float im = (w-1)/(float)(sizeof(note_freq)/sizeof(note_freq[0]));
230  uint16_t nx;
231  float signal;
232  float amp;
233 
234  for (uint16_t i=0;i< sizeof(note_freq)/sizeof(note_freq[0])-1;i++){
235  amp = fftHighRR[i].peakValue;//fft->read(&fftHighRR[i]);
236  signal = (log1p(amp)) * h;
237  if (signal>(h-1)) signal = h-1;
238  if (signal<0) signal = 0;
239  nx = (uint16_t)(im*fftHighRR[i].cqtBin);
240  //draw->fillRoundRect(x+nx,y,2,(uint16_t)signal,1,ILI9341_ORANGE);
241  draw->fillRoundRect(x+nx,y+h - (uint16_t)signal,2,(uint16_t)signal,1,ILI9341_CYAN);
242  amp = fftLowRR[i].avgValueFast;//fft2->read(&fftLowRR[i]);
243  signal = (log1p(amp)) * h;
244  if (signal>(h-1)) signal = h-1;
245  if (signal<0) signal = 0;
246  nx = (uint16_t)(im*fftLowRR[i].cqtBin);
247  draw->fillRoundRect(x+nx,y+h - (uint16_t)signal,2,(uint16_t)signal,1,ILI9341_MAGENTA);
248  }
249 
250  //make a second pass but only draw the oscillators
251  draw->setTextColor(ILI9341_GREENYELLOW);
252  for (uint16_t i=0;i < osc_bank_size;i++){
253  amp = oscBank[i].avgValueFast;//fft->read(&fftHighRR[i]);
254  signal = (log1p(amp)) * h;
255  if (signal<0) signal = 0;
256  if (signal>(h-1)) signal = h-1;
257  nx = (uint16_t)(im*oscBank[i].cqtBin);
258  if ((y+h - (uint16_t)signal) < h && signal > 1) draw->fillRoundRect(x+nx,y+h - (uint16_t)signal,2,4,1,CL(0xFF,0xA0,(uint8_t)(300*oscBank[i].transientValue)));
259  if ((y+h - (uint16_t)signal) < h && has_pop){
260  draw->setCursor(x+nx - 5,y+h - (uint16_t)signal - 35);
261  draw->print(note_name[oscBank[i].cqtBin]);
262  draw->setCursor(x+nx - 5,y+h - (uint16_t)signal - 50);
263  draw->printf("%.0f",oscBank[i].peakFrequency);
264  }
265  }
266 
267  //draw the border
268  draw->drawRoundRect(x,y,w,h,4,ILI9341_MAGENTA);
269 
270  if (fftHighRR[0].peakValue > fftLowRR[0].peakValue) {
271  fftRVal = fftHighRR[0];
272  draw->setTextColor(ILI9341_DARKCYAN);
273  } else{
274  fftRVal = fftLowRR[0];
275  draw->setTextColor(ILI9341_MAGENTA);
276  }
277  }; //called only when the app is active
static const char * note_name[]
Definition: Eris.h:744
static const float note_freq[]
Definition: Eris.h:745
SvcSerialCommandInterface * sci
Definition: AppBaseClass.h:39
ILI9341_t3_ERIS * draw
Definition: AppBaseClass.h:41
uint16_t high_range
Definition: appCQT.h:75
int16_t osc_bank_size
Definition: appCQT.h:74
bool is_active
Definition: appCQT.h:68
uint8_t fft_buffer_select_for_serial_transmit
Definition: appCQT.h:71
FFTReadRange fftLowRR[NOTE_ARRAY_LENGTH]
Definition: appCQT.h:83
erisAudioAnalyzeFFT1024 * fft
Definition: appCQT.h:79
FFTReadRange fftHighRR[NOTE_ARRAY_LENGTH]
Definition: appCQT.h:82
elapsedMillis fft_buffer_serial_transmit_elapsed
Definition: appCQT.h:72
FFTReadRange oscBank[OSC_BANK_SIZE]
Definition: appCQT.h:84
elapsedMillis cqt_serial_transmit_elapsed
Definition: appCQT.h:73
double update_calls
Definition: appCQT.h:70
FFTReadRange fftRVal
Definition: appCQT.h:81
erisAudioAnalyzeFFT1024 * fft2
Definition: appCQT.h:80
bool requestStartLZ4Message()
request to start a lz4 compressed message starts the message and returns true if available returns f...
void sendLZ4Message()
Calling this function signals the end of a compressed message. The txBuffer contents are lz4 compres...
static void sort_fftrr_by_cqt_bin(FFTReadRange *a, size_t n)
float peakValue
float transientValue
float phase
float avgValueSlow
uint16_t cqtBin
float avgValueFast
float peakFrequency

References avgValueFast, avgValueSlow, cqt_serial_transmit_elapsed, cqtBin, AppBaseClass::draw, fft, fft2, fft_buffer_select_for_serial_transmit, fft_buffer_serial_transmit_elapsed, fftHighRR, fftLowRR, fftRVal, AppBaseClass::h, AppBaseClass::has_pop, high_range, is_active, note_freq, note_name, osc_bank_size, oscBank, peakFrequency, peakValue, phase, SvcSerialCommandInterface::requestStartLZ4Message(), AppBaseClass::sci, SvcSerialCommandInterface::sendLZ4Message(), erisAudioAnalyzeFFT1024::sort_fftrr_by_cqt_bin(), transientValue, update_calls, AppBaseClass::w, AppBaseClass::x, and AppBaseClass::y.

+ Here is the call graph for this function: