diff --git a/Makefile b/Makefile index a1dce0a..c42a863 100644 --- a/Makefile +++ b/Makefile @@ -2,23 +2,30 @@ all : colorchord RAWDRAW:=DrawFunctions.o XDriver.o SOUND:=sound.o sound_alsa.o sound_pulse.o sound_null.o -OUTS := OutputVoronoi.o DisplayArray.o OutputLinear.o DisplayPie.o DisplayNetwork.o DisplayUSB2812.o DisplayDMX.o +OUTS := OutputVoronoi.o DisplayArray.o OutputLinear.o DisplayPie.o DisplayNetwork.o DisplayUSB2812.o DisplayDMX.o OutputProminent.o WINGCC:=i586-mingw32msvc-gcc -WINGCCFLAGS:= -O2 -ffast-math -Wl,--relax -Wl,--gc-sections -ffunction-sections -fdata-sections -s +WINGCCFLAGS:= -O2 -Wl,--relax -Wl,--gc-sections -ffunction-sections -fdata-sections -s WINLDFLAGS:=-lwinmm -lgdi32 -lws2_32 RAWDRAWLIBS:=-lX11 -lm -lpthread -lXinerama -lXext LDLIBS:=-lpthread -lasound -lm -lpulse-simple -lpulse -CFLAGS:=-g -Os -flto -Wall -ffast-math +CFLAGS:=-g -Os -flto -Wall EXTRALIBS:=-lusb-1.0 colorchord : os_generic.o main.o dft.o decompose.o filter.o color.o sort.o notefinder.o util.o outdrivers.o $(RAWDRAW) $(SOUND) $(OUTS) parameters.o chash.o gcc -o $@ $^ $(CFLAGS) $(LDLIBS) $(EXTRALIBS) $(RAWDRAWLIBS) +embeddedcc : os_generic.c embeddedcc.c dft.c + gcc -o $@ $^ $(CFLAGS) -DCCEMBEDDED $(LDFLAGS) $(EXTRALIBS) $(RAWDRAWLIBS) + +runembedded : embeddedcc + parec --format=u8 --rate=8000 --channels=1 --device=alsa_output.pci-0000_00_1b.0.analog-stereo.monitor | ./embeddedcc + + colorchord.exe : os_generic.c main.c dft.c decompose.c filter.c color.c sort.c notefinder.c util.c outdrivers.c DrawFunctions.c parameters.c chash.c WinDriver.c sound.c sound_null.c sound_win.c OutputVoronoi.c DisplayArray.c OutputLinear.c DisplayPie.c DisplayNetwork.c $(WINGCC) $(WINGCCFLAGS) -o $@ $^ $(WINLDFLAGS) clean : - rm -rf *.o *~ colorchord colorchord.exe + rm -rf *.o *~ colorchord colorchord.exe embeddedcc diff --git a/OutputLinear.c b/OutputLinear.c index 631db2c..6e3fbda 100644 --- a/OutputLinear.c +++ b/OutputLinear.c @@ -157,7 +157,9 @@ static void LEDUpdate(void * id, struct NoteFinder*nf) if( satQ > 1 ) satQ = 1; led->last_led_pos[i] = rledpos[ia]; led->last_led_amp[i] = sat; - int r = CCtoHEX( led->last_led_pos[i], 1.0, (led->steady_bright?sat:satQ) ); + float sendsat = (led->steady_bright?sat:satQ); + if( sendsat > 1 ) sendsat = 1; + int r = CCtoHEX( led->last_led_pos[i], 1.0, sendsat ); OutLEDs[i*3+0] = r & 0xff; OutLEDs[i*3+1] = (r>>8) & 0xff; diff --git a/OutputProminent.c b/OutputProminent.c new file mode 100644 index 0000000..aa5adcb --- /dev/null +++ b/OutputProminent.c @@ -0,0 +1,90 @@ +//Really basic driver, that just selects the most prominent color and washes all the LEDs with that. + +#include "outdrivers.h" +#include "notefinder.h" +#include +#include +#include "parameters.h" +#include +#include "color.h" +#include +#include +#include + +struct ProminentDriver +{ + int did_init; + int total_leds; + float satamp; +}; + +static void LEDUpdate(void * id, struct NoteFinder*nf) +{ + struct ProminentDriver * led = (struct ProminentDriver*)id; + + + //Step 1: Calculate the quantity of all the LEDs we'll want. + int totbins = nf->note_peaks;//nf->dists; + int i; + float selected_amp = 0; + float selected_note = 0; + +// if( totbins > led_bins ) totbins = led_bins; + + for( i = 0; i < totbins; i++ ) + { + float freq = nf->note_positions[i] / nf->freqbins; + float amp = nf->note_amplitudes2[i] * led->satamp; + if( amp > selected_amp ) + { + selected_amp = amp; + selected_note = freq; + } + } + + + + //Advance the LEDs to this position when outputting the values. + for( i = 0; i < led->total_leds; i++ ) + { + float sendsat = selected_amp; + if( sendsat > 1 ) sendsat = 1; + int r = CCtoHEX( selected_note, 1.0, sendsat ); + + OutLEDs[i*3+0] = r & 0xff; + OutLEDs[i*3+1] = (r>>8) & 0xff; + OutLEDs[i*3+2] = (r>>16) & 0xff; + } + +} + +static void LEDParams(void * id ) +{ + struct ProminentDriver * led = (struct ProminentDriver*)id; + + led->satamp = 2; RegisterValue( "satamp", PAFLOAT, &led->satamp, sizeof( led->satamp ) ); + led->total_leds = 4; RegisterValue( "leds", PAINT, &led->total_leds, sizeof( led->total_leds ) ); + + + printf( "Found Prominent for output. leds=%d\n", led->total_leds ); + +} + + +static struct DriverInstances * OutputProminent() +{ + struct DriverInstances * ret = malloc( sizeof( struct DriverInstances ) ); + memset( ret, 0, sizeof( struct DriverInstances ) ); + struct ProminentDriver * led = ret->id = malloc( sizeof( struct ProminentDriver ) ); + memset( led, 0, sizeof( struct ProminentDriver ) ); + + ret->Func = LEDUpdate; + ret->Params = LEDParams; + LEDParams( led ); + return ret; + +} + +REGISTER_OUT_DRIVER(OutputProminent); + + diff --git a/colorchord.exe b/colorchord.exe deleted file mode 100755 index f0899d3..0000000 Binary files a/colorchord.exe and /dev/null differ diff --git a/default.conf b/default.conf index f96c54e..502124b 100644 --- a/default.conf +++ b/default.conf @@ -17,7 +17,7 @@ buffer = 128 play = 0 rec = 1 channels = 2 -samplerate = 44100 +samplerate = 8000 wininput = 0 #Compiled version will default this. @@ -31,7 +31,7 @@ sourcename = alsa_output.pci-0000_00_1b.0.analog-stereo.monitor ################################## # How much to amplify the incoming signal. -amplify = 2.5 +amplify = 2.0 # What is the base note? I.e. the lowest note. # Note that it won't have very much impact until an octave up though! @@ -47,6 +47,13 @@ dft_q = 20.0000 dft_speedup = 1000.0000 octaves = 5 +# Should we use a progressive DFT? +# 0 = DFT Quick +# 1 = DFT Progressive +# 2 = DFT Progressive Integer +# 3 = DFT Progressive Integer Skippy +do_progressive_dft = 3 + filter_iter = 2 filter_strength = .5 @@ -63,7 +70,7 @@ note_attach_freq_iir = 0.3000 note_combine_distance = 0.5000 note_jumpability = 1.8000 note_minimum_new_distribution_value = 0.0200 -note_out_chop = 0.1000 +note_out_chop = 0.05000 #======================================================================= diff --git a/dft.c b/dft.c index c40ae19..bfa3d02 100644 --- a/dft.c +++ b/dft.c @@ -1,4 +1,3 @@ - #include "dft.h" #include #include @@ -6,6 +5,9 @@ #include #include + +#ifndef CCEMBEDDED + void DoDFT( float * outbins, float * frequencies, int bins, float * databuffer, int place_in_data_buffer, int size_of_data_buffer, float q ) { int i, j; @@ -88,10 +90,9 @@ static float * gbinqtys; static float * gbinqtyc; static float * phis; static float * gfrequencies; -static float * goutbins; static float * lastbins; static float * advances; - +static float * goutbins; static int gbins; static float gq; static float gspeedup; @@ -325,7 +326,7 @@ void DoDFTProgressiveInteger( float * outbins, float * frequencies, int bins, co - +#endif @@ -337,14 +338,6 @@ void DoDFTProgressiveInteger( float * outbins, float * frequencies, int bins, co ////////////////////////SKIPPY DFT -//Skippy DFT is a very ood one. - - - -#define OCTAVES 5 -#define FIXBPERO 24 -#define FIXBINS (FIXBPERO*OCTAVES) -#define BINCYCLE (1< +#include +#include + +int8_t Ssintable[512]; //Actually [sin][cos] pairs. + +int main() +{ + int i; + for( i = 0; i < 256; i++ ) + { + Ssintable[i*2+0] = (int8_t)((sinf( i / 256.0 * 6.283 ) * 127.0)); + Ssintable[i*2+1] = (int8_t)((cosf( i / 256.0 * 6.283 ) * 127.0)); + } + + printf( "const int8_t Ssintable[512] = {" ); + for( i = 0; i < 512; i++ ) + { + if( !(i & 0xf ) ) + { + printf( "\n\t" ); + } + printf( "%4d," ,Ssintable[i] ); + } + printf( "};\n" ); +} + */ + + + +uint16_t Sdatspace[FIXBINS*4]; //(advances,places,isses,icses) //For -static uint8_t Sdo_this_octave[BINCYCLE]; -static int16_t Saccum_octavebins[OCTAVES]; -static uint8_t Swhichoctaveplace; +uint8_t Sdo_this_octave[BINCYCLE]; +int16_t Saccum_octavebins[OCTAVES]; +uint8_t Swhichoctaveplace; +uint16_t embeddedbins[FIXBINS]; //This is updated every time the DFT hits the octavecount, or 1/32 updates. + +//From: http://stackoverflow.com/questions/1100090/looking-for-an-efficient-integer-square-root-algorithm-for-arm-thumb2 +/** + * \brief Fast Square root algorithm, with rounding + * + * This does arithmetic rounding of the result. That is, if the real answer + * would have a fractional part of 0.5 or greater, the result is rounded up to + * the next integer. + * - SquareRootRounded(2) --> 1 + * - SquareRootRounded(3) --> 2 + * - SquareRootRounded(4) --> 2 + * - SquareRootRounded(6) --> 2 + * - SquareRootRounded(7) --> 3 + * - SquareRootRounded(8) --> 3 + * - SquareRootRounded(9) --> 3 + * + * \param[in] a_nInput - unsigned integer for which to find the square root + * + * \return Integer square root of the input value. + */ +static uint16_t SquareRootRounded(uint32_t a_nInput) +{ + uint32_t op = a_nInput; + uint32_t res = 0; + uint32_t one = 1uL << 30; // The second-to-top bit is set: use 1u << 14 for uint16_t type; use 1uL<<30 for uint32_t type + + + // "one" starts at the highest power of four <= than the argument. + while (one > op) + { + one >>= 2; + } + + while (one != 0) + { + if (op >= res + one) + { + op = op - (res + one); + res = res + 2 * one; + } + res >>= 1; + one >>= 2; + } + + /* Do arithmetic rounding to nearest integer */ + if (op > res) + { + res++; + } + + return res; +} void HandleProgressiveIntSkippy( int8_t sample1 ) { @@ -390,27 +500,40 @@ void HandleProgressiveIntSkippy( int8_t sample1 ) { int16_t isps = Sdatspace[i*4+2]; int16_t ispc = Sdatspace[i*4+3]; - int16_t mux = ( (isps/256) * (isps/256)) + ((ispc/256) * (ispc/256)); // printf( "%d (%d %d)\n", mux, isps, ispc ); int octave = i / FIXBPERO; // mux >>= octave; - goutbins[i] = sqrt( mux ); -// goutbins[i]/=100.0; - goutbins[i]/=100*(1<>5; - Sdatspace[i*4+3] -= ispc>>5; - } +#ifndef CCEMBEDDED + uint32_t mux = ( (isps/256) * (isps/256)) + ((ispc/256) * (ispc/256)); + goutbins[i] = sqrt( mux ); + goutbins[i]/=25*(1<>= octave; + + Sdatspace[i*4+2] -= isps>>4; //XXX 4 is more responsive AND doesn't overflow as easily. + Sdatspace[i*4+3] -= ispc>>4; //XXX 4 is more responsive AND doesn't overflow as easily. + + //TRICKY: It is possible for the sin and cos accumulators to overflow, + //I DO NOT INTEND TO FIX THIS NOW! It could be easily fixed by using 32-bit integers, or + //by decreasing the quality a little bit, but it is an extreme case with a pure, full-volume sinewave. + } + return; } + for( i = 0; i < OCTAVES;i++ ) { Saccum_octavebins[i] += sample1; } uint16_t * ds = &Sdatspace[oct*FIXBPERO*4]; - int8_t * st; + const int8_t * st; sample1 = Saccum_octavebins[oct]>>(OCTAVES-oct); Saccum_octavebins[oct] = 0; @@ -436,13 +559,13 @@ void HandleProgressiveIntSkippy( int8_t sample1 ) //Add TS and TC to the datspace stuff. (24 instructions) tmp1 = (*ds); //Read out, sin component. 4 Accurate. // tmp1 -= tmp1>>4; //Subtract from the MSB (with carry) 2 -> 6 AS/IS: 7+7 = 14 - tmp1 += ts>>3; //Add MSBs with carry 2 -> 6 AS/IS: 6 + tmp1 += ts>>4; //Add MSBs with carry 2 -> 6 AS/IS: 6 *(ds++) = tmp1; //Store values back 4 tmp1 = *ds; //Read out, sin component. 4 // tmp1 -= tmp1>>4; //Subtract from the MSB (with carry) 2 -> 6 AS/IS: 7+7 = 14 - tmp1 += tc>>3; //Add MSBs with carry 2 -> 6 AS/IS: 6 + tmp1 += tc>>4; //Add MSBs with carry 2 -> 6 AS/IS: 6 *ds++ = tmp1; //Store values back 4 @@ -452,46 +575,82 @@ void HandleProgressiveIntSkippy( int8_t sample1 ) } } +void SetupDFTProgressiveIntegerSkippy() +{ + int i; + int j; + //Sdatspace = malloc(FIXBPERO*OCTAVES*8); + //memset(Sdatspace,0,FIXBPERO*OCTAVES*8); + //printf( "MS: %d\n", FIXBPERO*OCTAVES*8); + Sdonefirstrun = 1; +/* + for( i = 0; i < 256; i++ ) + { + Ssintable[i*2+0] = (int8_t)((sinf( i / 256.0 * 6.283 ) * 127.0)); + Ssintable[i*2+1] = (int8_t)((cosf( i / 256.0 * 6.283 ) * 127.0)); + } +*/ + for( i = 0; i < BINCYCLE; i++ ) + { + // Sdo_this_octave = + // 4 3 4 2 4 3 4 ... + //search for "first" zero + + for( j = 0; j <= OCTAVES; j++ ) + { + if( ((1< OCTAVES ) + { + fprintf( stderr, "Error: algorithm fault.\n" ); + exit( -1 ); + } + Sdo_this_octave[i] = OCTAVES-j-1; + } +} + +#ifndef CCEMBEDDED + +void UpdateBinsForProgressiveIntegerSkippy( const float * frequencies ) +{ + int i; + for( i = 0; i < FIXBINS; i++ ) + { + float freq = frequencies[(i%FIXBPERO) + (FIXBPERO*(OCTAVES-1))]; + Sdatspace[i*4] = (65536.0/freq);// / oneoveroctave; + } +} + +#endif + + +void UpdateBinsForProgressiveIntegerSkippyInt( const uint16_t * frequencies ) +{ + int i; + for( i = 0; i < FIXBINS; i++ ) + { + uint16_t freq = frequencies[i%FIXBPERO]; + Sdatspace[i*4] = freq;// / oneoveroctave; + } +} + +void Push8BitIntegerSkippy( int8_t dat ) +{ + HandleProgressiveIntSkippy( dat ); + HandleProgressiveIntSkippy( dat ); +} + + +#ifndef CCEMBEDDED + void DoDFTProgressiveIntegerSkippy( float * outbins, float * frequencies, int bins, const float * databuffer, int place_in_data_buffer, int size_of_data_buffer, float q, float speedup ) { static float backupbins[FIXBINS]; - int i, j; + int i; static int last_place; -//printf( "SKIPPY\n" ); - - if( !Sdonefirstrun ) - { - memset( outbins, 0, bins * sizeof( float ) ); - goutbins = outbins; - //Sdatspace = malloc(FIXBPERO*OCTAVES*8); - //memset(Sdatspace,0,FIXBPERO*OCTAVES*8); - //printf( "MS: %d\n", FIXBPERO*OCTAVES*8); - Sdonefirstrun = 1; - for( i = 0; i < 256; i++ ) - { - Ssintable[i*2+0] = (int8_t)((sinf( i / 256.0 * 6.283 ) * 127.0)); - Ssintable[i*2+1] = (int8_t)((cosf( i / 256.0 * 6.283 ) * 127.0)); - } - - for( i = 0; i < BINCYCLE; i++ ) - { - // Sdo_this_octave = - // 4 3 4 2 4 3 4 ... - //search for "first" zero - - for( j = 0; j <= OCTAVES; j++ ) - { - if( ((1< OCTAVES ) - { - fprintf( stderr, "Error: algorithm fault.\n" ); - exit( -1 ); - } - Sdo_this_octave[i] = OCTAVES-j-1; - } - } + memset( outbins, 0, bins * sizeof( float ) ); + goutbins = outbins; memcpy( outbins, backupbins, FIXBINS*4 ); @@ -501,13 +660,16 @@ void DoDFTProgressiveIntegerSkippy( float * outbins, float * frequencies, int bi return; } - - for( i = 0; i < bins; i++ ) + +//printf( "SKIPPY\n" ); + + if( !Sdonefirstrun ) { - float freq = frequencies[(i%FIXBPERO) + (FIXBPERO*(OCTAVES-1))]; - Sdatspace[i*4] = (65536.0/freq);// / oneoveroctave; + SetupDFTProgressiveIntegerSkippy(); + Sdonefirstrun = 1; } + UpdateBinsForProgressiveIntegerSkippy( frequencies ); for( i = last_place; i != place_in_data_buffer; i = (i+1)%size_of_data_buffer ) { @@ -519,23 +681,9 @@ void DoDFTProgressiveIntegerSkippy( float * outbins, float * frequencies, int bi last_place = place_in_data_buffer; memcpy( backupbins, outbins, FIXBINS*4 ); - - //Extract bins. -/* - for( i = 0; i < bins; i++ ) - { - int16_t isps = Sdatspace[i*4+2]; - int16_t ispc = Sdatspace[i*4+3]; - int16_t mux = ( (isps/256) * (isps/256)) + ((ispc/256) * (ispc/256)); -// printf( "%d (%d %d)\n", mux, isps, ispc ); - outbins[i] = sqrt( mux )/100.0; - } -*/ - -// printf( "\n"); } - +#endif diff --git a/dft.h b/dft.h index 944b949..1589c22 100644 --- a/dft.h +++ b/dft.h @@ -1,10 +1,13 @@ #ifndef _DFT_H #define _DFT_H +#include + +//Warning: Most ColorChords are not available for ColorChord Embedded. +#ifndef CCEMBEDDED //There are several options here, the last few are selectable by modifying the do_progressive_dft flag. - //Do a DFT on a live audio ring buffer. It assumes new samples are added on in the + direction, older samples go negative. //Frequencies are as a function of the samplerate, for example, a frequency of 22050 is actually 2 Hz @ 44100 SPS //bins = number of frequencies to check against. @@ -22,10 +25,40 @@ void DoDFTProgressive( float * outbins, float * frequencies, int bins, const flo //This is fast enough to run on an ESP8266 void DoDFTProgressiveInteger( float * outbins, float * frequencies, int bins, const float * databuffer, int place_in_data_buffer, int size_of_data_buffer, float q, float speedup ); +#endif + //Everything the integer one buys, except it only calculates 2 octaves worth of notes per audio frame. //This is sort of working, but still have some quality issues. //It would theoretically be fast enough to work on an AVR. +//NOTE: This is the only DFT available to the embedded port of ColorChord void DoDFTProgressiveIntegerSkippy( float * outbins, float * frequencies, int bins, const float * databuffer, int place_in_data_buffer, int size_of_data_buffer, float q, float speedup ); +//It's actually split into a few functions, which you can call on your own: +void SetupDFTProgressiveIntegerSkippy(); //Call at start. + +#ifndef CCEMBEDDED +void UpdateBinsForProgressiveIntegerSkippy( const float * frequencies ); //Update the frequencies +#endif + +void UpdateBinsForProgressiveIntegerSkippyInt( const uint16_t * frequencies ); +void Push8BitIntegerSkippy( int8_t dat ); //Call this to push on new frames of sound. + + +//You can # define these to be other things. +#ifndef OCTAVES +#define OCTAVES 5 +#endif + +#ifndef FIXBPERO +#define FIXBPERO 24 +#endif + +#define FIXBINS (FIXBPERO*OCTAVES) +#define BINCYCLE (1< + +#include "dft.h" +#define DFREQ 8000 +#define BASE_FREQ 55.0 + +const float bf_table[24] = { + 1.000000, 1.029302, 1.059463, 1.090508, 1.122462, 1.155353, + 1.189207, 1.224054, 1.259921, 1.296840, 1.334840, 1.373954, + 1.414214, 1.455653, 1.498307, 1.542211, 1.587401, 1.633915, + 1.681793, 1.731073, 1.781797, 1.834008, 1.887749, 1.943064 }; + +#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)])) + +/* The above table was generated using the following code: + +#include +#include + +int main() +{ + int i; + #define FIXBPERO 24 + printf( "const float bf_table[%d] = {", FIXBPERO ); + for( i = 0; i < FIXBPERO; i++ ) + { + if( ( i % 6 ) == 0 ) + printf( "\n\t" ); + printf( "%f, ", pow( 2, (float)i / (float)FIXBPERO ) ); + } + printf( "};\n" ); + return 0; +} +*/ + +void UpdateFreqs() +{ + uint16_t fbins[FIXBPERO]; + int i; + + BUILD_BUG_ON( sizeof(bf_table) != FIXBPERO*4 ); + + for( i = 0; i < FIXBPERO; i++ ) + { + float frq = ( bf_table[i] * BASE_FREQ ); + fbins[i] = ( 65536.0 ) / ( DFREQ ) * frq * 16; + } + + UpdateBinsForProgressiveIntegerSkippyInt( fbins ); +} + +void Init() +{ + //Step 1: Initialize the Integer DFT. + SetupDFTProgressiveIntegerSkippy(); + + //Step 2: Set up the frequency list. + UpdateFreqs(); +} + +void HandleFrameInfo() +{ + uint16_t folded_bins[FIXBPERO]; + + int i, j, k = 0; + + for( i = 0; i < FIXBPERO; i++ ) + folded_bins[i] = 0; + + for( j = 0; j < OCTAVES; j++ ) + { + for( i = 0; i < FIXBPERO; i++ ) + { + folded_bins[i] += embeddedbins[k++]; + } + } + + + + //XXX TODO Taper the first and last octaves. +// for( i = 0; i < freqbins; i++ ) +// { +// nf->outbins[i] *= (i+1.0)/nf->freqbins; +// } +// for( i = 0; i < freqbins; i++ ) +// { +// nf->outbins[freqs-i-1] *= (i+1.0)/nf->freqbins; +// } + + //We now have the system folded into one + + for( i = 0; i < FIXBPERO; i++ ) + { + printf( "%5d ", folded_bins[i] ); + } + printf( "\n" ); +} + +int main() +{ + int wf = 0; + int ci; + Init(); + while( ( ci = getchar() ) != EOF ) + { + int cs = ci - 0x80; + Push8BitIntegerSkippy( (int8_t)cs ); + //printf( "%d ", cs ); fflush( stdout ); + wf++; + if( wf == 64 ) + { + HandleFrameInfo(); + wf = 0; + } + } + return 0; +} + diff --git a/main.c b/main.c index 3664a82..57aae5d 100644 --- a/main.c +++ b/main.c @@ -44,7 +44,7 @@ int sample_channel = -1;REGISTER_PARAM( sample_channel, PAINT ); struct NoteFinder * nf; //Sound circular buffer -#define SOUNDCBSIZE 65536 +#define SOUNDCBSIZE 8096 #define MAX_CHANNELS 2 double VisTimeEnd, VisTimeStart; @@ -98,10 +98,15 @@ void SoundCB( float * out, float * in, int samplesr, int * samplesp, struct Soun for( j = 0; j < channelin; j++ ) { float f = in[i*channelin+j]; - if( f > -1 && f < 1 ) + if( f >= -1 && f <= 1 ) { fo += f; } + else + { + fo += (f>0)?1:-1; +// printf( "Sound fault A %d/%d %d/%d %f\n", j, channelin, i, samplesr, f ); + } } fo /= channelin; @@ -114,9 +119,13 @@ void SoundCB( float * out, float * in, int samplesr, int * samplesp, struct Soun float f = in[i*channelin+sample_channel]; if( f > -1 && f < 1 ) { - sound[soundhead] = f; - soundhead = (soundhead+1)%SOUNDCBSIZE; + f = (f>0)?1:-1; } + + //printf( "Sound fault B %d/%d\n", i, samplesr ); + sound[soundhead] = f; + soundhead = (soundhead+1)%SOUNDCBSIZE; + } } } @@ -374,6 +383,7 @@ int main(int argc, char ** argv) int thisy = sound[thissoundhead] * 128 + 128; thissoundhead = (thissoundhead-1+SOUNDCBSIZE)%SOUNDCBSIZE; for( i = 0; i < screenx; i++ ) { + if( thisy < 0 || thisy > 256 ) printf( "%d/%d\n", thisy,thissoundhead ); CNFGTackSegment( i, lasty, i+1, thisy ); lasty = thisy; thisy = sound[thissoundhead] * 128 + 128; thissoundhead = (thissoundhead-1+SOUNDCBSIZE)%SOUNDCBSIZE; diff --git a/quickwash.conf b/quickwash.conf new file mode 100644 index 0000000..ab598e8 --- /dev/null +++ b/quickwash.conf @@ -0,0 +1,26 @@ + +This is a vornoi thing: +outdrivers = DisplayArray, OutputProminent +lightx = 2 +lighty = 2 +leds = 4 +fromsides = 1 +shape_cutoff = 0.03 +satamp = 5.000 +amppow = 2.510 +distpow = 1.500 + +samplerate = 11025 +buffer = 64 + +sourcename = default + +amplify = 2.5 +note_attach_amp_iir = 0.9000 +note_attach_amp_iir2 = 0.550 +note_attach_freq_iir = 0.9000 +dft_iir = .6 +dft_q = 20.0000 +dft_speedup = 1000.0000 +note_jumpability = 1.0000 + diff --git a/sound_pulse.c b/sound_pulse.c index 513b53a..7033db8 100644 --- a/sound_pulse.c +++ b/sound_pulse.c @@ -267,6 +267,11 @@ void * InitSoundPulse( SoundCBType cb ) r->channelsRec = r->channelsPlay; r->sourceName = GetParameterS( "sourcename", NULL ); + if( strcmp( r->sourceName, "default" ) == 0 ) + { + r->sourceName = 0; + } + r->play = 0; r->rec = 0; r->buffer = GetParameterI( "buffer", 1024 );