From 87eb55e28e65cf2b6115af9e88382965b5d53be8 Mon Sep 17 00:00:00 2001 From: cnlohr Date: Wed, 7 Jan 2015 01:22:37 -0500 Subject: [PATCH] fix stability issues with silence --- TODO | 4 +++- default.conf | 2 +- notefinder.c | 9 +++++++-- parameters.c | 2 +- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/TODO b/TODO index bc904bc..ca66cea 100644 --- a/TODO +++ b/TODO @@ -1,7 +1,9 @@ Still to do: - +* Figure out why silence for any reasonable length of time results in sadness for the note finder. Try this: * Separate "LED Selection" from "output" algorithms. * For light finding, pick lights off the peaks to get number of lights to use. * For light shifting (for 1d-looping light systems) shift the centers of the notes, then vernoi between the notes. +* Consider running DFT on all channels and mixing results + diff --git a/default.conf b/default.conf index a299072..9795f25 100644 --- a/default.conf +++ b/default.conf @@ -33,7 +33,7 @@ channels = 2 samplerate = 44100 sound_source = PULSE #-1 indicates left and right, 0 left, 1 right. -sample_channel = 1 +sample_channel = -1 sourcename = alsa_output.pci-0000_00_1b.0.analog-stereo.monitor ################################## diff --git a/notefinder.c b/notefinder.c index dfccf13..320e2e0 100644 --- a/notefinder.c +++ b/notefinder.c @@ -238,7 +238,7 @@ void RunNoteFinder( struct NoteFinder * nf, const float * audio_stream, int head { for( j = 0; j < nf->dists; j++ ) { - if( !nf->dist_takens[j] && !nf->note_founds[i] && fabsloop( nf->note_positions[i], nf->dist_means[j], freqbins ) < nf->note_jumpability ) + if( !nf->dist_takens[j] && !nf->note_founds[i] && fabsloop( nf->note_positions[i], nf->dist_means[j], freqbins ) < nf->note_jumpability && nf->dist_amps[j] > 0.00001 ) //0.00001 for stability. { //Attach ourselves to this bin. nf->note_peaks_to_dists_mapping[i] = j; @@ -246,7 +246,9 @@ void RunNoteFinder( struct NoteFinder * nf, const float * audio_stream, int head if( nf->enduring_note_id[i] == 0 ) nf->enduring_note_id[i] = nf->current_note_id++; nf->note_founds[i] = 1; + nf->note_positions[i] = avgloop( nf->note_positions[i], (1.-nf->note_attach_freq_iir), nf->dist_means[j], nf->note_attach_freq_iir, nf->freqbins); + //I guess you can't IIR this like normal. ////note_positions[i] * (1.-note_attach_freq_iir) + dist_means[j] * note_attach_freq_iir; @@ -261,6 +263,7 @@ void RunNoteFinder( struct NoteFinder * nf, const float * audio_stream, int head //Combine like-notes. for( i = 0; i < note_peaks; i++ ) { +// printf( "%f %f %d\n", nf->note_amplitudes[i], nf->note_positions[i], nf->enduring_note_id[i] ); for( j = 0; j < note_peaks; j++ ) { if( i == j ) continue; @@ -280,9 +283,11 @@ void RunNoteFinder( struct NoteFinder * nf, const float * audio_stream, int head b = i; a = j; } + float newp = avgloop( nf->note_positions[a], nf->note_amplitudes[a], nf->note_positions[b], nf->note_amplitudes[b], freqbins ); + //Combine B into A. nf->note_amplitudes[a] += nf->note_amplitudes[b]; - nf->note_positions[a] = avgloop( nf->note_positions[a], nf->note_amplitudes[a], nf->note_positions[b], nf->note_amplitudes[b], freqbins ); + nf->note_positions[a] = newp; nf->note_amplitudes[b] = 0; nf->note_positions[b] = -100; nf->enduring_note_id[b] = 0; diff --git a/parameters.c b/parameters.c index 49af649..22ba5b8 100644 --- a/parameters.c +++ b/parameters.c @@ -210,7 +210,7 @@ void SetParametersFromString( const char * string ) else { //p is an orphan. - printf( "Orp: %s %s\n", name, value ); +// printf( "Orp: %s %s\n", name, value ); struct Param ** n = (struct Param **)HashTableInsert( parameters, name, 0 ); *n = malloc( sizeof ( struct Param ) ); (*n)->orphan = 1;