diff --git a/TODO b/TODO index 9dd1cb9..a7c2c83 100644 --- a/TODO +++ b/TODO @@ -1,7 +1,7 @@ Still to do: Try this: -* Separate "LED Selection" from "output" algorithms. << Do this by allowing arbitrary Lights Drivers +* Make Linear keep the order of the notes in-order. * For light finding, pick lights off the peaks to get number of lights to use. * For light shifting (for 1d-looping light systems) shift the centers of the notes, then vernoi between the notes. diff --git a/embeddednf.c b/embeddednf.c index 095d5ca..ddc5a5b 100644 --- a/embeddednf.c +++ b/embeddednf.c @@ -154,6 +154,7 @@ void HandleFrameInfo() //Sometimes you may notice every other bin being out-of //line, and this fixes that. We may consider running this //more than once, but in my experience, once is enough. + for( j = 0; j < FILTER_BLUR_PASSES; j++ ) { //Extra scoping because this is a large on-stack buffer. uint16_t folded_out[FIXBPERO]; @@ -281,14 +282,21 @@ void HandleFrameInfo() if( marked_note != -1 ) { hitnotes[marked_note] = 1; -// if( note_peak_amps[marked_note] <= this ) - note_peak_amps[marked_note] = note_peak_amps[marked_note] - (note_peak_amps[marked_note]>>AMP_1_NERFING_BITS) + (this>>AMP_1_NERFING_BITS); -// if( note_peak_amps2[marked_note] <= this ) - note_peak_amps2[marked_note] = note_peak_amps2[marked_note] - (note_peak_amps2[marked_note]>>AMP_2_NERFING_BITS) + (this>>AMP_2_NERFING_BITS); + note_peak_amps[marked_note] = note_peak_amps[marked_note] - (note_peak_amps[marked_note]>>AMP_1_NERFING_BITS) + (this>>(AMP_1_NERFING_BITS-3)); + note_peak_amps2[marked_note] = note_peak_amps2[marked_note] - (note_peak_amps2[marked_note]>>AMP_2_NERFING_BITS) + (this>>(AMP_2_NERFING_BITS-3)); } } } +#if 0 + for( i = 0; i < MAXNOTES; i++ ) + { + if( note_peak_freqs[i] == 255 ) continue; + printf( "%d / ", note_peak_amps[i] ); + } + printf( "\n" ); +#endif + //Now we need to handle combining notes. for( i = 0; i < MAXNOTES; i++ ) for( j = 0; j < i; j++ ) @@ -312,22 +320,36 @@ void HandleFrameInfo() continue; } + int into; + int from; + + if( note_peak_amps[i] > note_peak_amps[j] ) + { + into = i; + from = j; + } + else + { + into = j; + from = i; + } + //We need to combine the notes. We need to move the new note freq //towards the stronger of the two notes. - int16_t amp1 = note_peak_amps[i]; - int16_t amp2 = note_peak_amps[j]; + int16_t amp1 = note_peak_amps[into]; + int16_t amp2 = note_peak_amps[from]; //0 to 32768 porportional to how much of amp1 we want. uint32_t porp = (amp1<<15) / (amp1+amp2); uint16_t newnote = (nf1 * porp + nf2 * (32768-porp))>>15; - note_peak_freqs[i] = newnote; - note_peak_amps[i] = (note_peak_amps[i]+note_peak_amps[j])>>1; - note_peak_amps2[i] = (note_peak_amps2[i]+note_peak_amps2[j])>>1; + note_peak_freqs[into] = newnote; + note_peak_amps[into] = (note_peak_amps[into]>note_peak_amps[from])?note_peak_amps[into]:note_peak_amps[j]; + note_peak_amps2[into] = (note_peak_amps2[into]>note_peak_amps2[from])?note_peak_amps2[into]:note_peak_amps2[j]; - note_peak_freqs[j] = 255; - note_peak_amps[j] = 0; - note_jumped_to[j] = i; + note_peak_freqs[from] = 255; + note_peak_amps[from] = 0; + note_jumped_to[from] = i; } diff --git a/embeddednf.h b/embeddednf.h index bb64f7b..290cb2e 100644 --- a/embeddednf.h +++ b/embeddednf.h @@ -19,6 +19,8 @@ //vaporize in one frame doesn't mean it is annihilated immediately. #define MAXNOTES 12 +#define FILTER_BLUR_PASSES 2 + //Determines bit shifts for where notes lie. We represent notes with an uint8_t //We have to define all of the possible locations on the note line in this. //note_frequency = 0..((1<>8); + for( i = 0; i < MAXNOTES; i++ ) { uint16_t ist = note_peak_amps[i]; uint8_t nff = note_peak_freqs[i]; - if( nff == 255 || ist <= NERF_NOTE_SIZE_VALUE ) + if( nff == 255 ) + { + continue; + } + if( ist < note_nerf_a ) { continue; } +#if SORT_NOTES for( j = 0; j < sorted_map_count; j++ ) { if( note_peak_freqs[ sorted_note_map[j] ] > nff ) @@ -51,8 +64,10 @@ void UpdateLinearLEDs() { sorted_note_map[k] = sorted_note_map[k-1]; } - sorted_note_map[j] = i; +#else +#endif + sorted_note_map[sorted_map_count] = i; sorted_map_count++; } @@ -70,21 +85,17 @@ void UpdateLinearLEDs() for( i = 0; i < sorted_map_count; i++ ) { - local_peak_amps[i] = note_peak_amps[sorted_note_map[i]]; + printf( "%5d ", local_peak_amps[i] ); + local_peak_amps[i] = note_peak_amps[sorted_note_map[i]] - note_nerf_a; local_peak_amps2[i] = note_peak_amps2[sorted_note_map[i]]; local_peak_freq[i] = note_peak_freqs[sorted_note_map[i]]; } + printf( "\n" ); for( i = 0; i < sorted_map_count; i++ ) { uint16_t ist = local_peak_amps[i]; porpamps[i] = 0; - if( ist <= NERF_NOTE_SIZE_VALUE ) - { - local_peak_amps[i] = 0; - continue; - } - local_peak_amps[i] = ist - NERF_NOTE_SIZE_VALUE; total_size_all_notes += local_peak_amps[i]; } @@ -108,10 +119,15 @@ void UpdateLinearLEDs() int16_t total_unaccounted_leds = NUM_LIN_LEDS - total_accounted_leds; - for( i = 0; i < sorted_map_count && total_unaccounted_leds; i++ ) + int addedlast = 1; + do { - porpamps[i]++; total_unaccounted_leds--; - } + for( i = 0; i < sorted_map_count && total_unaccounted_leds; i++ ) + { + porpamps[i]++; total_unaccounted_leds--; + addedlast = 1; + } + } while( addedlast && total_unaccounted_leds ); //Put the frequencies on a ring. j = 0; @@ -314,74 +330,4 @@ uint32_t EHSVtoHEX( uint8_t hue, uint8_t sat, uint8_t val ) return or | (og<<8) | ((uint32_t)ob<<16); } -/* -uint32_t HSVtoHEX( float hue, float sat, float value ) -{ - float pr = 0; - float pg = 0; - float pb = 0; - - short ora = 0; - short og = 0; - short ob = 0; - - float ro = fmod( hue * 6, 6. ); - - float avg = 0; - - ro = fmod( ro + 6 + 1, 6 ); //Hue was 60* off... - - if( ro < 1 ) //yellow->red - { - pr = 1; - pg = 1. - ro; - } else if( ro < 2 ) - { - pr = 1; - pb = ro - 1.; - } else if( ro < 3 ) - { - pr = 3. - ro; - pb = 1; - } else if( ro < 4 ) - { - pb = 1; - pg = ro - 3; - } else if( ro < 5 ) - { - pb = 5 - ro; - pg = 1; - } else - { - pg = 1; - pr = ro - 5; - } - - //Actually, above math is backwards, oops! - pr *= value; - pg *= value; - pb *= value; - - avg += pr; - avg += pg; - avg += pb; - - pr = pr * sat + avg * (1.-sat); - pg = pg * sat + avg * (1.-sat); - pb = pb * sat + avg * (1.-sat); - - ora = pr * 255; - og = pb * 255; - ob = pg * 255; - - if( ora < 0 ) ora = 0; - if( ora > 255 ) ora = 255; - if( og < 0 ) og = 0; - if( og > 255 ) og = 255; - if( ob < 0 ) ob = 0; - if( ob > 255 ) ob = 255; - - return (ob<<16) | (og<<8) | ora; -} -*/ diff --git a/embeddedout.h b/embeddedout.h index 9d68137..25c755b 100644 --- a/embeddedout.h +++ b/embeddedout.h @@ -5,14 +5,15 @@ //Controls brightness -#define NOTE_FINAL_AMP 255 //Number from 0...255 +#define NOTE_FINAL_AMP 16 //Number from 0...255 //Controls, basically, the minimum size of the splotches. -#define NERF_NOTE_SIZE_VALUE 1 +#define NERF_NOTE_PORP 15 //value from 0 to 255 #define NUM_LIN_LEDS 296 -#define LIN_WRAPAROUND 1 //Whether the output lights wrap around. +#define LIN_WRAPAROUND 0 //Whether the output lights wrap around. +#define SORT_NOTES 0 //Whether the notes will be sorted. extern uint8_t ledArray[]; extern uint8_t ledOut[]; //[NUM_LIN_LEDS*3]