00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef RTAUDIO_MODULE_H
00031 #define RTAUDIO_MODULE_H
00032
00033 #include "FsfNode.h"
00034 #include "FsfCell.h"
00035
00036
00037
00038
00039 #include "AudioModule.h"
00040 #include "RtAudio.h"
00041
00042 #include <iostream>
00043
00044
00045 namespace rtaudiom{
00046
00049
00053
00055 void registerFactories();
00056
00058
00059 const long STREAM_OUTPUT_DEVICE=0;
00060 const long STREAM_OUTPUT_CHANNELS=1;
00061 const long STREAM_INPUT_DEVICE=2;
00062 const long STREAM_INPUT_CHANNELS=3;
00063 const long STREAM_AUDIO_FORMAT=4;
00064 const long STREAM_SAMPLE_RATE=5;
00065 const long STREAM_BUFFER_FRAMES=6;
00067
00068 const unsigned int RTAUDIO_FORMAT[6] = { 0x20, 0x10, 0x8, 0x4, 0x2, 0x1 };
00069
00070
00075 class CReceive : public fsf::CCell {
00076 public:
00078 CReceive();
00080 virtual void getTypeID(std::string &str) const { str.assign("RTAUDIO_RECEIVE"); }
00082 void makePulse(fsf::CNode *pNode=NULL);
00083 };
00084
00085
00089 class CInputInterface : public fsf::CNode {
00090 private:
00091 fsf::CMutex m_csInterface;
00092 RtAudio m_audio;
00093 RtAudio::StreamParameters m_parameters;
00094 unsigned int m_nFormat;
00095 unsigned int m_nSampleRate;
00096 unsigned int m_nBufferFrames;
00097 int m_nBufferSize;
00098 CReceive *m_pReceiveCell;
00099
00101 static int callback(void *outputBuffer, void *inputBuffer, unsigned int nBufferFrames,
00102 double streamTime, RtAudioStreamStatus status, void *pData);
00103
00105 void pushNode(fsf::CNode *pNode=NULL) const { if(m_pReceiveCell) m_pReceiveCell->makePulse(pNode); }
00106
00107 public:
00109
00110
00111 CInputInterface();
00113 CInputInterface(fsf::CNode *pParent, fsf::Time tTime=0);
00115 CInputInterface(const std::string &strName, fsf::CNode *pParent=NULL, fsf::Time tTime=0);
00117 CInputInterface(const CInputInterface& rhs);
00119 virtual ~CInputInterface();
00121 virtual fsf::CNode *clone() const { return new CInputInterface(*this); }
00123
00125
00126
00127 CInputInterface& operator=(const CInputInterface& rhs);
00128
00130 void setReceiveCell(CReceive *pCell) { m_pReceiveCell=pCell; }
00131
00133 bool open(int nInputDevice, int nInputChannels,
00134 unsigned int nFormat, unsigned int nSampleRate, unsigned int nBufferSize);
00136 bool close();
00138
00140
00141
00142 virtual void getTypeID(std::string &str) const { str.assign("RTAUDIO_INPUT_INTERFACE"); }
00144
00145 };
00146
00149 class COpenInputStream : public fsf::CCell {
00150 public:
00152 COpenInputStream();
00154 virtual void getTypeID(std::string &str) const { str.assign("RTAUDIO_OPEN_INPUT_STREAM"); }
00158 virtual void process(fsf::CPassiveHandle *pPassiveHandle, fsf::CActiveHandle *pActiveHandle, fsf::CActivePulse *pActivePulse);
00159 };
00160
00163 class CCloseInputStream : public fsf::CCell {
00164 public:
00166 CCloseInputStream();
00168 virtual void getTypeID(std::string &str) const { str.assign("RTAUDIO_CLOSE_INPUTSTREAM"); }
00171 virtual void process(fsf::CPassiveHandle *pPassiveHandle, fsf::CActiveHandle *pActiveHandle, fsf::CActivePulse *pActivePulse);
00172 };
00173
00174
00175
00178 class CSend : public fsf::CCell {
00179 public:
00181 CSend();
00183 virtual void getTypeID(std::string &str) const { str.assign("RTAUDIO_SEND"); }
00185 virtual void process(fsf::CPassiveHandle *pPassiveHandle, fsf::CActiveHandle *pActiveHandle, fsf::CActivePulse *pActivePulse);
00186 };
00187
00188
00191 class COutputInterface : public fsf::CNode {
00192 private:
00193 fsf::CMutex m_csInterface;
00194 RtAudio m_audio;
00195 RtAudio::StreamParameters m_parameters;
00196 unsigned int m_nFormat;
00197 unsigned int m_nSampleRate;
00198 unsigned int m_nBufferFrames;
00199 int m_nBufferSize;
00200 char *m_pBuffer;
00201
00203 static int callback(void *outputBuffer, void *inputBuffer, unsigned int nBufferFrames,
00204 double streamTime, RtAudioStreamStatus status, void *pData);
00205
00206 public:
00208
00209
00210 COutputInterface();
00212 COutputInterface(fsf::CNode *pParent, fsf::Time tTime=0);
00214 COutputInterface(const std::string &strName, fsf::CNode *pParent=NULL, fsf::Time tTime=0);
00216 COutputInterface(const COutputInterface& rhs);
00218 virtual ~COutputInterface();
00220 virtual fsf::CNode *clone() const { return new COutputInterface(*this); }
00222
00224
00225
00226 COutputInterface& operator=(const COutputInterface& rhs);
00228 bool open(int nOutputDevice, int nOutputChannels,
00229 unsigned int nFormat, unsigned int nSampleRate, unsigned int nBufferSize);
00231 bool close();
00233 void loadBuffer(audio::CAudioBuffer *pNode);
00235
00237
00238
00239 virtual void GetTypeID(std::string &str) { str.assign("RTAUDIO_OUTPUT_INTERFACE"); }
00241 };
00242
00245 class COpenOutputStream : public fsf::CCell {
00246 public:
00248 COpenOutputStream();
00250 virtual void getTypeID(std::string &str) const { str.assign("RTAUDIO_OPEN_OUTPUT_STREAM"); }
00251
00255 virtual void process(fsf::CPassiveHandle *pPassiveHandle, fsf::CActiveHandle *pActiveHandle, fsf::CActivePulse *pActivePulse);
00256 };
00257
00260 class CCloseOutputStream : public fsf::CCell {
00261 public:
00263 CCloseOutputStream();
00265 virtual void getTypeID(std::string &str) const { str.assign("RTAUDIO_CLOSE_OUTPUT_STREAM"); }
00268 virtual void process(fsf::CPassiveHandle *pPassiveHandle, fsf::CActiveHandle *pActiveHandle, fsf::CActivePulse *pActivePulse);
00269 };
00270
00271
00272
00274
00275
00276
00277
00278 bool openInputStream(fsf::CRepository *pRepository, std::string &strInterfaceName,
00279 int nInputDevice, int nInputChannels,
00280 unsigned int nFormat, unsigned int nSampleRate, unsigned int nBufferFrames=0);
00283 bool closeInputStream(fsf::CRepository *pRepository, std::string &strInterfaceName);
00284
00288 bool openOutputStream(fsf::CRepository *pRepository, std::string &strInterfaceName,
00289 int nOutputDevice, int nOutputChannels,
00290 unsigned int nFormat, unsigned int nSampleRate, unsigned int nBufferFrames=0);
00293 bool closeOutputStream(fsf::CRepository *pRepository, std::string &strInterfaceName);
00294
00296 int selectInputDevice();
00298 int selectOutputDevice();
00299
00301
00302 }
00303
00304 #endif // RTAUDIO_MODULE_H