This commit is contained in:
cnlohr 2018-10-21 00:00:29 -04:00
commit a02d56e20d
11 changed files with 243 additions and 24 deletions

View file

@ -35,19 +35,19 @@ ColorChord 2 running a voronoi diagram with Mayhem's Dr. Rocker
Current State of Affairs
------------------------
Currently, ColorChord 2 is designed to run on Linux or Windows. It's not particularly tied to an architecture, but does pretty much need a dedicated FPU to achieve any decent performance. Right now there aren't very many output options available for it. The most interesting one used for debugging is a vornoi-diagram-like thing called "DisplayShapeDriver."
Currently, ColorChord 2 is designed to run on Linux or Windows. It's not particularly tied to an architecture, but does pretty much need a dedicated FPU to achieve any decent performance. Right now there aren't very many output options available for it. The most interesting one used for debugging is a voronoi-diagram-like thing called "DisplayShapeDriver."
ColorChord: Embedded
--------------------
There is work on an embedded version of ColorChord, which avoids floating point operations anywhere in the output pipeline. Though I have made efforts to port it to AVRs, it doesn't seem feasable to operate on AVRs without some shifty tricks which I'd like to avoid, so I have retargeted my efforts to 32-bit systems, such as the STM32F303, STM32F407, and (somehow) the ESP8266. ColorChord Embedded uses a different codebase, located in the [embeddedcommon](embeddedcommon/) and distributed among the various embedded* folders.
There is work on an embedded version of ColorChord, which avoids floating point operations anywhere in the output pipeline. Though I have made efforts to port it to AVRs, it doesn't seem feasable to operate on AVRs without some shifty tricks which I'd like to avoid, so I have retargeted my efforts to 32-bit systems, such as the STM32F303, STM32F407, and (somehow) the ESP8266. ColorChord Embedded uses a different codebase, located in the [embeddedcommon](/embeddedcommon) and distributed among the various embedded* folders.
Building with Linux
-----------------
Use `apt-get` to install the following packages for Debian/Ubuntu/Mint:
```
apt-get install libpulse-dev libasound2-dev libx11-dev libxext-dev libxinerama-dev libusb-1.0-0-dev
apt-get install libpulse-dev libasound2-dev libx11-dev libxext-dev libxinerama-dev libusb-1.0-0-dev libudev-dev
```
To make colorchord, type:

View file

@ -0,0 +1,120 @@
//Copyright 2015 <>< Charles Lohr under the ColorChord License.
#include "outdrivers.h"
#include "notefinder.h"
#include <stdio.h>
#include "parameters.h"
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include "color.h"
#include "DrawFunctions.h"
#include <sys/mman.h>
#include <sys/stat.h> /* For mode constants */
#include <fcntl.h> /* For O_* constants */
#include <unistd.h>
extern struct NoteFinder * nf;
#ifndef O_DIRECT
#define O_DIRECT 00040000
#endif
struct FileWriteDriver
{
int lights_file;
int total_leds;
int inflate_to_u32;
int file_thread_usleep;
int asynchronous;
uint32_t pass_buffer[MAX_LEDS];
og_thread_t rt_thread;
og_sema_t rt_sema;
};
static void * LightsWrite( void * v )
{
struct FileWriteDriver * d = (struct FileWriteDriver *)v;
while(1)
{
OGLockSema( d->rt_sema );
if( d->lights_file > 0 )
{
int btos = ((d->inflate_to_u32)?4:3)*d->total_leds;
int r = write( d->lights_file, d->pass_buffer, btos );
if( r != btos ) goto fail_write;
}
else
{
const char * lightsfile = GetParameterS( "lightsfile", 0 );
if( lightsfile )
{
d->lights_file = open( lightsfile, O_WRONLY );
if( d->lights_file <= 0 )
{
fprintf( stderr, "Error: Can't open \"%s\" (%d)\n", lightsfile, d->lights_file );
}
else
{
fprintf( stderr, "File %s opened OK\n", lightsfile );
}
}
}
continue;
fail_write:
fprintf( stderr, "File writing fault\n" );
close( d->lights_file );
d->lights_file = 0;
}
return 0;
}
static void FileWriteUpdate(void * id, struct NoteFinder*nf)
{
struct FileWriteDriver * d = (struct FileWriteDriver*)id;
if( OGGetSema( d->rt_sema ) > 0 ) return;
if( !d->inflate_to_u32 )
{
memcpy( d->pass_buffer, OutLEDs, d->total_leds*3 );
}
else
{
int i;
for( i = 0; i < d->total_leds; i++ )
{
uint8_t * ol = &OutLEDs[i*3];
d->pass_buffer[i] = ol[0] | (ol[1]<<8) | (ol[2]<<16) | 0xff000000;
}
}
OGUnlockSema( d->rt_sema );
}
static void FileWriteParams(void * id )
{
struct FileWriteDriver * d = (struct FileWriteDriver*)id;
d->total_leds = 300; RegisterValue( "leds", PAINT, &d->total_leds, sizeof( d->total_leds ));
d->inflate_to_u32 = 1; RegisterValue( "inflate_to_u32", PAINT, &d->inflate_to_u32, sizeof( d->inflate_to_u32 ));
d->asynchronous = 1; RegisterValue( "file_async", PAINT, &d->asynchronous, sizeof( d->asynchronous ));
d->file_thread_usleep = 10000; RegisterValue( "file_thread_usleep", PAINT, &d->file_thread_usleep, sizeof( d->file_thread_usleep ));
}
static struct DriverInstances * DisplayFileWrite(const char * parameters)
{
struct DriverInstances * ret = malloc( sizeof( struct DriverInstances ) );
struct FileWriteDriver * d = ret->id = malloc( sizeof( struct FileWriteDriver ) );
memset( d, 0, sizeof( struct FileWriteDriver ) );
ret->Func = FileWriteUpdate;
ret->Params = FileWriteParams;
FileWriteParams( d );
printf( "Loaded DisplayFileWrite\n" );
d->rt_sema = OGCreateSema();
d->rt_thread = OGCreateThread( LightsWrite, d );
return ret;
}
REGISTER_OUT_DRIVER(DisplayFileWrite);

