synth.hpp 981 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #ifndef SYNTH
  2. #define SYNTH
  3. #include <vector>
  4. #include "sekai/VoiceSampler.h"
  5. #include "sekai/VoiceDefESPEAK.h"
  6. #define MAX_POLYPHONY 8
  7. class SynthRT: public VoiceSampler
  8. {
  9. public:
  10. SynthRT();
  11. VoiceDefESPEAK* voicedef;
  12. float period;
  13. bool enabled;
  14. float* impulse_response;
  15. int impulse_response_length;
  16. int samplerate;
  17. protected:
  18. bool addOnePulse();
  19. };
  20. class Synth
  21. {
  22. public:
  23. Synth();
  24. ~Synth();
  25. void init(int samplerate,int buffer_size);
  26. void noteOn(int notenum,int velocity);
  27. void noteOff(int notenum);
  28. void controllerEvent(int a1,int a2);
  29. void pitchBend(int a1,int a2);
  30. void fill(float* samples,int count);
  31. private:
  32. int samplerate=0;
  33. int buffer_size=0;
  34. char key[MAX_POLYPHONY];
  35. float freq[MAX_POLYPHONY];
  36. SynthRT* voice[MAX_POLYPHONY];
  37. int active_keys=0;
  38. //VoiceDefESPEAK* voicedef;
  39. float bend=0;
  40. float volume=1.0;
  41. int speed=64;
  42. };
  43. #endif