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.

147 lines
4.4KB

  1. /*
  2. Copyright (C) 2009 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. #include <math.h>
  16. #include <stdlib.h>
  17. #include <stdio.h>
  18. #include "ProcessedStretch.h"
  19. ProcessedStretch::ProcessedStretch(REALTYPE rap_,int in_bufsize_,FFTWindow w,bool bypass_,REALTYPE samplerate_,int stereo_mode_)
  20. : Stretch(rap_,in_bufsize_,w,bypass_,samplerate_,stereo_mode_)
  21. {
  22. };
  23. ProcessedStretch::~ProcessedStretch()
  24. {
  25. };
  26. void ProcessedStretch::set_parameters(ProcessParameters *ppar)
  27. {
  28. pars=*ppar;
  29. //update_free_filter();
  30. }
  31. void ProcessedStretch::setFreeFilterEnvelope(shared_envelope env)
  32. {
  33. m_free_filter_envelope = env;
  34. }
  35. void ProcessedStretch::setBufferSize(int sz)
  36. {
  37. jassert(sz > 0);
  38. Stretch::setBufferSize(sz);
  39. //if (nfreq != sz)
  40. {
  41. nfreq = bufsize;
  42. m_infreq = floatvector(nfreq);
  43. m_sumfreq = floatvector(nfreq);
  44. m_tmpfreq1 = floatvector(nfreq);
  45. m_tmpfreq2 = floatvector(nfreq);
  46. m_free_filter_freqs = floatvector(nfreq);
  47. fill_container(m_free_filter_freqs, 1.0f);
  48. }
  49. }
  50. void ProcessedStretch::copy(REALTYPE* freq1, REALTYPE* freq2)
  51. {
  52. for (int i = 0; i<nfreq; i++) freq2[i] = freq1[i];
  53. };
  54. void ProcessedStretch::add(REALTYPE *freq2,REALTYPE *freq1,REALTYPE a){
  55. for (int i=0;i<nfreq;i++) freq2[i]+=freq1[i]*a;
  56. };
  57. void ProcessedStretch::mul(REALTYPE *freq1,REALTYPE a){
  58. for (int i=0;i<nfreq;i++) freq1[i]*=a;
  59. };
  60. void ProcessedStretch::zero(REALTYPE *freq1){
  61. for (int i=0;i<nfreq;i++) freq1[i]=0.0;
  62. };
  63. REALTYPE ProcessedStretch::get_stretch_multiplier(REALTYPE pos_percents){
  64. REALTYPE result=1.0;
  65. /*
  66. if (pars.stretch_multiplier.get_enabled()){
  67. result*=pars.stretch_multiplier.get_value(pos_percents);
  68. };
  69. */
  70. ///REALTYPE transient=pars.get_transient(pos_percents);
  71. ///printf("\n%g\n",transient);
  72. ///REALTYPE threshold=0.05;
  73. ///REALTYPE power=1000.0;
  74. ///transient-=threshold;
  75. ///if (transient>0){
  76. /// transient*=power*(1.0+power);
  77. /// result/=(1.0+transient);
  78. ///};
  79. ///printf("tr=%g\n",result);
  80. return result;
  81. };
  82. void ProcessedStretch::process_spectrum(REALTYPE *freq)
  83. {
  84. for (auto& e : m_spectrum_processes)
  85. {
  86. spectrum_copy(nfreq, freq, m_infreq.data());
  87. if (e.m_index == SPT_Harmonics && *e.m_enabled == true)
  88. spectrum_do_harmonics(pars, m_tmpfreq1, nfreq, samplerate, m_infreq.data(), freq);
  89. if (e.m_index == SPT_TonalVsNoise && *e.m_enabled == true)
  90. spectrum_do_tonal_vs_noise(pars,nfreq,samplerate,m_tmpfreq1, m_infreq.data(), freq);
  91. if (e.m_index == SPT_FreqShift && *e.m_enabled == true)
  92. spectrum_do_freq_shift(pars,nfreq,samplerate,m_infreq.data(), freq);
  93. if (e.m_index == SPT_PitchShift && *e.m_enabled == true)
  94. spectrum_do_pitch_shift(pars,nfreq,m_infreq.data(), freq, pow(2.0f, pars.pitch_shift.cents / 1200.0f));
  95. if (e.m_index == SPT_RatioMix && *e.m_enabled == true)
  96. spectrum_do_ratiomix(pars,nfreq,samplerate, m_sumfreq, m_tmpfreq1, m_infreq.data(), freq);
  97. if (e.m_index == SPT_Spread && *e.m_enabled == true)
  98. spectrum_spread(nfreq,samplerate,m_tmpfreq1,m_infreq.data(), freq, pars.spread.bandwidth);
  99. if (e.m_index == SPT_Filter && *e.m_enabled == true)
  100. spectrum_do_filter(pars,nfreq,samplerate,m_infreq.data(), freq);
  101. if (e.m_index == SPT_Compressor && *e.m_enabled == true)
  102. spectrum_do_compressor(pars,nfreq, m_infreq.data(), freq);
  103. if (e.m_index == SPT_FreeFilter && *e.m_enabled == true)
  104. spectrum_do_free_filter(m_free_filter_envelope, nfreq, samplerate, m_infreq.data(), freq);
  105. }
  106. };
  107. //void ProcessedStretch::process_output(REALTYPE *smps,int nsmps){
  108. //};
  109. void ProcessedStretch::update_free_filter()
  110. {
  111. /*
  112. pars.free_filter.update_curve();
  113. if (pars.free_filter.get_enabled()) {
  114. for (int i=0;i<nfreq;i++){
  115. REALTYPE freq=(REALTYPE)i/(REALTYPE) nfreq*samplerate*0.5f;
  116. free_filter_freqs[i]=pars.free_filter.get_value(freq);
  117. };
  118. }else{
  119. for (int i=0;i<nfreq;i++){
  120. free_filter_freqs[i]=1.0f;
  121. };
  122. };
  123. */
  124. };