12-polyphonic "chiptune" MIDI synthesizer for LPC1768 (Standalone version)
Dependencies: ClockControl PowerControl mbed
Instrument.h@6:cda45a5e723e, 2014-12-23 (annotated)
- Committer:
- kayekss
- Date:
- Tue Dec 23 21:50:53 2014 +0000
- Revision:
- 6:cda45a5e723e
- Parent:
- 4:b2423ad4b248
Supports "Panic on offline" feature when using MIDI-port input
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kayekss | 0:727737138ac5 | 1 | #ifndef INSTRUMENT_H_ |
kayekss | 0:727737138ac5 | 2 | #define INSTRUMENT_H_ |
kayekss | 0:727737138ac5 | 3 | |
kayekss | 0:727737138ac5 | 4 | #include <stdint.h> |
kayekss | 0:727737138ac5 | 5 | #include "Wavetable.h" |
kayekss | 0:727737138ac5 | 6 | |
kayekss | 0:727737138ac5 | 7 | class Instrument { |
kayekss | 0:727737138ac5 | 8 | private: |
kayekss | 0:727737138ac5 | 9 | uint16_t samplingRate; // sampling rate |
kayekss | 0:727737138ac5 | 10 | uint8_t channelId; // channel ID |
kayekss | 0:727737138ac5 | 11 | bool enableFlag; // enable flag (whether this instrument is enabled) |
kayekss | 0:727737138ac5 | 12 | int32_t soundingPosition; // currently sounding note position |
kayekss | 0:727737138ac5 | 13 | uint32_t duration; // sounding duration |
kayekss | 0:727737138ac5 | 14 | Wavetable::wave_t wave; // wave parameters |
kayekss | 0:727737138ac5 | 15 | uint16_t frequency; // wave frequency |
kayekss | 0:727737138ac5 | 16 | uint8_t masterVolume; // + master volume |
kayekss | 0:727737138ac5 | 17 | uint8_t volume; // |- volume |
kayekss | 0:727737138ac5 | 18 | uint8_t expression; // |- expression (volume multiplier) |
kayekss | 0:727737138ac5 | 19 | uint8_t velocity; // |- note velocity (volume multiplier) |
kayekss | 0:727737138ac5 | 20 | uint16_t phase; // current phase (x256) |
kayekss | 0:727737138ac5 | 21 | uint16_t phaseDelta; // phase delta per sample (x256) |
kayekss | 0:727737138ac5 | 22 | |
kayekss | 0:727737138ac5 | 23 | public: |
kayekss | 0:727737138ac5 | 24 | Instrument(); |
kayekss | 0:727737138ac5 | 25 | ~Instrument(); |
kayekss | 0:727737138ac5 | 26 | |
kayekss | 0:727737138ac5 | 27 | void enable(); |
kayekss | 0:727737138ac5 | 28 | void disable(); |
kayekss | 0:727737138ac5 | 29 | void setSamplingRate(uint16_t); |
kayekss | 0:727737138ac5 | 30 | void advancePhase(); |
kayekss | 0:727737138ac5 | 31 | void resetPhase(); |
kayekss | 0:727737138ac5 | 32 | void setWave(Wavetable::wave_t); |
kayekss | 0:727737138ac5 | 33 | void setFrequency(uint16_t); |
kayekss | 0:727737138ac5 | 34 | void setVolume(uint8_t); |
kayekss | 0:727737138ac5 | 35 | void setExpression(uint8_t); |
kayekss | 0:727737138ac5 | 36 | void setVelocity(uint8_t); |
kayekss | 4:b2423ad4b248 | 37 | void resetDuration(); |
kayekss | 0:727737138ac5 | 38 | |
kayekss | 0:727737138ac5 | 39 | uint16_t getSamplingRate(); |
kayekss | 0:727737138ac5 | 40 | uint8_t getChannelId(); |
kayekss | 0:727737138ac5 | 41 | bool isEnable(); |
kayekss | 0:727737138ac5 | 42 | int16_t getSoundingPosition(); |
kayekss | 0:727737138ac5 | 43 | uint32_t getDuration(); |
kayekss | 0:727737138ac5 | 44 | Wavetable::wave_t getWave(); |
kayekss | 0:727737138ac5 | 45 | uint16_t getFrequency(); |
kayekss | 0:727737138ac5 | 46 | uint8_t getMasterVolume(); |
kayekss | 0:727737138ac5 | 47 | uint8_t getVolume(); |
kayekss | 0:727737138ac5 | 48 | uint8_t getExpression(); |
kayekss | 0:727737138ac5 | 49 | uint8_t getVelocity(); |
kayekss | 0:727737138ac5 | 50 | uint16_t getPhase(); |
kayekss | 0:727737138ac5 | 51 | uint16_t getPhaseDelta(); |
kayekss | 0:727737138ac5 | 52 | |
kayekss | 0:727737138ac5 | 53 | private: |
kayekss | 0:727737138ac5 | 54 | void calculatePhaseDelta(); |
kayekss | 0:727737138ac5 | 55 | void calculateMasterVolume(); |
kayekss | 0:727737138ac5 | 56 | }; |
kayekss | 0:727737138ac5 | 57 | |
kayekss | 0:727737138ac5 | 58 | #endif |