SndPcm.hxx

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG)
00003  *                         UNIVERSITAT POMPEU FABRA
00004  *
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  */
00021 
00022 /* alsa 0.9 backwards compatibility for alsa 1.0 */
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;                /* in frames / 2 */
00047         int latency_max;                /* in frames / 2 */
00048         int block;                                      /* block mode */
00049         int tick_time;                  /* disabled, otherwise in us */
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 //                      throw(SndPcmError("SndPcm::ReadBuf() Buffer Overrun!\n"));
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 //                      throw(SndPcmError("SndPcm::WriteBuf() Buffer Underrun!\n"));
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 //                      throw(SndPcmError("SndPcm::ReadBuf() Buffer Overrun!\n"));
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 //                      throw(SndPcmError("SndPcm::WriteBuf() Buffer Underrun!\n"));
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  * The functions which follow are taken from the latency test included
00102  * in the ALSA source distribution, with the following copyright note:
00103  *
00104  *  Latency test program
00105  *
00106  *     Author: Jaroslav Kysela <perex@suse.cz>
00107  *
00108  *     Author of bandpass filter sweep effect:
00109  *             Maarten de Boer <mdeboer@iua.upf.es>
00110  *
00111  *  This small demo program can be used for measuring latency between
00112  *  capture and playback. This latency is measured from driver (diff when
00113  *  playback and capture was started). Scheduler is set to SCHED_RR.
00114  *
00115  *
00116  *   This program is free software; you can redistribute it and/or modify
00117  *   it under the terms of the GNU General Public License as published by
00118  *   the Free Software Foundation; either version 2 of the License, or
00119  *   (at your option) any later version.
00120  *
00121  *   This program is distributed in the hope that it will be useful,
00122  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00123  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00124  *   GNU General Public License for more details.
00125  *
00126  *   You should have received a copy of the GNU General Public License
00127  *   along with this program; if not, write to the Free Software
00128  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
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 
Generated by  doxygen 1.6.3