00001 /* 00002 * Copyright (C) 2007 Anand K. Mistry 00003 * Copyright (C) 2008 Alan Calvert 00004 * 00005 * This program is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU General Public License 00007 * as published by the Free Software Foundation; either version 2 00008 * of the License, or (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 00018 * 02110-1301, USA. 00019 */ 00020 00021 #ifndef _AUDIOINPUTALSA_H_ 00022 #define _AUDIOINPUTALSA_H_ 00023 00024 #include "audioinput.h" 00025 00026 #ifdef USING_ALSA 00027 #include <alsa/asoundlib.h> 00028 #else 00029 typedef int snd_pcm_t; 00030 typedef int snd_pcm_uframes_t; 00031 #endif // USING_ALSA 00032 00033 class AudioInputALSA : public AudioInput 00034 { 00035 public: 00036 AudioInputALSA(const QString &device); 00037 ~AudioInputALSA() { Close(); }; 00038 00039 bool Open(uint sample_bits, uint sample_rate, uint channels); 00040 inline bool IsOpen(void) { return (pcm_handle != NULL); } 00041 void Close(void); 00042 00043 bool Start(void) { return (pcm_handle != NULL); } 00044 bool Stop(void); 00045 00046 inline int GetBlockSize(void) { return myth_block_bytes; }; 00047 int GetSamples(void* buf, uint nbytes); 00048 int GetNumReadyBytes(void); 00049 00050 private: 00051 bool PrepHwParams(void); 00052 bool PrepSwParams(void); 00053 int PcmRead(void* buf, uint nbytes); 00054 bool Recovery(int err); 00055 bool AlsaBad(int op_result, QString errmsg); 00056 00057 QByteArray alsa_device; 00058 snd_pcm_t* pcm_handle; 00059 snd_pcm_uframes_t period_size; 00060 int myth_block_bytes; 00061 }; 00062 #endif /* _AUDIOINPUTALSA_H_ */ 00063 /* vim: set expandtab tabstop=4 shiftwidth=4: */ 00064
1.6.3