00001
00002 #ifndef LAUDIO_HH
00003 #define LAUDIO_HH
00004
00005
00006
00007
00008 #ifdef sun
00009 #define SOLARIS_AUDIO
00010 #else
00011 #define OPEN_SOUND_SYSTEM
00012 #endif
00013
00014 #ifndef __CINT__
00015 #include <string>
00016 #include <stdexcept>
00017 #include <iosfwd>
00018 #else
00019 namespace std {
00020 class runtime_error;
00021 }
00022 #endif
00023
00024 #ifdef SOLARIS_AUDIO
00025 struct audio_info;
00026 struct audio_prinfo;
00027 #endif
00028
00037 class LAudio {
00038 public:
00039
00042 typedef unsigned int count_t;
00043
00049 enum iomode {m_listen, m_sing, m_monitor, m_converse};
00050
00053 enum ioport {p_Speaker=1, p_Phone=2, p_Line=4};
00054
00060 LAudio(void);
00061
00064 LAudio(const char* device);
00065
00069 ~LAudio(void);
00070
00075 void close(void);
00076
00081 void drain(void) throw(std::runtime_error);
00082
00086 void dumpStatus(std::ostream& out) const;
00087
00092 std::string getDevice(void) const;
00093
00098 const char* getEncoding(void) const throw(std::runtime_error);
00099
00103 count_t getMonitorGain(void) const throw(std::runtime_error);
00104
00109 count_t getPrecision(void) const throw(std::runtime_error);
00110
00115 count_t getSpeed(void) const throw(std::runtime_error);
00116
00120 double getVolume(void) const throw(std::runtime_error);
00121
00125 bool isOpen(void) const;
00126
00132 void mute(bool mute) throw(std::runtime_error);
00133
00142 void open(const char* device=0, iomode mode=m_sing);
00143
00151 void reSample(double freq, short data[], count_t length);
00152
00160 void reSample(double freq, float data[], count_t length);
00161
00170 void setEncoding(const char* encode) throw(std::runtime_error);
00171
00174 void setInputTransform(double bias, double scale);
00175
00181 void setPorts(count_t mask) throw(std::runtime_error);
00182
00188 void setMonitorGain(count_t gain) throw(std::runtime_error);
00189
00195 void setSpeed(count_t rate) throw(std::runtime_error);
00196
00202 void setPrecision(count_t bits) throw(std::runtime_error);
00203
00206 void setVolume(double volume) throw(std::runtime_error);
00207
00213 void sing(short data[], count_t length);
00214
00215 private:
00216 int Encode(const std::string& x) const throw(std::runtime_error);
00217 const char* Encode(int x) const;
00218
00219 #ifdef SOLARIS_AUDIO
00220 void dumpChannel(std::ostream& out, const char* title,
00221 const audio_prinfo& info) const throw(std::runtime_error);
00222 void getStatus(audio_info* info) const throw(std::runtime_error);
00223 void setStatus(const audio_info* info) throw(std::runtime_error);
00224 #endif
00225 short transform(double) const;
00226
00227 private:
00228 struct DspStatus {
00229 DspStatus(void);
00230 bool valid;
00231 int sample_rate;
00232 int format;
00233 int precision;
00234 int buffer_size;
00235 double gain;
00236 int samples;
00237 };
00238
00239 private:
00240 int mFD;
00241 iomode mMode;
00242 bool mBigEnd;
00243 DspStatus mInStat;
00244 DspStatus mOutStat;
00245 double mOutputSPS;
00246 int mOutputVal;
00247
00253 double mDt;
00254
00257 double mBias;
00258 double mScale;
00259 };
00260
00261 inline short
00262 LAudio::transform(double x) const {
00263 return short((x-mBias)*mScale);
00264 }
00265
00266 #endif // LAUDIO_HH