MBRSynth.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #ifndef MBRSYNTH_H
  2. #define MBRSYNTH_H
  3. #include <string.h>
  4. #include <fstream>
  5. #include <iostream>
  6. #include <sstream>
  7. #include <sekai/EventList.h>
  8. #include <sekai/ControlTrack.h>
  9. #include <sekai/VoiceSampler.h>
  10. #include <sekai/SynthInterface.h>
  11. #define IMPULSE_RESPONSE_MAX 2048
  12. enum synthType
  13. {
  14. FVOX=0,
  15. UTAU=1,
  16. MBROLA=2,
  17. ESPEAK=3
  18. };
  19. struct MBRConfig
  20. {
  21. synthType type;
  22. int mbr_period;
  23. float frame_period;
  24. int fft_size;
  25. };
  26. class MBRSynth : public IUnisyn, public VoiceSampler {
  27. int _samplerate = 0;
  28. std::map<std::string, VoiceDef *> _voicemap;
  29. EventList<PhoEvent> _phoEvents;
  30. float *_impulseResponse;
  31. ControlTrack *_ctrl = nullptr;
  32. std::string _basedir;
  33. MBRConfig* _config = nullptr;
  34. FILE* _debugfile = nullptr;
  35. float _maxvol=0;
  36. void getImpulseResponse(float currentTime, PhoEvent *event,
  37. float *impulseResponse, int *impulseResponseLength,
  38. float morph);
  39. void load(const std::string &unit);
  40. public:
  41. virtual void addUnit(const std::string &basename, int, float *, float *);
  42. virtual void setBasedir(const std::string &basedir) { _basedir= basedir; }
  43. virtual bool saveWave(const std::string &filename);
  44. virtual void setConfig(MBRConfig* config){_config=config;}
  45. protected:
  46. virtual bool addOnePulse();
  47. virtual float getLengthForUnit(const std::string &fileName);
  48. virtual std::string getPhoLine(const std::string &fileName,int index);
  49. virtual void postProcess(float* data, int size);
  50. public:
  51. MBRSynth(ControlTrack *ctrl, int buffer_size = IMPULSE_RESPONSE_MAX * 4);
  52. int samplerate() { return _samplerate; }
  53. void fix();
  54. };
  55. #endif