#include #include #include "DFT8Turbo.h" #include #include #define MAX_FREQS (24) #define OCTAVES (5) /* * The first thought was using an integration map and only operating when we need to, to pull the data out. * Now we're doing the thing below this block comment int16_t accumulated_total; //2 bytes int16_t last_accumulated_total_at_bin[MAX_FREQS*2]; //24 * 2 * sizeof(int16_t) = 96 bytes. uint8_t current_time; //1 byte uint8_t placecode[MAX_FREQS]; */ /* So, the idea here is we would keep a running total of the current ADC value, kept away in a int16_t. It is constantly summing, so we can take an integral of it. Or rather an integral range. Over time, we perform operations like adding or subtracting from a current place. NOTE: Optimizations: Only use 16 bins, lets action table be 16-bits wide. */ int16_t running_integral; int16_t cossindata[MAX_FREQS*OCTAVES*2]; //Contains COS and SIN data. uint8_t which_octave_for_op[MAX_FREQS]; //counts up, tells you which ocative you are operating on. uint8_t highbit_table[2< hits per 1024: %f %d (%f error)\n", topbin, f, (float)ACTIONTABLESIZE/f, dhrpertable, err * 100.0 ); float advance_per_step = dhrpertable/(float)ACTIONTABLESIZE; float fvadv = 0.0; int j; int actions = 0; int countset = 0; //XXX TODO Tricky: We need to start fadv off at such a place that there won't be a hicchup when going back around to 0. for( j = 0; j < ACTIONTABLESIZE; j++ ) { if( fvadv >= 0.5 ) { actiontable[j] |= 1<> longestzeroes) & 1) == 0 ); longestzeroes++ ); //longestzeroes goes: 255, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, ... //This isn't great, because we need to also know whether we are attacking the SIN side or the COS side. highbit_table[i] = longestzeroes; } //Repeat the highbit table in the second half. //XXX PICK UP HERE //Encode into highbit_table which cell is being operated on //Also, do the * MAX_FREQS here. That will placeintable = actiontable; // for( i = 0; i < ACTIONTABLESIZE; i++ ) printf( "%08x\n", actiontable[i] ); } int16_t running_integral; int16_t cossindata[MAX_FREQS*OCTAVES*2]; uint8_t which_octave_for_op[MAX_FREQS]; //counts up, tells you which ocative you are operating on. uint16_t * placeintable; //Put this in flash. uint32_t actiontable[ACTIONTABLESIZE]; void Turbo8BitRun( int8_t adcval ) { uint32_t actions = *(placeintable++); if( placeintable == &actiontable[ACTIONTABLESIZE] ) placeintable = actiontable; int b; for( b = 0; b < MAX_FREQS; b++ ) { if( ! ((1<>= 1; int octavebit = op & ((1<>5 ); //6 = Actually only feed algorithm numbers from -64 to 63. } last_place = place_in_data_buffer; #if 0 for( i = 0; i < bins; i++ ) { outbins[i] = 0; } for( i = 0; i < MAX_FREQS; i++ ) { int iss = nd[i].sinm>>8; int isc = nd[i].cosm>>8; int mux = iss * iss + isc * isc; if( mux == 0 ) mux = 1; if( i == 0 ) printf( "MUX: %d %d\n", isc, iss ); outbins[i+MAX_FREQS] = sqrt(mux)/200.0; } #endif }