paulstretch_cpp

PaulStretch
Log | Files | Refs | LICENSE

Player.h (3270B)


      1 /*
      2   Copyright (C) 2011 Nasca Octavian Paul
      3   Author: Nasca Octavian Paul
      4 
      5   This program is free software; you can redistribute it and/or modify
      6   it under the terms of version 2 of the GNU General Public License 
      7   as published by the Free Software Foundation.
      8 
      9   This program is distributed in the hope that it will be useful,
     10   but WITHOUT ANY WARRANTY; without even the implied warranty of
     11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12   GNU General Public License (version 2) for more details.
     13 
     14   You should have received a copy of the GNU General Public License (version 2)
     15   along with this program; if not, write to the Free Software Foundation,
     16   Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
     17 */
     18 #ifndef PLAYER_H
     19 #define PLAYER_H
     20 
     21 #include <string>
     22 #include "Input/AInputS.h"
     23 #include "Input/VorbisInputS.h"
     24 #include "Input/MP3InputS.h"
     25 #include "ProcessedStretch.h"
     26 #include "Thread.h"
     27 #include "BinauralBeats.h"
     28 #include "Mutex.h"
     29 #include "globals.h"
     30 
     31 #define PA_SOUND_BUFFER_SIZE 8192
     32 
     33 
     34 class Player:public Thread{
     35     public:
     36 	Player();
     37 	~Player();
     38 	
     39 	void startplay(std::string filename, REALTYPE startpos,REALTYPE rap, int fftsize,FILE_TYPE intype,bool bypass,ProcessParameters *ppar,BinauralBeatsParameters *bbpar);
     40 	    //startpos is from 0 (start) to 1.0 (end of file)
     41 	void stop();
     42 	void pause();
     43 	
     44 	void freeze();
     45 	void setrap(REALTYPE newrap);
     46 	
     47 	void seek(REALTYPE pos);
     48 	
     49 	void getaudiobuffer(int nsamples, float *out);//data este stereo
     50 	
     51 	enum ModeType{
     52 	    MODE_PLAY,MODE_STOP,MODE_PREPARING,MODE_PAUSE
     53 	};
     54 	
     55 	ModeType getmode();
     56 	
     57 	struct{
     58 	    float position;//0 is for start, 1 for end
     59 	    int playing;
     60 	    int samplerate;
     61 	    bool eof;
     62 	}info;
     63 
     64 	bool is_freeze(){
     65 	    return freeze_mode;
     66 	};
     67 	void set_window_type(FFTWindow window);
     68 	
     69 	void set_volume(REALTYPE vol);
     70 	void set_onset_detection_sensitivity(REALTYPE onset);
     71 	
     72 	void set_process_parameters(ProcessParameters *ppar,BinauralBeatsParameters *bbpar);
     73 	
     74 	BinauralBeats *binaural_beats;
     75 
     76     private:
     77 	void run();
     78     
     79 	InputS *ai;
     80 	ProcessedStretch *stretchl,*stretchr;
     81 
     82 	short int *inbuf_i;
     83 	int inbufsize;
     84 
     85 	Mutex taskmutex,bufmutex;
     86 	
     87 	ModeType mode;
     88 	
     89 	enum TaskMode{
     90 	    TASK_NONE, TASK_START, TASK_STOP,TASK_SEEK,TASK_RAP,TASK_PARAMETERS, TASK_ONSET
     91 	};
     92 	struct {
     93 	    TaskMode mode;
     94 
     95 	    REALTYPE startpos;
     96 	    REALTYPE rap;
     97 	    int fftsize;
     98 	    std::string filename;
     99 	    FILE_TYPE intype;
    100 	    bool bypass;
    101 	    ProcessParameters *ppar;
    102 	    BinauralBeatsParameters *bbpar;
    103 	}newtask,task;
    104 	
    105 	struct{
    106 	    REALTYPE *l,*r;
    107 	}inbuf;
    108 	
    109 	struct{
    110 	    int n;//how many buffers
    111 	    float **datal,**datar;//array of buffers
    112 	    int size;//size of one buffer
    113 	    int computek,outk;//current buffer
    114 	    int outpos;//the sample position in the current buffer (for out)
    115 	    int nfresh;//how many buffers are fresh added and need to be played
    116 		    //nfresh==0 for empty buffers, nfresh==n-1 for full buffers
    117 	    float *in_position;//the position(for input samples inside the input file) of each buffers
    118 	}outbuf;
    119 	bool first_in_buf;
    120 	
    121 	void newtaskcheck();
    122 	void computesamples();
    123 	bool freeze_mode,bypass_mode,paused;
    124 	REALTYPE volume,onset_detection_sensitivity;
    125 
    126 	std::string current_filename;
    127 	FFTWindow window_type;
    128 };
    129 
    130 #endif
    131