progress on turbo8. Still not working - also new algebra problem found.

This commit is contained in:
cnlohr 2019-04-07 03:47:58 -07:00
parent b9dc46c701
commit 0d23075125
5 changed files with 134 additions and 58 deletions

View file

@ -26,4 +26,4 @@ colorchord.exe : os_generic.c main.c dft.c decompose.c filter.c color.c notefin
clean : clean :
rm -rf *.o *~ colorchord colorchord.exe embeddedcc rm -rf *.o *~ ../embeddedcommon/*.o colorchord colorchord.exe embeddedcc

Binary file not shown.

View file

@ -54,6 +54,7 @@ float cpu_autolimit_interval = 0.016; REGISTER_PARAM( cpu_autolimit_interval, P
int sample_channel = -1;REGISTER_PARAM( sample_channel, PAINT ); int sample_channel = -1;REGISTER_PARAM( sample_channel, PAINT );
int showfps = 0; REGISTER_PARAM( showfps, PAINT ); int showfps = 0; REGISTER_PARAM( showfps, PAINT );
float in_amplitude = 1; REGISTER_PARAM( in_amplitude, PAFLOAT ); float in_amplitude = 1; REGISTER_PARAM( in_amplitude, PAFLOAT );
int shim_sinewave = 0; REGISTER_PARAM( shim_sinewave, PAINT );
struct NoteFinder * nf; struct NoteFinder * nf;
@ -96,6 +97,9 @@ void HandleMotion( int x, int y, int mask )
void SoundCB( float * out, float * in, int samplesr, int * samplesp, struct SoundDriver * sd ) void SoundCB( float * out, float * in, int samplesr, int * samplesp, struct SoundDriver * sd )
{ {
static og_sema_t tss;
if( !tss ) tss = OGCreateSema();
else OGLockSema( tss );
int channelin = sd->channelsRec; int channelin = sd->channelsRec;
// int channelout = sd->channelsPlay; // int channelout = sd->channelsPlay;
//*samplesp = 0; //*samplesp = 0;
@ -106,53 +110,90 @@ void SoundCB( float * out, float * in, int samplesr, int * samplesp, struct Soun
int i; int i;
int j; int j;
for( i = 0; i < samplesr; i++ ) if( out )
{ {
if( out ) for( i = 0; i < samplesr; i++ )
{ {
for( j = 0; j < channelin; j++ ) for( j = 0; j < channelin; j++ )
{ {
out[i*channelin+j] = 0; out[i*channelin+j] = 0;
} }
} }
}
if( sample_channel < 0 ) if( shim_sinewave )
{ {
float fo = 0; static double sinplace;
for( j = 0; j < channelin; j++ ) static double sinfreq = 0;
{ static int msp;
float f = in[i*channelin+j];
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; for( i = 0; i < samplesr; i++ )
sound[soundhead] = fo*in_amplitude;
soundhead = (soundhead+1)%SOUNDCBSIZE;
}
else
{ {
float f = in[i*channelin+sample_channel]; sinfreq = 3.14159 * 2 * 110 * pow( 2, 5.0/12 ) / 16000;
// sinfreq += .000001;
// if( sinfreq > .2 ) sinfreq = 0;
sinplace += sinfreq;
if( sinplace > (3.14159*2) ) sinplace -= 3.14159 * 2;
msp++;
float f = sin( sinplace );
//if( msp % 20000 > 10000 ) f = 0;
if( f > 1 || f < -1 ) if( f > 1 || f < -1 )
{ {
f = (f>0)?1:-1; f = (f>0)?1:-1;
} }
//printf( "Sound fault B %d/%d\n", i, samplesr ); //printf( "Sound fault B %d/%d\n", i, samplesr );
sound[soundhead] = f*in_amplitude; sound[soundhead] = f*in_amplitude;
soundhead = (soundhead+1)%SOUNDCBSIZE; soundhead = (soundhead+1)%SOUNDCBSIZE;
} }
} }
else
{
if( sample_channel < 0 )
{
for( i = 0; i < samplesr; i++ )
{
float fo = 0;
for( j = 0; j < channelin; j++ )
{
float f = in[i*channelin+j];
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;
sound[soundhead] = fo*in_amplitude;
soundhead = (soundhead+1)%SOUNDCBSIZE;
}
}
else
{
for( i = 0; i < samplesr; i++ )
{
float f = in[i*channelin+sample_channel];
if( f > 1 || f < -1 )
{
f = (f>0)?1:-1;
}
//printf( "Sound fault B %d/%d\n", i, samplesr );
sound[soundhead] = f*in_amplitude;
soundhead = (soundhead+1)%SOUNDCBSIZE;
}
}
}
SoundEventHappened( samplesr, in, 0, channelin ); SoundEventHappened( samplesr, in, 0, channelin );
if( out ) if( out )
@ -160,6 +201,8 @@ void SoundCB( float * out, float * in, int samplesr, int * samplesp, struct Soun
SoundEventHappened( samplesr, out, 1, sd->channelsPlay ); SoundEventHappened( samplesr, out, 1, sd->channelsPlay );
} }
*samplesp = samplesr; *samplesp = samplesr;
OGUnlockSema( tss );
} }
int main(int argc, char ** argv) int main(int argc, char ** argv)

View file

@ -89,15 +89,17 @@ note_out_chop = 0.05000
#Outputs #Outputs
shim_sinewave = 0
This is a vornoi thing: This is a vornoi thing:
outdrivers = OutputVoronoi, DisplayArray outdrivers = DisplayArray
lightx = 64 #lightx = 64
lighty = 32 #lighty = 32
fromsides = 1 #fromsides = 1
shape_cutoff = 0.03 #shape_cutoff = 0.03
satamp = 5.000 #satamp = 5.000
amppow = 2.510 #amppow = 2.510
distpow = 1.500 #distpow = 1.500

View file

@ -100,8 +100,8 @@
// Observation: The two tables are actually mirror images of each other, well diagonally mirrored. That's odd. But, would take CPU to exploit. // Observation: The two tables are actually mirror images of each other, well diagonally mirrored. That's odd. But, would take CPU to exploit.
#define SSTABLESIZE 256 #define SSTABLESIZE 256
int8_t spikysin_interleved_cos[SSTABLESIZE*2]; int8_t spikysin_interleved_cos[SSTABLESIZE][2];
uint16_t advancespeed[MAX_FREQS]; uint32_t advancespeed[MAX_FREQS];
static int CompTableWithPhase( int nelements, float phase, int scaling ) static int CompTableWithPhase( int nelements, float phase, int scaling )
{ {
@ -117,14 +117,14 @@ static int CompTableWithPhase( int nelements, float phase, int scaling )
combsin += sin( taued * (1<<o) + phase); combsin += sin( taued * (1<<o) + phase);
} }
combsin /= OCTAVES; combsin /= OCTAVES;
int csadapt = combsin * scaling; //No value is higher with five octaves. XXX TODO Lookout. If you change # of octaves, need to change this, too. int csadapt = combsin * scaling - 0.5; //No value is higher with five octaves. XXX TODO Lookout. If you change # of octaves, need to change this, too.
if( csadapt > highest ) highest = csadapt; if( csadapt > highest ) highest = csadapt;
if( -csadapt > highest ) highest = -csadapt; if( -csadapt > highest ) highest = -csadapt;
if( csadapt > 127 ) csadapt = 127; if( csadapt > 127 ) csadapt = 127;
if( csadapt < -127 ) csadapt = -127; //tricky: Keep balanced. if( csadapt < -128 ) csadapt = -128; //tricky: Keep balanced.
spikysin_interleved_cos[i*2+0] = csadapt; spikysin_interleved_cos[i][0] = csadapt;
float combcos = 0; float combcos = 0;
for( o = 0; o < OCTAVES; o++ ) for( o = 0; o < OCTAVES; o++ )
@ -132,14 +132,14 @@ static int CompTableWithPhase( int nelements, float phase, int scaling )
combcos += cos( taued * (1<<o) + phase ); combcos += cos( taued * (1<<o) + phase );
} }
combcos /= OCTAVES; combcos /= OCTAVES;
csadapt = combcos * scaling; //No value is higher with five octaves. XXX TODO Lookout. If you change # of octaves, need to change this, too. csadapt = combcos * scaling - 0.5; //No value is higher with five octaves. XXX TODO Lookout. If you change # of octaves, need to change this, too.
if( csadapt > highest ) highest = csadapt; if( csadapt > highest ) highest = csadapt;
if( -csadapt > highest ) highest = -csadapt; if( -csadapt > highest ) highest = -csadapt;
if( csadapt > 127 ) csadapt = 127; if( csadapt > 127 ) csadapt = 127;
if( csadapt < -127 ) csadapt = -127; //tricky: Keep balanced. if( csadapt < -128 ) csadapt = -128; //tricky: Keep balanced.
spikysin_interleved_cos[i*2+1] = csadapt; spikysin_interleved_cos[i][1] = csadapt;
} }
return highest; return highest;
} }
@ -166,7 +166,11 @@ static int Setup( float * frequencies, int bins )
} }
printf( "Best comp: %f : %d\n", bestphase, highest_val_at_best_phase ); printf( "Best comp: %f : %d\n", bestphase, highest_val_at_best_phase );
CompTableWithPhase( SSTABLESIZE, bestphase, (65536*128)/highest_val_at_best_phase ); //Set this because we would overflow the sinm and cosm regs if we don't. This is sort of like a master volume.
//use this as that input volume knob thing.
float further_reduce = 1.0;
CompTableWithPhase( SSTABLESIZE, bestphase, (65536*128*further_reduce)/highest_val_at_best_phase );
// for( i = 0; i < SSTABLESIZE; i++ ) // for( i = 0; i < SSTABLESIZE; i++ )
// { // {
@ -177,7 +181,7 @@ static int Setup( float * frequencies, int bins )
{ {
//frequencies[i] = SPS / Freq //frequencies[i] = SPS / Freq
// Need to decide how quickly we sweep through the table. // Need to decide how quickly we sweep through the table.
advancespeed[i] = 256.0 /* fixed point */ * 256.0 /* size of table */ / frequencies[i]; advancespeed[i] = 65536 * 256.0 /* fixed point */ * 256.0 /* size of table */ / frequencies[i];
//printf( "%f\n", frequencies[i] ); //printf( "%f\n", frequencies[i] );
} }
return 0; return 0;
@ -193,7 +197,7 @@ float toutbins[MAX_FREQS];
struct notedat struct notedat
{ {
uint16_t time; uint32_t time;
int32_t sinm; int32_t sinm;
int32_t cosm; int32_t cosm;
}; };
@ -205,30 +209,53 @@ void Turbo8BitRun( int8_t adcval )
int i; int i;
for( i = 0; i < MAX_FREQS; i++ ) for( i = 0; i < MAX_FREQS; i++ )
{ {
uint16_t ct = nd[i].time; uint32_t ct = nd[i].time;
int32_t muxres; int32_t muxres;
int32_t running; int32_t running;
int32_t rdesc, rdess; int32_t rdesc, rdess;
int8_t ss = spikysin_interleved_cos[(ct>>8) + 0]; uint8_t * spikysintable = &spikysin_interleved_cos[(ct>>24)][0];
muxres = ((int16_t)adcval * ss) >> 8;
int8_t ss = *(spikysintable++);
#define DECIR 8
muxres = ((int16_t)adcval * ss + (1<<(DECIR-1)) ) >> (DECIR);
running = nd[i].cosm; running = nd[i].cosm;
running += muxres; running += muxres;
rdesc = running >> 8; rdesc = running >> 8;
running -= rdesc>>6; running -= rdesc >> 3;
nd[i].cosm = running;
int8_t sc = spikysin_interleved_cos[(ct>>8) + 1]; nd[i].cosm = running;
muxres = ((int16_t)adcval * sc) >> 8; if( i == 0) printf( "MRX %5d %9d %9d %9d %9d\n", muxres, adcval, ss, running, nd[i].sinm );
int8_t sc = *(spikysintable++);
muxres = ((int16_t)adcval * sc + (1<<(DECIR-1)) ) >> (DECIR);
running = nd[i].sinm; running = nd[i].sinm;
running += muxres; running += muxres;
rdess = running>>8; rdess = running>>8;
running -= rdess>>6; running -= rdess >> 3;
nd[i].sinm = running; nd[i].sinm = running;
nd[i].time = ct + advancespeed[i]; nd[i].time = ct + advancespeed[i];
toutbins[i] = rdess * rdess + rdesc * rdesc; toutbins[i] = rdess * rdess + rdesc * rdesc;
//printf( "%d %d = %f %p\n", rdess, rdesc, toutbins[i], &toutbins[i] ); //printf( "%d %d = %f %p\n", rdess, rdesc, toutbins[i], &toutbins[i] );
} }
static uint8_t stater;
/* stater++;
if( stater == 16 )
{
stater = 0;
for( i = 0; i < MAX_FREQS; i++ )
{
nd[i].sinm -= nd[i].sinm >> 12;
nd[i].cosm -= nd[i].cosm >> 12;
nd[i].sinm += 8;
nd[i].cosm += 8;
}
}*/
} }
@ -243,8 +270,10 @@ void DoDFT8BitTurbo( float * outbins, float * frequencies, int bins, const float
{ {
int16_t ifr1 = (int16_t)( ((databuffer[i]) ) * 4095 ); int16_t ifr1 = (int16_t)( ((databuffer[i]) ) * 4095 );
//ifr1 += 4095; //ifr1 += 4095;
Turbo8BitRun( ifr1>>5 ); //ifr1 += 512;
Turbo8BitRun( ifr1>>5 ); //6 = Actually only feed algorithm numbers from -64 to 63.
} }
last_place = place_in_data_buffer;
for( i = 0; i < bins; i++ ) for( i = 0; i < bins; i++ )
{ {
@ -252,11 +281,13 @@ void DoDFT8BitTurbo( float * outbins, float * frequencies, int bins, const float
} }
for( i = 0; i < MAX_FREQS; i++ ) for( i = 0; i < MAX_FREQS; i++ )
{ {
int iss = nd[i].sinm; int iss = nd[i].sinm>>8;
int isc = nd[i].cosm; int isc = nd[i].cosm>>8;
int mux = iss * iss + isc * isc; int mux = iss * iss + isc * isc;
if( mux == 0 ) mux = 1; if( mux == 0 ) mux = 1;
outbins[i+MAX_FREQS] = sqrt(mux)/1000.0; if( i == 0 )
printf( "MUX: %d %d\n", isc, iss );
outbins[i+MAX_FREQS] = sqrt(mux)/200.0;
} }
} }