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.

237 lines
6.0KB

  1. /*
  2. Copyright (C) 2011 Nasca Octavian Paul
  3. Author: Nasca Octavian Paul
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of version 2 of the GNU General Public License
  6. as published by the Free Software Foundation.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License (version 2) for more details.
  11. You should have received a copy of the GNU General Public License (version 2)
  12. along with this program; if not, write to the Free Software Foundation,
  13. Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  14. */
  15. #pragma once
  16. #include "FreeEdit.h"
  17. #include "Stretch.h"
  18. struct ProcessParameters
  19. {
  20. ProcessParameters()
  21. {
  22. pitch_shift.enabled=false;
  23. pitch_shift.cents=0;
  24. octave.enabled=false;
  25. octave.om2=octave.om1=octave.o1=octave.o15=octave.o2=0.0f;
  26. octave.o0=1.0f;
  27. freq_shift.enabled=false;
  28. freq_shift.Hz=0;
  29. compressor.enabled=false;
  30. compressor.power=0.0f;
  31. filter.enabled=false;
  32. filter.stop=false;
  33. filter.low=0.0f;
  34. filter.high=22000.0f;
  35. filter.hdamp=0.0f;
  36. harmonics.enabled=false;
  37. harmonics.freq=440.0f;
  38. harmonics.bandwidth=25.0f;
  39. harmonics.nharmonics=10;
  40. harmonics.gauss=false;
  41. spread.enabled=false;
  42. spread.bandwidth=0.3f;
  43. tonal_vs_noise.enabled=false;
  44. tonal_vs_noise.preserve=0.5f;
  45. tonal_vs_noise.bandwidth=0.9f;
  46. };
  47. ~ProcessParameters(){
  48. };
  49. struct{
  50. bool enabled;
  51. int cents;
  52. }pitch_shift;
  53. struct{
  54. bool enabled;
  55. REALTYPE om2,om1,o0,o1,o15,o2;
  56. }octave;
  57. struct{
  58. bool enabled;
  59. int Hz;
  60. }freq_shift;
  61. struct{
  62. bool enabled;
  63. REALTYPE power;
  64. }compressor;
  65. struct{
  66. bool enabled;
  67. REALTYPE low,high;
  68. REALTYPE hdamp;
  69. bool stop;
  70. }filter;
  71. struct{
  72. bool enabled;
  73. REALTYPE freq;
  74. REALTYPE bandwidth;
  75. int nharmonics;
  76. bool gauss;
  77. }harmonics;
  78. struct{
  79. bool enabled;
  80. REALTYPE bandwidth;
  81. }spread;
  82. struct{
  83. bool enabled;
  84. REALTYPE preserve;
  85. REALTYPE bandwidth;
  86. }tonal_vs_noise;
  87. //FreeEdit free_filter;
  88. //FreeEdit stretch_multiplier;
  89. /*
  90. auto getMembers() const
  91. {
  92. return std::make_tuple(pitch_shift.enabled,
  93. pitch_shift.cents,
  94. octave.enabled,
  95. octave.o0,
  96. octave.o1,
  97. octave.o15,
  98. octave.o2,
  99. octave.om1,
  100. octave.om2,
  101. spread.enabled,
  102. spread.bandwidth,
  103. tonal_vs_noise.enabled,
  104. tonal_vs_noise.bandwidth,
  105. tonal_vs_noise.preserve,
  106. freq_shift.enabled,
  107. freq_shift.Hz,
  108. compressor.enabled,
  109. compressor.power,
  110. harmonics.bandwidth,
  111. harmonics.enabled,
  112. harmonics.freq,
  113. harmonics.gauss,
  114. harmonics.nharmonics,
  115. filter.enabled,
  116. filter.hdamp,
  117. filter.high,
  118. filter.low,
  119. filter.stop);
  120. }
  121. bool operator == (const ProcessParameters& other) const
  122. {
  123. return getMembers() == other.getMembers();
  124. }
  125. */
  126. bool operator == (const ProcessParameters& other) const noexcept
  127. {
  128. return pitch_shift.enabled == other.pitch_shift.enabled &&
  129. pitch_shift.cents == other.pitch_shift.cents &&
  130. octave.enabled == other.octave.enabled &&
  131. octave.o0 == other.octave.o0 &&
  132. octave.o1 == other.octave.o1 &&
  133. octave.o15 == other.octave.o15 &&
  134. octave.o2 == other.octave.o2 &&
  135. octave.om1 == other.octave.om1 &&
  136. octave.om2 == other.octave.om2 &&
  137. spread.enabled == other.spread.enabled &&
  138. spread.bandwidth == other.spread.bandwidth &&
  139. tonal_vs_noise.enabled == other.tonal_vs_noise.enabled &&
  140. tonal_vs_noise.bandwidth == other.tonal_vs_noise.bandwidth &&
  141. tonal_vs_noise.preserve == other.tonal_vs_noise.preserve &&
  142. freq_shift.enabled == other.freq_shift.enabled &&
  143. freq_shift.Hz == other.freq_shift.Hz &&
  144. compressor.enabled == other.compressor.enabled &&
  145. compressor.power == other.compressor.power &&
  146. harmonics.bandwidth == other.harmonics.bandwidth &&
  147. harmonics.enabled == other.harmonics.enabled &&
  148. harmonics.freq == other.harmonics.freq &&
  149. harmonics.gauss == other.harmonics.gauss &&
  150. harmonics.nharmonics == other.harmonics.nharmonics &&
  151. filter.enabled == other.filter.enabled &&
  152. filter.hdamp == other.filter.hdamp &&
  153. filter.high == other.filter.high &&
  154. filter.low == other.filter.low &&
  155. filter.stop == other.filter.stop;
  156. }
  157. };
  158. class SpectrumProcess
  159. {
  160. public:
  161. SpectrumProcess() {}
  162. SpectrumProcess(String name, int index) :
  163. m_name(name), m_index(index) {}
  164. String m_name;
  165. int m_index = -1;
  166. private:
  167. };
  168. std::vector<SpectrumProcess> make_spectrum_processes();
  169. class ProcessedStretch final : public Stretch
  170. {
  171. public:
  172. //stereo_mode: 0=mono,1=left,2=right
  173. ProcessedStretch(REALTYPE rap_,int in_bufsize_,FFTWindow w=W_HAMMING,bool bypass_=false,REALTYPE samplerate_=44100.0f,int stereo_mode=0);
  174. ~ProcessedStretch();
  175. void set_parameters(ProcessParameters *ppar);
  176. std::vector<int> m_spectrum_processes;
  177. void setBufferSize(int sz) override;
  178. private:
  179. REALTYPE get_stretch_multiplier(REALTYPE pos_percents) override;
  180. // void process_output(REALTYPE *smps,int nsmps);
  181. void process_spectrum(REALTYPE *freq) override;
  182. void do_harmonics(REALTYPE *freq1,REALTYPE *freq2);
  183. void do_pitch_shift(REALTYPE *freq1,REALTYPE *freq2,REALTYPE rap);
  184. void do_freq_shift(REALTYPE *freq1,REALTYPE *freq2);
  185. void do_octave(REALTYPE *freq1,REALTYPE *freq2);
  186. void do_filter(REALTYPE *freq1,REALTYPE *freq2);
  187. void do_free_filter(REALTYPE *freq1,REALTYPE *freq2);
  188. void do_compressor(REALTYPE *freq1,REALTYPE *freq2);
  189. void do_spread(REALTYPE *freq1,REALTYPE *freq2);
  190. void do_tonal_vs_noise(REALTYPE *freq1,REALTYPE *freq2);
  191. //void copy(const realvector& freq1,realvector& freq2);
  192. void copy(REALTYPE* freq1, REALTYPE* freq2);
  193. void add(REALTYPE *freq2,REALTYPE *freq1,REALTYPE a=1.0);
  194. void mul(REALTYPE *freq1,REALTYPE a);
  195. void zero(REALTYPE *freq1);
  196. void spread(REALTYPE *freq1,REALTYPE *freq2,REALTYPE spread_bandwidth);
  197. void update_free_filter();
  198. int nfreq=0;
  199. std::vector<REALTYPE> free_filter_freqs;
  200. ProcessParameters pars;
  201. std::vector<REALTYPE> infreq,sumfreq,tmpfreq1,tmpfreq2;
  202. //REALTYPE *fbfreq;
  203. };