gtkIOStream  1.7.0
GTK+ << C++ IOStream operators for GTK+. Now with ORBing, numerical computation, audio client and more ...
ALSAPlugin.H
Go to the documentation of this file.
1 /* Copyright 2000-2018 Matt Flax <flatmax@flatmax.org>
2  This file is part of GTK+ IOStream class set
3 
4  GTK+ IOStream is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  GTK+ IOStream is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You have received a copy of the GNU General Public License
15  along with GTK+ IOStream
16 */
17 #ifndef ALSAPLUGIN_H
18 #define ALSAPLUGIN_H
19 
20 #include "ALSA.H"
21 #include <alsa/pcm_external.h>
22 #include <alsa/pcm_plugin.h>
23 
24 #include <typeinfo>
25 
26 namespace ALSA {
27 
28 #define STATICFNNAME(name) name##_static
29 #define STATICFNDEF(retType, name) static retType STATICFNNAME(name) (snd_pcm_ioplug_t *io)
30 #define STATICFNBODY(name) {std::cout<<__func__<<std::endl; return static_cast<ALSAPlugin*>(io->private_data)->name();}
31 #define STATICFN(retType, name) STATICFNDEF(retType, name) STATICFNBODY(name)
32 
33 class ALSAPlugin : public Hardware {
34  snd_pcm_ioplug_t io;
35  snd_pcm_ioplug_callback_t ioplugCallback;
36 
37  // Define the various snd_pcm_ioplug_callback_t static functions
38  STATICFN(int, start)
39  STATICFN(int, stop)
40  STATICFN(snd_pcm_sframes_t, pointer)
41 
42  static snd_pcm_sframes_t transfer_static(snd_pcm_ioplug_t *io, const snd_pcm_channel_area_t *areas, snd_pcm_uframes_t offset, snd_pcm_uframes_t size){
43  std::cout<<__func__<<std::endl;
44  return static_cast<ALSAPlugin*>(io->private_data)->transfer(areas, offset, size);
45  }
46 
47  static int HWParams_static(snd_pcm_ioplug_t *io, snd_pcm_hw_params_t *params){
48  std::cout<<__func__<<std::endl;
49  return static_cast<ALSAPlugin*>(io->private_data)->HWParams(params);
50  }
51 
52  // virtual int setupHWParams()=0;
53 
54  virtual int HWParams(snd_pcm_hw_params_t *params){
55  std::cout<<__func__<<std::endl;
56  return 0;
57  }
58 
59 protected:
60  snd_pcm_t *slave;
61 
62  void setName(const char *name){
63  io.name=name;
64  }
65 public:
66 
68  assert("not debugged");
69  std::cout<<__func__<<std::endl;
70  io.version = SND_PCM_IOPLUG_VERSION;
71  setName("ALSAPlugin default name");
72  io.mmap_rw = 0;
73  io.callback = &ioplugCallback;
74  io.private_data=this;
75 
76  // setup the static callbacks
77  ioplugCallback.start=STATICFNNAME(start);
78  ioplugCallback.stop=STATICFNNAME(stop);
79  ioplugCallback.pointer=STATICFNNAME(pointer);
80  ioplugCallback.transfer=transfer_static;
81  ioplugCallback.hw_params=HWParams_static;
82  }
83 
84  virtual ~ALSAPlugin(){
85  std::cout<<__func__<<std::endl;
86  }
87 
91  virtual int parseConfig(const char *name, snd_config_t *conf, snd_pcm_stream_t stream, int mode){
92  //std::cout<<typeid(this).name()<<'\t'<<__func__<<std::endl;
93  return 0;
94  }
95 
97  virtual int start(){
98  //std::cout<<typeid(this).name()<<'\t'<<__func__<<std::endl;
99  /* When trying to start a PCM that's already running, the result is
100  EBADFD. We might have implicitly started the buffer by filling it
101  up, so just ignore this request if we're already running. */
102  if (snd_pcm_state(slave) == SND_PCM_STATE_RUNNING)
103  return 0;
104 
105  return snd_pcm_start(slave);
106  }
107 
109  virtual int stop(){
110  //std::cout<<typeid(this).name()<<'\t'<<__func__<<std::endl;
111  return snd_pcm_drop(slave);
112  }
113 
115  virtual snd_pcm_sframes_t pointer()=0;
116 
119  int create(const char *name, snd_pcm_stream_t stream, int mode){
120  return snd_pcm_ioplug_create(&io, name, stream, mode);
121  }
122 
123  virtual snd_pcm_sframes_t transfer(const snd_pcm_channel_area_t *areas, snd_pcm_uframes_t offset, snd_pcm_uframes_t size){
124  //std::cout<<typeid(this).name()<<'\t'<<__func__<<std::endl;
125  return size;
126  }
127 
130  virtual snd_pcm_t *getPCM(){
131  std::cout<<'\t'<<__func__<<'\t'<<__LINE__<<std::endl;
132  return io.pcm;
133  }
134 
137  snd_pcm_t **getPCMP(){
138  return &(io.pcm);
139  }
140 
141 };
142 };
143 #endif // ALSAPLUGIN_H
void setName(const char *name)
The slave.
Definition: ALSAPlugin.H:62
virtual snd_pcm_sframes_t transfer(const snd_pcm_channel_area_t *areas, snd_pcm_uframes_t offset, snd_pcm_uframes_t size)
Definition: ALSAPlugin.H:123
virtual int stop()
stop method
Definition: ALSAPlugin.H:109
Definition: ALSA.H:26
snd_pcm_t * slave
Definition: ALSAPlugin.H:60
virtual snd_pcm_sframes_t pointer()=0
virtual pointer method
stop const snd_pcm_channel_area_t * areas
Definition: ALSAPlugin.H:42
stop const snd_pcm_channel_area_t snd_pcm_uframes_t offset
Definition: ALSAPlugin.H:42
snd_pcm_ioplug_callback_t ioplugCallback
The ALSA plugin.
Definition: ALSAPlugin.H:35
#define STATICFNNAME(name)
Definition: ALSAPlugin.H:28
STATICFN(int, start) STATICFN(int
The callback functions.
virtual int parseConfig(const char *name, snd_config_t *conf, snd_pcm_stream_t stream, int mode)
Definition: ALSAPlugin.H:91
snd_pcm_t ** getPCMP()
Definition: ALSAPlugin.H:137
virtual int start()
start method
Definition: ALSAPlugin.H:97
snd_pcm_ioplug_t io
Definition: ALSAPlugin.H:34
virtual int HWParams(snd_pcm_hw_params_t *params)
Definition: ALSAPlugin.H:54
stop const snd_pcm_channel_area_t snd_pcm_uframes_t snd_pcm_uframes_t size
Definition: ALSAPlugin.H:42
virtual snd_pcm_t * getPCM()
Definition: ALSAPlugin.H:130
int create(const char *name, snd_pcm_stream_t stream, int mode)
Definition: ALSAPlugin.H:119
virtual ~ALSAPlugin()
Definition: ALSAPlugin.H:84
static int HWParams_static(snd_pcm_ioplug_t *io, snd_pcm_hw_params_t *params)
Definition: ALSAPlugin.H:47
gtkIOStream: /tmp/gtkiostream/include/ALSA/ALSAPlugin.H Source File
GTK+ IOStream  Beta