Swadge 2024 2.0.0
APIs to develop games for the Magfest Swadge
Loading...
Searching...
No Matches
embeddedNf.h
Go to the documentation of this file.
1// Copyright 2015 <>< Charles Lohr under the ColorChord License.
2
3#ifndef _EMBEDDED_NF_H
4#define _EMBEDDED_NF_H
5
6#include "ccconfig.h"
7
8// Use a 32-bit DFT. It won't work for AVRs, but for any 32-bit systems where
9// they can multiply quickly, this is the bees knees.
10#define USE_32DFT
11
12#ifndef D_FREQ
13 #define D_FREQ 8000
14#endif
15
16// You may make this a float. If PRECOMPUTE_FREQUENCY_TABLE is defined, then
17// it will create the table at compile time, and the float will never be used
18// runtime.
19#define BASE_FREQ 55.0
20
21// The higher the number the slackier your FFT will be come.
22#ifndef FUZZ_IIR_BITS
23 #define FUZZ_IIR_BITS 1
24#endif
25
26// Notes are the individually identifiable notes we receive from the sound.
27// We track up to this many at one time. Just because a note may appear to
28// vaporize in one frame doesn't mean it is annihilated immediately.
29#ifndef MAX_NOTES
30 #define MAX_NOTES 12
31#endif
32
33// We take the raw signal off of the
34#ifndef FILTER_BLUR_PASSES
35 #define FILTER_BLUR_PASSES 2
36#endif
37
38// Determines bit shifts for where notes lie. We represent notes with an
39// uint8_t. We have to define all of the possible locations on the note line
40// in this. note_frequency = 0..((1<<SEMI_BITS_PER_BIN)*FIX_B_PER_O-1)
41#ifndef SEMI_BITS_PER_BIN
42 #define SEMI_BITS_PER_BIN 3
43#endif
44
45#define NOTE_RANGE ((1 << SEMI_BITS_PER_BIN) * FIX_B_PER_O)
46
47// If there is detected note this far away from an established note, we will
48// then consider this new note the same one as last time, and move the
49// established note. This is also used when combining notes. It is this
50// distance times two.
51#ifndef MAX_JUMP_DISTANCE
52 #define MAX_JUMP_DISTANCE 4
53#endif
54
55#ifndef MAX_COMBINE_DISTANCE
56 #define MAX_COMBINE_DISTANCE 7
57#endif
58
59// These control how quickly the IIR for the note strengths respond. AMP 1 is
60// the response for the slow-response, or what we use to determine size of
61// splotches, AMP 2 is the quick response, or what we use to see the visual
62// strength of the notes.
63#ifndef AMP_1_IIR_BITS
64 #define AMP_1_IIR_BITS 4
65#endif
66
67#ifndef AMP_2_IIR_BITS
68 #define AMP_2_IIR_BITS 2
69#endif
70
71// This is the amplitude, coming from folded_bins. If the value is below this
72// it is considered a non-note.
73#ifndef MIN_AMP_FOR_NOTE
74 #define MIN_AMP_FOR_NOTE 80
75#endif
76
77// If the strength of a note falls below this, the note will disappear, and be
78// recycled back into the unused list of notes.
79#ifndef MINIMUM_AMP_FOR_NOTE_TO_DISAPPEAR
80 #define MINIMUM_AMP_FOR_NOTE_TO_DISAPPEAR 64
81#endif
82
83// This prevents compilation of any floating-point code, but it does come with
84// an added restriction: Both D_FREQ and BASE_FREQ must be #defined to be
85// constants.
86#define PRECOMPUTE_FREQUENCY_TABLE
87
88#include "DFT32.h"
89
90typedef struct
91{
92 uint16_t folded_bins[FIX_B_PER_O]; //<! The folded fourier output.
93 uint16_t fuzzed_bins[FIX_BINS]; //<! The Full DFT after IIR, Blur and Taper
94 // frequency of note; Note if it is == 255,
95 // then it means it is not set. It is
96 // generally a value from
97 uint8_t note_peak_frequencies[MAX_NOTES];
98 uint16_t note_peak_amps[MAX_NOTES];
99 uint16_t note_peak_amps2[MAX_NOTES]; // (Responds quicker)
100 uint8_t note_jumped_to[MAX_NOTES]; // When a note combines into another one,
101 // this records where it went. I.e. if
102 // your note just disappeared, check this
103 // flag.
105
106void UpdateFrequencies(dft32_data* dd); // Not user-useful on most systems.
107void HandleFrameInfo(embeddedNf_data* ed, dft32_data* dd); // Not user-useful on most systems
108
109// Call this when starting.
111
112#endif
#define FIX_BINS
Definition DFT32.h:34
#define FIX_B_PER_O
Definition DFT32.h:30
Definition DFT32.h:55
void HandleFrameInfo(embeddedNf_data *ed, dft32_data *dd)
TODO.
Definition embeddedNf.c:123
#define MAX_NOTES
Definition embeddedNf.h:30
void UpdateFrequencies(dft32_data *dd)
TODO.
Definition embeddedNf.c:52
void InitColorChord(embeddedNf_data *ed, dft32_data *dd)
Definition embeddedNf.c:91
Definition embeddedNf.h:91