No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

synth.h 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #ifndef SYNTH_H_
  2. #define SYNTH_H_
  3. #include <stdint.h>
  4. typedef uint32_t fixed;
  5. #define SYNTH_NUM_VOICES 16
  6. #define TUNING 440
  7. #include "envelope.h"
  8. #include "filter.h"
  9. #include "oscillator.h"
  10. #include "voice.h"
  11. #include "sineosc.h"
  12. struct Key {
  13. uint8_t note, velocity;
  14. };
  15. struct Synth {
  16. struct Voice voices[SYNTH_NUM_VOICES];
  17. float osc_attack, osc_decay, osc_sustain, osc_release;
  18. float filter_attack, filter_decay, filter_sustain, filter_release;
  19. float unison_spread;
  20. float stereo_spread;
  21. uint8_t monophonic;
  22. float tuning; // 440.0Hz
  23. float pitch_bend_range;
  24. float cutoff, filter_eg_intensity, filter_kbd_track, lfo_freq;
  25. // private
  26. struct SineOsc lfo_osc;
  27. struct Key key_stack[SYNTH_NUM_VOICES];
  28. uint8_t key_stack_size;
  29. float volume, pitch_bend, lfo_depth;
  30. uint32_t time;
  31. };
  32. void synth_init(struct Synth *synth);
  33. void synth_load_patch(struct Synth *synth, const char *filename);
  34. void synth_note_on(struct Synth *synth, uint8_t note, uint8_t velocity);
  35. void synth_note_off(struct Synth *synth, uint8_t note, uint8_t velocity);
  36. void synth_render_sample(struct Synth *synth, float *out);
  37. void synth_set_pulse_width(struct Synth *s, uint8_t width);
  38. void synth_set_unison_spread(struct Synth *s, uint8_t spread);
  39. void synth_set_stereo_spread(struct Synth *s, uint8_t spread);
  40. void synth_set_cutoff_freq(struct Synth *s, uint8_t freq);
  41. void synth_set_resonance(struct Synth *s, uint8_t res);
  42. void synth_set_volume(struct Synth *s, uint8_t vol);
  43. void synth_pitch_bend(struct Synth *s, int16_t bend);
  44. void synth_set_lfo_depth(struct Synth *s, uint8_t mod);
  45. #endif /* SYNTH_H_ */