add all the updated changes to the 2812 driver and usb drivers

This commit is contained in:
cnlohr 2015-01-17 17:39:49 -05:00
parent d5c518ec0a
commit bc45b5feb0
15 changed files with 176 additions and 81 deletions

View file

@ -68,10 +68,10 @@ static void DPOParams(void * id )
{
struct DPODriver * d = (struct DPODriver*)id;
d->xn = 16; RegisterValue( "lightx", PINT, &d->xn, sizeof( d->xn ) );
d->yn = 9; RegisterValue( "lighty", PINT, &d->yn, sizeof( d->yn ) );
d->zigzag = 0; RegisterValue( "zigzag", PINT, &d->zigzag, sizeof( d->zigzag ) );
d->rot90 = 0; RegisterValue( "rot90", PINT, &d->rot90, sizeof( d->rot90 ) );
d->xn = 16; RegisterValue( "lightx", PAINT, &d->xn, sizeof( d->xn ) );
d->yn = 9; RegisterValue( "lighty", PAINT, &d->yn, sizeof( d->yn ) );
d->zigzag = 0; RegisterValue( "zigzag", PAINT, &d->zigzag, sizeof( d->zigzag ) );
d->rot90 = 0; RegisterValue( "rot90", PAINT, &d->rot90, sizeof( d->rot90 ) );
}

View file

@ -5,13 +5,19 @@
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include "color.h"
#include "DrawFunctions.h"
#include <unistd.h>
#ifdef WIN32
#include <windows.h>
#define MSG_NOSIGNAL 0
#else
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include "color.h"
#include "DrawFunctions.h"
#include <unistd.h>
#endif
#define MAX_BUFFER 1487
@ -44,7 +50,7 @@ static void DPOUpdate(void * id, struct NoteFinder*nf)
if( hname )
{
bzero(&d->servaddr, sizeof(d->servaddr));
memset(&d->servaddr, 0, sizeof(d->servaddr));
d->servaddr.sin_family = hname->h_addrtype;
d->servaddr.sin_port = htons( d->port );
d->servaddr.sin_addr.s_addr = *(long*)hname->h_addr;
@ -81,7 +87,7 @@ static void DPOUpdate(void * id, struct NoteFinder*nf)
buffer[i++] = OutLEDs[j*3+2]; //BLUE
buffer[i++] = OutLEDs[j*3+1]; //GREEN
}
int r = sendto( d->socket, buffer, i, MSG_NOSIGNAL, &d->servaddr, sizeof( d->servaddr ) );
int r = sendto( d->socket, buffer, i, MSG_NOSIGNAL,(const struct sockaddr *) &d->servaddr, sizeof( d->servaddr ) );
if( r < 0 )
{
fprintf( stderr, "Send fault.\n" );
@ -97,11 +103,11 @@ static void DPOParams(void * id )
struct DPODriver * d = (struct DPODriver*)id;
strcpy( d->address, "localhost" );
d->leds = 10; RegisterValue( "leds", PINT, &d->leds, sizeof( d->leds ) );
d->skipfirst = 1; RegisterValue( "skipfirst", PINT, &d->skipfirst, sizeof( d->skipfirst ) );
d->port = 7777; RegisterValue( "port", PINT, &d->port, sizeof( d->port ) );
d->firstval = 0; RegisterValue( "firstval", PINT, &d->firstval, sizeof( d->firstval ) );
RegisterValue( "address", PBUFFER, d->address, sizeof( d->address ) );
d->leds = 10; RegisterValue( "leds", PAINT, &d->leds, sizeof( d->leds ) );
d->skipfirst = 1; RegisterValue( "skipfirst", PAINT, &d->skipfirst, sizeof( d->skipfirst ) );
d->port = 7777; RegisterValue( "port", PAINT, &d->port, sizeof( d->port ) );
d->firstval = 0; RegisterValue( "firstval", PAINT, &d->firstval, sizeof( d->firstval ) );
RegisterValue( "address", PABUFFER, d->address, sizeof( d->address ) );
d->socket = -1;
d->oldaddress[0] = 0;
}

View file

@ -57,9 +57,9 @@ static void DPOParams(void * id )
{
struct DPODriver * d = (struct DPODriver*)id;
d->leds = 9; RegisterValue( "leds", PINT, &d->leds, sizeof( d->leds ) );
d->pie_min = .18; RegisterValue( "pie_min", PFLOAT, &d->pie_min, sizeof( d->pie_min ) );
d->pie_max = .3; RegisterValue( "pie_max", PFLOAT, &d->pie_max, sizeof( d->pie_max ) );
d->leds = 9; RegisterValue( "leds", PAINT, &d->leds, sizeof( d->leds ) );
d->pie_min = .18; RegisterValue( "pie_min", PAFLOAT, &d->pie_min, sizeof( d->pie_min ) );
d->pie_max = .3; RegisterValue( "pie_max", PAFLOAT, &d->pie_max, sizeof( d->pie_max ) );
}

View file

@ -63,7 +63,7 @@ static void LEDUpdate(void * id, struct NoteFinder*nf)
if( libusb_init(NULL) < 0 )
{
fprintf( stderr, "Error: Could not initialize libUSB\n" );
exit( -99 );
// exit( -99 );
}
led->devh = libusb_open_device_with_vid_pid( NULL, 0xabcd, 0xf003 );
@ -71,7 +71,7 @@ static void LEDUpdate(void * id, struct NoteFinder*nf)
if( !led->devh )
{
fprintf( stderr, "Error: Cannot find device.\n" );
exit( -98 );
// exit( -98 );
}
}
@ -122,9 +122,9 @@ static void LEDUpdate(void * id, struct NoteFinder*nf)
source = sx + sy * led->yn;
}
}
led->last_leds[i*3+0] = OutLEDs[source*3+0] * led->outamp;
led->last_leds[i*3+2] = OutLEDs[source*3+1] * led->outamp;
led->last_leds[i*3+1] = OutLEDs[source*3+2] * led->outamp;
led->last_leds[i*3+0] = OutLEDs[source*3+1] * led->outamp;
led->last_leds[i*3+1] = OutLEDs[source*3+0] * led->outamp;
led->last_leds[i*3+2] = OutLEDs[source*3+2] * led->outamp;
}
led->readyFlag = 1;

View file

@ -2,9 +2,10 @@ 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
OUTS := OutputVoronoi.o DisplayArray.o OutputLinear.o DisplayPie.o DisplayNetwork.o DisplayUSB2812.o
#LEDOUTDriver.o DisplayOUTDriver.o
WINGCC:=i586-mingw32msvc-gcc
WINGCCFLAGS:= -lwinmm -lgdi32 -lws2_32 -O2 -ffast-math -g
RAWDRAWLIBS:=-lX11 -lm -lpthread -lXinerama -lXext
LDLIBS:=-lpthread -lasound -lm -lpulse-simple -lpulse
@ -14,6 +15,9 @@ 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)
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) -o $@ $^ $(WINGCCFLAGS)
clean :
rm -rf *.o *~ colorchord

View file

