OKAY! EmbeddedCC is almost ready!

This commit is contained in:
cnlohr 2015-04-04 18:35:03 -04:00
parent 9e0a963355
commit 96002c5583
5 changed files with 75 additions and 104 deletions

2
TODO
View file

@ -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.

View file

@ -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;
}

View file

@ -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<<SEMIBITSPERBIN)*FIXBPERO-1)
@ -29,16 +31,16 @@
//If there is detected note this far away from an established note, we will
//then consider this new note the same one as last time, and move the established
//note. This is also used when combining notes. It is this distance times two.
#define MAX_JUMP_DISTANCE 5
#define MAX_JUMP_DISTANCE 4
#define AMP_1_NERFING_BITS 4
#define AMP_1_NERFING_BITS 5
#define AMP_2_NERFING_BITS 3
//This is the amplitude, coming from folded_bins. If the value is below this
//it is considered a non-note.
#define MIN_AMP_FOR_NOTE 64
#define MINIMUM_AMP_FOR_NOTE_TO_DISAPPEAR (1<<(AMP_1_NERFING_BITS))
#define MIN_AMP_FOR_NOTE 128
#define MINIMUM_AMP_FOR_NOTE_TO_DISAPPEAR 100

View file

@ -26,20 +26,33 @@ void UpdateLinearLEDs()
uint16_t j, l;
uint32_t total_size_all_notes = 0;
int32_t porpamps[MAXNOTES]; //LEDs for each corresponding note.
uint8_t sorted_note_map[MAXNOTES]; //mapping from which note into the array of notes from the rest of the system.
uint8_t sorted_map_count = 0;
uint32_t note_nerf_a = 0;
for( i = 0; i < MAXNOTES; i++ )
{
if( note_peak_freqs[i] == 255 ) continue;
note_nerf_a += note_peak_amps[i];
}
note_nerf_a = ((note_nerf_a * NERF_NOTE_PORP)>>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;
int addedlast = 1;
do
{
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;
}
*/

View file

@ -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]