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.

132 lines
3.2KB

  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. #ifndef PLAYER_H
  16. #define PLAYER_H
  17. #include <string>
  18. #include "Input/AInputS.h"
  19. #include "Input/VorbisInputS.h"
  20. #include "Input/MP3InputS.h"
  21. #include "ProcessedStretch.h"
  22. #include "Thread.h"
  23. #include "BinauralBeats.h"
  24. #include "Mutex.h"
  25. #include "globals.h"
  26. #define PA_SOUND_BUFFER_SIZE 8192
  27. class Player:public Thread{
  28. public:
  29. Player();
  30. ~Player();
  31. void startplay(std::string filename, REALTYPE startpos,REALTYPE rap, int fftsize,FILE_TYPE intype,bool bypass,ProcessParameters *ppar,BinauralBeatsParameters *bbpar);
  32. //startpos is from 0 (start) to 1.0 (end of file)
  33. void stop();
  34. void pause();
  35. void freeze();
  36. void setrap(REALTYPE newrap);
  37. void seek(REALTYPE pos);
  38. void getaudiobuffer(int nsamples, float *out);//data este stereo
  39. enum ModeType{
  40. MODE_PLAY,MODE_STOP,MODE_PREPARING,MODE_PAUSE
  41. };
  42. ModeType getmode();
  43. struct{
  44. float position;//0 is for start, 1 for end
  45. int playing;
  46. int samplerate;
  47. bool eof;
  48. }info;
  49. bool is_freeze(){
  50. return freeze_mode;
  51. };
  52. void set_window_type(FFTWindow window);
  53. void set_volume(REALTYPE vol);
  54. void set_onset_detection_sensitivity(REALTYPE onset);
  55. void set_process_parameters(ProcessParameters *ppar,BinauralBeatsParameters *bbpar);
  56. BinauralBeats *binaural_beats;
  57. private:
  58. void run();
  59. InputS *ai;
  60. ProcessedStretch *stretchl,*stretchr;
  61. short int *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 {
  69. TaskMode mode;
  70. REALTYPE startpos;
  71. REALTYPE rap;
  72. int fftsize;
  73. std::string filename;
  74. FILE_TYPE intype;
  75. bool bypass;
  76. ProcessParameters *ppar;
  77. BinauralBeatsParameters *bbpar;
  78. }newtask,task;
  79. struct{
  80. REALTYPE *l,*r;
  81. }inbuf;
  82. struct{
  83. int n;//how many buffers
  84. float **datal,**datar;//array of buffers
  85. int size;//size of one buffer
  86. int computek,outk;//current buffer
  87. int outpos;//the sample position in the current buffer (for out)
  88. int nfresh;//how many buffers are fresh added and need to be played
  89. //nfresh==0 for empty buffers, nfresh==n-1 for full buffers
  90. float *in_position;//the position(for input samples inside the input file) of each buffers
  91. }outbuf;
  92. bool first_in_buf;
  93. void newtaskcheck();
  94. void computesamples();
  95. bool freeze_mode,bypass_mode,paused;
  96. REALTYPE volume,onset_detection_sensitivity;
  97. std::string current_filename;
  98. FFTWindow window_type;
  99. };
  100. #endif