SoDaRadio-5.0.3-master:8901fb5
AudioIfc.hxx
Go to the documentation of this file.
1 #ifndef AUDIO_PCM_HDR
2 #define AUDIO_PCM_HDR
3 
4 
5 /*
6  Copyright (c) 2012, Matthew H. Reilly (kb1vc)
7  All rights reserved.
8 
9  Redistribution and use in source and binary forms, with or without
10  modification, are permitted provided that the following conditions are
11  met:
12 
13  Redistributions of source code must retain the above copyright
14  notice, this list of conditions and the following disclaimer.
15  Redistributions in binary form must reproduce the above copyright
16  notice, this list of conditions and the following disclaimer in
17  the documentation and/or other materials provided with the
18  distribution.
19 
20  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32 
33 #include "SoDaBase.hxx"
34 namespace SoDa {
44  class AudioIfc : public SoDaBase {
45  public:
47 
48  /*
49  * constructor
50  * @param sample_rate in Hz -- 48000 is a good choice
51  * @param fmt -- the format of the data (FLOAT, DFLOAT, INT32, INT16, INT8)
52  * @param _sample_count_hint -- the size of the buffers passed to
53  * and from the audio device (in samples)
54  */
55  AudioIfc(unsigned int _sample_rate,
56  DataFormat _fmt,
57  unsigned int _sample_count_hint,
58  const std::string & name = "AudioIfc") : SoDaBase(name) {
59  sample_rate = _sample_rate;
60  sample_count_hint = _sample_count_hint;
61  format = _fmt;
62  switch (format) {
63  case FLOAT: datatype_size = sizeof(float);
64  break;
65  case DFLOAT: datatype_size = sizeof(double);
66  break;
67  case INT32: datatype_size = sizeof(int);
68  break;
69  case INT16: datatype_size = sizeof(short);
70  break;
71  case INT8: datatype_size = sizeof(char);
72  break;
73  }
74  }
75 
82  virtual int send(void * buf, unsigned int len) = 0;
83 
90  virtual bool sendBufferReady(unsigned int len) = 0;
91 
92 
100  virtual int recv(void * buf, unsigned int len, bool block = true) = 0;
101 
108  virtual bool recvBufferReady(unsigned int len) = 0;
109 
110 
116  virtual bool setOutGain(float gain) {
117  out_gain = gain;
118  return true;
119  }
120 
126  virtual bool setInGain(float gain) {
127  in_gain = gain;
128  return true;
129  }
130 
135  virtual float getOutGain() { return out_gain; }
136 
141  virtual float getInGain() { return in_gain; }
142 
147  virtual void sleepOut() = 0;
151  virtual void wakeOut() = 0;
152 
158  virtual void sleepIn() = 0;
162  virtual void wakeIn() = 0;
163 
164 
165  virtual std::string currentPlaybackState() { return std::string("UNKNOWN"); }
166  virtual std::string currentCaptureState() { return std::string("UNKNOWN"); }
167 
168  protected:
169  unsigned int sample_rate;
171  unsigned int sample_count_hint;
172 
173  float in_gain;
174  float out_gain;
175 
177  };
178 }
179 
180 
181 #endif
The Baseclass for all SoDa objects, and useful commonly used classes.
virtual float getInGain()
get the gain for the input device.
Definition: AudioIfc.hxx:141
virtual void sleepIn()=0
stop the input stream so that we don't encounter a buffer overflow while the transmitter is inactive...
virtual bool setOutGain(float gain)
set the gain for the output device.
Definition: AudioIfc.hxx:116
unsigned int sample_rate
Definition: AudioIfc.hxx:169
virtual std::string currentCaptureState()
Definition: AudioIfc.hxx:166
virtual int send(void *buf, unsigned int len)=0
send – send a buffer to the audio output
unsigned int sample_count_hint
Definition: AudioIfc.hxx:171
virtual std::string currentPlaybackState()
Definition: AudioIfc.hxx:165
virtual int recv(void *buf, unsigned int len, bool block=true)=0
recv – get a buffer of data from the audio input
virtual bool recvBufferReady(unsigned int len)=0
recvBufferReady – is there enough space in the audio device recv buffer for a call from recv...
virtual bool sendBufferReady(unsigned int len)=0
sendBufferReady – is there enough space in the audio device send buffer for a call from send...
virtual float getOutGain()
get the gain for the output device.
Definition: AudioIfc.hxx:135
virtual void sleepOut()=0
stop the output stream so that we don't encounter a buffer underflow while the reciever is muted...
virtual void wakeOut()=0
start the output stream
Generic Audio Interface Class.
Definition: AudioIfc.hxx:44
AudioIfc(unsigned int _sample_rate, DataFormat _fmt, unsigned int _sample_count_hint, const std::string &name="AudioIfc")
Definition: AudioIfc.hxx:55
DataFormat format
Definition: AudioIfc.hxx:170
The SoDa Base class.
Definition: SoDaBase.hxx:167
virtual bool setInGain(float gain)
set the gain for the input device.
Definition: AudioIfc.hxx:126
virtual void wakeIn()=0
start the input stream