update : use 11025 Hz. also, fix overflow bug with combining notes
This commit is contained in:
parent
f2a1086c97
commit
4f7eabb24e
|
@ -17,7 +17,7 @@ buffer = 128
|
|||
play = 0
|
||||
rec = 1
|
||||
channels = 2
|
||||
samplerate = 8000
|
||||
samplerate = 11025
|
||||
wininput = 0
|
||||
|
||||
#Compiled version will default this.
|
||||
|
|
17
embeddednf.c
17
embeddednf.c
|
@ -6,6 +6,7 @@ uint16_t fuzzed_bins[FIXBINS];
|
|||
uint8_t note_peak_freqs[MAXNOTES];
|
||||
uint16_t note_peak_amps[MAXNOTES];
|
||||
uint16_t note_peak_amps2[MAXNOTES];
|
||||
uint8_t note_jumped_to[MAXNOTES];
|
||||
|
||||
|
||||
static const float bf_table[24] = {
|
||||
|
@ -215,7 +216,7 @@ void HandleFrameInfo()
|
|||
if( thisfreq > 255-(1<<SEMIBITSPERBIN) )
|
||||
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
|
||||
//through the existing notes to see if we have any matches.
|
||||
|
@ -314,11 +315,13 @@ void HandleFrameInfo()
|
|||
uint32_t porp = (amp1<<15) / (amp1+amp2);
|
||||
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_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_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!!!
|
||||
#if 1
|
||||
#if 0
|
||||
for( i = 0; i < MAXNOTES; i++ )
|
||||
{
|
||||
if( note_peak_freqs[i] == 255 ) continue;
|
||||
|
@ -350,10 +353,12 @@ void HandleFrameInfo()
|
|||
#if 0
|
||||
for( i = 0; i < FIXBPERO; i++ )
|
||||
{
|
||||
printf( "%5d ", folded_bins[i] );
|
||||
printf( "%4d ", folded_bins[i] );
|
||||
}
|
||||
printf( "\n" );
|
||||
#endif
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -5,7 +5,10 @@
|
|||
//they can multiply quickly, this is the bees knees.
|
||||
#define USE_32DFT
|
||||
|
||||
#ifndef DFREQ
|
||||
#define DFREQ 8000
|
||||
#endif
|
||||
|
||||
#define BASE_FREQ 55.0 // You may make this a float.
|
||||
|
||||
//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
|
||||
//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
|
||||
//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.
|
||||
#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_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 uint16_t note_peak_amps[]; //[MAXNOTES]
|
||||
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
|
||||
//save several bytes of RAM on not having to keep fuzzed_bins around.
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
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
|
||||
|
||||
embeddedcc : ../embeddednf.c ../DFT32.c embeddedcc.c
|
||||
gcc -o $@ $^ $(CFLAGS) $(LDFLAGS)
|
||||
|
||||
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 :
|
||||
rm -rf embeddedcc *~
|
||||
|
|
Loading…
Reference in a new issue