ERIS CORE

◆ update()

void erisAudioAnalyzeFFT1024::update ( void  )
virtual

Implements AudioStream.

Definition at line 178 of file eris_analyze_fft1024.cpp.

179 {
180  audio_block_t *block;
181 
182  block = receiveReadOnly();
183  if (!block) return;
184 
185 
186  //FAT Audio - add the ability to turn FFT on or OFF to save CPU
187  if (!enabled){
188  release(block);
189  return;
190  };
191 
192  uint16_t ofs;
193  //calcuate active subsampling step and offset
194  if (ssr == SS_LOWFREQ){
197  }
198  else if (ssr == SS_HIGHFREQ){
201  }
202  BLOCKS_PER_FFT = ((1024 / AUDIO_BLOCK_SAMPLES) * subsample_by);
204  if (ssr == SS_LOWFREQ) BLOCK_REFRESH_SIZE = BLOCKS_PER_FFT/2;//((subsample_lowfreqrange/subsample_highfreqrange) * 2);//BLOCK_REFRESH_SIZE/(subsample_lowfreqrange/2);//BLOCKS_PER_FFT/4;
205 
206  ofs = (AUDIO_BLOCK_SAMPLES/subsample_by) * (sample_block);
207 
208  if (sample_block < BLOCKS_PER_FFT -1){
209  copy_to_fft_buffer(buffer+ofs, block->data,subsample_by);
210  release(block);
211  sample_block++;
212  } else{
213  copy_to_fft_buffer(buffer+ofs, block->data,subsample_by);
214  release(block);
215  #ifdef ENABLE_F32_FFT
216 
217  //copy buffer while casting to float and scale to the range -1 to 1
218  //(NVIC_DISABLE_IRQ(IRQ_SOFTWARE));
219  if(outputflag == false && is_analyzed){
220  for (int16_t i=0; i < 1024; i++){
221  tmp_buffer[i] = ((float32_t)buffer[i] / (float32_t)32768.0);
222  //if (SS_LOWFREQ) tmp_buffer[i] *= subsample_lowfreqrange/(float32_t)subsample_highfreqrange; //scale match the low range
223  if (!std::isfinite(tmp_buffer[i])) tmp_buffer[i] = 0.0;
224  }
225  outputflag = true;
226  }
227  //(NVIC_ENABLE_IRQ(IRQ_SOFTWARE));
228 
229  #else
230  memcpy(tmp_buffer,buffer,2048 * sizeof(int16_t));
231  apply_window_to_fft_buffer(tmp_buffer, window);
232  arm_cfft_radix4_q15(&fft_inst, tmp_buffer);
233  outputflag = false; //output flag is false while updating the fft results
234 
235  for (int i=0; i < 512; i++) {
236  uint32_t tmp = *((uint32_t *)tmp_buffer + i); // real & imag
237  uint32_t magsq = multiply_16tx16t_add_16bx16b(tmp, tmp);
238  output[i] = sqrt_uint32_approx(magsq);
239  output_packed[i] = tmp;//normalized_atan2((float)real,(float)imag)*180/PI;//atan2(imag,real)*180/PI;
240  }
241  #endif
242 
243  if (sample_block!= 0){
245  ofs = (AUDIO_BLOCK_SAMPLES/subsample_by) * sample_block;
246  //fft overlap - restore tmp cpy of last half to first half
247  memmove(buffer,&buffer[(AUDIO_BLOCK_SAMPLES/subsample_by)*BLOCK_REFRESH_SIZE], (AUDIO_BLOCK_SAMPLES/subsample_by) * (BLOCKS_PER_FFT - BLOCK_REFRESH_SIZE) * sizeof(int16_t));
248  }
249 
250  }
251 }
static void release(audio_block_t *block)
audio_block_t * receiveReadOnly(unsigned int index=0)
void copy_to_fft_buffer(void *destination, const void *source, int subsample)
arm_cfft_radix4_instance_f32 fft_inst
static void apply_window_to_fft_buffer(void *buffer, const void *window)
@ SS_LOWFREQ
@ SS_HIGHFREQ
int16_t data[AUDIO_BLOCK_SAMPLES]
Definition: AudioStream.h:78

References apply_window_to_fft_buffer(), BLOCK_REFRESH_SIZE, BLOCKS_PER_FFT, copy_to_fft_buffer(), audio_block_struct::data, enabled, fft_inst, is_analyzed, MEM_STEP, outputflag, AudioStream::receiveReadOnly(), AudioStream::release(), sample_block, SS_HIGHFREQ, SS_LOWFREQ, ssr, subsample_by, subsample_highfreqrange, subsample_lowfreqrange, and window.

+ Here is the call graph for this function: