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.

129 lines
3.6KB

  1. /*
  2. Copyright (C) 2006-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. #ifndef STRETCH_H
  16. #define STRETCH_H
  17. #include "globals.h"
  18. #ifdef KISSFFT
  19. #include <kiss_fftr.h>
  20. #else
  21. #include <fftw3.h>
  22. #endif
  23. enum FFTWindow{W_RECTANGULAR,W_HAMMING,W_HANN,W_BLACKMAN,W_BLACKMAN_HARRIS};
  24. class FFT{//FFT class that considers phases as random
  25. public:
  26. FFT(int nsamples_);//samples must be even
  27. ~FFT();
  28. void smp2freq();//input is smp, output is freq (phases are discarded)
  29. void freq2smp();//input is freq,output is smp (phases are random)
  30. void applywindow(FFTWindow type);
  31. REALTYPE *smp;//size of samples/2
  32. REALTYPE *freq;//size of samples
  33. int nsamples;
  34. private:
  35. #ifdef KISSFFT
  36. kiss_fftr_cfg plankfft,plankifft;
  37. kiss_fft_scalar *datar;
  38. kiss_fft_cpx *datac;
  39. #else
  40. fftwf_plan planfftw,planifftw;
  41. REALTYPE *data;
  42. #endif
  43. struct{
  44. REALTYPE *data;
  45. FFTWindow type;
  46. }window;
  47. unsigned int rand_seed;
  48. static unsigned int start_rand_seed;
  49. };
  50. class Stretch{
  51. public:
  52. Stretch(REALTYPE rap_,int in_bufsize_,FFTWindow w=W_HAMMING,bool bypass_=false,REALTYPE samplerate_=44100,int stereo_mode_=0);
  53. //in_bufsize is also a half of a FFT buffer (in samples)
  54. virtual ~Stretch();
  55. int get_max_bufsize(){
  56. return bufsize*3;
  57. };
  58. int get_bufsize(){
  59. return bufsize;
  60. };
  61. REALTYPE get_onset_detection_sensitivity(){
  62. return onset_detection_sensitivity;
  63. };
  64. REALTYPE process(REALTYPE *smps,int nsmps);//returns the onset value
  65. void set_freezing(bool new_freezing){
  66. freezing=new_freezing;
  67. };
  68. REALTYPE *out_buf;//pot sa pun o variabila "max_out_bufsize" si asta sa fie marimea lui out_buf si pe out_bufsize sa il folosesc ca marime adaptiva
  69. int get_nsamples(REALTYPE current_pos_percents);//how many samples are required
  70. int get_nsamples_for_fill();//how many samples are required to be added for a complete buffer refill (at start of the song or after seek)
  71. int get_skip_nsamples();//used for shorten
  72. void set_rap(REALTYPE newrap);//set the current stretch value
  73. void set_onset_detection_sensitivity(REALTYPE detection_sensitivity){
  74. onset_detection_sensitivity=detection_sensitivity;
  75. if (detection_sensitivity<1e-3) extra_onset_time_credit=0.0;
  76. };
  77. void here_is_onset(REALTYPE onset);
  78. FFTWindow window_type;
  79. protected:
  80. int bufsize;
  81. virtual void process_spectrum(REALTYPE *freq){};
  82. virtual REALTYPE get_stretch_multiplier(REALTYPE pos_percents);
  83. REALTYPE samplerate;
  84. int stereo_mode;//0=mono,1=left,2=right
  85. private:
  86. void do_analyse_inbuf(REALTYPE *smps);
  87. void do_next_inbuf_smps(REALTYPE *smps);
  88. REALTYPE do_detect_onset();
  89. // REALTYPE *in_pool;//de marimea in_bufsize
  90. REALTYPE rap,onset_detection_sensitivity;
  91. REALTYPE *old_out_smps;
  92. REALTYPE *old_freq;
  93. REALTYPE *new_smps,*old_smps,*very_old_smps;
  94. FFT *infft,*outfft;
  95. FFT *fft;
  96. long double remained_samples;//0..1
  97. long double extra_onset_time_credit;
  98. REALTYPE c_pos_percents;
  99. int skip_samples;
  100. bool require_new_buffer;
  101. bool bypass,freezing;
  102. };
  103. #endif