Make the incomplete MIDIToneGenerator project work with up to three notes, using...
[pub/lufa.git] / Projects / Incomplete / MIDIToneGenerator / MIDIToneGenerator.h
index c064437..2936ca2 100644 (file)
                /** LED mask for the library LED driver, to indicate that an error has occurred in the USB interface. */\r
                #define LEDMASK_USB_ERROR        (LEDS_LED1 | LEDS_LED3)\r
                \r
-               #define SCALE_FACTOR             65536\r
-               #define BASE_FREQUENCY           27.5\r
-               #define NOTE_OCTIVE_RATIO        1.05946\r
-               #define BASE_PITCH_INDEX         21\r
-               #define MAX_SIMULTANEOUS_NOTES   3\r
+               /** Scale factor used to convert the floating point frequencies and ratios into a fixed point number */\r
+               #define SCALE_FACTOR               65536\r
                \r
-               #define BASE_INCREMENT           (((F_CPU / 255 / 2) / BASE_FREQUENCY))\r
+               /** Base (lowest) allowable MIDI note frequency */\r
+               #define BASE_FREQUENCY             27.5\r
                \r
+               /** Ratio between each note in an octave */\r
+               #define NOTE_OCTIVE_RATIO          1.05946\r
+               \r
+               /** Lowest valid MIDI pitch index */\r
+               #define BASE_PITCH_INDEX           21\r
+               \r
+               /** Maximum number of MIDI notes that can be played simultaneously */\r
+               #define MAX_SIMULTANEOUS_NOTES     3\r
+               \r
+               /** Number of samples in the virtual sample table (can be expanded to lower maximum frequency, but allow for\r
+                *  more simultaneous notes due to the reduced amount of processing time needed when the samples are spaced out)\r
+                */\r
+               #define VIRTUAL_SAMPLE_TABLE_SIZE  512\r
+               \r
+               /** Sample table increments per period for the base MIDI note frequency */\r
+               #define BASE_INCREMENT             (((F_CPU / VIRTUAL_SAMPLE_TABLE_SIZE / 2) / BASE_FREQUENCY))\r
+\r
+       /* Type Defines: */\r
+               typedef struct\r
+               {\r
+                       uint8_t  LRUAge;\r
+                       uint8_t  Pitch;\r
+                       uint32_t TableIncrement;\r
+                       uint32_t TablePosition;\r
+               } DDSNoteData;          \r
+\r
        /* Function Prototypes: */\r
                void SetupHardware(void);\r
                \r