update : use 11025 Hz. also, fix overflow bug with combining notes

This commit is contained in:
cnlohr 2015-04-03 15:34:11 -04:00
parent f2a1086c97
commit 4f7eabb24e
4 changed files with 21 additions and 11 deletions

View file

@ -17,7 +17,7 @@ buffer = 128
play = 0 play = 0
rec = 1 rec = 1
channels = 2 channels = 2
samplerate = 8000 samplerate = 11025
wininput = 0 wininput = 0
#Compiled version will default this. #Compiled version will default this.

View file

@ -6,6 +6,7 @@ uint16_t fuzzed_bins[FIXBINS];
uint8_t note_peak_freqs[MAXNOTES]; uint8_t note_peak_freqs[MAXNOTES];
uint16_t note_peak_amps[MAXNOTES]; uint16_t note_peak_amps[MAXNOTES];
uint16_t note_peak_amps2[MAXNOTES]; uint16_t note_peak_amps2[MAXNOTES];
uint8_t note_jumped_to[MAXNOTES];
static const float bf_table[24] = { static const float bf_table[24] = {
@ -215,7 +216,7 @@ void HandleFrameInfo()
if( thisfreq > 255-(1<<SEMIBITSPERBIN) ) if( thisfreq > 255-(1<<SEMIBITSPERBIN) )
thisfreq = (1<<SEMIBITSPERBIN)*FIXBPERO - (256-thisfreq); thisfreq = (1<<SEMIBITSPERBIN)*FIXBPERO - (256-thisfreq);
//printf( "Peak At: %3d /(%2d) %4d/%4d/%4d\n", thisfreq, i,prev, this, next ); // printf( "---%3d /(%2d) %4d/%4d/%4d---", thisfreq, i,prev, this, next );
//Okay, we have a peak, and a frequency. Now, we need to search //Okay, we have a peak, and a frequency. Now, we need to search
//through the existing notes to see if we have any matches. //through the existing notes to see if we have any matches.
@ -314,11 +315,13 @@ void HandleFrameInfo()
uint32_t porp = (amp1<<15) / (amp1+amp2); uint32_t porp = (amp1<<15) / (amp1+amp2);
uint16_t newnote = (nf1 * porp + nf2 * (32768-porp))>>15; uint16_t newnote = (nf1 * porp + nf2 * (32768-porp))>>15;
note_peak_amps[i] = amp1 + amp2;
note_peak_amps[j] = 0;
note_peak_freqs[i] = newnote; note_peak_freqs[i] = newnote;
note_peak_amps[i] = (note_peak_amps[i]+note_peak_amps[j])>>1;
note_peak_amps2[i] = (note_peak_amps2[i]+note_peak_amps2[j])>>1;
note_peak_freqs[j] = 255; note_peak_freqs[j] = 255;
note_peak_amps2[i] += note_peak_amps2[j]; note_peak_amps[j] = 0;
note_jumped_to[j] = i;
} }
@ -338,7 +341,7 @@ void HandleFrameInfo()
} }
//We now have notes!!! //We now have notes!!!
#if 1 #if 0
for( i = 0; i < MAXNOTES; i++ ) for( i = 0; i < MAXNOTES; i++ )
{ {
if( note_peak_freqs[i] == 255 ) continue; if( note_peak_freqs[i] == 255 ) continue;
@ -350,10 +353,12 @@ void HandleFrameInfo()
#if 0 #if 0
for( i = 0; i < FIXBPERO; i++ ) for( i = 0; i < FIXBPERO; i++ )
{ {
printf( "%5d ", folded_bins[i] ); printf( "%4d ", folded_bins[i] );
} }
printf( "\n" ); printf( "\n" );
#endif #endif
} }

View file

@ -5,7 +5,10 @@
//they can multiply quickly, this is the bees knees. //they can multiply quickly, this is the bees knees.
#define USE_32DFT #define USE_32DFT
#ifndef DFREQ
#define DFREQ 8000 #define DFREQ 8000
#endif
#define BASE_FREQ 55.0 // You may make this a float. #define BASE_FREQ 55.0 // You may make this a float.
//The higher the number the slackier your FFT will be come. //The higher the number the slackier your FFT will be come.
@ -23,14 +26,14 @@
//This is the amplitude, coming from folded_bins. If the value is below this //This is the amplitude, coming from folded_bins. If the value is below this
//it is considered a non-note. //it is considered a non-note.
#define MIN_AMP_FOR_NOTE 128 #define MIN_AMP_FOR_NOTE 64
//If there is detected note this far away from an established note, we will //If there is detected note this far away from an established note, we will
//then consider this new note the same one as last time, and move the established //then consider this new note the same one as last time, and move the established
//note. This is also used when combining notes. It is this distance times two. //note. This is also used when combining notes. It is this distance times two.
#define MAX_JUMP_DISTANCE 7 #define MAX_JUMP_DISTANCE 7
#define MINIMUM_AMP_FOR_NOTE_TO_DISAPPEAR 64 #define MINIMUM_AMP_FOR_NOTE_TO_DISAPPEAR 32
#define AMP_1_NERFING_BITS 5 #define AMP_1_NERFING_BITS 5
#define AMP_2_NERFING_BITS 3 #define AMP_2_NERFING_BITS 3
@ -48,6 +51,8 @@ extern uint16_t fuzzed_bins[]; //[FIXBINS] <- The Full DFT after IIR, Blur and
extern uint8_t note_peak_freqs[]; extern uint8_t note_peak_freqs[];
extern uint16_t note_peak_amps[]; //[MAXNOTES] extern uint16_t note_peak_amps[]; //[MAXNOTES]
extern uint16_t note_peak_amps2[]; //[MAXNOTES] (Responds quicker) extern uint16_t note_peak_amps2[]; //[MAXNOTES] (Responds quicker)
extern uint8_t note_jumped_to[]; //[MAXNOTES] When a note combines into another one,
//this records where it went. I.e. if your note just disappeared, check this flag.
//XXX: TODO: Consider doing the fuzz IIR on the folded bins. That way we can //XXX: TODO: Consider doing the fuzz IIR on the folded bins. That way we can
//save several bytes of RAM on not having to keep fuzzed_bins around. //save several bytes of RAM on not having to keep fuzzed_bins around.

View file

@ -1,13 +1,13 @@
all : embeddedcc all : embeddedcc
CFLAGS:=-Ofast -DCCEMBEDDED -I.. -flto -m32 CFLAGS:=-Ofast -DCCEMBEDDED -I.. -flto -m32 -DDFREQ=11025
LDFLAGS:=-ffunction-sections -Wl,--gc-sections -fno-asynchronous-unwind-tables -Wl,--strip-all LDFLAGS:=-ffunction-sections -Wl,--gc-sections -fno-asynchronous-unwind-tables -Wl,--strip-all
embeddedcc : ../embeddednf.c ../DFT32.c embeddedcc.c embeddedcc : ../embeddednf.c ../DFT32.c embeddedcc.c
gcc -o $@ $^ $(CFLAGS) $(LDFLAGS) gcc -o $@ $^ $(CFLAGS) $(LDFLAGS)
runembedded : embeddedcc runembedded : embeddedcc
parec --format=u8 --rate=8000 --channels=1 --device=alsa_output.pci-0000_00_1b.0.analog-stereo.monitor | ./embeddedcc parec --format=u8 --rate=11025 --channels=1 --device=alsa_output.pci-0000_00_1b.0.analog-stereo.monitor | ./embeddedcc
clean : clean :
rm -rf embeddedcc *~ rm -rf embeddedcc *~