Skip to content

Commit

Permalink
added calculateOnRequestOnly
Browse files Browse the repository at this point in the history
  • Loading branch information
florianlink committed Jun 15, 2016
1 parent a3cffc2 commit 5d129ee
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 15 deletions.
37 changes: 29 additions & 8 deletions analyze_fft1024.cpp
Expand Up @@ -103,15 +103,10 @@ void AudioAnalyzeFFT1024::update(void)
copy_to_fft_buffer(buffer+0x500, blocklist[5]->data);
copy_to_fft_buffer(buffer+0x600, blocklist[6]->data);
copy_to_fft_buffer(buffer+0x700, blocklist[7]->data);
if (window) apply_window_to_fft_buffer(buffer, window);
arm_cfft_radix4_q15(&fft_inst, buffer);
// TODO: support averaging multiple copies
for (int i=0; i < 512; i++) {
uint32_t tmp = *((uint32_t *)buffer + i); // real & imag
uint32_t magsq = multiply_16tx16t_add_16bx16b(tmp, tmp);
output[i] = sqrt_uint32_approx(magsq);
}
outputflag = true;
if (!onRequestOnly) {
calculateFFT();
}
release(blocklist[0]);
release(blocklist[1]);
release(blocklist[2]);
Expand All @@ -128,4 +123,30 @@ void AudioAnalyzeFFT1024::update(void)
#endif
}

bool AudioAnalyzeFFT1024::available()
{
if (outputflag == true) {
if (onRequestOnly) {
noInterrupts();
calculateFFT();
interrupts();
}
outputflag = false;
return true;
}
return false;
}

void AudioAnalyzeFFT1024::calculateFFT()
{
if (window) apply_window_to_fft_buffer(buffer, window);

arm_cfft_radix4_q15(&fft_inst, buffer);

// TODO: support averaging multiple copies
for (int i=0; i < 512; i++) {
uint32_t tmp = *((uint32_t *)buffer + i); // real & imag
uint32_t magsq = multiply_16tx16t_add_16bx16b(tmp, tmp);
output[i] = sqrt_uint32_approx(magsq);
}
}
17 changes: 10 additions & 7 deletions analyze_fft1024.h
Expand Up @@ -50,16 +50,16 @@ class AudioAnalyzeFFT1024 : public AudioStream
{
public:
AudioAnalyzeFFT1024() : AudioStream(1, inputQueueArray),
window(AudioWindowHanning1024), state(0), outputflag(false) {
window(AudioWindowHanning1024), state(0), outputflag(false), onRequestOnly(false) {
arm_cfft_radix4_init_q15(&fft_inst, 1024, 0, 1);
}
bool available() {
if (outputflag == true) {
outputflag = false;
return true;
}
return false;

bool available();

void calculateOnRequestOnly(bool flag) {
onRequestOnly = flag;
}

float read(unsigned int binNumber) {
if (binNumber > 511) return 0.0;
return (float)(output[binNumber]) * (1.0 / 16384.0);
Expand Down Expand Up @@ -88,6 +88,8 @@ class AudioAnalyzeFFT1024 : public AudioStream
uint16_t output[512] __attribute__ ((aligned (4)));
private:
void init(void);
void calculateFFT(void);

const int16_t *window;
audio_block_t *blocklist[8];
int16_t buffer[2048] __attribute__ ((aligned (4)));
Expand All @@ -98,6 +100,7 @@ class AudioAnalyzeFFT1024 : public AudioStream
volatile bool outputflag;
audio_block_t *inputQueueArray[1];
arm_cfft_radix4_instance_q15 fft_inst;
bool onRequestOnly;
};

#endif

0 comments on commit 5d129ee

Please sign in to comment.