kwave  18.07.70
PlayBack-ALSA.h
Go to the documentation of this file.
1 /***************************************************************************
2  PlayBack-ALSA.h - playback device for ALSA
3  -------------------
4  begin : Sat Mar 03 2005
5  copyright : (C) 2005 by Thomas Eschenbacher
6  email : Thomas.Eschenbacher@gmx.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef PLAY_BACK_ALSA_H
19 #define PLAY_BACK_ALSA_H
20 
21 #include "config.h"
22 #ifdef HAVE_ALSA_SUPPORT
23 
24 /*
25  * use the new ALSA HW/SW params API, needed to compile under SuSE-9.0
26  * (workaround as seen in http://www.linuxjournal.com/article/6735)
27  */
28 #define ALSA_PCM_NEW_HW_PARAMS_API
29 #define ALSA_PCM_NEW_SW_PARAMS_API
30 
31 #include <alsa/asoundlib.h>
32 
33 #include <QList>
34 #include <QMap>
35 #include <QString>
36 
38 #include "libkwave/SampleArray.h"
39 
40 namespace Kwave
41 {
42 
43  class SampleEncoder;
44 
46  {
47  public:
48 
50  PlayBackALSA();
51 
53  virtual ~PlayBackALSA() Q_DECL_OVERRIDE;
54 
59  virtual QString open(const QString &device, double rate,
60  unsigned int channels, unsigned int bits,
61  unsigned int bufbase) Q_DECL_OVERRIDE;
62 
67  virtual int write(const Kwave::SampleArray &samples) Q_DECL_OVERRIDE;
68 
73  virtual int close() Q_DECL_OVERRIDE;
74 
76  virtual QStringList supportedDevices() Q_DECL_OVERRIDE;
77 
79  virtual QString fileFilter() Q_DECL_OVERRIDE;
80 
88  virtual QList<unsigned int> supportedBits(const QString &device)
89  Q_DECL_OVERRIDE;
90 
101  virtual int detectChannels(const QString &device,
102  unsigned int &min, unsigned int &max)
103  Q_DECL_OVERRIDE;
104 
105  protected:
106 
114  snd_pcm_t *openDevice(const QString &device);
115 
127  int openDevice(const QString &device, unsigned int rate,
128  unsigned int channels, unsigned int bits);
129 
142  int setFormat(snd_pcm_hw_params_t *hw_params, unsigned int bits);
143 
145  int flush();
146 
148  void scanDevices();
149 
156  QString alsaDeviceName(const QString &name);
157 
158  private:
159 
164  QList<int> detectSupportedFormats(const QString &device);
165 
173  int mode2format(int bits);
174 
175  private:
176 
178  QString m_device_name;
179 
181  snd_pcm_t *m_handle;
182 
184  double m_rate;
185 
187  unsigned int m_channels;
188 
190  unsigned int m_bits;
191 
196  unsigned int m_bytes_per_sample;
197 
199  unsigned int m_bufbase;
200 
202  QByteArray m_buffer;
203 
205  unsigned int m_buffer_size;
206 
208  unsigned int m_buffer_used;
209 
211  snd_pcm_format_t m_format;
212 
214  snd_pcm_uframes_t m_chunk_size;
215 
221  static QMap<QString, QString> m_device_list;
222 
230 
233 
234  };
235 }
236 
237 #endif /* HAVE_ALSA_SUPPORT */
238 
239 #endif /* PLAY_BACK_ALSA_H */
240 
241 //***************************************************************************
242 //***************************************************************************
snd_pcm_t * openDevice(const QString &device)
Definition: App.h:33
snd_pcm_format_t m_format
virtual QString open(const QString &device, double rate, unsigned int channels, unsigned int bits, unsigned int bufbase) Q_DECL_OVERRIDE
unsigned int m_bufbase
QList< int > detectSupportedFormats(const QString &device)
snd_pcm_t * m_handle
virtual QString fileFilter() Q_DECL_OVERRIDE
unsigned int m_channels
QString alsaDeviceName(const QString &name)
const char name[16]
Definition: memcpy.c:510
virtual int write(const Kwave::SampleArray &samples) Q_DECL_OVERRIDE
Kwave::SampleEncoder * m_encoder
virtual ~PlayBackALSA() Q_DECL_OVERRIDE
snd_pcm_uframes_t m_chunk_size
int setFormat(snd_pcm_hw_params_t *hw_params, unsigned int bits)
virtual QList< unsigned int > supportedBits(const QString &device) Q_DECL_OVERRIDE
static QMap< QString, QString > m_device_list
virtual int detectChannels(const QString &device, unsigned int &min, unsigned int &max) Q_DECL_OVERRIDE
unsigned int m_buffer_size
int mode2format(int bits)
virtual QStringList supportedDevices() Q_DECL_OVERRIDE
unsigned int m_bytes_per_sample
unsigned int m_buffer_used
virtual int close() Q_DECL_OVERRIDE
QList< int > m_supported_formats
unsigned int m_bits