View file

@ -45,6 +45,19 @@ struct DPODriver
static void DPOUpdate(void * id, struct NoteFinder*nf)
{
struct DPODriver * d = (struct DPODriver*)id;
#ifdef WIN32
static int wsa_did_start;
if( !wsa_did_start )
{
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD(2, 2);
err = WSAStartup(wVersionRequested, &wsaData);
}
#endif
int i, j;
if( strcmp( d->oldaddress, d->address ) != 0 || d->socket == -1 || d->oldport != d->port )

View file

@ -3,9 +3,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 DisplayUSB2812.o DisplayDMX.o OutputProminent.o RecorderPlugin.o DisplayHIDAPI.o hidapi.o OutputCells.o DisplaySHM.o
OUTS := OutputVoronoi.o DisplayArray.o OutputLinear.o DisplayPie.o DisplayNetwork.o DisplayUSB2812.o DisplayDMX.o OutputProminent.o RecorderPlugin.o DisplayHIDAPI.o hidapi.o OutputCells.o DisplaySHM.o DisplayFileWrite.o
WINGCC:= i686-w64-mingw32-gcc
WINGCCFLAGS:= -g -DICACHE_FLASH_ATTR= -I../embeddedcommon -I. -O1 #-O2 -Wl,--relax -Wl,--gc-sections -ffunction-sections -fdata-sections
WINLDFLAGS:=-lwinmm -lgdi32 -lws2_32 -lsetupapi
@ -13,13 +14,14 @@ RAWDRAWLIBS:=-lX11 -lm -lpthread -lXinerama -lXext
LDLIBS:=-lpthread -lasound -lm -lpulse-simple -lpulse -ludev -lrt
CFLAGS:=-g -Os -flto -Wall -ffast-math -I../embeddedcommon -I. -DICACHE_FLASH_ATTR=
CFLAGS:=-g -O0 -flto -Wall -ffast-math -I../embeddedcommon -I. -DICACHE_FLASH_ATTR=
EXTRALIBS:=-lusb-1.0
colorchord : os_generic.o main.o dft.o decompose.o filter.o color.o notefinder.o util.o outdrivers.o $(RAWDRAW) $(SOUND) $(OUTS) parameters.o chash.o hook.o ../embeddedcommon/DFT32.o configs.o
gcc -o $@ $^ $(CFLAGS) $(LDLIBS) $(EXTRALIBS) $(RAWDRAWLIBS)
colorchord.exe : os_generic.c main.c dft.c decompose.c filter.c color.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 hook.c RecorderPlugin.c ../embeddedcommon/DFT32.c OutputCells.c configs.c hidapi.c DisplayHIDAPI.c
colorchord.exe : os_generic.c main.c dft.c decompose.c filter.c color.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 OutputProminent.c DisplayArray.c OutputLinear.c DisplayPie.c DisplayNetwork.c hook.c RecorderPlugin.c ../embeddedcommon/DFT32.c OutputCells.c configs.c hidapi.c DisplayHIDAPI.c
$(WINGCC) $(WINGCCFLAGS) -o $@ $^ $(WINLDFLAGS)

View file

@ -8,7 +8,6 @@
#include <string.h>
#include "color.h"
#include <math.h>
#include "DrawFunctions.h"
//Uses: note_amplitudes2[note] for how many lights to use.
//Uses: note_amplitudes_out[note] for how bright it should be.
@ -135,7 +134,6 @@ static void DPOUpdate(void * id, struct NoteFinder*nf)
OutLEDs[led*3+2] = ( color >> 16 ) & 0xff;
led++;
}
CNFGColor ( 0xffffff );
}
static void DPOParams(void * id )

View file

@ -18,7 +18,7 @@ play = 0
rec = 1
channels = 2
samplerate = 44100
wininput = 1
wininput = -1
#Compiled version will default this.
#sound_source = ALSA
@ -59,7 +59,7 @@ octaves = 5
# 2 = DFT Progressive Integer
# 3 = DFT Progressive Integer Skippy
# 4 = Integer, 32-Bit, Progressive, Skippy.
do_progressive_dft = 4fa
do_progressive_dft = 4
filter_iter = 2

View file

@ -0,0 +1,70 @@
# This is the keyboard test for Clevo and PowerSpec 1510 and 1710 laptops, using the kernel module found here:
# https://github.com/cnlohr/clevo_xsm_wmi
cpu_autolimit_interval=.002
cpu_autolimit = 1
headless=1
octaves = 5
base_hz = 82.406889228
#General GUI properties.
title = PA Test
set_screenx = 720
set_screeny = 480
in_amplitude = 1.0
sample_channel = -1
sourcename = alsa_output.pci-0000_00_1f.3.analog-stereo.monitor
#bluez_sink.40_EF_4C_CA_A4_5D.monitor
#alsa_output.pci-0000_00_1f.3.analog-stereo.monitor
## alsa_output.pci-0000_00_1b.0.analog-stereo.monitor
# alsa_output.pci-0000_01_00.1.hdmi-stereo-extra2.monitor (On desktop)
#alsa_output.pci-0000_00_1f.3.analog-stereo.monitor
#default
# alsa_output.pci-0000_00_1b.0.analog-stereo.monitor
#alsa_output.pci-0000_00_1f.3.analog-stereo.monitor << New laptop
#use pactl list | grep pci- | grep monitor
#How many bins a note can jump from frame to frame to be considered a slide.
#this is used to prevent notes from popping in and out a lot.
note_combine_distance = 0.5000
note_jumpability = 1.8000
note_minimum_new_distribution_value = 0.0200
note_out_chop = 0.05000
#compress_coefficient = 4.0
#compress_exponent = .5
How much to slack everything?
note_attach_amp_iir = 0.4500
note_attach_amp_iir2 = 0.350
note_attach_freq_iir = 0.3000
#=======================================================================
#Outputs
#DisplayArray
outdrivers = OutputCells, DisplayFileWrite # DisplayArray
lightsfile = /sys/devices/platform/clevo_xsm_wmi/kb_rgb
inflate_to_u32 = 1
lightx = 1
lighty = 3
fromsides = 1
leds = 3
qtyamp = 5
file_thread_usleep = 18000
light_siding = 2.0
timebased=0
satamp = 1.00
amppow = 1.010
distpow = 1.500

View file

