Marsyas
0.6.0-alpha
|
00001 /* 00002 ** Copyright (C) 1998-2013 George Tzanetakis <gtzan@cs.uvic.ca> 00003 ** 00004 ** This program is free software; you can redistribute it and/or modify 00005 ** it under the terms of the GNU General Public License as published by 00006 ** the Free Software Foundation; either version 2 of the License, or 00007 ** (at your option) any later version. 00008 ** 00009 ** This program is distributed in the hope that it will be useful, 00010 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 ** GNU General Public License for more details. 00013 ** 00014 ** You should have received a copy of the GNU General Public License 00015 ** along with this program; if not, write to the Free Software 00016 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 */ 00018 00019 #ifndef MARSYAS_AUDIOSOURCE_H 00020 #define MARSYAS_AUDIOSOURCE_H 00021 00022 00023 00024 #include <marsyas/realtime/realvec_queue.h> 00025 #include <marsyas/system/MarSystem.h> 00026 00027 #include "RtAudio.h" 00028 00029 #include <mutex> 00030 #include <condition_variable> 00031 #include <atomic> 00032 00033 class RtAudio; 00034 00035 namespace Marsyas 00036 { 00037 00065 class AudioSource:public MarSystem 00066 { 00067 private: 00068 00069 struct InputData 00070 { 00071 InputData(): overrun(false) {} 00072 InputData(const InputData &): overrun(false) {} 00073 00074 std::mutex mutex; 00075 std::condition_variable condition; 00076 00077 realvec_queue buffer; 00078 00079 std::atomic<mrs_natural> watermark; 00080 bool overrun; 00081 00082 unsigned int sample_rate; 00083 unsigned int channel_count; 00084 } shared; 00085 00086 mrs_natural old_source_block_size_; 00087 mrs_natural old_dest_block_size_; 00088 00089 RtAudio* audio_; 00090 00091 bool isInitialized_; 00092 bool stopped_; 00093 00094 void addControls(); 00095 void myUpdate(MarControlPtr sender); 00096 00097 void initRtAudio( 00098 mrs_natural sample_rate, 00099 mrs_natural *block_size, 00100 mrs_natural channel_count, 00101 bool realtime 00102 ); 00103 00104 void start(); 00105 void stop(); 00106 00107 void localActivate(bool state); 00108 00109 void clearBuffer(); 00110 bool reformatBuffer(mrs_natural sourceBlockSize, 00111 mrs_natural destBlockSize, 00112 mrs_natural channel_count, 00113 bool realtime, bool resize); 00114 00115 static int recordCallback(void *outputBuffer, void *inputBuffer, 00116 unsigned int nBufferFrames, double streamTime, unsigned int status, void *userData); 00117 00118 public: 00119 AudioSource(std::string name); 00120 ~AudioSource(); 00121 MarSystem* clone() const; 00122 00123 void myProcess(realvec& in, realvec& out); 00124 }; 00125 00126 }//namespace Marsyas 00127 00128 00129 #endif 00130 00131 00132 00133