2015-01-07 04:51:39 +01:00
|
|
|
#ifndef _DFT_H
|
|
|
|
#define _DFT_H
|
|
|
|
|
2015-04-01 06:21:01 +02:00
|
|
|
#include <stdint.h>
|
2015-02-11 07:10:16 +01:00
|
|
|
|
2015-04-01 06:21:01 +02:00
|
|
|
//Warning: Most ColorChords are not available for ColorChord Embedded.
|
|
|
|
#ifndef CCEMBEDDED
|
2015-02-11 07:10:16 +01:00
|
|
|
|
2015-04-01 06:21:01 +02:00
|
|
|
//There are several options here, the last few are selectable by modifying the do_progressive_dft flag.
|
2015-01-07 04:51:39 +01:00
|
|
|
|
|
|
|
//Do a DFT on a live audio ring buffer. It assumes new samples are added on in the + direction, older samples go negative.
|
|
|
|
//Frequencies are as a function of the samplerate, for example, a frequency of 22050 is actually 2 Hz @ 44100 SPS
|
|
|
|
//bins = number of frequencies to check against.
|
|
|
|
void DoDFT( float * outbins, float * frequencies, int bins, float * databuffer, int place_in_data_buffer, int size_of_data_buffer, float q );
|
|
|
|
|
2015-02-11 07:10:16 +01:00
|
|
|
//Skip many of the samples on lower frequencies.
|
2015-01-07 04:51:39 +01:00
|
|
|
//Speedup = target number of data points
|
|
|
|
void DoDFTQuick( float * outbins, float * frequencies, int bins, const float * databuffer, int place_in_data_buffer, int size_of_data_buffer, float q, float speedup );
|
|
|
|
|
2015-02-10 06:57:10 +01:00
|
|
|
//An unusual tool to do a "progressive" DFT, using data from previous rounds.
|
|
|
|
void DoDFTProgressive( float * outbins, float * frequencies, int bins, const float * databuffer, int place_in_data_buffer, int size_of_data_buffer, float q, float speedup );
|
|
|
|
|
|
|
|
//A progressive DFT that's done using only low-bit integer math.
|
2015-02-11 07:10:16 +01:00
|
|
|
//This is almost fast enough to work on an AVR, with two AVRs, it's likely that it could be powerful enough.
|
|
|
|
//This is fast enough to run on an ESP8266
|
2015-02-10 06:57:10 +01:00
|
|
|
void DoDFTProgressiveInteger( float * outbins, float * frequencies, int bins, const float * databuffer, int place_in_data_buffer, int size_of_data_buffer, float q, float speedup );
|
|
|
|
|
2015-04-01 06:21:01 +02:00
|
|
|
#endif
|
|
|
|
|
2015-02-11 07:10:16 +01:00
|
|
|
//Everything the integer one buys, except it only calculates 2 octaves worth of notes per audio frame.
|
|
|
|
//This is sort of working, but still have some quality issues.
|
|
|
|
//It would theoretically be fast enough to work on an AVR.
|
2015-04-01 06:21:01 +02:00
|
|
|
//NOTE: This is the only DFT available to the embedded port of ColorChord
|
2015-02-11 07:10:16 +01:00
|
|
|
void DoDFTProgressiveIntegerSkippy( float * outbins, float * frequencies, int bins, const float * databuffer, int place_in_data_buffer, int size_of_data_buffer, float q, float speedup );
|
2015-02-10 06:57:10 +01:00
|
|
|
|
2015-04-01 06:21:01 +02:00
|
|
|
//It's actually split into a few functions, which you can call on your own:
|
|
|
|
void SetupDFTProgressiveIntegerSkippy(); //Call at start.
|
|
|
|
|
|
|
|
#ifndef CCEMBEDDED
|
|
|
|
void UpdateBinsForProgressiveIntegerSkippy( const float * frequencies ); //Update the frequencies
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void UpdateBinsForProgressiveIntegerSkippyInt( const uint16_t * frequencies );
|
|
|
|
void Push8BitIntegerSkippy( int8_t dat ); //Call this to push on new frames of sound.
|
|
|
|
|
|
|
|
|
|
|
|
//You can # define these to be other things.
|
|
|
|
#ifndef OCTAVES
|
|
|
|
#define OCTAVES 5
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef FIXBPERO
|
|
|
|
#define FIXBPERO 24
|
|
|
|
#endif
|
|
|
|
|
2015-04-03 20:10:25 +02:00
|
|
|
#ifndef FIXBINS
|
2015-04-01 06:21:01 +02:00
|
|
|
#define FIXBINS (FIXBPERO*OCTAVES)
|
2015-04-03 20:10:25 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef BINCYCLE
|
2015-04-01 06:21:01 +02:00
|
|
|
#define BINCYCLE (1<<OCTAVES)
|
2015-04-03 20:10:25 +02:00
|
|
|
#endif
|
2015-04-01 06:21:01 +02:00
|
|
|
|
2015-04-02 04:59:12 +02:00
|
|
|
//This variable determins how much to nerf the current sample of the DFT.
|
|
|
|
//I've found issues when this is smaller, but bigger values do have a negative
|
|
|
|
//impact on quality. We should strongly consider using 32-bit accumulators.
|
|
|
|
#ifndef SHIFT_ADD_DETAIL
|
|
|
|
#define SHIFT_ADD_DETAIL 5
|
|
|
|
#endif
|
|
|
|
|
2015-04-01 06:21:01 +02:00
|
|
|
//Whenever you need to read the bins, you can do it from here.
|
|
|
|
extern uint16_t Sdatspace[]; //(advances,places,isses,icses)
|
2015-04-03 20:10:25 +02:00
|
|
|
extern uint16_t embeddedbins[]; //This is updated every time the DFT hits the octavecount, or every BINCYCLE updates.
|
2015-04-01 06:21:01 +02:00
|
|
|
|
2015-01-07 04:51:39 +01:00
|
|
|
#endif
|
|
|
|
|