ERIS CORE

◆ updateOscillatorBank()

void FASTRUN AppCQT::updateOscillatorBank ( bool  low_range_switch)
inlineprotected

Definition at line 329 of file appCQT.h.

329  {
330  bool found;
331  float peak_read=-1000;
332  float peak;
333 
334  if(fft==NULL || fft2==NULL) return;
335  //sort the FFTReadRange array by cqt bin number
336  if (low_range_switch) {erisAudioAnalyzeFFT1024::sort_fftrr_by_cqt_bin(fftLowRR,NOTE_ARRAY_LENGTH);}
338  //read the fft ranges, which stores the results into the FFTReadRange array
339  for (uint16_t i=0; i < NOTE_ARRAY_LENGTH; i++){
340  if (low_range_switch) peak = fft2->read(&fftLowRR[i]);
341  else peak = fft->read(&fftHighRR[i]);
342  if (peak>peak_read){
343  peak_read = peak;
344  }
345  }
346  //update the oscillator bank with the current values
347  for (uint16_t i=0; i < osc_bank_size; i++){
348  if (oscBank[i].cqtBin >= high_range){
349  if (low_range_switch==false){
350  oscBank[i] = fftHighRR[oscBank[i].cqtBin];
351  }
352  }else if (low_range_switch==true){
353  oscBank[i] = fftLowRR[oscBank[i].cqtBin];
354  }
355  }
356  //sort the updated cqt bins by peakValue
357  if (low_range_switch){erisAudioAnalyzeFFT1024::sort_fftrr_by_value(fftLowRR,NOTE_ARRAY_LENGTH);
359 
360  //Add the new osc settings
361  //low range
362  if (low_range_switch){
363  for(uint16_t i=0; i < osc_bank_size; i++){
364  found = false;
365  for (uint16_t j=0; j < osc_bank_size; j++){
366  if (oscBank[j].cqtBin == fftLowRR[i].cqtBin){
367  //oscBank[j] = fftLowRR[i];
368  found = true;break;
369  }
370  }
371  if(!found){
372  for(int16_t k= osc_bank_size-1; k >= 0;k--){
373  if ((oscBank[k].avgValueFast) < (fftLowRR[i].avgValueFast)){
374  //fftLowRR[i].phase = 0;
375  pll_p = 0.0;
376  pll_f = 1.0;
377  oscBank[k] = fftLowRR[i];
378  break;
379  }
380  }
381  }
382  }
383  } else for(uint16_t i=0; i < osc_bank_size; i++){ //high range
384  found = false;
385  for (uint16_t j=0; j < osc_bank_size; j++){
386  if (oscBank[j].cqtBin == fftHighRR[i].cqtBin){
387  //oscBank[j] = fftHighRR[i];
388  found = true;break;
389  }
390  }
391  if(!found){
392  for(int16_t k= osc_bank_size-1; k >= 0;k--){
393  if ((oscBank[k].avgValueFast) < (fftHighRR[i].avgValueFast)){
394  //fftHighRR[i].phase = 0;
395  pll_p = 0.0;
396  pll_f = 1.0;
397  oscBank[k] = fftHighRR[i];
398  break;
399  }
400  }
401  }
402  }
403 
404  pll_p = 0.0;
405  pll_f = 1.0;
406 
407  //sort the updated cqt bins by peakValue
408  if (low_range_switch){erisAudioAnalyzeFFT1024::sort_fftrr_by_value(fftLowRR,NOTE_ARRAY_LENGTH);
410 
411  //take the phase from the dominant frequency component
412  float dominantPhase = 0;
413  if (low_range_switch){
414  dominantPhase = fftLowRR[0].phase;
415  } else dominantPhase = fftHighRR[0].phase;;
416 
417  //actually update the oscillators -- IF the data is not TOO old
418  //if (updateRT_call_period > am->data->read(FFT_AGE_THRESHOLD)) return;
419 
420  for(int16_t i=0; i < osc_bank_size; i++){
421  float a,f;
422  float64_t phase_aligner;
423  if( ( (oscBank[i].cqtBin <= high_range) && (low_range_switch == true)) || ((oscBank[i].cqtBin > high_range) && (low_range_switch == false))){
424  if (oscBank[i].peakFrequency > 30.0){
425  f = oscBank[i].peakFrequency;
426  a = sqrt(oscBank[i].avgValueFast)/OSC_BANK_SIZE;
427  if(!isnan(a)){
428  phase_aligner = ((dominantPhase - oscBank[i].phase)/dominantPhase);
429  phase_aligner = (phase_aligner * (float64_t)osc[i]->getPhase()) + pll_p;
430  if(!isnan(phase_aligner)) phase_aligner=0;
431  f = (pll_f * f * octave_down[am->data->read(OCTAVE_DOWN_INTERVAL)]);
432  if (f < 20) f = 20;
433  if (f > 20000) f = 20000;
434  if(osc[i] != NULL){
435  osc[i]->frequency(f);
436  osc[i]->amplitude(a);
437  osc[i]->phase(phase_aligner);
438  }
439  };
440  }
441  }
442  }
443 
444  return;
445  }
const float octave_down[]
Definition: Eris.h:739
AppManager * am
Definition: AppBaseClass.h:38
float64_t pll_p
Definition: appCQT.h:76
erisAudioSynthWaveform * osc[OSC_BANK_SIZE]
Definition: appCQT.h:78
float64_t pll_f
Definition: appCQT.h:77
uint16_t high_range
Definition: appCQT.h:75
int16_t osc_bank_size
Definition: appCQT.h:74
FFTReadRange fftLowRR[NOTE_ARRAY_LENGTH]
Definition: appCQT.h:83
erisAudioAnalyzeFFT1024 * fft
Definition: appCQT.h:79
FFTReadRange fftHighRR[NOTE_ARRAY_LENGTH]
Definition: appCQT.h:82
FFTReadRange oscBank[OSC_BANK_SIZE]
Definition: appCQT.h:84
erisAudioAnalyzeFFT1024 * fft2
Definition: appCQT.h:80
SvcDataDictionary * data
Definition: AppManager.h:63
void frequency(float freq)
void phase(float angle)
int32_t read(const char *key)
returns the int32_t value of the record
static void sort_fftrr_by_cqt_bin(FFTReadRange *a, size_t n)
static void sort_fftrr_by_value(FFTReadRange *a, size_t n)
float read(unsigned int binNumber)
uint16_t cqtBin
float avgValueFast
float peakFrequency

References AppBaseClass::am, AudioSynthWaveformhd::amplitude(), avgValueFast, cqtBin, AppManager::data, fft, fft2, fftHighRR, fftLowRR, AudioSynthWaveformhd::frequency(), high_range, octave_down, osc, osc_bank_size, oscBank, peakFrequency, AudioSynthWaveformhd::phase(), pll_f, pll_p, SvcDataDictionary::read(), erisAudioAnalyzeFFT1024::read(), erisAudioAnalyzeFFT1024::sort_fftrr_by_cqt_bin(), and erisAudioAnalyzeFFT1024::sort_fftrr_by_value().

Referenced by update().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: