SndPcm.hxx
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #define ALSA_PCM_OLD_HW_PARAMS_API
00024 #define ALSA_PCM_OLD_SW_PARAMS_API
00025
00026 #include <alsa/asoundlib.h>
00027 #include "Err.hxx"
00028
00029 class SndPcmError : public CLAM::Err
00030 {
00031 public:
00032 SndPcmError(const char* _str)
00033 :Err(_str){
00034
00035 }
00036 };
00037
00038 class SndPcm
00039 {
00040 public:
00041 snd_pcm_format_t format;
00042 int rate;
00043 int channels_in;
00044 int channels_out;
00045 int latency;
00046 int latency_min;
00047 int latency_max;
00048 int block;
00049 int tick_time;
00050 int tick_time_ok;
00051
00052 snd_pcm_t *phandle, *chandle;
00053
00054 char error_str[1024];
00055 void cat_error(const char* fmt,...);
00056
00057 void ReadBuf(short* data)
00058 {
00059 int res = readbuf(chandle,(char*) data,latency);
00060 if (res>=0) return;
00061 if (res == -EPIPE)
00062
00063 RecoverXRun(data);
00064 }
00065 void WriteBuf(short* data)
00066 {
00067 int res = writebuf(phandle,(char*) data,latency);
00068 if (res>=0) return;
00069 if (res == -EPIPE)
00070
00071 RecoverXRun(data);
00072 }
00073 void ReadBuf(short* data,int len)
00074 {
00075 int res = readbuf(chandle,(char*) data,len);
00076 if (res>=0) return;
00077 if (res == -EPIPE)
00078
00079 RecoverXRun(data);
00080 }
00081 void WriteBuf(short* data,int len)
00082 {
00083 int res = writebuf(phandle,(char*) data,len);
00084 if (res>=0) return;
00085 if (res == -EPIPE)
00086
00087 RecoverXRun(data);
00088 }
00089 SndPcm(int irate,int ichannels_in,int ichannels_out,int ilatency,
00090 const char* pdevice,const char* cdevice);
00091 ~SndPcm();
00092
00093 void Start(void);
00094 void Stop(void);
00095 void RecoverXRun(short* data);
00096
00097 void Poll(void);
00098
00099 private:
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131 int setparams_stream(snd_pcm_t *handle,
00132 snd_pcm_hw_params_t *params,
00133 int channels,
00134 const char *id);
00135 int setparams_bufsize(snd_pcm_t *handle,
00136 snd_pcm_hw_params_t *params,
00137 snd_pcm_hw_params_t *tparams,
00138 snd_pcm_uframes_t bufsize,
00139 const char *id);
00140 int setparams_set(snd_pcm_t *handle,
00141 snd_pcm_hw_params_t *params,
00142 snd_pcm_sw_params_t *swparams,
00143 const char *id);
00144 int setparams(snd_pcm_t *phandle, snd_pcm_t *chandle, int *bufsize);
00145 long readbuf(snd_pcm_t *handle, char *buf, long len);
00146 long writebuf(snd_pcm_t *handle, char *buf, long len);
00147 };
00148