ERIS CORE

◆ read() [2/4]

float erisAudioAnalyzeFFT1024::read ( float  freq_from,
float  freq_to,
FFTReadRange *  fftRR = NULL 
)
inline

Definition at line 203 of file eris_analyze_fft1024.h.

203  {
204  //convert f to bin
205  float bw;
206  float bin_size;
207  unsigned int start_bin;
208  unsigned int stop_bin;
209 
210  bw = AUDIO_SAMPLE_RATE_EXACT/2.0/(float)subsample_by;
211  bin_size = bw/1024.0f;
212  start_bin = (unsigned int)(freq_from / bin_size);
213  stop_bin = (unsigned int)(freq_to / bin_size);
214  if (start_bin > 511 || stop_bin > 511){
215  start_bin = 0;
216  stop_bin = 0;
217  }
218  /*
219  Serial.print(F("fft read: "));
220  Serial.print(subsample_by);Serial.print(F(","));
221  Serial.print(bw);Serial.print(F(","));
222  Serial.print(freq_from);Serial.print(F(","));
223  Serial.print(freq_to);Serial.print(F(","));
224  Serial.print(bin_size);Serial.print(F(","));
225  Serial.print(start_bin);Serial.print(F(","));
226  Serial.println(stop_bin);
227  */
228  if(fftRR){
229  fftRR->startBin = start_bin;
230  fftRR->stopBin = stop_bin;
231  fftRR->startFrequency = freq_from;
232  fftRR->stopFrequency = freq_to;
233  }
234 
235  if (freq_to > bw){
236  if(fftRR){
237  int16_t cqtBin;
238  cqtBin = fftRR->cqtBin;
239  //memset(&fftRR,0,sizeof(FFTReadRange));
240  fftRR->cqtBin = cqtBin;
241  fftRR->peakBin=0;
242  fftRR->estimatedFrequency=0;
243  fftRR->peakFrequency=0;
244  fftRR->peakValue=0;
245  fftRR->avgValueFast=0; //used to calc moving average convergence / divergence (MACD)
246  fftRR->avgValueSlow=0; //by comparing a short and long moving average; slow transient detection
247  fftRR->transientValue=0; //difference between the peak and fast peak values
248  }
249  return 0;
250  }
251 
252  float rval = read(start_bin,stop_bin,fftRR);
253  if(fftRR){
254 
255  //from the peak bin calc the freq
256  fftRR->peakFrequency = (fftRR->peakBin * bin_size) - (bin_size/2.0); //center of the fft bin
257  if (fftRR->peakFrequency < 0) fftRR->peakFrequency = 0.01;
258  float ratio = 1;
259  if ((fftRR->peakBin > 1) && (fftRR->peakBin < 510)){
260  //from the balance of the side lobes, estimate the actual frequency
261  float lobeFrequency = 1;
262  if ((output[fftRR->peakBin+1]-output[fftRR->peakBin-1]) > 0.1 && (output[fftRR->peakBin] > 0)){
263  //pos lobe
264  ratio = (output[fftRR->peakBin+1] - output[fftRR->peakBin-1] + output[fftRR->peakBin+1]) / (1.0 * output[fftRR->peakBin]);
265  lobeFrequency = ((fftRR->peakBin+1) * bin_size) - bin_size/2;
266  } else if (output[fftRR->peakBin-1] > 0.1 && (output[fftRR->peakBin] > 0)){
267  //neg lobe
268  ratio = (output[fftRR->peakBin-1]-output[fftRR->peakBin+1] + output[fftRR->peakBin-1]) / (1.0 * output[fftRR->peakBin]);
269  lobeFrequency = ((fftRR->peakBin-1) * bin_size) - bin_size/2;
270  }
271  fftRR->estimatedFrequency = (fftRR->peakFrequency * (1-ratio)) + (lobeFrequency * ratio);
272  //clamp estimate
273  if (fftRR->estimatedFrequency > fftRR->stopFrequency)fftRR->estimatedFrequency = fftRR->stopFrequency;
274  if (fftRR->estimatedFrequency < fftRR->startFrequency)fftRR->estimatedFrequency = fftRR->startFrequency;
275  }
276  if (ssr == SS_HIGHFREQ) ratio = 0.5;
277  else ratio = 0.995;
278  fftRR->avgValueFast = (fftRR->avgValueFast * ratio) + (fftRR->peakValue * (1.0f -ratio)); //used to calc moving average convergence / divergence (MACD)
279  //fftRR->avgValueFast = fftRR->peakValue;
280  ratio = 0.285;
281  fftRR->avgValueSlow = (fftRR->avgValueSlow * ratio) + (fftRR->avgValueFast * (1.0f -ratio)); //by comparing a short and long moving average; slow transient detection
282  if(fftRR->peakValue > fftRR->avgValueFast) fftRR->avgValueFast = (fftRR->avgValueFast/7.0 )+(fftRR->peakValue/3.0);
283  if (fftRR->avgValueFast > 0){
284  fftRR->transientValue = (fftRR->transientValue + (fftRR->avgValueFast - fftRR->avgValueSlow)/(0.00001 + fftRR->avgValueFast))* 0.5;
285  } else fftRR->transientValue = 0;
286  fftRR->transientValue *= 0.95;
287  fftRR->avgValueFast *= 0.998;
288  fftRR->avgValueSlow *= 0.998;
289  }
290 
291  return rval;
292  }
float read(unsigned int binNumber)
uint16_t cqtBin
@ SS_HIGHFREQ

References cqtBin, read(), SS_HIGHFREQ, ssr, and subsample_by.

+ Here is the call graph for this function: