The starts of Embedded ColorChord
This commit is contained in:
parent
9035f16add
commit
6d75249cb8
15
Makefile
15
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
|
||||
|
|
|
@ -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;
|
||||
|
|
90
OutputProminent.c
Normal file
90
OutputProminent.c
Normal file
|
@ -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 <stdio.h>
|
||||
#include <string.h>
|
||||
#include "parameters.h"
|
||||
#include <stdlib.h>
|
||||
#include "color.h"
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <unistd.h>
|
||||
|
||||
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);
|
||||
|
||||
|
BIN
colorchord.exe
BIN
colorchord.exe
Binary file not shown.
13
default.conf
13
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
|
||||
|
||||
|
||||
#=======================================================================
|
||||
|
|
310
dft.c
310
dft.c
|
@ -1,4 +1,3 @@
|
|||
|
||||
#include "dft.h"
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
@ -6,6 +5,9 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
#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<<OCTAVES)
|
||||
|
||||
//NOTES to self:
|
||||
//
|
||||
|
@ -354,13 +347,130 @@ void DoDFTProgressiveInteger( float * outbins, float * frequencies, int bins, co
|
|||
// We can do two at the same time, this frees us up some
|
||||
|
||||
static uint8_t Sdonefirstrun;
|
||||
static int8_t Ssintable[512]; //Actually [sin][cos] pairs.
|
||||
static uint16_t Sdatspace[FIXBINS*4]; //(advances,places,isses,icses)
|
||||
//int8_t Ssintable[512]; //Actually [sin][cos] pairs.
|
||||
const int8_t Ssintable[512] = {
|
||||
0, 127, 3, 126, 6, 126, 9, 126, 12, 126, 15, 126, 18, 125, 21, 125,
|
||||
24, 124, 27, 123, 30, 123, 33, 122, 36, 121, 39, 120, 42, 119, 45, 118,
|
||||
48, 117, 51, 116, 54, 114, 57, 113, 59, 112, 62, 110, 65, 108, 67, 107,
|
||||
70, 105, 73, 103, 75, 102, 78, 100, 80, 98, 82, 96, 85, 94, 87, 91,
|
||||
89, 89, 91, 87, 94, 85, 96, 82, 98, 80, 100, 78, 102, 75, 103, 73,
|
||||
105, 70, 107, 67, 108, 65, 110, 62, 112, 59, 113, 57, 114, 54, 116, 51,
|
||||
117, 48, 118, 45, 119, 42, 120, 39, 121, 36, 122, 33, 123, 30, 123, 27,
|
||||
124, 24, 125, 21, 125, 18, 126, 15, 126, 12, 126, 9, 126, 6, 126, 3,
|
||||
127, 0, 126, -3, 126, -6, 126, -9, 126, -12, 126, -15, 125, -18, 125, -21,
|
||||
124, -24, 123, -27, 123, -30, 122, -33, 121, -36, 120, -39, 119, -42, 118, -45,
|
||||
117, -48, 116, -51, 114, -54, 113, -57, 112, -59, 110, -62, 108, -65, 107, -67,
|
||||
105, -70, 103, -73, 102, -75, 100, -78, 98, -80, 96, -82, 94, -85, 91, -87,
|
||||
89, -89, 87, -91, 85, -94, 82, -96, 80, -98, 78,-100, 75,-102, 73,-103,
|
||||
70,-105, 67,-107, 65,-108, 62,-110, 59,-111, 57,-113, 54,-114, 51,-116,
|
||||
48,-117, 45,-118, 42,-119, 39,-120, 36,-121, 33,-122, 30,-123, 27,-123,
|
||||
24,-124, 21,-125, 18,-125, 15,-126, 12,-126, 9,-126, 6,-126, 3,-126,
|
||||
0,-127, -3,-126, -6,-126, -9,-126, -12,-126, -15,-126, -18,-125, -21,-125,
|
||||
-24,-124, -27,-123, -30,-123, -33,-122, -36,-121, -39,-120, -42,-119, -45,-118,
|
||||
-48,-117, -51,-116, -54,-114, -57,-113, -59,-112, -62,-110, -65,-108, -67,-107,
|
||||
-70,-105, -73,-103, -75,-102, -78,-100, -80, -98, -82, -96, -85, -94, -87, -91,
|
||||
-89, -89, -91, -87, -94, -85, -96, -82, -98, -80,-100, -78,-101, -75,-103, -73,
|
||||
-105, -70,-107, -67,-108, -65,-110, -62,-111, -59,-113, -57,-114, -54,-116, -51,
|
||||
-117, -48,-118, -45,-119, -42,-120, -39,-121, -36,-122, -33,-123, -30,-123, -27,
|
||||
-124, -24,-125, -21,-125, -18,-126, -15,-126, -12,-126, -9,-126, -6,-126, -3,
|
||||
-127, 0,-126, 3,-126, 6,-126, 9,-126, 12,-126, 15,-125, 18,-125, 21,
|
||||
-124, 24,-123, 27,-123, 30,-122, 33,-121, 36,-120, 39,-119, 42,-118, 45,
|
||||
-117, 48,-116, 51,-114, 54,-113, 57,-112, 59,-110, 62,-108, 65,-107, 67,
|
||||
-105, 70,-103, 73,-102, 75,-100, 78, -98, 80, -96, 82, -94, 85, -91, 87,
|
||||
-89, 89, -87, 91, -85, 94, -82, 96, -80, 98, -78, 100, -75, 101, -73, 103,
|
||||
-70, 105, -67, 107, -65, 108, -62, 110, -59, 111, -57, 113, -54, 114, -51, 116,
|
||||
-48, 117, -45, 118, -42, 119, -39, 120, -36, 121, -33, 122, -30, 123, -27, 123,
|
||||
-24, 124, -21, 125, -18, 125, -15, 126, -12, 126, -9, 126, -6, 126, -3, 126,};
|
||||
/** The above table was created using the following code:
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
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<<octave);
|
||||
Sdatspace[i*4+2] -= isps>>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);
|
||||
#endif
|
||||
|
||||
|
||||
uint32_t rmux = ( (isps) * (isps)) + ((ispc) * (ispc));
|
||||
embeddedbins[i] = SquareRootRounded( rmux );
|
||||
embeddedbins[i] >>= 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<<j) & i) == 0 ) break;
|
||||
}
|
||||
if( j > 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<<j) & i) == 0 ) break;
|
||||
}
|
||||
if( j > 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
|
||||
|
||||
|
||||
|
||||
|
|
35
dft.h
35
dft.h
|
@ -1,10 +1,13 @@
|
|||
#ifndef _DFT_H
|
||||
#define _DFT_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
//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<<OCTAVES)
|
||||
|
||||
//Whenever you need to read the bins, you can do it from here.
|
||||
extern uint16_t Sdatspace[]; //(advances,places,isses,icses)
|
||||
extern uint16_t embeddedbins[]; //This is updated every time the DFT hits the octavecount, or 1/32 updates.
|
||||
|
||||
#endif
|
||||
|
||||
|
|
123
embeddedcc.c
Normal file
123
embeddedcc.c
Normal file
|
@ -0,0 +1,123 @@
|
|||
//
|
||||
// This is the teststrap for the Embedded ColorChord System.
|
||||
// It is intended as a minimal scaffolding for testing Embedded ColorChord.
|
||||
//
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#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 <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
18
main.c
18
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;
|
||||
|
|
26
quickwash.conf
Normal file
26
quickwash.conf
Normal file
|
@ -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
|
||||
|
|
@ -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 );
|
||||
|
|
Loading…
Reference in a new issue