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.

138 lines
3.6KB

  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. #ifdef PLAYERCLASSSTILLPRESENT
  17. #include <string>
  18. #include "Input/AInputS.h"
  19. #include "ProcessedStretch.h"
  20. #include "BinauralBeats.h"
  21. #include "Mutex.h"
  22. #include "globals.h"
  23. using StretchRef = std::shared_ptr<ProcessedStretch>;
  24. class Player:public Thread{
  25. public:
  26. Player();
  27. ~Player();
  28. void startplay(String filename, REALTYPE startpos,REALTYPE rap, int fftsize,bool bypass,ProcessParameters *ppar,
  29. BinauralBeatsParameters *bbpar, double loop_start, double loop_end, int numoutchans);
  30. //startpos is from 0 (start) to 1.0 (end of file)
  31. void stop();
  32. void pause();
  33. void freeze();
  34. void setrap(REALTYPE newrap);
  35. void seek(REALTYPE pos);
  36. void getaudiobuffer(int nsamples, float *out);//data este stereo
  37. enum ModeType{
  38. MODE_PLAY,MODE_STOP,MODE_PREPARING,MODE_PAUSE
  39. };
  40. ModeType getmode();
  41. struct player_soundfile_info_t{
  42. float position = 0.0f;//0 is for start, 1 for end
  43. double liveposition = 0.0;
  44. int playing=0;
  45. int samplerate=0;
  46. bool eof=false;
  47. }info;
  48. bool is_freeze(){
  49. return freeze_mode;
  50. };
  51. void set_window_type(FFTWindow window);
  52. void set_volume(REALTYPE vol);
  53. void set_onset_detection_sensitivity(REALTYPE onset);
  54. void set_process_parameters(ProcessParameters *ppar,BinauralBeatsParameters *bbpar);
  55. std::unique_ptr<BinauralBeats> binaural_beats;
  56. void setPreBufferAmount(double x) { m_prebufferamount = jlimit(0.1,2.0, x); }
  57. private:
  58. void run() override;
  59. std::unique_ptr<InputS> ai;
  60. std::vector<StretchRef> m_stretchers;
  61. std::vector<float> inbuf_i;
  62. int inbufsize;
  63. Mutex taskmutex,bufmutex;
  64. ModeType mode;
  65. enum TaskMode{
  66. TASK_NONE, TASK_START, TASK_STOP,TASK_SEEK,TASK_RAP,TASK_PARAMETERS, TASK_ONSET
  67. };
  68. struct player_task_t {
  69. TaskMode mode;
  70. REALTYPE startpos=0.0;
  71. REALTYPE rap;
  72. int fftsize;
  73. String filename;
  74. int m_num_outchans = 2;
  75. bool bypass;
  76. ProcessParameters *ppar;
  77. BinauralBeatsParameters *bbpar;
  78. double m_loop_start = 0.0;
  79. double m_loop_end = 1.0;
  80. }newtask,task;
  81. struct{
  82. float2dvector m_inbuf;
  83. }inbuf;
  84. struct player_outbuf_t{
  85. int n;//how many buffers
  86. float3dvector channeldatas;
  87. int size;//size of one buffer
  88. int computek,outk;//current buffer
  89. int outpos;//the sample position in the current buffer (for out)
  90. int nfresh;//how many buffers are fresh added and need to be played
  91. //nfresh==0 for empty buffers, nfresh==n-1 for full buffers
  92. std::vector<float> in_position;//the position(for input samples inside the input file) of each buffers
  93. }outbuf;
  94. bool first_in_buf;
  95. void newtaskcheck();
  96. void computesamples();
  97. bool freeze_mode,bypass_mode,paused;
  98. REALTYPE volume,onset_detection_sensitivity;
  99. String current_filename;
  100. FFTWindow window_type;
  101. double m_prebufferamount = 0.2;
  102. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Player)
  103. };
  104. #endif