@ -141,15 +141,15 @@ static void DPOParams(void * id )
struct DPODriver * d = (struct DPODriver*)id;
//XXX WRONG
d->xn = 160; RegisterValue( "lightx", PINT, &d->xn, sizeof( d->xn ) );
d->yn = 90; RegisterValue( "lighty", PINT, &d->yn, sizeof( d->yn ) );
d->cutoff = .01; RegisterValue( "Voronoi_cutoff", PFLOAT, &d->cutoff, sizeof( d->cutoff ) );
d->satamp = 5; RegisterValue( "satamp", PFLOAT, &d->satamp, sizeof( d->satamp ) );
d->xn = 160; RegisterValue( "lightx", PAINT, &d->xn, sizeof( d->xn ) );
d->yn = 90; RegisterValue( "lighty", PAINT, &d->yn, sizeof( d->yn ) );
d->cutoff = .01; RegisterValue( "Voronoi_cutoff", PAFLOAT, &d->cutoff, sizeof( d->cutoff ) );
d->satamp = 5; RegisterValue( "satamp", PAFLOAT, &d->satamp, sizeof( d->satamp ) );
d->amppow = 2.51; RegisterValue( "amppow", PFLOAT, &d->amppow, sizeof( d->amppow ) );
d->distpow = 1.5; RegisterValue( "distpow", PFLOAT, &d->distpow, sizeof( d->distpow ) );
d->amppow = 2.51; RegisterValue( "amppow", PAFLOAT, &d->amppow, sizeof( d->amppow ) );
d->distpow = 1.5; RegisterValue( "distpow", PAFLOAT, &d->distpow, sizeof( d->distpow ) );
d->from_sides = 1; RegisterValue( "fromsides", PINT, &d->from_sides, sizeof( d->from_sides ) );
d->from_sides = 1; RegisterValue( "fromsides", PAINT, &d->from_sides, sizeof( d->from_sides ) );
d->note_peaks = 0;
}

View file

@ -2,6 +2,7 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <malloc.h>
#define I_AM_LITTLE (((union { unsigned x; unsigned char c; }){1}).c)

View file

@ -18,7 +18,10 @@ play = 0
rec = 1
channels = 2
samplerate = 44100
sound_source = PULSE
wininput = 0
#Compiled version will default this.
#sound_source = PULSE
#-1 indicates left and right, 0 left, 1 right.
sample_channel = -1
sourcename = alsa_output.pci-0000_00_1b.0.analog-stereo.monitor
@ -69,8 +72,8 @@ note_out_chop = 0.1000
This is a vornoi thing:
outdrivers = DisplayArray, OutputVoronoi
lightx = 72
lighty = 48
lightx = 64
lighty = 32
fromsides = 1
shape_cutoff = 0.03
satamp = 5.000

18
linearpie.conf Normal file
View file

@ -0,0 +1,18 @@
#What display output driver should be used?
outdrivers = DisplayPie, OutputLinear
leds = 100
light_siding = 2.2
satamp = 6.000
is_loop=1
led_floor = .1
note_attach_amp_iir2 = .0500
note_attach_amp_iir2 = .1500
note_attach_freq_iir = 0.3000
steady_bright = 0
#dft_iir = 0.0
#dft_q = 20.0000
#dft_speedup = 1000.0000
pie_min=.15
pie_max=.25

51
main.c
View file