@ -50,8 +50,10 @@ 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 );
float cpu_autolimit_interval = 0.016; REGISTER_PARAM( cpu_autolimit_interval, PAFLOAT );
int sample_channel = -1;REGISTER_PARAM( sample_channel, PAINT );
int showfps = 0; REGISTER_PARAM( showfps, PAINT );
float in_amplitude = 1; REGISTER_PARAM( in_amplitude, PAFLOAT );
struct NoteFinder * nf;
@ -132,7 +134,7 @@ void SoundCB( float * out, float * in, int samplesr, int * samplesp, struct Soun
}
fo /= channelin;
sound[soundhead] = fo;
sound[soundhead] = fo*in_amplitude;
soundhead = (soundhead+1)%SOUNDCBSIZE;
}
else
@ -146,7 +148,7 @@ void SoundCB( float * out, float * in, int samplesr, int * samplesp, struct Soun
//printf( "Sound fault B %d/%d\n", i, samplesr );
sound[soundhead] = f;
sound[soundhead] = f*in_amplitude;
soundhead = (soundhead+1)%SOUNDCBSIZE;
}
@ -352,7 +354,6 @@ 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;
@ -434,8 +435,8 @@ int main(int argc, char ** argv)
if( cpu_autolimit )
{
SecToWait = .016 - ( ThisTime - LastFrameTime );
LastFrameTime += .016;
SecToWait = cpu_autolimit_interval - ( ThisTime - LastFrameTime );
LastFrameTime += cpu_autolimit_interval;
if( SecToWait < -.1 ) LastFrameTime = ThisTime - .1;
if( SecToWait > 0 )
OGUSleep( (int)( SecToWait * 1000000 ) );

View file

@ -1,7 +1,8 @@
outdrivers = DisplayArray,DisplayNetwork, OutputProminent
outdrivers = DisplayNetwork, OutputProminent ##DisplayArray,
light_siding = 1.0 #Turn this to ~1.9 for more uniformity, ~1.0 for less.
leds = 1
satamp = 1.600
showfps = 1
is_loop=0
led_floor = .1 #Turn to .25 for more uniformity, .1 for less.
#note_attach_amp_iir = .3 #.3000
@ -12,11 +13,16 @@ steady_bright = 0
#dft_q = 20.0000
#dft_speedup = 1000.0000
sourcename = alsa_output.pci-0000_01_00.1.hdmi-stereo.monitor
sourcename =
#alsa_output.pci-0000_00_1b.0.analog-stereo.monitor
# home: alsa_output.pci-0000_01_00.1.hdmi-stereo.monitor
skipfirst = 1
firstval = 0
port = 7777
address = 192.168.11.143
address = 10.0.0.167
#192.168.4.1
#192.168.11.143
headless=0
slope=.10
amplify=.3
@ -25,3 +31,4 @@ amplify=.3
lightx = 20
lighty = 20
cpu_autolimit_interval = .01

View file

@ -1,12 +1,20 @@
cpu_autolimit = 1
headless=1
#General GUI properties.
title = PA Test
set_screenx = 720
set_screeny = 480
in_amplitude = 3.0
sample_channel = -1
sourcename = alsa_output.pci-0000_01_00.1.hdmi-stereo-extra2.monitor
sourcename = alsa_output.pci-0000_00_1f.3.analog-stereo.monitor
#sourcename = bluez_sink.40_EF_4C_CA_A4_5D.monitor
#alsa_output.pci-0000_00_1f.3.analog-stereo.monitor
## alsa_output.pci-0000_00_1b.0.analog-stereo.monitor
# alsa_output.pci-0000_01_00.1.hdmi-stereo-extra2.monitor (On desktop)
#alsa_output.pci-0000_00_1f.3.analog-stereo.monitor
#default
# alsa_output.pci-0000_00_1b.0.analog-stereo.monitor
@ -39,10 +47,10 @@ shm_notes = /ccnotes
lightx = 20
lighty = 4
fromsides = 1
leds = 120
qtyamp = 120
leds = 14
qtyamp = 20
satamp = 2.800
satamp = 4.800
amppow = 2.510
distpow = 1.500

View file

@ -249,7 +249,7 @@ static unsigned int i2sBlock[WS_BLOCKSIZE/4];
//DMA underrun counter
#ifdef USE_2812_INTERRUPTS
#if USE_2812_INTERRUPTS
volatile uint8_t ws2812_dma_complete;
@ -496,7 +496,7 @@ void ws2812_push( uint8_t * buffer, uint16_t buffersize )
}
#endif
#ifdef USE_2812_INTERRUPTS
#if USE_2812_INTERRUPTS
uint16_t leftover = buffersize & 0x1f;
if( leftover ) leftover = 32 - leftover;