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.

98 lines
3.0KB

  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. void process(REALTYPE *smps,int nsmps);
  56. // virtual void process_output(REALTYPE *smps,int nsmps){};
  57. int in_bufsize;
  58. int poolsize;//how many samples are inside the input_pool size (need to know how many samples to fill when seeking)
  59. int out_bufsize;
  60. 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
  61. int get_nsamples(REALTYPE current_pos_percents);//how many samples are required to be added in the pool next time
  62. 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)
  63. void set_rap(REALTYPE newrap);//set the current stretch value
  64. FFTWindow window_type;
  65. protected:
  66. virtual void process_spectrum(REALTYPE *freq){};
  67. virtual REALTYPE get_stretch_multiplier(REALTYPE pos_percents);
  68. REALTYPE samplerate;
  69. int stereo_mode;//0=mono,1=left,2=right
  70. private:
  71. REALTYPE *in_pool;//de marimea in_bufsize
  72. REALTYPE rap;
  73. REALTYPE *old_out_smp_buf;
  74. FFT *infft,*outfft;
  75. long double remained_samples;//how many fraction of samples has remained (0..1)
  76. bool bypass;
  77. };
  78. #endif