@ -14,17 +14,22 @@
#include "outdrivers.h"
#include "parameters.h"
#ifdef WIN32
#include <windows.h>
#endif
int lastfps;
short screenx, screeny;
int gargc;
char ** gargv;
struct DriverInstances * outdriver[MAX_OUT_DRIVERS];
int set_screenx = 640; REGISTER_PARAM( set_screenx, PINT );
int set_screeny = 480; REGISTER_PARAM( set_screeny, PINT );
char sound_source[16]; REGISTER_PARAM( sound_source, PBUFFER );
int cpu_autolimit = 1; REGISTER_PARAM( cpu_autolimit, PINT );
int sample_channel = -1;REGISTER_PARAM( sample_channel, PINT );
int set_screenx = 640; REGISTER_PARAM( set_screenx, PAINT );
int set_screeny = 480; REGISTER_PARAM( set_screeny, PAINT );
char sound_source[16]; REGISTER_PARAM( sound_source, PABUFFER );
int cpu_autolimit = 1; REGISTER_PARAM( cpu_autolimit, PAINT );
int sample_channel = -1;REGISTER_PARAM( sample_channel, PAINT );
struct NoteFinder * nf;
@ -74,6 +79,7 @@ void SoundCB( float * out, float * in, int samplesr, int * samplesp, struct Soun
int i;
int j;
for( i = 0; i < samplesr; i++ )
{
if( sample_channel < 0 )
@ -152,6 +158,16 @@ int main(int argc, char ** argv)
double LastFileTimeInit = 0;
double LastFileTimeDefault = 0;
#ifdef WIN32
WSADATA wsaData;
WSAStartup(0x202, &wsaData);
strcpy( sound_source, "WIN" );
#else
strcpy( sound_source, "PULSE" );
#endif
gargc = argc;
gargv = argv;
@ -181,7 +197,22 @@ int main(int argc, char ** argv)
double SecToWait;
CNFGBGColor = 0x800000;
CNFGDialogColor = 0x444444;
CNFGSetup( "ColorChord Test", set_screenx, set_screeny );
char title[1024];
char * tp = title;
memcpy( tp, "ColorChord ", strlen( "ColorChord " ) );
tp += strlen( "ColorChord " );
for( i = 1; i < argc; i++ )
{
memcpy( tp, argv[i], strlen( argv[i] ) );
tp += strlen( argv[i] );
*tp = ' ';
tp++;
}
*tp = 0;
CNFGSetup( title, set_screenx, set_screeny );
char * OutDriverNames = strdup( GetParameterS( "outdrivers", "null" ) );
@ -352,13 +383,19 @@ int main(int argc, char ** argv)
sprintf( stt, "[9] Key: %d [0] (%3.1f) [-]", gKey, nf->base_hz );
CNFGDrawText( stt, 2 );
CNFGColor( 0xffffff );
CNFGPenX = 440; CNFGPenY = screeny-10;
sprintf( stt, "FPS: %d", lastfps );
CNFGDrawText( stt, 2 );
//Finish Rawdraw with FPS counter, and a nice delay loop.
frames++;
CNFGSwapBuffers();
ThisTime = OGGetAbsoluteTime();
if( ThisTime > LastFPSTime + 1 )
{
printf( "FPS: %d\n", frames );
// printf( "FPS: %d\n", frames );
lastfps = frames;
frames = 0;
LastFPSTime+=1;
}

View file

@ -40,24 +40,24 @@ struct NoteFinder * CreateNoteFinder( int spsRec )
ret->ofreqs = 0; //force a re-init.
RegisterValue( "octaves", PINT, &ret->octaves, sizeof( ret->octaves ) );
RegisterValue( "freqbins", PINT, &ret->freqbins, sizeof( ret->freqbins ) );
RegisterValue( "base_hz", PFLOAT, &ret->base_hz, sizeof( ret->base_hz ) );
RegisterValue( "filter_strength", PFLOAT, &ret->filter_strength, sizeof( ret->filter_strength ) );
RegisterValue( "filter_iter", PINT, &ret->filter_iter, sizeof( ret->filter_iter ) );
RegisterValue( "decompose_iterations", PINT, &ret->decompose_iterations, sizeof( ret->decompose_iterations ) );
RegisterValue( "amplify", PFLOAT, &ret->amplify, sizeof( ret->amplify ) );
RegisterValue( "dft_speedup", PFLOAT, &ret->dft_speedup, sizeof( ret->dft_speedup ) );
RegisterValue( "dft_q", PFLOAT, &ret->dft_q, sizeof( ret->dft_q ) );
RegisterValue( "default_sigma", PFLOAT, &ret->default_sigma, sizeof( ret->default_sigma ) );
RegisterValue( "note_jumpability", PFLOAT, &ret->note_jumpability, sizeof( ret->note_jumpability ) );
RegisterValue( "note_combine_distance", PFLOAT, &ret->note_combine_distance, sizeof( ret->note_combine_distance ) );
RegisterValue( "note_attach_freq_iir", PFLOAT, &ret->note_attach_freq_iir, sizeof( ret->note_attach_freq_iir ) );
RegisterValue( "note_attach_amp_iir", PFLOAT, &ret->note_attach_amp_iir, sizeof( ret->note_attach_amp_iir ) );
RegisterValue( "note_attach_amp_iir2", PFLOAT, &ret->note_attach_amp_iir2, sizeof( ret->note_attach_amp_iir2 ) );
RegisterValue( "note_minimum_new_distribution_value", PFLOAT, &ret->note_minimum_new_distribution_value, sizeof( ret->note_minimum_new_distribution_value ) );
RegisterValue( "note_out_chop", PFLOAT, &ret->note_out_chop, sizeof( ret->note_out_chop ) );
RegisterValue( "dft_iir", PFLOAT, &ret->dft_iir, sizeof( ret->dft_iir ) );
RegisterValue( "octaves", PAINT, &ret->octaves, sizeof( ret->octaves ) );
RegisterValue( "freqbins", PAINT, &ret->freqbins, sizeof( ret->freqbins ) );
RegisterValue( "base_hz", PAFLOAT, &ret->base_hz, sizeof( ret->base_hz ) );
RegisterValue( "filter_strength", PAFLOAT, &ret->filter_strength, sizeof( ret->filter_strength ) );
RegisterValue( "filter_iter", PAINT, &ret->filter_iter, sizeof( ret->filter_iter ) );
RegisterValue( "decompose_iterations", PAINT, &ret->decompose_iterations, sizeof( ret->decompose_iterations ) );
RegisterValue( "amplify", PAFLOAT, &ret->amplify, sizeof( ret->amplify ) );
RegisterValue( "dft_speedup", PAFLOAT, &ret->dft_speedup, sizeof( ret->dft_speedup ) );
RegisterValue( "dft_q", PAFLOAT, &ret->dft_q, sizeof( ret->dft_q ) );
RegisterValue( "default_sigma", PAFLOAT, &ret->default_sigma, sizeof( ret->default_sigma ) );
RegisterValue( "note_jumpability", PAFLOAT, &ret->note_jumpability, sizeof( ret->note_jumpability ) );
RegisterValue( "note_combine_distance", PAFLOAT, &ret->note_combine_distance, sizeof( ret->note_combine_distance ) );
RegisterValue( "note_attach_freq_iir", PAFLOAT, &ret->note_attach_freq_iir, sizeof( ret->note_attach_freq_iir ) );
RegisterValue( "note_attach_amp_iir", PAFLOAT, &ret->note_attach_amp_iir, sizeof( ret->note_attach_amp_iir ) );
RegisterValue( "note_attach_amp_iir2", PAFLOAT, &ret->note_attach_amp_iir2, sizeof( ret->note_attach_amp_iir2 ) );
RegisterValue( "note_minimum_new_distribution_value", PAFLOAT, &ret->note_minimum_new_distribution_value, sizeof( ret->note_minimum_new_distribution_value ) );
RegisterValue( "note_out_chop", PAFLOAT, &ret->note_out_chop, sizeof( ret->note_out_chop ) );
RegisterValue( "dft_iir", PAFLOAT, &ret->dft_iir, sizeof( ret->dft_iir ) );
AddCallback( "freqbins", ChangeNFParameters, ret );
AddCallback( "octaves", ChangeNFParameters, ret );

View file

@ -26,10 +26,10 @@ float GetParameterF( const char * name, float defa )
{
switch( p->t )
{
case PFLOAT: return *((float*)p->lp->ptr);
case PINT: return *((int*)p->lp->ptr);
case PSTRING:
case PBUFFER: if( p->lp->ptr ) return atof( p->lp->ptr );
case PAFLOAT: return *((float*)p->lp->ptr);
case PAINT: return *((int*)p->lp->ptr);
case PASTRING:
case PABUFFER: if( p->lp->ptr ) return atof( p->lp->ptr );
default: break;
}
}
@ -46,10 +46,10 @@ int GetParameterI( const char * name, int defa )
{
switch( p->t )
{
case PFLOAT: return *((float*)p->lp->ptr);
case PINT: return *((int*)p->lp->ptr);
case PSTRING:
case PBUFFER: if( p->lp->ptr ) return atoi( p->lp->ptr );
case PAFLOAT: return *((float*)p->lp->ptr);
case PAINT: return *((int*)p->lp->ptr);
case PASTRING:
case PABUFFER: if( p->lp->ptr ) return atoi( p->lp->ptr );
default: break;
}
}
@ -67,10 +67,10 @@ const char * GetParameterS( const char * name, const char * defa )
{
switch( p->t )
{
case PFLOAT: snprintf( returnbuffer, sizeof( returnbuffer ), "%0.4f", *((float*)p->lp->ptr) ); return returnbuffer;
case PINT: snprintf( returnbuffer, sizeof( returnbuffer ), "%d", *((int*)p->lp->ptr) ); return returnbuffer;
case PSTRING:
case PBUFFER: return p->lp->ptr;
case PAFLOAT: snprintf( returnbuffer, sizeof( returnbuffer ), "%0.4f", *((float*)p->lp->ptr) ); return returnbuffer;
case PAINT: snprintf( returnbuffer, sizeof( returnbuffer ), "%d", *((int*)p->lp->ptr) ); return returnbuffer;
case PASTRING:
case PABUFFER: return p->lp->ptr;
default: break;
}
}
@ -88,21 +88,21 @@ static int SetParameter( struct Param * p, const char * str )
switch( p->t )
{
case PFLOAT:
case PAFLOAT:
while( lp )
{
*((float*)lp->ptr) = atof( str );
lp = lp->lp;
}
break;
case PINT:
case PAINT:
while( lp )
{
*((int*)lp->ptr) = atoi( str );
lp = lp->lp;
}
break;
case PBUFFER:
case PABUFFER:
while( lp )
{
strncpy( (char*)lp->ptr, str, p->size );
@ -111,7 +111,7 @@ static int SetParameter( struct Param * p, const char * str )
lp = lp->lp;
}
break;
case PSTRING:
case PASTRING:
while( lp )
{
free( lp->ptr );
@ -144,7 +144,7 @@ void RegisterValue( const char * name, enum ParamType t, void * ptr, int size )
//Entry already exists.
if( p->orphan )
{
if( p->t != PSTRING )
if( p->t != PASTRING )
{
fprintf( stderr, "Warning: Orphan parameter %s was not a PSTRING.\n", name );
}
@ -246,7 +246,7 @@ void SetParametersFromString( const char * string )
struct Param ** n = (struct Param **)HashTableInsert( parameters, name, 0 );
*n = malloc( sizeof ( struct Param ) );
(*n)->orphan = 1;
(*n)->t = PSTRING;
(*n)->t = PASTRING;
(*n)->lp = malloc( sizeof( struct LinkedParameter ) );
(*n)->lp->lp = 0;
(*n)->lp->ptr = strdup( value );

View file

@ -6,10 +6,10 @@
enum ParamType
{
NONE,
PFLOAT,
PINT,
PSTRING, //const char *, cannot set.
PBUFFER,
PAFLOAT,
PAINT,
PASTRING, //const char *, cannot set.
PABUFFER,
NUM_PARAMS,
};

View file

@ -1,3 +1,5 @@
//XXX THIS DRIVER IS INCOMPLETE XXX
#include <windows.h>
#include "parameters.h"
#include "sound.h"

24
usb.conf Normal file
View file

@ -0,0 +1,24 @@
outdrivers = DisplayUSB2812, OutputVoronoi
leds = 512
lightx = 32
lighty = 16
fromsides = 1
shape_cutoff = 0.03
satamp = 2.000
amppow = 2.5
distpow = 1.500
zigzag = 1
rot90 = 1
ledoutamp = .5
note_attach_amp_iir = .3000
note_attach_amp_iir2 = .1500
note_attach_freq_iir = 0.3000
steady_bright = 0
skipfirst = 1
firstval = 0
port = 7777
address = 192.168.0.245