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.

153 lines
4.3KB

  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. #pragma once
  16. #include "globals.h"
  17. #include "Input/AInputS.h"
  18. #include "ProcessedStretch.h"
  19. #include "BinauralBeats.h"
  20. #include "StretchSource.h"
  21. #include "../JuceLibraryCode/JuceHeader.h"
  22. #include "../ps3_BufferingAudioSource.h"
  23. class RenderInfo
  24. {
  25. public:
  26. double m_progress_percent = 0.0;
  27. double m_elapsed_time = 0.0;
  28. std::atomic<bool> m_cancel{ false };
  29. String m_txt;
  30. };
  31. using RenderInfoRef = std::shared_ptr<RenderInfo>;
  32. class RenderParameters
  33. {
  34. public:
  35. File inaudio;
  36. File outaudio;
  37. double pos1 = 0.0;
  38. double pos2 = 1.0;
  39. int64_t numLoops = 0;
  40. int wavformat = 2;
  41. int sampleRate = 0;
  42. int numoutchans = 2;
  43. double minrenderlen = 1.0;
  44. double maxrenderlen = 1000000.0;
  45. double voldb = 0.0;
  46. bool clipFloatOutput = true;
  47. std::function<void(RenderInfoRef)> completion_callback;
  48. };
  49. #ifdef USEPSCONTROL
  50. class Control
  51. {
  52. public:
  53. Control(AudioFormatManager* afm);
  54. ~Control();
  55. void processAudio(AudioBuffer<float>& buf);
  56. void startplay(bool bypass, bool realtime, Range<double> playrange, int numoutchans, String& err);
  57. void stopplay();
  58. void set_seek_pos(REALTYPE x);
  59. REALTYPE get_seek_pos();
  60. double getLivePlayPosition();
  61. bool playing();
  62. void setStretchAmount(double rate);
  63. void setFFTSize(double size);
  64. int getFFTSize() { return m_fft_size_to_use; }
  65. void setOnsetDetection(double x);
  66. StretchAudioSource* getStretchAudioSource() { return m_stretch_source.get(); }
  67. void set_input_file(File filename, std::function<void(String)> cb);//return non empty String if the file cannot be opened
  68. String get_input_filename();
  69. String get_stretch_info(Range<double> playrange);
  70. double getPreBufferingPercent();
  71. double get_stretch()
  72. {
  73. return process.stretch;
  74. };
  75. double get_onset_detection_sensitivity()
  76. {
  77. return process.onset_detection_sensitivity;
  78. };
  79. void set_stretch_controls(double stretch_s,int mode,double fftsize_s,double onset_detection_sensitivity);//*_s sunt de la 0.0 la 1.0
  80. double get_stretch_control(double stretch,int mode);
  81. void update_player_stretch();
  82. void set_window_type(FFTWindow window);
  83. /// void pre_analyse_whole_audio(InputS *ai);
  84. RenderInfoRef Render2(RenderParameters renpars);
  85. ProcessParameters ppar;
  86. BinauralBeatsParameters bbpar;
  87. void update_process_parameters();//pt. player
  88. struct{
  89. double fftsize_s,stretch_s;
  90. int mode_s;
  91. }gui_sliders;
  92. FFTWindow window_type;
  93. void setPreBufferAmount(int x);
  94. int getPreBufferAmount() { return m_prebuffer_amount; }
  95. double getPreBufferAmountSeconds();
  96. bool isResampling()
  97. {
  98. return m_stretch_source->isResampling();
  99. }
  100. void setAudioVisualizer(AudioVisualiserComponent* comp);
  101. void setOutputAudioFileToRecord(File f);
  102. void setPrebufferThreadPriority(int v);
  103. int getPrebufferThreadPriority() { return m_prebufthreadprior; }
  104. private:
  105. REALTYPE volume;
  106. int m_prebufthreadprior = 4;
  107. int get_optimized_updown(int n,bool up);
  108. int optimizebufsize(int bufsize);
  109. std::string getfftsizestr(int fftsize);
  110. struct control_process_t{
  111. int bufsize;
  112. double stretch;
  113. double onset_detection_sensitivity;
  114. }process;
  115. struct control_infileinfo_t {
  116. int samplerate=0;
  117. int64_t nsamples=0;
  118. String filename;
  119. }wavinfo;//input
  120. REALTYPE seek_pos;
  121. AudioFormatManager* m_afm = nullptr;
  122. TimeSliceThread m_bufferingthread;
  123. std::unique_ptr<StretchAudioSource> m_stretch_source;
  124. std::unique_ptr<MyBufferingAudioSource> m_buffering_source;
  125. int m_prebuffer_amount = 1;
  126. bool m_recreate_buffering_source = true;
  127. File m_audio_out_file;
  128. int m_fft_size_to_use = 1024;
  129. double m_last_outpos_pos = 0.0;
  130. double m_last_in_pos = 0.0;
  131. std::vector<int> m_bufamounts{ 4096,8192,16384,32768,65536,262144 };
  132. };
  133. #endif