aboutsummaryrefslogtreecommitdiffstats
path: root/Projects/Incomplete/MIDIToneGenerator/MIDIToneGenerator.h
diff options
context:
space:
mode:
authorDean Camera <dean@fourwalledcubicle.com>2010-11-25 02:46:35 +0000
committerDean Camera <dean@fourwalledcubicle.com>2010-11-25 02:46:35 +0000
commitfd77bf5c9459360b8d3ae1679dfab71169d4a982 (patch)
treeb11da5c16536cbee1ae974cb15eabda5f7bc9640 /Projects/Incomplete/MIDIToneGenerator/MIDIToneGenerator.h
parent857a82674f1e15b3a8394a61ea3592e4d5e9afe5 (diff)
downloadlufa-fd77bf5c9459360b8d3ae1679dfab71169d4a982.tar.gz
lufa-fd77bf5c9459360b8d3ae1679dfab71169d4a982.tar.bz2
lufa-fd77bf5c9459360b8d3ae1679dfab71169d4a982.zip
Make the incomplete MIDIToneGenerator project work with up to three notes, using a LRU (Least Recently Used) algorithm to discard the oldest set note when the note table becomes full.
Diffstat (limited to 'Projects/Incomplete/MIDIToneGenerator/MIDIToneGenerator.h')
-rw-r--r--Projects/Incomplete/MIDIToneGenerator/MIDIToneGenerator.h36
1 files changed, 30 insertions, 6 deletions
diff --git a/Projects/Incomplete/MIDIToneGenerator/MIDIToneGenerator.h b/Projects/Incomplete/MIDIToneGenerator/MIDIToneGenerator.h
index c0644374a..2936ca2c7 100644
--- a/Projects/Incomplete/MIDIToneGenerator/MIDIToneGenerator.h
+++ b/Projects/Incomplete/MIDIToneGenerator/MIDIToneGenerator.h
@@ -65,14 +65,38 @@
/** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */
#define LEDMASK_USB_ERROR (LEDS_LED1 | LEDS_LED3)
- #define SCALE_FACTOR 65536
- #define BASE_FREQUENCY 27.5
- #define NOTE_OCTIVE_RATIO 1.05946
- #define BASE_PITCH_INDEX 21
- #define MAX_SIMULTANEOUS_NOTES 3
+ /** Scale factor used to convert the floating point frequencies and ratios into a fixed point number */
+ #define SCALE_FACTOR 65536
- #define BASE_INCREMENT (((F_CPU / 255 / 2) / BASE_FREQUENCY))
+ /** Base (lowest) allowable MIDI note frequency */
+ #define BASE_FREQUENCY 27.5
+ /** Ratio between each note in an octave */
+ #define NOTE_OCTIVE_RATIO 1.05946
+
+ /** Lowest valid MIDI pitch index */
+ #define BASE_PITCH_INDEX 21
+
+ /** Maximum number of MIDI notes that can be played simultaneously */
+ #define MAX_SIMULTANEOUS_NOTES 3
+
+ /** Number of samples in the virtual sample table (can be expanded to lower maximum frequency, but allow for
+ * more simultaneous notes due to the reduced amount of processing time needed when the samples are spaced out)
+ */
+ #define VIRTUAL_SAMPLE_TABLE_SIZE 512
+
+ /** Sample table increments per period for the base MIDI note frequency */
+ #define BASE_INCREMENT (((F_CPU / VIRTUAL_SAMPLE_TABLE_SIZE / 2) / BASE_FREQUENCY))
+
+ /* Type Defines: */
+ typedef struct
+ {
+ uint8_t LRUAge;
+ uint8_t Pitch;
+ uint32_t TableIncrement;
+ uint32_t TablePosition;
+ } DDSNoteData;
+
/* Function Prototypes: */
void SetupHardware(void);