From fec652de8f24b2784563162e6e2bbe5b00729a78 Mon Sep 17 00:00:00 2001 From: bbkiwi Date: Wed, 12 Apr 2017 14:16:39 +1200 Subject: [PATCH 01/15] Using current esp82xx submodule For embeddedout.c FIXED SORT, new features, additional Update routine Custom commands for these More options for dummy_leds.c for embeddedlinux testing changed embedded8266/esp82xx to most recent subproject Improved UpdateLinearLEDs FIXING SORT_NOTES, adding rotation and shifting options Added new update routine UpdateRotatingLEDs() to embeddedcommon/embeddedout.c with custom commands controling above via web gui Added improved dummy_leds.c to embeddedlinux so can compile to show a ring colorchord2 .conf files changed to my sound sources, IP and LED setup embedded8266/ccconfig.h now allows SORT_NOTES 1 as I fixed the option modified embedded8266/user.cfg changed to my SDK, slowed baud rate for burning as mac needs slower added code to embedded8266/user/custom_commands.c for two additional commands gCOLORCHORD_ADVANCE_SHIFT = 0; gCOLORCHORD_SUPRESS_FLIP_DIR = 1; added code embedded8266/user/user_main.c and embeddedcommon/embeddedcc.c to handle the new features of embeddedout.c new global variable int framecount incremented in NewFrame() and used in the UpdateLinearLEDs and UpdateRotatingLEDs in embeddedcommon/embeddedcc.c replaced Init() and InitColorChord() embeddedcommon/embeddedout.c added three global variables: total_note_a_prev, diff_a_prev and rot_dir so this info will persist between calls to the Update routines. added printfs for debugging (only when using embeddedlinux, not on embedded8266) modified UpdateLinearLEDs() FIXED LIN_WRAPAROUND so ledFreqOUTold is not saved in case LIN_WRAPAROUND 0 computes total of note_peak_amps so can react to overall sound intensity FIXED SORT_NOTES - removed old code from first loops added new sort on local_peak_amp2 after the loop code can be improved to switch between keys TODO allow inc/dec sorting as param TODO sort uses pointer, but need to fix to handle both uint8_t and uint16_t added FEATURE code to rotate the display, speed and direction being controled by by these extern gCOLORCHORD_ADVANCE_SHIFT and gCOLORCHORD_SUPRESS_FLIP_DIR removed old commented out code added UpdateRotatingLEDs() new FEATURE code to rotate one LED at dominant color and amp (as in UpdateSameLEDs) the speed and direction being controled by same parameters as above embeddedcommon/embeddedout.h added extern variables and changed compiler directives embeddedlinux mods of Makefile and ccconfig.h to suit my set up and test improved dummy_leds mods of dummy_leds.c to have a RING option mods of embeddedcc.c added comment is there a tool param? added debug printfs added global framecount --- colorchord2/cells_output.conf | 8 +- colorchord2/netlight_esp8266.conf | 5 +- embedded8266/ccconfig.h | 6 +- embedded8266/esp82xx | 2 +- embedded8266/user.cfg | 13 +- embedded8266/user/custom_commands.c | 10 +- embedded8266/user/user_main.c | 8 +- embeddedcommon/embeddedout.c | 298 +++++++++++++++++++++------- embeddedcommon/embeddedout.h | 23 ++- embeddedlinux/Makefile | 20 +- embeddedlinux/ccconfig.h | 7 +- embeddedlinux/dummy_leds.c | 41 +++- embeddedlinux/embeddedcc.c | 26 ++- 13 files changed, 351 insertions(+), 116 deletions(-) diff --git a/colorchord2/cells_output.conf b/colorchord2/cells_output.conf index ca6c5d5..a82f58a 100644 --- a/colorchord2/cells_output.conf +++ b/colorchord2/cells_output.conf @@ -1,7 +1,7 @@ #for a two-ring WS2812 light, 24 LEDs per layer, one layer clockwise, the other counter-clockwise. outdrivers = DisplayPie,DisplayNetwork,OutputCells -leds = 48 +leds = 16 light_siding = 1.9 #Turn this to ~1.9 for more uniformity, ~1.0 for less. satamp = 1.600 is_loop=1 @@ -12,7 +12,7 @@ skipfirst = 3 firstval = 0 port = 7777 #address = 192.168.11.231 -address = 192.168.43.128 +address = 192.168.20.9 slope=.10 amplify=.4 @@ -21,10 +21,10 @@ amplify=.4 compress_coefficient = 4.0 compress_exponent = .5 -sourcename = alsa_output.pci-0000_00_1f.3.analog-stereo.monitor +sourcename = #alsa_output.pci-0000_00_1f.3.analog-stereo.monitor fliprg = 1 -skittlequantity = 24 +skittlequantity = 8 timebased = 1 qtyamp = 30 diff --git a/colorchord2/netlight_esp8266.conf b/colorchord2/netlight_esp8266.conf index e48f8eb..f379095 100644 --- a/colorchord2/netlight_esp8266.conf +++ b/colorchord2/netlight_esp8266.conf @@ -1,5 +1,5 @@ outdrivers = DisplayPie,DisplayNetwork, OutputLinear -leds = 276 +leds = 16 light_siding = 1.0 #Turn this to ~1.9 for more uniformity, ~1.0 for less. satamp = 1.600 is_loop=0 @@ -20,7 +20,8 @@ sourcename = alsa_output.pci-0000_01_00.1.hdmi-stereo-extra1.monitor skipfirst = 1 firstval = 1 port = 7777 -address = 192.168.4.1 +#address = 192.168.4.1 +address = 192.168.1.5 slope=.10 amplify=.3 diff --git a/embedded8266/ccconfig.h b/embedded8266/ccconfig.h index b3a09e5..66411c4 100644 --- a/embedded8266/ccconfig.h +++ b/embedded8266/ccconfig.h @@ -9,6 +9,7 @@ #define NUM_LIN_LEDS 255 #define DFREQ 16000 + #define memcpy ets_memcpy #define memset ets_memset @@ -53,9 +54,10 @@ extern uint8_t gNERF_NOTE_PORP; //=15 extern uint8_t gUSE_NUM_LIN_LEDS; // = NUM_LIN_LEDS #define USE_NUM_LIN_LEDS gUSE_NUM_LIN_LEDS -//We are not enabling these for the ESP8266 port. +//We are not enabling for the ESP8266 port. #define LIN_WRAPAROUND 0 -#define SORT_NOTES 0 +//but trying this now +#define SORT_NOTES 1 diff --git a/embedded8266/esp82xx b/embedded8266/esp82xx index 113e0d1..0946dfc 160000 --- a/embedded8266/esp82xx +++ b/embedded8266/esp82xx @@ -1 +1 @@ -Subproject commit 113e0d1a182cd138510f748abf2854c0e84cfa23 +Subproject commit 0946dfc45ece5da728ff9813b544aa49f239fd64 diff --git a/embedded8266/user.cfg b/embedded8266/user.cfg index 5945534..f7d86ba 100644 --- a/embedded8266/user.cfg +++ b/embedded8266/user.cfg @@ -10,20 +10,25 @@ COM_PORT = 7777 BACKEND_PORT = 7878 PAGE_OFFSET = 65536 # 1048576 +#SLOWTICK_MS = 10 # bb overrides default of 50 + #SDK_DEFAULT = $(HOME)/esp8266/esp-open-sdk ESP_GCC_VERS = 4.8.5 -SDK = $(HOME)/esp8266/esp_iot_sdk_v1.5.2 -PAGE_SCRIPTS = main.js +SDK = $(ESP_ROOT)/esp_iot_sdk_v1.5.2 -FWBURNFLAGS = -b 1000000 +# using -b 1500000 flash often fails using mac, not win7 +# commenting out burns slower but works +FWBURNFLAGS = -b 115200 # ok mac +#FWBURNFLAGS = -b 1500000 # ok win 7 OPTS += -DICACHE_FLASH #OPTS += -DVERIFY_FLASH_WRITE #OPTS += -DDEBUG #OPTS += -DFREQ=12500 + PAGE_TITLE = ColorChord Control Panel -PAGE_SCRIPT = +PAGE_SCRIPTS = main.js #bb PAGE_HEADING = ColorChord: Embedded PAGE_INFO = diff --git a/embedded8266/user/custom_commands.c b/embedded8266/user/custom_commands.c index 3afe2ef..e53fa6e 100644 --- a/embedded8266/user/custom_commands.c +++ b/embedded8266/user/custom_commands.c @@ -11,7 +11,7 @@ extern volatile uint8_t sounddata[]; extern volatile uint16_t soundhead; -#define CONFIGURABLES 17 //(plus1) +#define CONFIGURABLES 19 //(plus1) extern uint8_t RootNoteOffset; //Set to define what the root note is. 0 = A. uint8_t gDFTIIR = 6; @@ -29,23 +29,25 @@ uint8_t gNERF_NOTE_PORP = 15; uint8_t gUSE_NUM_LIN_LEDS = NUM_LIN_LEDS; uint8_t gCOLORCHORD_ACTIVE = 1; uint8_t gCOLORCHORD_OUTPUT_DRIVER = 0; +uint8_t gCOLORCHORD_ADVANCE_SHIFT = 0; +int8_t gCOLORCHORD_SUPRESS_FLIP_DIR = 1; struct SaveLoad { uint8_t configs[CONFIGURABLES]; } settings; -uint8_t gConfigDefaults[CONFIGURABLES] = { 0, 6, 1, 2, 3, 4, 7, 4, 2, 80, 64, 12, 15, NUM_LIN_LEDS, 1, 0, 0 }; +uint8_t gConfigDefaults[CONFIGURABLES] = { 0, 6, 1, 2, 3, 4, 7, 4, 2, 80, 64, 12, 15, NUM_LIN_LEDS, 1, 0, 0, 1, 0 }; uint8_t * gConfigurables[CONFIGURABLES] = { &RootNoteOffset, &gDFTIIR, &gFUZZ_IIR_BITS, &gFILTER_BLUR_PASSES, &gSEMIBITSPERBIN, &gMAX_JUMP_DISTANCE, &gMAX_COMBINE_DISTANCE, &gAMP_1_IIR_BITS, &gAMP_2_IIR_BITS, &gMIN_AMP_FOR_NOTE, &gMINIMUM_AMP_FOR_NOTE_TO_DISAPPEAR, &gNOTE_FINAL_AMP, - &gNERF_NOTE_PORP, &gUSE_NUM_LIN_LEDS, &gCOLORCHORD_ACTIVE, &gCOLORCHORD_OUTPUT_DRIVER, 0 }; + &gNERF_NOTE_PORP, &gUSE_NUM_LIN_LEDS, &gCOLORCHORD_ACTIVE, &gCOLORCHORD_OUTPUT_DRIVER, &gCOLORCHORD_ADVANCE_SHIFT, &gCOLORCHORD_SUPRESS_FLIP_DIR, 0 }; char * gConfigurableNames[CONFIGURABLES] = { "gROOT_NOTE_OFFSET", "gDFTIIR", "gFUZZ_IIR_BITS", "gFILTER_BLUR_PASSES", "gSEMIBITSPERBIN", "gMAX_JUMP_DISTANCE", "gMAX_COMBINE_DISTANCE", "gAMP_1_IIR_BITS", "gAMP_2_IIR_BITS", "gMIN_AMP_FOR_NOTE", "gMINIMUM_AMP_FOR_NOTE_TO_DISAPPEAR", "gNOTE_FINAL_AMP", - "gNERF_NOTE_PORP", "gUSE_NUM_LIN_LEDS", "gCOLORCHORD_ACTIVE", "gCOLORCHORD_OUTPUT_DRIVER", 0 }; + "gNERF_NOTE_PORP", "gUSE_NUM_LIN_LEDS", "gCOLORCHORD_ACTIVE", "gCOLORCHORD_OUTPUT_DRIVER","gCOLORCHORD_ADVANCE_SHIFT", "gCOLORCHORD_SUPRESS_FLIP_DIR", 0 }; void ICACHE_FLASH_ATTR CustomStart( ) { diff --git a/embedded8266/user/user_main.c b/embedded8266/user/user_main.c index 3b858e7..ce01c57 100644 --- a/embedded8266/user/user_main.c +++ b/embedded8266/user/user_main.c @@ -28,6 +28,8 @@ #define procTaskPrio 0 #define procTaskQueueLen 1 +int framecount = 0; + static volatile os_timer_t some_timer; static struct espconn *pUdpServer; @@ -52,7 +54,8 @@ extern uint8_t gCOLORCHORD_OUTPUT_DRIVER; static void NewFrame() { if( !gCOLORCHORD_ACTIVE ) return; - + framecount++; + //printf("NEW FRAME %d ******\n", framecount); //uint8_t led_outs[NUM_LIN_LEDS*3]; int i; HandleFrameInfo(); @@ -65,6 +68,9 @@ static void NewFrame() case 1: UpdateAllSameLEDs(); break; + case 2: + UpdateRotatingLEDs(); + break; }; //SendSPI2812( ledOut, NUM_LIN_LEDS ); diff --git a/embeddedcommon/embeddedout.c b/embeddedcommon/embeddedout.c index 12a3cf1..b8b338b 100644 --- a/embeddedcommon/embeddedout.c +++ b/embeddedcommon/embeddedout.c @@ -1,5 +1,6 @@ //Copyright 2015 <>< Charles Lohr under the ColorChord License. + #include "embeddedout.h" //uint8_t ledArray[NUM_LIN_LEDS]; //Points to which notes correspond to these LEDs @@ -11,6 +12,9 @@ uint8_t ledFreqOut[NUM_LIN_LEDS]; uint8_t ledFreqOutOld[NUM_LIN_LEDS]; uint8_t RootNoteOffset; +uint32_t total_note_a_prev = 0; +int diff_a_prev = 0; +int rot_dir = 1; // initial rotation direction 1 void UpdateLinearLEDs() { @@ -20,6 +24,8 @@ void UpdateLinearLEDs() extern uint16_t note_peak_amps[]; //[MAXNOTES] extern uint16_t note_peak_amps2[]; //[MAXNOTES] (Responds quicker) extern uint8_t note_jumped_to[]; //[MAXNOTES] When a note combines into another one, + extern uint8_t gCOLORCHORD_ADVANCE_SHIFT; // controls speed of shifting if 0 no shift + extern int8_t gCOLORCHORD_SUPRESS_FLIP_DIR; //if non-zero will cause flipping shift on peaks, also controls speed */ //Goal: Make splotches of light that are porportional to the strength of notes. @@ -33,16 +39,36 @@ void UpdateLinearLEDs() 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; + uint32_t total_note_a = 0; + int diff_a = 0; + int8_t jshift; + +#if DEBUGPRINT + printf( "Note Peak Freq: " ); + for( i = 0; i < MAXNOTES; i++ ) printf( " %5d /", note_peak_freqs[i] ); + printf( "\n" ); + printf( "Note Peak Amps: " ); + for( i = 0; i < MAXNOTES; i++ ) printf( " %5d /", note_peak_amps[i] ); + printf( "\n" ); + printf( "Note Peak Amp2: " ); + for( i = 0; i < MAXNOTES; i++ ) printf( " %5d /", note_peak_amps2[i] ); + printf( "\n" ); + printf( "Note jumped to: " ); + for( i = 0; i < MAXNOTES; i++ ) printf( " %5d /", note_jumped_to[i] ); + printf( "\n" ); +#endif for( i = 0; i < MAXNOTES; i++ ) { if( note_peak_freqs[i] == 255 ) continue; - note_nerf_a += note_peak_amps[i]; + total_note_a += note_peak_amps[i]; } - note_nerf_a = ((note_nerf_a * NERF_NOTE_PORP)>>8); + diff_a = total_note_a_prev - total_note_a; + note_nerf_a = ((total_note_a * NERF_NOTE_PORP)>>8); + // ignore notes with amp too small or freq 255 for( i = 0; i < MAXNOTES; i++ ) { uint16_t ist = note_peak_amps[i]; @@ -55,48 +81,73 @@ void UpdateLinearLEDs() { continue; } - -#if SORT_NOTES - for( j = 0; j < sorted_map_count; j++ ) - { - if( note_peak_freqs[ sorted_note_map[j] ] > nff ) - { - break; - } - } - for( k = sorted_map_count; k > j; k-- ) - { - 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++; } -#if 0 - for( i = 0; i < sorted_map_count; i++ ) - { - printf( "%d: %d: %d /", sorted_note_map[i], note_peak_freqs[sorted_note_map[i]], note_peak_amps[sorted_note_map[i]] ); - } - printf( "\n" ); -#endif + uint16_t local_peak_amps[MAXNOTES]; uint16_t local_peak_amps2[MAXNOTES]; + uint16_t hold16; + uint8_t hold8; uint8_t local_peak_freq[MAXNOTES]; + uint8_t local_note_jumped_to[MAXNOTES]; +#if SORT_NOTES + // can sort based on freq, amps etc - could mod to switch on a parameter + uint16_t *sort_key; // leaving untyped so can point to 16 or 8 bit, but may not best way + switch(1) { + case 1 : + sort_key = local_peak_amps2; + break; + case 2 : + sort_key = local_peak_amps; + break; + case 3 : + sort_key = local_peak_freq; + break; + } +#endif //Make a copy of all of the variables into local ones so we don't have to keep double-dereferencing. + //set sort key for( i = 0; i < sorted_map_count; 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( "%5d ", local_peak_amps[i] ); + local_note_jumped_to[i] = note_jumped_to[sorted_note_map[i]]; + } + +#if SORT_NOTES + // note local_note_jumped_to still give original indices of notes (which may not even been inclued + // due to being eliminated as too small amplitude + for( i = 0; i < sorted_map_count - 1; i++ ) + { + for( j = i + 1; j < sorted_map_count; j++ ) + { + //if (local_peak_freq[i] > local_peak_freq[j]) // inc sort on freq + if (*(sort_key+i) < *(sort_key+j)) // dec sort + { + hold8 = local_peak_freq[j]; + local_peak_freq[j] = local_peak_freq[i]; + local_peak_freq[i] = hold8; + hold8 = sorted_note_map[j]; + sorted_note_map[j] = sorted_note_map[i]; + sorted_note_map[i] = hold8; + hold8 = local_note_jumped_to[j]; + local_note_jumped_to[j] = local_note_jumped_to[i]; + local_note_jumped_to[i] = hold8; + hold16 = local_peak_amps[j]; + local_peak_amps[j] = local_peak_amps[i]; + local_peak_amps[i] = hold16; + hold16 = local_peak_amps2[j]; + local_peak_amps2[j] = local_peak_amps2[i]; + local_peak_amps2[i] = hold16; + } + } } -// printf( "\n" ); +#endif for( i = 0; i < sorted_map_count; i++ ) { @@ -126,6 +177,43 @@ void UpdateLinearLEDs() int16_t total_unaccounted_leds = USE_NUM_LIN_LEDS - total_accounted_leds; +#if DEBUGPRINT + printf( "note_nerf_a = %d, total_size_all_notes = %d, porportional = %d, total_accounted_leds = %d \n", note_nerf_a, total_size_all_notes, porportional, total_accounted_leds ); + printf("snm: "); + for( i = 0; i < sorted_map_count; i++ ) printf( "%d /", sorted_note_map[i]); + printf( "\n" ); + + printf("npf: "); + for( i = 0; i < sorted_map_count; i++ ) printf( "%d /", note_peak_freqs[sorted_note_map[i]]); + printf( "\n" ); + + printf("lpf: "); + for( i = 0; i < sorted_map_count; i++ ) printf( "%d /", local_peak_freq[i]); + printf( "\n" ); + + printf("npa: "); + for( i = 0; i < sorted_map_count; i++ ) printf( "%d /", note_peak_amps[sorted_note_map[i]]); + printf( "\n" ); + + printf("lpa: "); + for( i = 0; i < sorted_map_count; i++ ) printf( "%d /", local_peak_amps[i]); + printf( "\n" ); + + printf("lpa2: "); + for( i = 0; i < sorted_map_count; i++ ) printf( "%d /", local_peak_amps2[i]); + printf( "\n" ); + + printf("porp: "); + for( i = 0; i < sorted_map_count; i++ ) printf( "%d /", porpamps[i]); + printf( "\n" ); + + printf("lnjt: "); + for( i = 0; i < sorted_map_count; i++ ) printf( "%d /", local_note_jumped_to[i]); + printf( "\n" ); + +#endif + + int addedlast = 1; do { @@ -151,6 +239,10 @@ void UpdateLinearLEDs() //This part totally can't run on an embedded system. #if LIN_WRAPAROUND + //printf("NOTERANGE: %d ", NOTERANGE); //192 + // bb this code finds an index ledSpin so that shifting the led display will have the minimum deviation + // from the previous display. + // this will cancel out shifting effects below uint16_t midx = 0; uint32_t mqty = 100000000; for( j = 0; j < USE_NUM_LIN_LEDS; j++ ) @@ -179,86 +271,81 @@ void UpdateLinearLEDs() } ledSpin = midx; + printf("spin: %d, min deviation: %d\n", ledSpin, mqty); // bb #else ledSpin = 0; #endif +//TODO FIX if change gCOLORCHORD_SUPRESS_FLIP_DIR from non-zero to zero rot_dir will not reinitialize to 1 + // if option change direction on max peaks of total amplitude + if (gCOLORCHORD_SUPRESS_FLIP_DIR == 0) { + if (diff_a_prev < 0 && diff_a > 0) rot_dir *= -1; + } else rot_dir = gCOLORCHORD_SUPRESS_FLIP_DIR; + + // want possible extra spin to relate to changes peak intensity + // now every gCOLORCHORD_ADVANCE_SHIFT th frame + if (gCOLORCHORD_ADVANCE_SHIFT != 0) { +//NOTE need - in front of rot_dir to make rotation direction consistent with UpdateRotationLEDs + jshift = (ledSpin - rot_dir * framecount/gCOLORCHORD_ADVANCE_SHIFT ) % USE_NUM_LIN_LEDS; // neg % pos is neg so fix with + if ( jshift < 0 ) jshift += USE_NUM_LIN_LEDS; + //printf("tnap tna %d %d dap da %d %d rot_dir %d, j shift %d\n",total_note_a_prev, total_note_a, diff_a_prev, diff_a, rot_dir, j); + } else { + jshift = ledSpin; + } - j = ledSpin; - for( l = 0; l < USE_NUM_LIN_LEDS; l++, j++ ) +#if DEBUGPRINT + printf("rot_dir %d, jshift %d\n", rot_dir, jshift); + printf("leds: "); +#endif + for( l = 0; l < USE_NUM_LIN_LEDS; l++, jshift++ ) { - if( j >= USE_NUM_LIN_LEDS ) j = 0; - ledFreqOutOld[l] = ledFreqOut[j]; - - uint16_t amp = ledAmpOut[j]; + if( jshift >= USE_NUM_LIN_LEDS ) j = 0; +// bb note: lefFreqOutOld used only if wraparound +#if LIN_WRAPAROUND + ledFreqOutOld[l] = ledFreqOut[jshift]; +#endif + uint16_t amp = ledAmpOut[jshift]; +#if DEBUGPRINT + printf("%d:%d/", ledFreqOut[jshift], amp); +#endif if( amp > 255 ) amp = 255; - uint32_t color = ECCtoHEX( (ledFreqOut[j]+RootNoteOffset)%NOTERANGE, 255, amp ); + uint32_t color = ECCtoHEX( (ledFreqOut[jshift]+RootNoteOffset)%NOTERANGE, 255, amp ); ledOut[l*3+0] = ( color >> 0 ) & 0xff; ledOut[l*3+1] = ( color >> 8 ) & 0xff; ledOut[l*3+2] = ( color >>16 ) & 0xff; } -/* j = ledSpin; - for( i = 0; i < sorted_map_count; i++ ) - { - while( porpamps[i] > 0 ) - { - uint16_t amp = ((uint32_t)local_peak_amps2[i] * NOTE_FINAL_AMP) >> 8; - if( amp > 255 ) amp = 255; - uint32_t color = ECCtoHEX( local_peak_freq[i], 255, amp ); - ledOut[j*3+0] = ( color >> 0 ) & 0xff; - ledOut[j*3+1] = ( color >> 8 ) & 0xff; - ledOut[j*3+2] = ( color >>16 ) & 0xff; - - j++; - if( j == USE_NUM_LIN_LEDS ) j = 0; - porpamps[i]--; - } - }*/ - - //Now, we use porpamps to march through the LEDs, coloring them. -/* j = 0; - for( i = 0; i < sorted_map_count; i++ ) - { - while( porpamps[i] > 0 ) - { - uint16_t amp = ((uint32_t)local_peak_amps2[i] * NOTE_FINAL_AMP) >> 8; - if( amp > 255 ) amp = 255; - uint32_t color = ECCtoHEX( local_peak_freq[i], 255, amp ); - ledOut[j*3+0] = ( color >> 0 ) & 0xff; - ledOut[j*3+1] = ( color >> 8 ) & 0xff; - ledOut[j*3+2] = ( color >>16 ) & 0xff; - - j++; - porpamps[i]--; - } - }*/ +#if DEBUGPRINT + printf( "\n" ); + printf("bytes: "); + for( i = 0; i < USE_NUM_LIN_LEDS; i++ ) printf( "%02x%02x%02x-", ledOut[i*3+0], ledOut[i*3+1],ledOut[i*3+2]); + printf( "\n\n" ); +#endif + total_note_a_prev = total_note_a; + diff_a_prev = diff_a; } - - - void UpdateAllSameLEDs() { int i; + int8_t j; uint8_t freq = 0; uint16_t amp = 0; + for( i = 0; i < MAXNOTES; i++ ) { uint16_t ist = note_peak_amps2[i]; uint8_t ifrq = note_peak_freqs[i]; - if( ist > amp && ifrq != 255 ) + if( ifrq != 255 && ist > amp ) { freq = ifrq; amp = ist; } } - - amp = (((uint32_t)(amp))*NOTE_FINAL_AMP)>>10; + amp = (((uint32_t)(amp))*NOTE_FINAL_AMP)>>8; //bb was 10 if( amp > 255 ) amp = 255; uint32_t color = ECCtoHEX( (freq+RootNoteOffset)%NOTERANGE, 255, amp ); - for( i = 0; i < USE_NUM_LIN_LEDS; i++ ) { ledOut[i*3+0] = ( color >> 0 ) & 0xff; @@ -267,6 +354,63 @@ void UpdateAllSameLEDs() } } +void UpdateRotatingLEDs() +{ + int i; + int8_t jshift; + uint8_t freq = 0; + uint16_t amp = 0; + uint32_t note_nerf_a = 0; + uint32_t total_note_a = 0; + int diff_a = 0; + + for( i = 0; i < MAXNOTES; i++ ) + { + uint16_t ist = note_peak_amps2[i]; + uint8_t ifrq = note_peak_freqs[i]; + if( ifrq != 255 ) + { + if( ist > amp ) { + freq = ifrq; + amp = ist; + } + total_note_a += note_peak_amps[i]; + } + } + diff_a = total_note_a_prev - total_note_a; + amp = (((uint32_t)(amp))*NOTE_FINAL_AMP)>>8; //bb was 10 + + if( amp > 255 ) amp = 255; + uint32_t color = ECCtoHEX( (freq+RootNoteOffset)%NOTERANGE, 255, amp ); + // if option change direction on max peaks of total amplitude + + + if (gCOLORCHORD_SUPRESS_FLIP_DIR == 0) { + if (diff_a_prev < 0 && diff_a > 0) rot_dir *= -1; + } else rot_dir = gCOLORCHORD_SUPRESS_FLIP_DIR; + + if (gCOLORCHORD_ADVANCE_SHIFT != 0) { + // now every gCOLORCHORD_ADVANCE_SHIFT/rot_dir th frame + jshift = ((rot_dir)*framecount/gCOLORCHORD_ADVANCE_SHIFT) % USE_NUM_LIN_LEDS; // neg % pos is neg so fix + if( jshift < 0 ) jshift += USE_NUM_LIN_LEDS; + //printf("tnap tna %d %d dap da %d %d rot_dir %d, jshift %d \n",total_note_a_prev, total_note_a, diff_a_prev, diff_a, rot_dir, jshift); + } else {q + jshift = 0; + } + + //for( i = 0; i < USE_NUM_LIN_LEDS; i++ ) + for( i = 0; i < 1; i++, jshift++ ) + { + if( jshift >= USE_NUM_LIN_LEDS ) jshift = 0; + ledOut[jshift*3+0] = ( color >> 0 ) & 0xff; + ledOut[jshift*3+1] = ( color >> 8 ) & 0xff; + ledOut[jshift*3+2] = ( color >>16 ) & 0xff; + } + total_note_a_prev = total_note_a; + diff_a_prev = diff_a; + +} + diff --git a/embeddedcommon/embeddedout.h b/embeddedcommon/embeddedout.h index 146f010..3929719 100644 --- a/embeddedcommon/embeddedout.h +++ b/embeddedcommon/embeddedout.h @@ -1,10 +1,21 @@ //Copyright 2015 <>< Charles Lohr under the ColorChord License. + + #ifndef _EMBEDDEDOUT_H #define _EMBEDDEDOUT_H #include "embeddednf.h" +extern int framecount; //bb +extern uint8_t gCOLORCHORD_ADVANCE_SHIFT; // bb how much rotaion is used +extern int8_t gCOLORCHORD_SUPRESS_FLIP_DIR; //bb if non-zero will cause flipping shift on peaks + +//TODO fix +// print debug info wont work on esp8266 need debug to go to usb there +#ifndef DEBUGPRINT +#define DEBUGPRINT 0 +#endif //Controls brightness #ifndef NOTE_FINAL_AMP @@ -28,11 +39,14 @@ #ifndef LIN_WRAPAROUND //Whether the output lights wrap around. //(Can't easily run on embedded systems) -#define LIN_WRAPAROUND 0 +//(might be ok on ESP8266) +//(but will cancel effect of gCOLORCHORD_ADVANCE_SHIFT) +//TODO prevent above? +#define LIN_WRAPAROUND 0 #endif #ifndef SORT_NOTES -#define SORT_NOTES 0 //Whether the notes will be sorted. BUGGY Don't use. +#define SORT_NOTES 1 //Whether the notes will be sorted. bb FIXED so hopefull not BUGGY #endif extern uint8_t ledArray[]; @@ -40,11 +54,16 @@ extern uint8_t ledOut[]; //[NUM_LIN_LEDS*3] extern uint8_t RootNoteOffset; //Set to define what the root note is. 0 = A. //For doing the nice linear strip LED updates +//Also added rotation direction changing at peak total amp2 LEDs void UpdateLinearLEDs(); //For making all the LEDs the same and quickest. Good for solo instruments? void UpdateAllSameLEDs(); +//For using dominant note as in UpdateAllSameLEDs but display one light and rotate with direction changing at peak total amp2 LEDs +void UpdateRotatingLEDs(); + + uint32_t ECCtoHEX( uint8_t note, uint8_t sat, uint8_t val ); uint32_t EHSVtoHEX( uint8_t hue, uint8_t sat, uint8_t val ); //hue = 0..255 // TODO: TEST ME!!! diff --git a/embeddedlinux/Makefile b/embeddedlinux/Makefile index 8ccdf93..fe7f4fb 100644 --- a/embeddedlinux/Makefile +++ b/embeddedlinux/Makefile @@ -12,13 +12,25 @@ embeddedcc : ../embeddedcommon/embeddednf.c ../embeddedcommon/DFT32.c embeddedc dummy_leds : dummy_leds.c gcc -o $@ $^ -lX11 -lpthread $(CFLAGS) $(LDFLAGS) -SOUNDDEVICE:= --device=alsa_output.pci-0000_00_1b.0.analog-stereo.monitor -#OUTIP:=192.168.4.1 -OUTIP:=127.0.0.1 + +#If specifiy device not seems to work +#To find correct devices looked here and used pacmd and list-cards +#https://ubuntuforums.org/showthread.php?t=1517726 +#SOUNDDEVICE:= --device=alsa_output.pci-0000_00_05.0.analog-stereo.monitor # to use playing of mp3 +SOUNDDEVICE:= --device=alsa_input.pci-0000_00_05.0.analog-stereo # to use mic +#By leading this blank it takes a default output which works +#SOUNDDEVICE:= + +#OUTIP:=192.168.20.9 +#OUTIP:=192.168.1.5 # not work for ubuntu guest in Virtual Machine +#OUTIP:=10.0.2.15 # works for ubuntu guest in Virtual Machine +OUTIP:=127.0.0.1 # works for ubuntu guest in Virtual Machine runembedded : embeddedcc - parec --format=u8 --rate=16000 --channels=1 $(SOUNDDEVICE) --latency=128 | ./embeddedcc $(OUTIP) 1 + parec --format=u8 --rate=16000 --channels=1 $(SOUNDDEVICE) --latency=128 | ./embeddedcc $(OUTIP) 1 +runembeddeddbg : embeddedcc + parec -v --format=u8 --rate=16000 --channels=1 $(SOUNDDEVICE) --latency=128 | ./embeddedcc $(OUTIP) 1 > dbout.txt clean : rm -rf embeddedcc *~ dummy_leds diff --git a/embeddedlinux/ccconfig.h b/embeddedlinux/ccconfig.h index e4a5a30..234b8a4 100644 --- a/embeddedlinux/ccconfig.h +++ b/embeddedlinux/ccconfig.h @@ -1,9 +1,12 @@ #ifndef _CCCONFIG_H #define _CCCONFIG_H + #define CCEMBEDDED -#define NUM_LIN_LEDS 300 -#define USE_NUM_LIN_LEDS 300 +#define RING +#define LEDS_PER_ROW 16 +#define NUM_LIN_LEDS 16 +#define USE_NUM_LIN_LEDS NUM_LIN_LEDS #define DFREQ 16000 diff --git a/embeddedlinux/dummy_leds.c b/embeddedlinux/dummy_leds.c index 7f99064..65271a7 100644 --- a/embeddedlinux/dummy_leds.c +++ b/embeddedlinux/dummy_leds.c @@ -21,16 +21,20 @@ int wid, hei; uint8_t mesg[NUM_LIN_LEDS*3+3]; -#define LEDS_PER_ROW 15 -#define LED_SIZE 15 +#ifdef RING +#define LED_SIZE 150 +#else +#define LED_SIZE 55 +#endif + void thread_function( void * tf ) { int n; struct sockaddr_in cliaddr; socklen_t len; - XEvent exppp; + XEvent exppp; while(1) { @@ -39,9 +43,9 @@ void thread_function( void * tf ) //XSendEventXClearArea( d, w, 0, 0, 1, 1, 1 ); XLockDisplay( d ); memset(&exppp, 0, sizeof(exppp)); - exppp.type = Expose; - exppp.xexpose.window = w; - XSendEvent(d,w,False,ExposureMask,&exppp); + exppp.type = Expose; + exppp.xexpose.window = w; + XSendEvent(d,w,False,ExposureMask,&exppp); XFlush( d ); XUnlockDisplay( d ); } @@ -83,7 +87,14 @@ int main(void) } s = DefaultScreen(d); +#ifndef RING w = XCreateSimpleWindow(d, RootWindow(d, s), 10, 10, wid*LED_SIZE, hei*LED_SIZE, 1, BlackPixel(d, s), WhitePixel(d, s)); +#else + int thetaextent = 23040/LEDS_PER_ROW; // 360*64/LEDS_PER_ROW + int outermostradius = 2*hei*LED_SIZE; + int innermostradius = outermostradius/2; + w = XCreateSimpleWindow(d, RootWindow(d, s), 10, 10, outermostradius, outermostradius, 1, BlackPixel(d, s), BlackPixel(d, s)); +#endif XSetStandardProperties( d, w, "LED Simulaor", "LED Simulator", None, NULL, 0, NULL ); XSelectInput(d, w, ExposureMask | KeyPressMask); XMapWindow(d, w); @@ -93,15 +104,29 @@ int main(void) while (1) { XNextEvent(d, &e); if (e.type == Expose) { - for( n = 0; n < NUM_LIN_LEDS; n++ ) + // loop backwards so inner sectors cover outer ones + for( n = NUM_LIN_LEDS -1; n >= 0; n-- ) { unsigned long color = ( mesg[n*3+3] << 8 ) | ( mesg[n*3+4] << 16 ) | (mesg[n*3+5] << 0); XSetForeground(d, dgc, color); int x = n % wid; int y = n / wid; - +#ifndef RING XFillRectangle(d, w, dgc, x*LED_SIZE, y*LED_SIZE, LED_SIZE, LED_SIZE); +#else + // led 0 starts in innermost ring. The outermost ring may not be complete + // if NUM_LIN_LEDS is not a multiple of LEDS_PER_ROW + int thetastart = x*thetaextent; + int outerradius = innermostradius + (y+1)*LED_SIZE; + XFillArc(d, w, dgc, (outermostradius - outerradius)/2 , (outermostradius - outerradius)/2 , outerradius, outerradius, thetastart, thetaextent); +#endif + } +#ifdef RING + // Inner black hole + XSetForeground(d, dgc, 0); + XFillArc(d, w, dgc, (outermostradius - innermostradius)/2 , (outermostradius - innermostradius)/2 , innermostradius, innermostradius, 0, 23040); +#endif } } diff --git a/embeddedlinux/embeddedcc.c b/embeddedlinux/embeddedcc.c index ee663eb..c9bf1a1 100644 --- a/embeddedlinux/embeddedcc.c +++ b/embeddedlinux/embeddedcc.c @@ -17,16 +17,23 @@ struct sockaddr_in servaddr; int sock; #define expected_lights NUM_LIN_LEDS - int toskip = 1; +int framecount = 0; +//TODO explore relation of NUM_LIN_LEDS and following two params +uint8_t gCOLORCHORD_ADVANCE_SHIFT = 3; +int8_t gCOLORCHORD_SUPRESS_FLIP_DIR = -7; // neg clockwise, pos anticlockwise, zero will flip on peak total amp2 +// ratio of gCOLORCHORD_ADVANCE_SHIFT / gCOLORCHORD_SUPRESS_FLIP_DIR when less than 1 has interesting effect void NewFrame() { int i; char buffer[3000]; - + framecount++; + //printf("NEW FRAME %d ******\n", framecount); HandleFrameInfo(); - UpdateLinearLEDs(); + //UpdateLinearLEDs(); + //UpdateAllSameLEDs(); + UpdateRotatingLEDs(); buffer[0] = 0; buffer[1] = 0; @@ -35,6 +42,8 @@ void NewFrame() for( i = 0; i < expected_lights * 3; i++ ) { buffer[i+toskip*3] = ledOut[i]; +// printf("In NF: %d\n", ledOut[i]); + } int r = send(sock,buffer,expected_lights*3+3,0); @@ -45,6 +54,7 @@ int main( int argc, char ** argv ) { int wf = 0; int ci; + // bb no [tool] argument expected or used? if( argc < 2 ) { @@ -53,7 +63,11 @@ int main( int argc, char ** argv ) } printf( "%d\n", argc ); + for (int i = 0; i < argc; i++) + { printf( "%s\n", argv[i] ); + } toskip = (argc > 2)?atoi(argv[2]):0; + fprintf( stderr, " toskip = %d \n", toskip ); sock = socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP); @@ -61,14 +75,16 @@ int main( int argc, char ** argv ) servaddr.sin_family = AF_INET; servaddr.sin_addr.s_addr = inet_addr(argv[1]); servaddr.sin_port=htons(7777); - + fprintf(stderr, "The IP address is %s\n", inet_ntoa(servaddr.sin_addr.s_addr)); connect( sock, (struct sockaddr *)&servaddr, sizeof(servaddr) ); - Init(); + InitColorChord(); // bb changed from Init() which does not seem to exist; while( ( ci = getchar() ) != EOF ) { int cs = ci - 0x80; +//printf("byte: %d\n", cs); +// putchar(ci); #ifdef USE_32DFT PushSample32( ((int8_t)cs)*32 ); #else From 7dd6a3586578bfd532af107b55c67f03be98d470 Mon Sep 17 00:00:00 2001 From: bbkiwi Date: Fri, 14 Apr 2017 13:21:13 +1200 Subject: [PATCH 02/15] Typo removed rogue "q" --- embeddedcommon/embeddedout.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/embeddedcommon/embeddedout.c b/embeddedcommon/embeddedout.c index b8b338b..5aa0063 100644 --- a/embeddedcommon/embeddedout.c +++ b/embeddedcommon/embeddedout.c @@ -394,7 +394,7 @@ void UpdateRotatingLEDs() jshift = ((rot_dir)*framecount/gCOLORCHORD_ADVANCE_SHIFT) % USE_NUM_LIN_LEDS; // neg % pos is neg so fix if( jshift < 0 ) jshift += USE_NUM_LIN_LEDS; //printf("tnap tna %d %d dap da %d %d rot_dir %d, jshift %d \n",total_note_a_prev, total_note_a, diff_a_prev, diff_a, rot_dir, jshift); - } else {q + } else { jshift = 0; } From 0a78029047615b31ba2ca77d65a58d7477042974 Mon Sep 17 00:00:00 2001 From: bbkiwi Date: Fri, 14 Apr 2017 19:18:06 +1200 Subject: [PATCH 03/15] Bug fix UpdateLinearLEDs, Improved UpdateRotatingLEDs UpdateLinearLEDs can now use LIN_WRAPAROUND while rotating LEDs UpdateRotatingLEDs now has code to have LED arc length proportional to amp2 can have constant intensity or related to amp2 --- embeddedcommon/embeddedout.c | 50 ++++++++++++++++++++++++++---------- embeddedcommon/embeddedout.h | 2 -- 2 files changed, 36 insertions(+), 16 deletions(-) diff --git a/embeddedcommon/embeddedout.c b/embeddedcommon/embeddedout.c index 5aa0063..4e73a95 100644 --- a/embeddedcommon/embeddedout.c +++ b/embeddedcommon/embeddedout.c @@ -271,7 +271,7 @@ void UpdateLinearLEDs() } ledSpin = midx; - printf("spin: %d, min deviation: %d\n", ledSpin, mqty); // bb + //printf("spin: %d, min deviation: %d\n", ledSpin, mqty); // bb #else ledSpin = 0; @@ -299,10 +299,12 @@ void UpdateLinearLEDs() #endif for( l = 0; l < USE_NUM_LIN_LEDS; l++, jshift++ ) { - if( jshift >= USE_NUM_LIN_LEDS ) j = 0; + if( jshift >= USE_NUM_LIN_LEDS ) jshift = 0; // bb note: lefFreqOutOld used only if wraparound #if LIN_WRAPAROUND - ledFreqOutOld[l] = ledFreqOut[jshift]; + if( ledSpin >= USE_NUM_LIN_LEDS ) ledSpin = 0; + ledFreqOutOld[l] = ledFreqOut[ledSpin]; + ledSpin++; #endif uint16_t amp = ledAmpOut[jshift]; #if DEBUGPRINT @@ -360,9 +362,12 @@ void UpdateRotatingLEDs() int8_t jshift; uint8_t freq = 0; uint16_t amp = 0; + uint16_t amp2 = 0; uint32_t note_nerf_a = 0; uint32_t total_note_a = 0; + //uint32_t total_note_a2 = 0; int diff_a = 0; + int32_t led_arc_len; for( i = 0; i < MAXNOTES; i++ ) { @@ -370,42 +375,59 @@ void UpdateRotatingLEDs() uint8_t ifrq = note_peak_freqs[i]; if( ifrq != 255 ) { - if( ist > amp ) { + if( ist > amp2 ) { freq = ifrq; - amp = ist; + amp2 = ist; } total_note_a += note_peak_amps[i]; + //total_note_a2 += ist; } } + diff_a = total_note_a_prev - total_note_a; - amp = (((uint32_t)(amp))*NOTE_FINAL_AMP)>>8; //bb was 10 - if( amp > 255 ) amp = 255; - uint32_t color = ECCtoHEX( (freq+RootNoteOffset)%NOTERANGE, 255, amp ); - // if option change direction on max peaks of total amplitude + // can set color intensity using amp2 + //amp = (((uint32_t)(amp2))*NOTE_FINAL_AMP)>>8; //bb was 10 + //if( amp > 255 ) amp = 255; + //uint32_t color = ECCtoHEX( (freq+RootNoteOffset)%NOTERANGE, 255, amp ); + uint32_t color = ECCtoHEX( (freq+RootNoteOffset)%NOTERANGE, 255, 255 ); + // can have led_arc_len a fixed size or proportional to amp2 + //led_arc_len = 5; + led_arc_len = (amp2 * USE_NUM_LIN_LEDS) >> 14; // empirical + //printf("test %d %d \n", amp2, led_arc_len); + // if option change direction on max peaks of total amplitude if (gCOLORCHORD_SUPRESS_FLIP_DIR == 0) { if (diff_a_prev < 0 && diff_a > 0) rot_dir *= -1; } else rot_dir = gCOLORCHORD_SUPRESS_FLIP_DIR; if (gCOLORCHORD_ADVANCE_SHIFT != 0) { - // now every gCOLORCHORD_ADVANCE_SHIFT/rot_dir th frame - jshift = ((rot_dir)*framecount/gCOLORCHORD_ADVANCE_SHIFT) % USE_NUM_LIN_LEDS; // neg % pos is neg so fix + // On each gCOLORCHORD_ADVANCE_SHIFT/rot_dir-th frame make rotational shift + jshift = ((rot_dir)*framecount/gCOLORCHORD_ADVANCE_SHIFT - led_arc_len/2) % USE_NUM_LIN_LEDS; // neg % pos is neg so fix if( jshift < 0 ) jshift += USE_NUM_LIN_LEDS; //printf("tnap tna %d %d dap da %d %d rot_dir %d, jshift %d \n",total_note_a_prev, total_note_a, diff_a_prev, diff_a, rot_dir, jshift); } else { - jshift = 0; + jshift = (0 - led_arc_len/2) % USE_NUM_LIN_LEDS; // neg % pos is neg so fix + if( jshift < 0 ) jshift += USE_NUM_LIN_LEDS; } - //for( i = 0; i < USE_NUM_LIN_LEDS; i++ ) - for( i = 0; i < 1; i++, jshift++ ) + for( i = 0; i < led_arc_len; i++, jshift++ ) { + // even if led_arc_len exceeds USE+NUM_LIN_LEDS using jshift will prevent over running ledOut if( jshift >= USE_NUM_LIN_LEDS ) jshift = 0; ledOut[jshift*3+0] = ( color >> 0 ) & 0xff; ledOut[jshift*3+1] = ( color >> 8 ) & 0xff; ledOut[jshift*3+2] = ( color >>16 ) & 0xff; } + + for( i = led_arc_len; i < USE_NUM_LIN_LEDS; i++, jshift++ ) + { + if( jshift >= USE_NUM_LIN_LEDS ) jshift = 0; + ledOut[jshift*3+0] = 0x0; + ledOut[jshift*3+1] = 0x0; + ledOut[jshift*3+2] = 0x0; + } total_note_a_prev = total_note_a; diff_a_prev = diff_a; diff --git a/embeddedcommon/embeddedout.h b/embeddedcommon/embeddedout.h index 3929719..314051a 100644 --- a/embeddedcommon/embeddedout.h +++ b/embeddedcommon/embeddedout.h @@ -40,8 +40,6 @@ extern int8_t gCOLORCHORD_SUPRESS_FLIP_DIR; //bb if non-zero will cause flipping //Whether the output lights wrap around. //(Can't easily run on embedded systems) //(might be ok on ESP8266) -//(but will cancel effect of gCOLORCHORD_ADVANCE_SHIFT) -//TODO prevent above? #define LIN_WRAPAROUND 0 #endif From 32b4b3647309d3d27bd2c8568a7467ffd1ea13a2 Mon Sep 17 00:00:00 2001 From: bbkiwi Date: Fri, 14 Apr 2017 23:48:41 +1200 Subject: [PATCH 04/15] UpdateRotatingLEDs now uses gNOTE_FINAL_AMP --- embeddedcommon/embeddedout.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/embeddedcommon/embeddedout.c b/embeddedcommon/embeddedout.c index 4e73a95..8322345 100644 --- a/embeddedcommon/embeddedout.c +++ b/embeddedcommon/embeddedout.c @@ -271,7 +271,7 @@ void UpdateLinearLEDs() } ledSpin = midx; - //printf("spin: %d, min deviation: %d\n", ledSpin, mqty); // bb + //printf("spin: %d, min deviation: %d\n", ledSpin, mqty); #else ledSpin = 0; @@ -300,7 +300,7 @@ void UpdateLinearLEDs() for( l = 0; l < USE_NUM_LIN_LEDS; l++, jshift++ ) { if( jshift >= USE_NUM_LIN_LEDS ) jshift = 0; -// bb note: lefFreqOutOld used only if wraparound +//note: lefFreqOutOld used only if wraparound #if LIN_WRAPAROUND if( ledSpin >= USE_NUM_LIN_LEDS ) ledSpin = 0; ledFreqOutOld[l] = ledFreqOut[ledSpin]; @@ -344,7 +344,7 @@ void UpdateAllSameLEDs() amp = ist; } } - amp = (((uint32_t)(amp))*NOTE_FINAL_AMP)>>8; //bb was 10 + amp = (((uint32_t)(amp))*NOTE_FINAL_AMP)>>10; if( amp > 255 ) amp = 255; uint32_t color = ECCtoHEX( (freq+RootNoteOffset)%NOTERANGE, 255, amp ); @@ -387,14 +387,14 @@ void UpdateRotatingLEDs() diff_a = total_note_a_prev - total_note_a; // can set color intensity using amp2 - //amp = (((uint32_t)(amp2))*NOTE_FINAL_AMP)>>8; //bb was 10 - //if( amp > 255 ) amp = 255; + amp = (((uint32_t)(amp2))*NOTE_FINAL_AMP)>>10; + if( amp > 255 ) amp = 255; //uint32_t color = ECCtoHEX( (freq+RootNoteOffset)%NOTERANGE, 255, amp ); uint32_t color = ECCtoHEX( (freq+RootNoteOffset)%NOTERANGE, 255, 255 ); // can have led_arc_len a fixed size or proportional to amp2 //led_arc_len = 5; - led_arc_len = (amp2 * USE_NUM_LIN_LEDS) >> 14; // empirical + led_arc_len = (amp * USE_NUM_LIN_LEDS) >> 8; //printf("test %d %d \n", amp2, led_arc_len); // if option change direction on max peaks of total amplitude From 5381f0f1281077ede7e5215cab5615921bd8b1f5 Mon Sep 17 00:00:00 2001 From: bbkiwi Date: Sun, 16 Apr 2017 14:21:01 +1200 Subject: [PATCH 05/15] Added .gitignore and notes dir --- .gitignore | 63 ++++++++++++++++++++++++++++ program_notes/Add Custom Command.txt | 13 ++++++ 2 files changed, 76 insertions(+) create mode 100644 .gitignore create mode 100644 program_notes/Add Custom Command.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5ced94a --- /dev/null +++ b/.gitignore @@ -0,0 +1,63 @@ +# bb colorcord binaries and debugging files +colorchord2/colorchord +*.bin +embedded8266/web/page.mpfs +embedded8266/web/tmp/ +embedded8266/web/mfsmaker +embeddedlinux/embeddedcc +embeddedlinux/dbout.txt + + +# Recommended for c-programs +# Prerequisites +*.d + +# Object files +*.o +*.ko +*.obj +*.elf + +# Linker output +*.ilk +*.map +*.exp + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.a +*.la +*.lo + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + +# Debug files +*.dSYM/ +*.su +*.idb +*.pdb + +# Kernel Module Compile Results +*.mod* +*.cmd +.tmp_versions/ +modules.order +Module.symvers +Mkfile.old +dkms.conf diff --git a/program_notes/Add Custom Command.txt b/program_notes/Add Custom Command.txt new file mode 100644 index 0000000..ccaac71 --- /dev/null +++ b/program_notes/Add Custom Command.txt @@ -0,0 +1,13 @@ +To add custom command that specifies a parameter that can be used in embeddedout.c + +1. In embedded8266/user/custom_commands.c and embeddedlinux/embeddedcc.c +Add declaration of variables with initial value + +2. In embedded8266/user/custom_commands.c +Increase value of #define CONFIGURABLES to be one more than the number of variables below if (plus1) +update values of gConfigDefaults, *gConfigurables and *gConfigurableNames + (note all end in extra 0) + +3 In embeddedcommon/embeddedout.h +Add declaration as extern +and the variables then can be used by all routines in embeddedout.c From 76fe5350603adf1927e86ae28bc927bb4c42cc27 Mon Sep 17 00:00:00 2001 From: bbkiwi Date: Sun, 16 Apr 2017 23:36:34 +1200 Subject: [PATCH 06/15] Improved Output Options added Custom Command --- .gitignore | 1 + embedded8266/user/custom_commands.c | 14 +++++---- embeddedcommon/embeddedout.c | 45 +++++++++++++++++------------ embeddedcommon/embeddedout.h | 7 +++-- embeddedlinux/embeddedcc.c | 8 +++-- 5 files changed, 45 insertions(+), 30 deletions(-) diff --git a/.gitignore b/.gitignore index 5ced94a..c651e39 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ embedded8266/web/page.mpfs embedded8266/web/tmp/ embedded8266/web/mfsmaker embeddedlinux/embeddedcc +embeddedlinux/dummy_leds embeddedlinux/dbout.txt diff --git a/embedded8266/user/custom_commands.c b/embedded8266/user/custom_commands.c index e53fa6e..ad8f3c8 100644 --- a/embedded8266/user/custom_commands.c +++ b/embedded8266/user/custom_commands.c @@ -11,7 +11,7 @@ extern volatile uint8_t sounddata[]; extern volatile uint16_t soundhead; -#define CONFIGURABLES 19 //(plus1) +#define CONFIGURABLES 20 //(plus1) extern uint8_t RootNoteOffset; //Set to define what the root note is. 0 = A. uint8_t gDFTIIR = 6; @@ -29,25 +29,27 @@ uint8_t gNERF_NOTE_PORP = 15; uint8_t gUSE_NUM_LIN_LEDS = NUM_LIN_LEDS; uint8_t gCOLORCHORD_ACTIVE = 1; uint8_t gCOLORCHORD_OUTPUT_DRIVER = 0; -uint8_t gCOLORCHORD_ADVANCE_SHIFT = 0; -int8_t gCOLORCHORD_SUPRESS_FLIP_DIR = 1; +uint8_t gCOLORCHORD_SHIFT_INTERVAL = 0; +uint8_t gCOLORCHORD_FLIP_ON_PEAK = 0; +int8_t gCOLORCHORD_SHIFT_DISTANCE = 0; //distance of shift + struct SaveLoad { uint8_t configs[CONFIGURABLES]; } settings; -uint8_t gConfigDefaults[CONFIGURABLES] = { 0, 6, 1, 2, 3, 4, 7, 4, 2, 80, 64, 12, 15, NUM_LIN_LEDS, 1, 0, 0, 1, 0 }; +uint8_t gConfigDefaults[CONFIGURABLES] = { 0, 6, 1, 2, 3, 4, 7, 4, 2, 80, 64, 12, 15, NUM_LIN_LEDS, 1, 0, 0, 0, 0, 0 }; uint8_t * gConfigurables[CONFIGURABLES] = { &RootNoteOffset, &gDFTIIR, &gFUZZ_IIR_BITS, &gFILTER_BLUR_PASSES, &gSEMIBITSPERBIN, &gMAX_JUMP_DISTANCE, &gMAX_COMBINE_DISTANCE, &gAMP_1_IIR_BITS, &gAMP_2_IIR_BITS, &gMIN_AMP_FOR_NOTE, &gMINIMUM_AMP_FOR_NOTE_TO_DISAPPEAR, &gNOTE_FINAL_AMP, - &gNERF_NOTE_PORP, &gUSE_NUM_LIN_LEDS, &gCOLORCHORD_ACTIVE, &gCOLORCHORD_OUTPUT_DRIVER, &gCOLORCHORD_ADVANCE_SHIFT, &gCOLORCHORD_SUPRESS_FLIP_DIR, 0 }; + &gNERF_NOTE_PORP, &gUSE_NUM_LIN_LEDS, &gCOLORCHORD_ACTIVE, &gCOLORCHORD_OUTPUT_DRIVER, &gCOLORCHORD_SHIFT_INTERVAL, &gCOLORCHORD_FLIP_ON_PEAK, &gCOLORCHORD_SHIFT_DISTANCE, 0 }; char * gConfigurableNames[CONFIGURABLES] = { "gROOT_NOTE_OFFSET", "gDFTIIR", "gFUZZ_IIR_BITS", "gFILTER_BLUR_PASSES", "gSEMIBITSPERBIN", "gMAX_JUMP_DISTANCE", "gMAX_COMBINE_DISTANCE", "gAMP_1_IIR_BITS", "gAMP_2_IIR_BITS", "gMIN_AMP_FOR_NOTE", "gMINIMUM_AMP_FOR_NOTE_TO_DISAPPEAR", "gNOTE_FINAL_AMP", - "gNERF_NOTE_PORP", "gUSE_NUM_LIN_LEDS", "gCOLORCHORD_ACTIVE", "gCOLORCHORD_OUTPUT_DRIVER","gCOLORCHORD_ADVANCE_SHIFT", "gCOLORCHORD_SUPRESS_FLIP_DIR", 0 }; + "gNERF_NOTE_PORP", "gUSE_NUM_LIN_LEDS", "gCOLORCHORD_ACTIVE", "gCOLORCHORD_OUTPUT_DRIVER","gCOLORCHORD_SHIFT_INTERVAL", "gCOLORCHORD_FLIP_ON_PEAK", "gCOLORCHORD_SHIFT_DISTANCE", 0 }; void ICACHE_FLASH_ATTR CustomStart( ) { diff --git a/embeddedcommon/embeddedout.c b/embeddedcommon/embeddedout.c index 8322345..5dc53dc 100644 --- a/embeddedcommon/embeddedout.c +++ b/embeddedcommon/embeddedout.c @@ -24,8 +24,9 @@ void UpdateLinearLEDs() extern uint16_t note_peak_amps[]; //[MAXNOTES] extern uint16_t note_peak_amps2[]; //[MAXNOTES] (Responds quicker) extern uint8_t note_jumped_to[]; //[MAXNOTES] When a note combines into another one, - extern uint8_t gCOLORCHORD_ADVANCE_SHIFT; // controls speed of shifting if 0 no shift - extern int8_t gCOLORCHORD_SUPRESS_FLIP_DIR; //if non-zero will cause flipping shift on peaks, also controls speed + extern uint8_t gCOLORCHORD_SHIFT_INTERVAL; // controls speed of shifting if 0 no shift + extern uint8_t gCOLORCHORD_FLIP_ON_PEAK; //if non-zero gives flipping at peaks of shift direction, 0 no flip + extern int8_t gCOLORCHORD_SHIFT_DISTANCE; //distance of shift */ //Goal: Make splotches of light that are porportional to the strength of notes. @@ -41,6 +42,7 @@ void UpdateLinearLEDs() uint32_t note_nerf_a = 0; uint32_t total_note_a = 0; int diff_a = 0; + int8_t shift_dist = 0; int8_t jshift; #if DEBUGPRINT @@ -276,17 +278,19 @@ void UpdateLinearLEDs() #else ledSpin = 0; #endif -//TODO FIX if change gCOLORCHORD_SUPRESS_FLIP_DIR from non-zero to zero rot_dir will not reinitialize to 1 // if option change direction on max peaks of total amplitude - if (gCOLORCHORD_SUPRESS_FLIP_DIR == 0) { - if (diff_a_prev < 0 && diff_a > 0) rot_dir *= -1; - } else rot_dir = gCOLORCHORD_SUPRESS_FLIP_DIR; + if (gCOLORCHORD_FLIP_ON_PEAK ) { + if (diff_a_prev < 0 && diff_a > 0) { + rot_dir *= -1; + shift_dist = rot_dir * gCOLORCHORD_SHIFT_DISTANCE; + } + } else shift_dist = gCOLORCHORD_SHIFT_DISTANCE; // want possible extra spin to relate to changes peak intensity - // now every gCOLORCHORD_ADVANCE_SHIFT th frame - if (gCOLORCHORD_ADVANCE_SHIFT != 0) { -//NOTE need - in front of rot_dir to make rotation direction consistent with UpdateRotationLEDs - jshift = (ledSpin - rot_dir * framecount/gCOLORCHORD_ADVANCE_SHIFT ) % USE_NUM_LIN_LEDS; // neg % pos is neg so fix with + // now every gCOLORCHORD_SHIFT_INTERVAL th frame + if (gCOLORCHORD_SHIFT_INTERVAL != 0) { + //NOTE need - in front of rot_dir to make rotation direction consistent with UpdateRotationLEDs + jshift = (ledSpin - shift_dist * framecount/gCOLORCHORD_SHIFT_INTERVAL ) % USE_NUM_LIN_LEDS; // neg % pos is neg so fix with if ( jshift < 0 ) jshift += USE_NUM_LIN_LEDS; //printf("tnap tna %d %d dap da %d %d rot_dir %d, j shift %d\n",total_note_a_prev, total_note_a, diff_a_prev, diff_a, rot_dir, j); } else { @@ -294,7 +298,7 @@ void UpdateLinearLEDs() } #if DEBUGPRINT - printf("rot_dir %d, jshift %d\n", rot_dir, jshift); + printf("rot_dir %d, shift_dist %d, jshift %d\n", rot_dir, shift_dist, jshift); printf("leds: "); #endif for( l = 0; l < USE_NUM_LIN_LEDS; l++, jshift++ ) @@ -360,6 +364,7 @@ void UpdateRotatingLEDs() { int i; int8_t jshift; + int8_t shift_dist; uint8_t freq = 0; uint16_t amp = 0; uint16_t amp2 = 0; @@ -397,14 +402,18 @@ void UpdateRotatingLEDs() led_arc_len = (amp * USE_NUM_LIN_LEDS) >> 8; //printf("test %d %d \n", amp2, led_arc_len); - // if option change direction on max peaks of total amplitude - if (gCOLORCHORD_SUPRESS_FLIP_DIR == 0) { - if (diff_a_prev < 0 && diff_a > 0) rot_dir *= -1; - } else rot_dir = gCOLORCHORD_SUPRESS_FLIP_DIR; + // want possible extra spin to relate to changes peak intensity + if (gCOLORCHORD_FLIP_ON_PEAK ) { + if (diff_a_prev < 0 && diff_a > 0) { + rot_dir *= -1; + shift_dist = rot_dir * gCOLORCHORD_SHIFT_DISTANCE; + } + } else shift_dist = gCOLORCHORD_SHIFT_DISTANCE; - if (gCOLORCHORD_ADVANCE_SHIFT != 0) { - // On each gCOLORCHORD_ADVANCE_SHIFT/rot_dir-th frame make rotational shift - jshift = ((rot_dir)*framecount/gCOLORCHORD_ADVANCE_SHIFT - led_arc_len/2) % USE_NUM_LIN_LEDS; // neg % pos is neg so fix + // now every gCOLORCHORD_SHIFT_INTERVAL th frame + if (gCOLORCHORD_SHIFT_INTERVAL != 0) { + // On each gCOLORCHORD_SHIFT_INTERVAL/rot_dir-th frame make rotational shift + jshift = (shift_dist * framecount/gCOLORCHORD_SHIFT_INTERVAL - led_arc_len/2) % USE_NUM_LIN_LEDS; // neg % pos is neg so fix if( jshift < 0 ) jshift += USE_NUM_LIN_LEDS; //printf("tnap tna %d %d dap da %d %d rot_dir %d, jshift %d \n",total_note_a_prev, total_note_a, diff_a_prev, diff_a, rot_dir, jshift); } else { diff --git a/embeddedcommon/embeddedout.h b/embeddedcommon/embeddedout.h index 314051a..247c478 100644 --- a/embeddedcommon/embeddedout.h +++ b/embeddedcommon/embeddedout.h @@ -7,9 +7,10 @@ #include "embeddednf.h" -extern int framecount; //bb -extern uint8_t gCOLORCHORD_ADVANCE_SHIFT; // bb how much rotaion is used -extern int8_t gCOLORCHORD_SUPRESS_FLIP_DIR; //bb if non-zero will cause flipping shift on peaks +extern int framecount; +extern uint8_t gCOLORCHORD_SHIFT_INTERVAL; //how frame interval between shifts. if 0 no shift +extern uint8_t gCOLORCHORD_FLIP_ON_PEAK; //if non-zero will cause flipping shift on peaks +extern int8_t gCOLORCHORD_SHIFT_DISTANCE; //distance of shift //TODO fix // print debug info wont work on esp8266 need debug to go to usb there diff --git a/embeddedlinux/embeddedcc.c b/embeddedlinux/embeddedcc.c index c9bf1a1..b7c992e 100644 --- a/embeddedlinux/embeddedcc.c +++ b/embeddedlinux/embeddedcc.c @@ -20,9 +20,11 @@ int sock; int toskip = 1; int framecount = 0; //TODO explore relation of NUM_LIN_LEDS and following two params -uint8_t gCOLORCHORD_ADVANCE_SHIFT = 3; -int8_t gCOLORCHORD_SUPRESS_FLIP_DIR = -7; // neg clockwise, pos anticlockwise, zero will flip on peak total amp2 -// ratio of gCOLORCHORD_ADVANCE_SHIFT / gCOLORCHORD_SUPRESS_FLIP_DIR when less than 1 has interesting effect +// ratio of gCOLORCHORD_SHIFT_INTERVAL / gCOLORCHORD_SHIFT_DISTANCE when less than 1 has interesting effect +uint8_t gCOLORCHORD_SHIFT_INTERVAL = 5; +uint8_t gCOLORCHORD_FLIP_ON_PEAK = 0; // non-zero will flip on peak total amp2 +int8_t gCOLORCHORD_SHIFT_DISTANCE = -1; //distance of shift + anticlockwise, - clockwise, 0 no shift + void NewFrame() { From ae6ef5b9e4811ed0fdb561fa38c28b34fab69e0b Mon Sep 17 00:00:00 2001 From: bbkiwi Date: Mon, 17 Apr 2017 23:42:16 +1200 Subject: [PATCH 07/15] Work on speeding up sort --- embeddedcommon/embeddedout.c | 41 +++++++++++++++++++++--------------- embeddedcommon/embeddedout.h | 2 +- embeddedlinux/embeddedcc.c | 6 +++--- 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/embeddedcommon/embeddedout.c b/embeddedcommon/embeddedout.c index 5dc53dc..47b89c8 100644 --- a/embeddedcommon/embeddedout.c +++ b/embeddedcommon/embeddedout.c @@ -88,69 +88,76 @@ void UpdateLinearLEDs() } - uint16_t local_peak_amps[MAXNOTES]; uint16_t local_peak_amps2[MAXNOTES]; uint16_t hold16; uint8_t hold8; - uint8_t local_peak_freq[MAXNOTES]; + uint16_t local_peak_freq[MAXNOTES]; // using 16 bit so can easily choose amps, amps2 or freq as key uint8_t local_note_jumped_to[MAXNOTES]; #if SORT_NOTES // can sort based on freq, amps etc - could mod to switch on a parameter - uint16_t *sort_key; // leaving untyped so can point to 16 or 8 bit, but may not best way - switch(1) { + uint16_t *sort_key; + uint16_t *non_key[2]; + switch(3) { case 1 : sort_key = local_peak_amps2; + non_key[0] = local_peak_amps; + non_key[1] = local_peak_freq; break; case 2 : sort_key = local_peak_amps; + non_key[0] = local_peak_amps2; + non_key[1] = local_peak_freq; break; case 3 : sort_key = local_peak_freq; + non_key[0] = local_peak_amps; + non_key[1] = local_peak_amps2; break; } #endif - //Make a copy of all of the variables into local ones so we don't have to keep double-dereferencing. - //set sort key for( i = 0; i < sorted_map_count; 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]]; + local_peak_freq[i] = (uint16_t) note_peak_freqs[sorted_note_map[i]]; local_note_jumped_to[i] = note_jumped_to[sorted_note_map[i]]; } + #if SORT_NOTES // note local_note_jumped_to still give original indices of notes (which may not even been inclued // due to being eliminated as too small amplitude + // TODO bubble sort on key and reorder sorted_note_map for( i = 0; i < sorted_map_count - 1; i++ ) { for( j = i + 1; j < sorted_map_count; j++ ) { - //if (local_peak_freq[i] > local_peak_freq[j]) // inc sort on freq if (*(sort_key+i) < *(sort_key+j)) // dec sort { - hold8 = local_peak_freq[j]; - local_peak_freq[j] = local_peak_freq[i]; - local_peak_freq[i] = hold8; + hold16 = *(sort_key+j); + *(sort_key+j) = *(sort_key+i); + *(sort_key+i) = hold16; + hold16 = *(non_key[0]+j); + *(non_key[0]+j) = *(non_key[0]+i); + *(non_key[0]+i) = hold16; + hold16 = *(non_key[1]+j); + *(non_key[1]+j) = *(non_key[1]+i); + *(non_key[1]+i) = hold16; hold8 = sorted_note_map[j]; sorted_note_map[j] = sorted_note_map[i]; sorted_note_map[i] = hold8; hold8 = local_note_jumped_to[j]; local_note_jumped_to[j] = local_note_jumped_to[i]; local_note_jumped_to[i] = hold8; - hold16 = local_peak_amps[j]; - local_peak_amps[j] = local_peak_amps[i]; - local_peak_amps[i] = hold16; - hold16 = local_peak_amps2[j]; - local_peak_amps2[j] = local_peak_amps2[i]; - local_peak_amps2[i] = hold16; } } } + #endif + for( i = 0; i < sorted_map_count; i++ ) { uint16_t ist = local_peak_amps[i]; diff --git a/embeddedcommon/embeddedout.h b/embeddedcommon/embeddedout.h index 247c478..f6184a7 100644 --- a/embeddedcommon/embeddedout.h +++ b/embeddedcommon/embeddedout.h @@ -15,7 +15,7 @@ extern int8_t gCOLORCHORD_SHIFT_DISTANCE; //distance of shift //TODO fix // print debug info wont work on esp8266 need debug to go to usb there #ifndef DEBUGPRINT -#define DEBUGPRINT 0 +#define DEBUGPRINT 1 #endif //Controls brightness diff --git a/embeddedlinux/embeddedcc.c b/embeddedlinux/embeddedcc.c index b7c992e..488bc60 100644 --- a/embeddedlinux/embeddedcc.c +++ b/embeddedlinux/embeddedcc.c @@ -23,7 +23,7 @@ int framecount = 0; // ratio of gCOLORCHORD_SHIFT_INTERVAL / gCOLORCHORD_SHIFT_DISTANCE when less than 1 has interesting effect uint8_t gCOLORCHORD_SHIFT_INTERVAL = 5; uint8_t gCOLORCHORD_FLIP_ON_PEAK = 0; // non-zero will flip on peak total amp2 -int8_t gCOLORCHORD_SHIFT_DISTANCE = -1; //distance of shift + anticlockwise, - clockwise, 0 no shift +int8_t gCOLORCHORD_SHIFT_DISTANCE = 0; //distance of shift + anticlockwise, - clockwise, 0 no shift void NewFrame() @@ -33,9 +33,9 @@ void NewFrame() framecount++; //printf("NEW FRAME %d ******\n", framecount); HandleFrameInfo(); - //UpdateLinearLEDs(); + UpdateLinearLEDs(); //UpdateAllSameLEDs(); - UpdateRotatingLEDs(); + //UpdateRotatingLEDs(); buffer[0] = 0; buffer[1] = 0; From bf42ba889f7f3f2ae9de49a0facabfa14dde518f Mon Sep 17 00:00:00 2001 From: bbkiwi Date: Tue, 18 Apr 2017 18:02:48 +1200 Subject: [PATCH 08/15] bubble sort, new params for custom commands SORT_NOTES is now controllable via web gui 0 no sort, 1 sort inc by freq, 2 sort dec by amps, 3 by amps2 LIN_WRAPAROUND now controllable via web gui 0 no, else yes ESP8266 now running much slower 32 HZ before 200 Hz not sure why. Code shouldn't be that much slower --- embedded8266/user/custom_commands.c | 19 +++-- embeddedcommon/embeddedout.c | 115 ++++++++++++---------------- embeddedcommon/embeddedout.h | 14 ++-- embeddedlinux/embeddedcc.c | 2 + 4 files changed, 72 insertions(+), 78 deletions(-) diff --git a/embedded8266/user/custom_commands.c b/embedded8266/user/custom_commands.c index ad8f3c8..c284b96 100644 --- a/embedded8266/user/custom_commands.c +++ b/embedded8266/user/custom_commands.c @@ -11,7 +11,7 @@ extern volatile uint8_t sounddata[]; extern volatile uint16_t soundhead; -#define CONFIGURABLES 20 //(plus1) +#define CONFIGURABLES 22 //(plus1) extern uint8_t RootNoteOffset; //Set to define what the root note is. 0 = A. uint8_t gDFTIIR = 6; @@ -32,6 +32,9 @@ uint8_t gCOLORCHORD_OUTPUT_DRIVER = 0; uint8_t gCOLORCHORD_SHIFT_INTERVAL = 0; uint8_t gCOLORCHORD_FLIP_ON_PEAK = 0; int8_t gCOLORCHORD_SHIFT_DISTANCE = 0; //distance of shift +uint8_t gCOLORCHORD_SORT_NOTES = 0; // 0 no sort, 1 inc freq, 2 dec amps, 3 dec amps2 +uint8_t gCOLORCHORD_LIN_WRAPAROUND = 0; // 0 no adjusting, else current led display has minimum deviation to prev + struct SaveLoad @@ -39,17 +42,17 @@ struct SaveLoad uint8_t configs[CONFIGURABLES]; } settings; -uint8_t gConfigDefaults[CONFIGURABLES] = { 0, 6, 1, 2, 3, 4, 7, 4, 2, 80, 64, 12, 15, NUM_LIN_LEDS, 1, 0, 0, 0, 0, 0 }; +uint8_t gConfigDefaults[CONFIGURABLES] = { 0, 6, 1, 2, 3, 4, 7, 4, 2, 80, 64, 12, 15, NUM_LIN_LEDS, 1, 0, 0, 0, 0, 0, 0, 0 }; uint8_t * gConfigurables[CONFIGURABLES] = { &RootNoteOffset, &gDFTIIR, &gFUZZ_IIR_BITS, &gFILTER_BLUR_PASSES, &gSEMIBITSPERBIN, &gMAX_JUMP_DISTANCE, &gMAX_COMBINE_DISTANCE, &gAMP_1_IIR_BITS, &gAMP_2_IIR_BITS, &gMIN_AMP_FOR_NOTE, &gMINIMUM_AMP_FOR_NOTE_TO_DISAPPEAR, &gNOTE_FINAL_AMP, - &gNERF_NOTE_PORP, &gUSE_NUM_LIN_LEDS, &gCOLORCHORD_ACTIVE, &gCOLORCHORD_OUTPUT_DRIVER, &gCOLORCHORD_SHIFT_INTERVAL, &gCOLORCHORD_FLIP_ON_PEAK, &gCOLORCHORD_SHIFT_DISTANCE, 0 }; + &gNERF_NOTE_PORP, &gUSE_NUM_LIN_LEDS, &gCOLORCHORD_ACTIVE, &gCOLORCHORD_OUTPUT_DRIVER, &gCOLORCHORD_SHIFT_INTERVAL, &gCOLORCHORD_FLIP_ON_PEAK, &gCOLORCHORD_SHIFT_DISTANCE, &gCOLORCHORD_SORT_NOTES, &gCOLORCHORD_LIN_WRAPAROUND, 0 }; char * gConfigurableNames[CONFIGURABLES] = { "gROOT_NOTE_OFFSET", "gDFTIIR", "gFUZZ_IIR_BITS", "gFILTER_BLUR_PASSES", "gSEMIBITSPERBIN", "gMAX_JUMP_DISTANCE", "gMAX_COMBINE_DISTANCE", "gAMP_1_IIR_BITS", "gAMP_2_IIR_BITS", "gMIN_AMP_FOR_NOTE", "gMINIMUM_AMP_FOR_NOTE_TO_DISAPPEAR", "gNOTE_FINAL_AMP", - "gNERF_NOTE_PORP", "gUSE_NUM_LIN_LEDS", "gCOLORCHORD_ACTIVE", "gCOLORCHORD_OUTPUT_DRIVER","gCOLORCHORD_SHIFT_INTERVAL", "gCOLORCHORD_FLIP_ON_PEAK", "gCOLORCHORD_SHIFT_DISTANCE", 0 }; + "gNERF_NOTE_PORP", "gUSE_NUM_LIN_LEDS", "gCOLORCHORD_ACTIVE", "gCOLORCHORD_OUTPUT_DRIVER","gCOLORCHORD_SHIFT_INTERVAL", "gCOLORCHORD_FLIP_ON_PEAK", "gCOLORCHORD_SHIFT_DISTANCE", "gCOLORCHORD_SORT_NOTES", "gCOLORCHORD_LIN_WRAPAROUND", 0 }; void ICACHE_FLASH_ATTR CustomStart( ) { @@ -235,10 +238,10 @@ int ICACHE_FLASH_ATTR CustomCommand(char * buffer, int retsize, char *pusrdata, i++; } - buffend += ets_sprintf( buffend, "rBASE_FREQ=%d\trDFREQ=%d\trOCTAVES=%d\trFIXBPERO=%d\trNOTERANGE=%d\trSORT_NOTES=%d\t", - (int)BASE_FREQ, (int)DFREQ, (int)OCTAVES, (int)FIXBPERO, (int)(NOTERANGE),(int)SORT_NOTES ); - buffend += ets_sprintf( buffend, "rMAXNOTES=%d\trNUM_LIN_LEDS=%d\trLIN_WRAPAROUND=%d\trLIN_WRAPAROUND=%d\t", - (int)MAXNOTES, (int)NUM_LIN_LEDS, (int)LIN_WRAPAROUND, (int)LIN_WRAPAROUND ); + buffend += ets_sprintf( buffend, "rBASE_FREQ=%d\trDFREQ=%d\trOCTAVES=%d\trFIXBPERO=%d\trNOTERANGE=%d\t", + (int)BASE_FREQ, (int)DFREQ, (int)OCTAVES, (int)FIXBPERO, (int)(NOTERANGE) ); + buffend += ets_sprintf( buffend, "rMAXNOTES=%d\trNUM_LIN_LEDS=%d\t", + (int)MAXNOTES, (int)NUM_LIN_LEDS ); return buffend-buffer; } diff --git a/embeddedcommon/embeddedout.c b/embeddedcommon/embeddedout.c index 47b89c8..5de428c 100644 --- a/embeddedcommon/embeddedout.c +++ b/embeddedcommon/embeddedout.c @@ -27,6 +27,8 @@ void UpdateLinearLEDs() extern uint8_t gCOLORCHORD_SHIFT_INTERVAL; // controls speed of shifting if 0 no shift extern uint8_t gCOLORCHORD_FLIP_ON_PEAK; //if non-zero gives flipping at peaks of shift direction, 0 no flip extern int8_t gCOLORCHORD_SHIFT_DISTANCE; //distance of shift + extern uint8_t gCOLORCHORD_SORT_NOTES; // 0 no sort, 1 inc freq, 2 dec amps, 3 dec amps2 + extern uint8_t gCOLORCHORD_LIN_WRAPAROUND; // 0 no adjusting, else current led display has minimum deviation to prev */ //Goal: Make splotches of light that are porportional to the strength of notes. @@ -87,75 +89,54 @@ void UpdateLinearLEDs() sorted_map_count++; } - - uint16_t local_peak_amps[MAXNOTES]; - uint16_t local_peak_amps2[MAXNOTES]; - uint16_t hold16; - uint8_t hold8; - uint16_t local_peak_freq[MAXNOTES]; // using 16 bit so can easily choose amps, amps2 or freq as key - uint8_t local_note_jumped_to[MAXNOTES]; -#if SORT_NOTES - // can sort based on freq, amps etc - could mod to switch on a parameter - uint16_t *sort_key; - uint16_t *non_key[2]; - switch(3) { - case 1 : - sort_key = local_peak_amps2; - non_key[0] = local_peak_amps; - non_key[1] = local_peak_freq; - break; - case 2 : - sort_key = local_peak_amps; - non_key[0] = local_peak_amps2; - non_key[1] = local_peak_freq; - break; - case 3 : - sort_key = local_peak_freq; - non_key[0] = local_peak_amps; - non_key[1] = local_peak_amps2; - break; - } -#endif - //Make a copy of all of the variables into local ones so we don't have to keep double-dereferencing. - for( i = 0; i < sorted_map_count; 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] = (uint16_t) note_peak_freqs[sorted_note_map[i]]; - local_note_jumped_to[i] = note_jumped_to[sorted_note_map[i]]; - } - - -#if SORT_NOTES +//#if SORT_NOTES +if ( gCOLORCHORD_SORT_NOTES ) { // note local_note_jumped_to still give original indices of notes (which may not even been inclued // due to being eliminated as too small amplitude - // TODO bubble sort on key and reorder sorted_note_map - for( i = 0; i < sorted_map_count - 1; i++ ) + // bubble sort on key to reorder sorted_note_map + uint8_t hold8; + uint8_t change; + int not_correct_order; + for( i = 0; i < sorted_map_count; i++ ) { - for( j = i + 1; j < sorted_map_count; j++ ) + change = 0; + for( j = 0; j < sorted_map_count -1 - i; j++ ) { - if (*(sort_key+i) < *(sort_key+j)) // dec sort + switch(gCOLORCHORD_SORT_NOTES) { + case 2 : // amps decreasing + not_correct_order = note_peak_amps[sorted_note_map[j]] < note_peak_amps[sorted_note_map[j+1]]; + break; + case 3 : // amps2 decreasing + not_correct_order = note_peak_amps2[sorted_note_map[j]] < note_peak_amps2[sorted_note_map[j+1]]; + break; + default : // freq increasing + not_correct_order = note_peak_freqs[sorted_note_map[j]] > note_peak_freqs[sorted_note_map[j+1]]; + } + if ( not_correct_order ) // dec sort { - hold16 = *(sort_key+j); - *(sort_key+j) = *(sort_key+i); - *(sort_key+i) = hold16; - hold16 = *(non_key[0]+j); - *(non_key[0]+j) = *(non_key[0]+i); - *(non_key[0]+i) = hold16; - hold16 = *(non_key[1]+j); - *(non_key[1]+j) = *(non_key[1]+i); - *(non_key[1]+i) = hold16; + change = 1; hold8 = sorted_note_map[j]; - sorted_note_map[j] = sorted_note_map[i]; - sorted_note_map[i] = hold8; - hold8 = local_note_jumped_to[j]; - local_note_jumped_to[j] = local_note_jumped_to[i]; - local_note_jumped_to[i] = hold8; + sorted_note_map[j] = sorted_note_map[j+1]; + sorted_note_map[j+1] = hold8; } } + if (!change) break; } +} +//#endif + //Make a copy of all of the variables into local ones so we don't have to keep double-dereferencing. + uint16_t local_peak_amps[MAXNOTES]; + uint16_t local_peak_amps2[MAXNOTES]; + uint8_t local_peak_freq[MAXNOTES]; + uint8_t local_note_jumped_to[MAXNOTES]; -#endif + for( i = 0; i < sorted_map_count; 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]]; + local_note_jumped_to[i] = note_jumped_to[sorted_note_map[i]]; + } for( i = 0; i < sorted_map_count; i++ ) @@ -247,7 +228,8 @@ void UpdateLinearLEDs() } //This part totally can't run on an embedded system. -#if LIN_WRAPAROUND +//#if LIN_WRAPAROUND +if (gCOLORCHORD_LIN_WRAPAROUND ) { //printf("NOTERANGE: %d ", NOTERANGE); //192 // bb this code finds an index ledSpin so that shifting the led display will have the minimum deviation // from the previous display. @@ -281,10 +263,11 @@ void UpdateLinearLEDs() ledSpin = midx; //printf("spin: %d, min deviation: %d\n", ledSpin, mqty); - -#else +} else { +//#else ledSpin = 0; -#endif +//#endif +} // if option change direction on max peaks of total amplitude if (gCOLORCHORD_FLIP_ON_PEAK ) { if (diff_a_prev < 0 && diff_a > 0) { @@ -312,11 +295,13 @@ void UpdateLinearLEDs() { if( jshift >= USE_NUM_LIN_LEDS ) jshift = 0; //note: lefFreqOutOld used only if wraparound -#if LIN_WRAPAROUND +//#if LIN_WRAPAROUND +if ( gCOLORCHORD_LIN_WRAPAROUND ) { if( ledSpin >= USE_NUM_LIN_LEDS ) ledSpin = 0; ledFreqOutOld[l] = ledFreqOut[ledSpin]; ledSpin++; -#endif +} +//#endif uint16_t amp = ledAmpOut[jshift]; #if DEBUGPRINT printf("%d:%d/", ledFreqOut[jshift], amp); diff --git a/embeddedcommon/embeddedout.h b/embeddedcommon/embeddedout.h index f6184a7..d6c11c2 100644 --- a/embeddedcommon/embeddedout.h +++ b/embeddedcommon/embeddedout.h @@ -11,11 +11,14 @@ extern int framecount; extern uint8_t gCOLORCHORD_SHIFT_INTERVAL; //how frame interval between shifts. if 0 no shift extern uint8_t gCOLORCHORD_FLIP_ON_PEAK; //if non-zero will cause flipping shift on peaks extern int8_t gCOLORCHORD_SHIFT_DISTANCE; //distance of shift +extern uint8_t gCOLORCHORD_SORT_NOTES; // 0 no sort, 1 inc freq, 2 dec amps, 3 dec amps2 +extern uint8_t gCOLORCHORD_LIN_WRAPAROUND; // 0 no adjusting, else current led display has minimum deviation to prev + //TODO fix // print debug info wont work on esp8266 need debug to go to usb there #ifndef DEBUGPRINT -#define DEBUGPRINT 1 +#define DEBUGPRINT 0 #endif //Controls brightness @@ -36,18 +39,19 @@ extern int8_t gCOLORCHORD_SHIFT_DISTANCE; //distance of shift #define USE_NUM_LIN_LEDS NUM_LIN_LEDS #endif - +/* #ifndef LIN_WRAPAROUND //Whether the output lights wrap around. //(Can't easily run on embedded systems) //(might be ok on ESP8266) #define LIN_WRAPAROUND 0 #endif - +*/ +/* #ifndef SORT_NOTES -#define SORT_NOTES 1 //Whether the notes will be sorted. bb FIXED so hopefull not BUGGY +#define SORT_NOTES 1 //FIXED 0 no sort, 1 sort on inc freq, 2 on dec amps, 3 on dec amps2, default inc freq #endif - +*/ extern uint8_t ledArray[]; extern uint8_t ledOut[]; //[NUM_LIN_LEDS*3] extern uint8_t RootNoteOffset; //Set to define what the root note is. 0 = A. diff --git a/embeddedlinux/embeddedcc.c b/embeddedlinux/embeddedcc.c index 488bc60..f9b41dc 100644 --- a/embeddedlinux/embeddedcc.c +++ b/embeddedlinux/embeddedcc.c @@ -24,6 +24,8 @@ int framecount = 0; uint8_t gCOLORCHORD_SHIFT_INTERVAL = 5; uint8_t gCOLORCHORD_FLIP_ON_PEAK = 0; // non-zero will flip on peak total amp2 int8_t gCOLORCHORD_SHIFT_DISTANCE = 0; //distance of shift + anticlockwise, - clockwise, 0 no shift +uint8_t gCOLORCHORD_SORT_NOTES = 1; // 0 no sort, 1 inc freq, 2 dec amps, 3 dec amps2 +uint8_t gCOLORCHORD_LIN_WRAPAROUND = 0; // 0 no adjusting, else current led display has minimum deviation to prev void NewFrame() From 69676546c60aafa93578e14afd94f0301f4ce933 Mon Sep 17 00:00:00 2001 From: bbkiwi Date: Sun, 23 Apr 2017 17:36:22 +1200 Subject: [PATCH 09/15] Improved spinning LEDs on peaks changes in embeddedout.c to shift computed display around the LED ring by using a modular frame count gFRAMECOUNT_MOD_SHIFT_INTERVAL and putting the shift into global gROTATIONSHIFT added few more comments tidied indents --- embedded8266/ccconfig.h | 4 +- embedded8266/user/user_main.c | 8 +- embeddedcommon/embeddedout.c | 200 +++++++++++++++++----------------- embeddedcommon/embeddedout.h | 5 +- embeddedlinux/ccconfig.h | 3 +- embeddedlinux/embeddedcc.c | 20 ++-- 6 files changed, 123 insertions(+), 117 deletions(-) diff --git a/embedded8266/ccconfig.h b/embedded8266/ccconfig.h index 66411c4..3e29078 100644 --- a/embedded8266/ccconfig.h +++ b/embedded8266/ccconfig.h @@ -55,9 +55,9 @@ extern uint8_t gUSE_NUM_LIN_LEDS; // = NUM_LIN_LEDS #define USE_NUM_LIN_LEDS gUSE_NUM_LIN_LEDS //We are not enabling for the ESP8266 port. -#define LIN_WRAPAROUND 0 +//#define LIN_WRAPAROUND 0 //but trying this now -#define SORT_NOTES 1 +//#define SORT_NOTES 1 diff --git a/embedded8266/user/user_main.c b/embedded8266/user/user_main.c index ce01c57..bf9e62d 100644 --- a/embedded8266/user/user_main.c +++ b/embedded8266/user/user_main.c @@ -28,7 +28,8 @@ #define procTaskPrio 0 #define procTaskQueueLen 1 -int framecount = 0; +int gFRAMECOUNT_MOD_SHIFT_INTERVAL = 0; +int gROTATIONSHIFT = 0; //Amount of spinning of pattern around a LED ring static volatile os_timer_t some_timer; static struct espconn *pUdpServer; @@ -54,8 +55,9 @@ extern uint8_t gCOLORCHORD_OUTPUT_DRIVER; static void NewFrame() { if( !gCOLORCHORD_ACTIVE ) return; - framecount++; - //printf("NEW FRAME %d ******\n", framecount); + gFRAMECOUNT_MOD_SHIFT_INTERVAL++; + if ( gFRAMECOUNT_MOD_SHIFT_INTERVAL >= gCOLORCHORD_SHIFT_INTERVAL ) gFRAMECOUNT_MOD_SHIFT_INTERVAL = 0; + //printf("MOD FRAME %d ******\n", gFRAMECOUNT_MOD_SHIFT_INTERVAL); //uint8_t led_outs[NUM_LIN_LEDS*3]; int i; HandleFrameInfo(); diff --git a/embeddedcommon/embeddedout.c b/embeddedcommon/embeddedout.c index 5de428c..4bb8b76 100644 --- a/embeddedcommon/embeddedout.c +++ b/embeddedcommon/embeddedout.c @@ -31,8 +31,8 @@ void UpdateLinearLEDs() extern uint8_t gCOLORCHORD_LIN_WRAPAROUND; // 0 no adjusting, else current led display has minimum deviation to prev */ - //Goal: Make splotches of light that are porportional to the strength of notes. - //Color them according to value in note_peak_amps2. + //Goal: Make splotches of light that are proportional to the amps strength of notes. + //Color them according to note_peak_freq with brightness related to amps2 uint8_t i; int8_t k; @@ -89,41 +89,39 @@ void UpdateLinearLEDs() sorted_map_count++; } -//#if SORT_NOTES -if ( gCOLORCHORD_SORT_NOTES ) { - // note local_note_jumped_to still give original indices of notes (which may not even been inclued - // due to being eliminated as too small amplitude - // bubble sort on key to reorder sorted_note_map - uint8_t hold8; - uint8_t change; - int not_correct_order; - for( i = 0; i < sorted_map_count; i++ ) - { - change = 0; - for( j = 0; j < sorted_map_count -1 - i; j++ ) + if ( gCOLORCHORD_SORT_NOTES ) { + // note local_note_jumped_to still give original indices of notes (which may not even been inclued + // due to being eliminated as too small amplitude + // bubble sort on key to reorder sorted_note_map + uint8_t hold8; + uint8_t change; + int not_correct_order; + for( i = 0; i < sorted_map_count; i++ ) { - switch(gCOLORCHORD_SORT_NOTES) { - case 2 : // amps decreasing - not_correct_order = note_peak_amps[sorted_note_map[j]] < note_peak_amps[sorted_note_map[j+1]]; - break; - case 3 : // amps2 decreasing - not_correct_order = note_peak_amps2[sorted_note_map[j]] < note_peak_amps2[sorted_note_map[j+1]]; - break; - default : // freq increasing - not_correct_order = note_peak_freqs[sorted_note_map[j]] > note_peak_freqs[sorted_note_map[j+1]]; - } - if ( not_correct_order ) // dec sort + change = 0; + for( j = 0; j < sorted_map_count -1 - i; j++ ) { - change = 1; - hold8 = sorted_note_map[j]; - sorted_note_map[j] = sorted_note_map[j+1]; - sorted_note_map[j+1] = hold8; + switch(gCOLORCHORD_SORT_NOTES) { + case 2 : // amps decreasing + not_correct_order = note_peak_amps[sorted_note_map[j]] < note_peak_amps[sorted_note_map[j+1]]; + break; + case 3 : // amps2 decreasing + not_correct_order = note_peak_amps2[sorted_note_map[j]] < note_peak_amps2[sorted_note_map[j+1]]; + break; + default : // freq increasing + not_correct_order = note_peak_freqs[sorted_note_map[j]] > note_peak_freqs[sorted_note_map[j+1]]; + } + if ( not_correct_order ) // dec sort + { + change = 1; + hold8 = sorted_note_map[j]; + sorted_note_map[j] = sorted_note_map[j+1]; + sorted_note_map[j+1] = hold8; + } } + if (!change) break; } - if (!change) break; } -} -//#endif //Make a copy of all of the variables into local ones so we don't have to keep double-dereferencing. uint16_t local_peak_amps[MAXNOTES]; uint16_t local_peak_amps2[MAXNOTES]; @@ -214,7 +212,10 @@ if ( gCOLORCHORD_SORT_NOTES ) { } } while( addedlast && total_unaccounted_leds ); - //Put the frequencies on a ring. + //Assign the ring LEDs info. + //Each note (above a minimum amplitude) produces an arc of the ring. + //The arc color relates to the notes frequency, the intensity to amps2, + // and the arc length proportionally assgined to amps j = 0; for( i = 0; i < sorted_map_count; i++ ) { @@ -227,81 +228,74 @@ if ( gCOLORCHORD_SORT_NOTES ) { } } - //This part totally can't run on an embedded system. -//#if LIN_WRAPAROUND -if (gCOLORCHORD_LIN_WRAPAROUND ) { - //printf("NOTERANGE: %d ", NOTERANGE); //192 - // bb this code finds an index ledSpin so that shifting the led display will have the minimum deviation - // from the previous display. - // this will cancel out shifting effects below - uint16_t midx = 0; - uint32_t mqty = 100000000; - for( j = 0; j < USE_NUM_LIN_LEDS; j++ ) - { - uint32_t dqty; - uint16_t localj; - - dqty = 0; - localj = j; - for( l = 0; l < USE_NUM_LIN_LEDS; l++ ) + //This part possibly run on an embedded system with small number of LEDs. + if (gCOLORCHORD_LIN_WRAPAROUND ) { + //printf("NOTERANGE: %d ", NOTERANGE); //192 + // bb this code finds an index ledSpin so that shifting the led display will have the minimum deviation + // from the previous display. + // this will cancel out shifting effects below + uint16_t midx = 0; + uint32_t mqty = 100000000; + for( j = 0; j < USE_NUM_LIN_LEDS; j++ ) { - int32_t d = (int32_t)ledFreqOut[localj] - (int32_t)ledFreqOutOld[l]; - if( d < 0 ) d *= -1; - if( d > (NOTERANGE>>1) ) { d = NOTERANGE - d + 1; } - dqty += ( d * d ); - - localj++; - if( localj == USE_NUM_LIN_LEDS ) localj = 0; - } - - if( dqty < mqty ) - { - mqty = dqty; - midx = j; + uint32_t dqty; + uint16_t localj; + dqty = 0; + localj = j; + for( l = 0; l < USE_NUM_LIN_LEDS; l++ ) + { + int32_t d = (int32_t)ledFreqOut[localj] - (int32_t)ledFreqOutOld[l]; + if( d < 0 ) d *= -1; + if( d > (NOTERANGE>>1) ) { d = NOTERANGE - d + 1; } + dqty += ( d * d ); + localj++; + if( localj == USE_NUM_LIN_LEDS ) localj = 0; + } + if( dqty < mqty ) + { + mqty = dqty; + midx = j; + } } + ledSpin = midx; + //printf("spin: %d, min deviation: %d\n", ledSpin, mqty); + } else { + ledSpin = 0; } - - ledSpin = midx; - //printf("spin: %d, min deviation: %d\n", ledSpin, mqty); -} else { -//#else - ledSpin = 0; -//#endif -} // if option change direction on max peaks of total amplitude if (gCOLORCHORD_FLIP_ON_PEAK ) { if (diff_a_prev < 0 && diff_a > 0) { rot_dir *= -1; - shift_dist = rot_dir * gCOLORCHORD_SHIFT_DISTANCE; } - } else shift_dist = gCOLORCHORD_SHIFT_DISTANCE; + } else rot_dir = 1; // want possible extra spin to relate to changes peak intensity // now every gCOLORCHORD_SHIFT_INTERVAL th frame - if (gCOLORCHORD_SHIFT_INTERVAL != 0) { - //NOTE need - in front of rot_dir to make rotation direction consistent with UpdateRotationLEDs - jshift = (ledSpin - shift_dist * framecount/gCOLORCHORD_SHIFT_INTERVAL ) % USE_NUM_LIN_LEDS; // neg % pos is neg so fix with - if ( jshift < 0 ) jshift += USE_NUM_LIN_LEDS; - //printf("tnap tna %d %d dap da %d %d rot_dir %d, j shift %d\n",total_note_a_prev, total_note_a, diff_a_prev, diff_a, rot_dir, j); + if (gCOLORCHORD_SHIFT_INTERVAL != 0 ) { + if ( gFRAMECOUNT_MOD_SHIFT_INTERVAL == 0 ) { + gROTATIONSHIFT -= rot_dir * gCOLORCHORD_SHIFT_DISTANCE; // -= to be consistent with UpdateRotationLEDs + //printf("tnap tna %d %d dap da %d %d rot_dir %d, j shift %d\n",total_note_a_prev, total_note_a, diff_a_prev, diff_a, rot_dir, j); + } } else { - jshift = ledSpin; + gROTATIONSHIFT = 0; // reset } + jshift = ( ledSpin + gROTATIONSHIFT ) % USE_NUM_LIN_LEDS; // neg % pos is neg so fix + if ( jshift < 0 ) jshift += USE_NUM_LIN_LEDS; + #if DEBUGPRINT - printf("rot_dir %d, shift_dist %d, jshift %d\n", rot_dir, shift_dist, jshift); + printf("rot_dir %d, gROTATIONSHIFT %d, jshift %d, gFRAMECOUNT_MOD_SHIFT_INTERVAL %d\n", rot_dir, gROTATIONSHIFT, jshift, gFRAMECOUNT_MOD_SHIFT_INTERVAL); printf("leds: "); #endif for( l = 0; l < USE_NUM_LIN_LEDS; l++, jshift++ ) { if( jshift >= USE_NUM_LIN_LEDS ) jshift = 0; //note: lefFreqOutOld used only if wraparound -//#if LIN_WRAPAROUND -if ( gCOLORCHORD_LIN_WRAPAROUND ) { - if( ledSpin >= USE_NUM_LIN_LEDS ) ledSpin = 0; - ledFreqOutOld[l] = ledFreqOut[ledSpin]; - ledSpin++; -} -//#endif + if ( gCOLORCHORD_LIN_WRAPAROUND ) { + if( ledSpin >= USE_NUM_LIN_LEDS ) ledSpin = 0; + ledFreqOutOld[l] = ledFreqOut[ledSpin]; + ledSpin++; + } uint16_t amp = ledAmpOut[jshift]; #if DEBUGPRINT printf("%d:%d/", ledFreqOut[jshift], amp); @@ -365,6 +359,9 @@ void UpdateRotatingLEDs() //uint32_t total_note_a2 = 0; int diff_a = 0; int32_t led_arc_len; + char stret[256]; + char *stt = &stret[0]; + for( i = 0; i < MAXNOTES; i++ ) { @@ -384,38 +381,41 @@ void UpdateRotatingLEDs() diff_a = total_note_a_prev - total_note_a; // can set color intensity using amp2 - amp = (((uint32_t)(amp2))*NOTE_FINAL_AMP)>>10; + amp = (((uint32_t)(amp2))*NOTE_FINAL_AMP)>>10; // for PC 14; if( amp > 255 ) amp = 255; //uint32_t color = ECCtoHEX( (freq+RootNoteOffset)%NOTERANGE, 255, amp ); uint32_t color = ECCtoHEX( (freq+RootNoteOffset)%NOTERANGE, 255, 255 ); // can have led_arc_len a fixed size or proportional to amp2 //led_arc_len = 5; - led_arc_len = (amp * USE_NUM_LIN_LEDS) >> 8; - //printf("test %d %d \n", amp2, led_arc_len); + led_arc_len = (amp * (USE_NUM_LIN_LEDS + 1) ) >> 8; + //printf("amp2 = %d, amp = %d, led_arc_len = %d, NOTE_FINAL_AMP = %d\n", amp2, amp, led_arc_len, NOTE_FINAL_AMP ); + //stt += ets_sprintf( stt, "amp2 = %d, amp = %d, led_arc_len = %d, NOTE_FINAL_AMP = %d\n", amp2, amp, led_arc_len, NOTE_FINAL_AMP ); + //uart0_sendStr(stret); // want possible extra spin to relate to changes peak intensity if (gCOLORCHORD_FLIP_ON_PEAK ) { if (diff_a_prev < 0 && diff_a > 0) { rot_dir *= -1; - shift_dist = rot_dir * gCOLORCHORD_SHIFT_DISTANCE; } - } else shift_dist = gCOLORCHORD_SHIFT_DISTANCE; + } else rot_dir = 1; // now every gCOLORCHORD_SHIFT_INTERVAL th frame - if (gCOLORCHORD_SHIFT_INTERVAL != 0) { - // On each gCOLORCHORD_SHIFT_INTERVAL/rot_dir-th frame make rotational shift - jshift = (shift_dist * framecount/gCOLORCHORD_SHIFT_INTERVAL - led_arc_len/2) % USE_NUM_LIN_LEDS; // neg % pos is neg so fix - if( jshift < 0 ) jshift += USE_NUM_LIN_LEDS; - //printf("tnap tna %d %d dap da %d %d rot_dir %d, jshift %d \n",total_note_a_prev, total_note_a, diff_a_prev, diff_a, rot_dir, jshift); + if (gCOLORCHORD_SHIFT_INTERVAL != 0 ) { + if ( gFRAMECOUNT_MOD_SHIFT_INTERVAL == 0 ) { + gROTATIONSHIFT += rot_dir * gCOLORCHORD_SHIFT_DISTANCE; + //printf("tnap tna %d %d dap da %d %d rot_dir %d, j shift %d\n",total_note_a_prev, total_note_a, diff_a_prev, diff_a, rot_dir, j); + } } else { - jshift = (0 - led_arc_len/2) % USE_NUM_LIN_LEDS; // neg % pos is neg so fix - if( jshift < 0 ) jshift += USE_NUM_LIN_LEDS; + gROTATIONSHIFT = 0; // reset } + jshift = ( gROTATIONSHIFT - led_arc_len/2 ) % USE_NUM_LIN_LEDS; // neg % pos is neg so fix + if ( jshift < 0 ) jshift += USE_NUM_LIN_LEDS; + for( i = 0; i < led_arc_len; i++, jshift++ ) { - // even if led_arc_len exceeds USE+NUM_LIN_LEDS using jshift will prevent over running ledOut + // even if led_arc_len exceeds USE_NUM_LIN_LEDS using jshift will prevent over running ledOut if( jshift >= USE_NUM_LIN_LEDS ) jshift = 0; ledOut[jshift*3+0] = ( color >> 0 ) & 0xff; ledOut[jshift*3+1] = ( color >> 8 ) & 0xff; diff --git a/embeddedcommon/embeddedout.h b/embeddedcommon/embeddedout.h index d6c11c2..647cd4a 100644 --- a/embeddedcommon/embeddedout.h +++ b/embeddedcommon/embeddedout.h @@ -7,7 +7,8 @@ #include "embeddednf.h" -extern int framecount; +extern int gFRAMECOUNT_MOD_SHIFT_INTERVAL; +extern int gROTATIONSHIFT; //Amount of spinning of pattern around a LED ring extern uint8_t gCOLORCHORD_SHIFT_INTERVAL; //how frame interval between shifts. if 0 no shift extern uint8_t gCOLORCHORD_FLIP_ON_PEAK; //if non-zero will cause flipping shift on peaks extern int8_t gCOLORCHORD_SHIFT_DISTANCE; //distance of shift @@ -23,7 +24,7 @@ extern uint8_t gCOLORCHORD_LIN_WRAPAROUND; // 0 no adjusting, else current led d //Controls brightness #ifndef NOTE_FINAL_AMP -#define NOTE_FINAL_AMP 12 //Number from 0...255 +#define NOTE_FINAL_AMP 150 //Number from 0...255 #endif //Controls, basically, the minimum size of the splotches. diff --git a/embeddedlinux/ccconfig.h b/embeddedlinux/ccconfig.h index 234b8a4..086e108 100644 --- a/embeddedlinux/ccconfig.h +++ b/embeddedlinux/ccconfig.h @@ -3,12 +3,13 @@ #define CCEMBEDDED +#define DEBUGPRINT 0 #define RING #define LEDS_PER_ROW 16 #define NUM_LIN_LEDS 16 #define USE_NUM_LIN_LEDS NUM_LIN_LEDS #define DFREQ 16000 - +#define NOTE_FINAL_AMP 15 #endif diff --git a/embeddedlinux/embeddedcc.c b/embeddedlinux/embeddedcc.c index f9b41dc..6f1a69c 100644 --- a/embeddedlinux/embeddedcc.c +++ b/embeddedlinux/embeddedcc.c @@ -18,26 +18,28 @@ int sock; #define expected_lights NUM_LIN_LEDS int toskip = 1; -int framecount = 0; +int gFRAMECOUNT_MOD_SHIFT_INTERVAL = 0; +int gROTATIONSHIFT = 0; //Amount of spinning of pattern around a LED ring + //TODO explore relation of NUM_LIN_LEDS and following two params // ratio of gCOLORCHORD_SHIFT_INTERVAL / gCOLORCHORD_SHIFT_DISTANCE when less than 1 has interesting effect -uint8_t gCOLORCHORD_SHIFT_INTERVAL = 5; -uint8_t gCOLORCHORD_FLIP_ON_PEAK = 0; // non-zero will flip on peak total amp2 -int8_t gCOLORCHORD_SHIFT_DISTANCE = 0; //distance of shift + anticlockwise, - clockwise, 0 no shift +uint8_t gCOLORCHORD_SHIFT_INTERVAL = 5; // shift after this many frames, 0 no shifts +uint8_t gCOLORCHORD_FLIP_ON_PEAK = 1; // non-zero will flip on peak total amp2 +int8_t gCOLORCHORD_SHIFT_DISTANCE = 1; //distance of shift + anticlockwise, - clockwise, 0 no shift uint8_t gCOLORCHORD_SORT_NOTES = 1; // 0 no sort, 1 inc freq, 2 dec amps, 3 dec amps2 uint8_t gCOLORCHORD_LIN_WRAPAROUND = 0; // 0 no adjusting, else current led display has minimum deviation to prev - void NewFrame() { int i; char buffer[3000]; - framecount++; - //printf("NEW FRAME %d ******\n", framecount); + gFRAMECOUNT_MOD_SHIFT_INTERVAL++; + if ( gFRAMECOUNT_MOD_SHIFT_INTERVAL >= gCOLORCHORD_SHIFT_INTERVAL ) gFRAMECOUNT_MOD_SHIFT_INTERVAL = 0; + //printf("MOD FRAME %d ******\n", gFRAMECOUNT_MOD_SHIFT_INTERVAL); HandleFrameInfo(); - UpdateLinearLEDs(); + //UpdateLinearLEDs(); //UpdateAllSameLEDs(); - //UpdateRotatingLEDs(); + UpdateRotatingLEDs(); buffer[0] = 0; buffer[1] = 0; From 829a456bd177ebbc817b47be29507352e1b13929 Mon Sep 17 00:00:00 2001 From: bbkiwi Date: Mon, 24 Apr 2017 15:13:12 +1200 Subject: [PATCH 10/15] Using both NUM_LIN_LEDS and USE_NUM_LIN_LEDS UpdateLinearLEDs() modified to make a linear pattern on USE_NUM_LIN_LEDS leds then place this pattern as an arc into a ring with NUM_LIN_LEDS leds the placement can be shifted so that it rotates A few more comments. Refactor some names to reflect their purpose better TODO UpdateRotatingLEDs() is almost a special case of UpdateLinearLEDs with a few more improvements they can be combined --- embedded8266/ccconfig.h | 2 +- embedded8266/user/user_main.c | 2 +- embeddedcommon/embeddedout.c | 79 +++++++++++++++++++++-------------- embeddedlinux/ccconfig.h | 2 +- embeddedlinux/embeddedcc.c | 6 +-- 5 files changed, 53 insertions(+), 38 deletions(-) diff --git a/embedded8266/ccconfig.h b/embedded8266/ccconfig.h index 3e29078..a1b5136 100644 --- a/embedded8266/ccconfig.h +++ b/embedded8266/ccconfig.h @@ -6,7 +6,7 @@ #define HPABUFFSIZE 512 #define CCEMBEDDED -#define NUM_LIN_LEDS 255 +#define NUM_LIN_LEDS 16 #define DFREQ 16000 diff --git a/embedded8266/user/user_main.c b/embedded8266/user/user_main.c index bf9e62d..f1cebec 100644 --- a/embedded8266/user/user_main.c +++ b/embedded8266/user/user_main.c @@ -76,7 +76,7 @@ static void NewFrame() }; //SendSPI2812( ledOut, NUM_LIN_LEDS ); - ws2812_push( ledOut, USE_NUM_LIN_LEDS * 3 ); + ws2812_push( ledOut, NUM_LIN_LEDS * 3 ); } os_event_t procTaskQueue[procTaskQueueLen]; diff --git a/embeddedcommon/embeddedout.c b/embeddedcommon/embeddedout.c index 4bb8b76..5696a08 100644 --- a/embeddedcommon/embeddedout.c +++ b/embeddedcommon/embeddedout.c @@ -6,7 +6,7 @@ //uint8_t ledArray[NUM_LIN_LEDS]; //Points to which notes correspond to these LEDs uint8_t ledOut[NUM_LIN_LEDS*3]; -uint16_t ledSpin; +uint16_t minimizingShift; uint16_t ledAmpOut[NUM_LIN_LEDS]; uint8_t ledFreqOut[NUM_LIN_LEDS]; uint8_t ledFreqOutOld[NUM_LIN_LEDS]; @@ -31,14 +31,16 @@ void UpdateLinearLEDs() extern uint8_t gCOLORCHORD_LIN_WRAPAROUND; // 0 no adjusting, else current led display has minimum deviation to prev */ - //Goal: Make splotches of light that are proportional to the amps strength of notes. + //Notes are found above a minimum amplitude + //Goal: On a linear array of size USE_NUM_LIN_LEDS Make splotches of light that are proportional to the amps strength of theses notes. //Color them according to note_peak_freq with brightness related to amps2 + //Put this linear array on a ring with NUM_LIN_LEDS and optionally rotate it with optionally direction changes on peak amps2 uint8_t i; int8_t k; uint16_t j, l; uint32_t total_size_all_notes = 0; - int32_t porpamps[MAXNOTES]; //LEDs for each corresponding note. + int32_t porpamps[MAXNOTES]; //number of 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; @@ -92,7 +94,7 @@ void UpdateLinearLEDs() if ( gCOLORCHORD_SORT_NOTES ) { // note local_note_jumped_to still give original indices of notes (which may not even been inclued // due to being eliminated as too small amplitude - // bubble sort on key to reorder sorted_note_map + // bubble sort on a specified key to reorder sorted_note_map uint8_t hold8; uint8_t change; int not_correct_order; @@ -111,7 +113,7 @@ void UpdateLinearLEDs() default : // freq increasing not_correct_order = note_peak_freqs[sorted_note_map[j]] > note_peak_freqs[sorted_note_map[j+1]]; } - if ( not_correct_order ) // dec sort + if ( not_correct_order ) { change = 1; hold8 = sorted_note_map[j]; @@ -136,7 +138,6 @@ void UpdateLinearLEDs() local_note_jumped_to[i] = note_jumped_to[sorted_note_map[i]]; } - for( i = 0; i < sorted_map_count; i++ ) { uint16_t ist = local_peak_amps[i]; @@ -146,7 +147,7 @@ void UpdateLinearLEDs() if( total_size_all_notes == 0 ) { - for( j = 0; j < USE_NUM_LIN_LEDS * 3; j++ ) + for( j = 0; j < NUM_LIN_LEDS * 3; j++ ) { ledOut[j] = 0; } @@ -212,10 +213,10 @@ void UpdateLinearLEDs() } } while( addedlast && total_unaccounted_leds ); - //Assign the ring LEDs info. - //Each note (above a minimum amplitude) produces an arc of the ring. - //The arc color relates to the notes frequency, the intensity to amps2, - // and the arc length proportionally assgined to amps + //Assign the linear LEDs info for 0, 1, ..., USE_NUM_LIN_LEDS + //Each note (above a minimum amplitude) produces an interval + //Its color relates to the notes frequency, the intensity to amps2, + // and the length proportional to amps j = 0; for( i = 0; i < sorted_map_count; i++ ) { @@ -231,9 +232,8 @@ void UpdateLinearLEDs() //This part possibly run on an embedded system with small number of LEDs. if (gCOLORCHORD_LIN_WRAPAROUND ) { //printf("NOTERANGE: %d ", NOTERANGE); //192 - // bb this code finds an index ledSpin so that shifting the led display will have the minimum deviation - // from the previous display. - // this will cancel out shifting effects below + // finds an index minimizingShift so that shifting the used leds will have the minimum deviation + // from the previous linear pattern uint16_t midx = 0; uint32_t mqty = 100000000; for( j = 0; j < USE_NUM_LIN_LEDS; j++ ) @@ -257,10 +257,10 @@ void UpdateLinearLEDs() midx = j; } } - ledSpin = midx; - //printf("spin: %d, min deviation: %d\n", ledSpin, mqty); + minimizingShift = midx; + //printf("spin: %d, min deviation: %d\n", minimizingShift, mqty); } else { - ledSpin = 0; + minimizingShift = 0; } // if option change direction on max peaks of total amplitude if (gCOLORCHORD_FLIP_ON_PEAK ) { @@ -273,39 +273,54 @@ void UpdateLinearLEDs() // now every gCOLORCHORD_SHIFT_INTERVAL th frame if (gCOLORCHORD_SHIFT_INTERVAL != 0 ) { if ( gFRAMECOUNT_MOD_SHIFT_INTERVAL == 0 ) { - gROTATIONSHIFT -= rot_dir * gCOLORCHORD_SHIFT_DISTANCE; // -= to be consistent with UpdateRotationLEDs + gROTATIONSHIFT += rot_dir * gCOLORCHORD_SHIFT_DISTANCE; //printf("tnap tna %d %d dap da %d %d rot_dir %d, j shift %d\n",total_note_a_prev, total_note_a, diff_a_prev, diff_a, rot_dir, j); } } else { gROTATIONSHIFT = 0; // reset } - jshift = ( ledSpin + gROTATIONSHIFT ) % USE_NUM_LIN_LEDS; // neg % pos is neg so fix - if ( jshift < 0 ) jshift += USE_NUM_LIN_LEDS; + // compute shift to start rotating pattern around all the LEDs + jshift = ( gROTATIONSHIFT ) % NUM_LIN_LEDS; // neg % pos is neg so fix + if ( jshift < 0 ) jshift += NUM_LIN_LEDS; #if DEBUGPRINT printf("rot_dir %d, gROTATIONSHIFT %d, jshift %d, gFRAMECOUNT_MOD_SHIFT_INTERVAL %d\n", rot_dir, gROTATIONSHIFT, jshift, gFRAMECOUNT_MOD_SHIFT_INTERVAL); printf("leds: "); #endif - for( l = 0; l < USE_NUM_LIN_LEDS; l++, jshift++ ) + // put linear pattern of USE_NUM_LIN_LEDS on ring NUM_LIN_LEDs + for( l = 0; l < USE_NUM_LIN_LEDS; l++, jshift++, minimizingShift++ ) { - if( jshift >= USE_NUM_LIN_LEDS ) jshift = 0; -//note: lefFreqOutOld used only if wraparound + if( jshift >= NUM_LIN_LEDS ) jshift = 0; + //lefFreqOutOld and adjusting minimizingShift needed only if wraparound if ( gCOLORCHORD_LIN_WRAPAROUND ) { - if( ledSpin >= USE_NUM_LIN_LEDS ) ledSpin = 0; - ledFreqOutOld[l] = ledFreqOut[ledSpin]; - ledSpin++; + if( minimizingShift >= USE_NUM_LIN_LEDS ) minimizingShift = 0; + ledFreqOutOld[l] = ledFreqOut[minimizingShift]; } - uint16_t amp = ledAmpOut[jshift]; + uint16_t amp = ledAmpOut[minimizingShift]; #if DEBUGPRINT - printf("%d:%d/", ledFreqOut[jshift], amp); + printf("%d:%d/", ledFreqOut[minimizingShift], amp); #endif if( amp > 255 ) amp = 255; - uint32_t color = ECCtoHEX( (ledFreqOut[jshift]+RootNoteOffset)%NOTERANGE, 255, amp ); - ledOut[l*3+0] = ( color >> 0 ) & 0xff; - ledOut[l*3+1] = ( color >> 8 ) & 0xff; - ledOut[l*3+2] = ( color >>16 ) & 0xff; + uint32_t color = ECCtoHEX( (ledFreqOut[minimizingShift]+RootNoteOffset)%NOTERANGE, 255, amp ); + ledOut[jshift*3+0] = ( color >> 0 ) & 0xff; + ledOut[jshift*3+1] = ( color >> 8 ) & 0xff; + ledOut[jshift*3+2] = ( color >>16 ) & 0xff; } + // blackout remaining LEDs on ring +//TODO this could be sped up in case NUM_LIN_LEDS is much greater than USE_NUM_LIN_LEDS +// by blacking out only previous gCOLORCHORD_SHIFT_DISTANCE LEDs that were not overwritten +// but if direction changing might be tricky + for( l = USE_NUM_LIN_LEDS; l < NUM_LIN_LEDS; l++, jshift++ ) + { + if( jshift >= NUM_LIN_LEDS ) jshift = 0; + ledOut[jshift*3+0] = 0x0; + ledOut[jshift*3+1] = 0x0; + ledOut[jshift*3+2] = 0x0; + } + + + #if DEBUGPRINT printf( "\n" ); printf("bytes: "); diff --git a/embeddedlinux/ccconfig.h b/embeddedlinux/ccconfig.h index 086e108..6a27b2f 100644 --- a/embeddedlinux/ccconfig.h +++ b/embeddedlinux/ccconfig.h @@ -7,7 +7,7 @@ #define RING #define LEDS_PER_ROW 16 #define NUM_LIN_LEDS 16 -#define USE_NUM_LIN_LEDS NUM_LIN_LEDS +#define USE_NUM_LIN_LEDS 8 #define DFREQ 16000 #define NOTE_FINAL_AMP 15 diff --git a/embeddedlinux/embeddedcc.c b/embeddedlinux/embeddedcc.c index 6f1a69c..75c1246 100644 --- a/embeddedlinux/embeddedcc.c +++ b/embeddedlinux/embeddedcc.c @@ -26,7 +26,7 @@ int gROTATIONSHIFT = 0; //Amount of spinning of pattern around a LED ring uint8_t gCOLORCHORD_SHIFT_INTERVAL = 5; // shift after this many frames, 0 no shifts uint8_t gCOLORCHORD_FLIP_ON_PEAK = 1; // non-zero will flip on peak total amp2 int8_t gCOLORCHORD_SHIFT_DISTANCE = 1; //distance of shift + anticlockwise, - clockwise, 0 no shift -uint8_t gCOLORCHORD_SORT_NOTES = 1; // 0 no sort, 1 inc freq, 2 dec amps, 3 dec amps2 +uint8_t gCOLORCHORD_SORT_NOTES = 2; // 0 no sort, 1 inc freq, 2 dec amps, 3 dec amps2 uint8_t gCOLORCHORD_LIN_WRAPAROUND = 0; // 0 no adjusting, else current led display has minimum deviation to prev void NewFrame() @@ -37,9 +37,9 @@ void NewFrame() if ( gFRAMECOUNT_MOD_SHIFT_INTERVAL >= gCOLORCHORD_SHIFT_INTERVAL ) gFRAMECOUNT_MOD_SHIFT_INTERVAL = 0; //printf("MOD FRAME %d ******\n", gFRAMECOUNT_MOD_SHIFT_INTERVAL); HandleFrameInfo(); - //UpdateLinearLEDs(); + UpdateLinearLEDs(); //UpdateAllSameLEDs(); - UpdateRotatingLEDs(); + //UpdateRotatingLEDs(); buffer[0] = 0; buffer[1] = 0; From c494b619176488b063f0e1f67e738252a860c3cd Mon Sep 17 00:00:00 2001 From: bbkiwi Date: Tue, 25 Apr 2017 15:11:28 +1200 Subject: [PATCH 11/15] UpdateAllSameLEDs() and UpdateRotatingLEDs() fixed to use NUM_LIN_LEDs --- embeddedcommon/embeddedout.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/embeddedcommon/embeddedout.c b/embeddedcommon/embeddedout.c index 5696a08..284ee7f 100644 --- a/embeddedcommon/embeddedout.c +++ b/embeddedcommon/embeddedout.c @@ -353,7 +353,7 @@ void UpdateAllSameLEDs() if( amp > 255 ) amp = 255; uint32_t color = ECCtoHEX( (freq+RootNoteOffset)%NOTERANGE, 255, amp ); - for( i = 0; i < USE_NUM_LIN_LEDS; i++ ) + for( i = 0; i < NUM_LIN_LEDS; i++ ) { ledOut[i*3+0] = ( color >> 0 ) & 0xff; ledOut[i*3+1] = ( color >> 8 ) & 0xff; @@ -403,7 +403,7 @@ void UpdateRotatingLEDs() // can have led_arc_len a fixed size or proportional to amp2 //led_arc_len = 5; - led_arc_len = (amp * (USE_NUM_LIN_LEDS + 1) ) >> 8; + led_arc_len = (amp * (NUM_LIN_LEDS + 1) ) >> 8; //printf("amp2 = %d, amp = %d, led_arc_len = %d, NOTE_FINAL_AMP = %d\n", amp2, amp, led_arc_len, NOTE_FINAL_AMP ); //stt += ets_sprintf( stt, "amp2 = %d, amp = %d, led_arc_len = %d, NOTE_FINAL_AMP = %d\n", amp2, amp, led_arc_len, NOTE_FINAL_AMP ); //uart0_sendStr(stret); @@ -425,21 +425,21 @@ void UpdateRotatingLEDs() gROTATIONSHIFT = 0; // reset } - jshift = ( gROTATIONSHIFT - led_arc_len/2 ) % USE_NUM_LIN_LEDS; // neg % pos is neg so fix - if ( jshift < 0 ) jshift += USE_NUM_LIN_LEDS; + jshift = ( gROTATIONSHIFT - led_arc_len/2 ) % NUM_LIN_LEDS; // neg % pos is neg so fix + if ( jshift < 0 ) jshift += NUM_LIN_LEDS; for( i = 0; i < led_arc_len; i++, jshift++ ) { - // even if led_arc_len exceeds USE_NUM_LIN_LEDS using jshift will prevent over running ledOut - if( jshift >= USE_NUM_LIN_LEDS ) jshift = 0; + // even if led_arc_len exceeds NUM_LIN_LEDS using jshift will prevent over running ledOut + if( jshift >= NUM_LIN_LEDS ) jshift = 0; ledOut[jshift*3+0] = ( color >> 0 ) & 0xff; ledOut[jshift*3+1] = ( color >> 8 ) & 0xff; ledOut[jshift*3+2] = ( color >>16 ) & 0xff; } - for( i = led_arc_len; i < USE_NUM_LIN_LEDS; i++, jshift++ ) + for( i = led_arc_len; i < NUM_LIN_LEDS; i++, jshift++ ) { - if( jshift >= USE_NUM_LIN_LEDS ) jshift = 0; + if( jshift >= NUM_LIN_LEDS ) jshift = 0; ledOut[jshift*3+0] = 0x0; ledOut[jshift*3+1] = 0x0; ledOut[jshift*3+2] = 0x0; From 4b0c5a7b17e0fdde2cf12348ad437f7e85185dad Mon Sep 17 00:00:00 2001 From: bbkiwi Date: Tue, 25 Apr 2017 20:19:20 +1200 Subject: [PATCH 12/15] UpdateRotatingLEDs()now takes NOTE_FINAL_AMP (instead of 255) for brightness --- embeddedcommon/embeddedout.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/embeddedcommon/embeddedout.c b/embeddedcommon/embeddedout.c index 284ee7f..234ca19 100644 --- a/embeddedcommon/embeddedout.c +++ b/embeddedcommon/embeddedout.c @@ -399,7 +399,7 @@ void UpdateRotatingLEDs() amp = (((uint32_t)(amp2))*NOTE_FINAL_AMP)>>10; // for PC 14; if( amp > 255 ) amp = 255; //uint32_t color = ECCtoHEX( (freq+RootNoteOffset)%NOTERANGE, 255, amp ); - uint32_t color = ECCtoHEX( (freq+RootNoteOffset)%NOTERANGE, 255, 255 ); + uint32_t color = ECCtoHEX( (freq+RootNoteOffset)%NOTERANGE, 255, NOTE_FINAL_AMP ); // can have led_arc_len a fixed size or proportional to amp2 //led_arc_len = 5; From 39bfd1c59c59a1379260fe11737dd459e6e7fd34 Mon Sep 17 00:00:00 2001 From: bbkiwi Date: Tue, 25 Apr 2017 20:35:37 +1200 Subject: [PATCH 13/15] Whoops! Undoing previous commit --- embeddedcommon/embeddedout.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/embeddedcommon/embeddedout.c b/embeddedcommon/embeddedout.c index 234ca19..284ee7f 100644 --- a/embeddedcommon/embeddedout.c +++ b/embeddedcommon/embeddedout.c @@ -399,7 +399,7 @@ void UpdateRotatingLEDs() amp = (((uint32_t)(amp2))*NOTE_FINAL_AMP)>>10; // for PC 14; if( amp > 255 ) amp = 255; //uint32_t color = ECCtoHEX( (freq+RootNoteOffset)%NOTERANGE, 255, amp ); - uint32_t color = ECCtoHEX( (freq+RootNoteOffset)%NOTERANGE, 255, NOTE_FINAL_AMP ); + uint32_t color = ECCtoHEX( (freq+RootNoteOffset)%NOTERANGE, 255, 255 ); // can have led_arc_len a fixed size or proportional to amp2 //led_arc_len = 5; From a35ec015eddf11ae1ad1a8b547db5f2e44f46b10 Mon Sep 17 00:00:00 2001 From: bbkiwi Date: Sun, 14 May 2017 20:04:52 +1200 Subject: [PATCH 14/15] Modified Oscope Slider and note display Since no sound should give 127 on ADC slider fixed to expand display around that value rather than just multiply added extra column to note display so have note number expanded factor for showing amp and amp2 --- embedded8266/web/page/main.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/embedded8266/web/page/main.js b/embedded8266/web/page/main.js index 9c59ab6..594a8ce 100644 --- a/embedded8266/web/page/main.js +++ b/embedded8266/web/page/main.js @@ -124,12 +124,12 @@ function GotOScope(req,data) { var x2 = (i+1) * canvas.clientWidth / samps; var samp = parseInt( data.substr(i*2+2,2),16 ); - var y2 = ( 1.-mult*samp / 255 ) * canvas.clientHeight; + var y2 = ( 0.5 - mult* (samp / 255 - 0.33) ) * canvas.clientHeight; if( i == 0 ) { var x1 = i * canvas.clientWidth / samps; - var y1 = ( 1.-mult*lastsamp / 255 ) * canvas.clientHeight; + var y1 = ( 0.5 - mult* (lastsamp / 255 - 0.33) ) * canvas.clientHeight; ctx.moveTo( x1, y1 ); } @@ -349,7 +349,7 @@ function GotNotes(req,data) var elems = Number(secs[1] ); - ctx.canvas.width = 400; + ctx.canvas.width = 600; ctx.canvas.height = elems*25; @@ -367,24 +367,26 @@ function GotNotes(req,data) var amped2 = parseInt( data.substr(i*12+6,4),16 ); var jump = parseInt( data.substr(i*12+10,2),16 ); + ctx.fillStyle = "#ffffff"; + ctx.fillText( i+1, 0, i*25 + 20 ); + if( peak == 255 ) { ctx.fillStyle = "#ffffff"; - ctx.fillText( jump, 10, i*25 + 20 ); + ctx.fillText( jump, 60, i*25 + 20 ); continue; } ctx.fillStyle = CCColorDetail( peak ); ctx.lineWidth = 0; - ctx.fillRect( 0, i*25, 100,25); - ctx.fillRect( 101, i*25, amped/200,25); - ctx.fillRect( 229, i*25, amped2/200,25); + ctx.fillRect( 100, i*25, 50,25); + ctx.fillRect( 201, i*25, amped/20,25); + ctx.fillRect( 329, i*25, amped2/20,25); - ctx.fillStyle = "#000000"; - ctx.fillText( peak, 10, i*25 + 20 ); ctx.fillStyle = "#ffffff"; - ctx.fillText( amped, 121, i*25 + 20 ); - ctx.fillText( amped2, 240, i*25 + 20 ); + ctx.fillText( peak, 110, i*25 + 20 ); + ctx.fillText( amped, 221, i*25 + 20 ); + ctx.fillText( amped2, 340, i*25 + 20 ); } var samp = parseInt( data.substr(i*2,2),16 ); From ab40cee7a08f3109ce80a7b878b884acc11c6f3d Mon Sep 17 00:00:00 2001 From: bbkiwi Date: Sat, 4 Aug 2018 14:27:58 +1200 Subject: [PATCH 15/15] branch dev submodule esp82xx from bbkiwi --- .gitmodules | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index ed48a58..919f4a3 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,4 @@ [submodule "embedded8266/esp82xx"] path = embedded8266/esp82xx - url = https://github.com/cnlohr/esp82xx.git + url = https://github.com/bbkiwi/esp82xx.git +