SoDaRadio-12.2.0-cut_dependencies:6c82803
Loading...
Searching...
No Matches
AudioIfc.hxx
Go to the documentation of this file.
1#pragma once
2
3/*
4 Copyright (c) 2012,2025, 2026 Matthew H. Reilly (kb1vc)
5 All rights reserved.
6
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are
9 met:
10
11 Redistributions of source code must retain the above copyright
12 notice, this list of conditions and the following disclaimer.
13 Redistributions in binary form must reproduce the above copyright
14 notice, this list of conditions and the following disclaimer in
15 the documentation and/or other materials provided with the
16 distribution.
17
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29*/
30
31#include "SoDaBase.hxx"
32#include <memory>
33
34namespace SoDa {
35 class AudioIfc;
36 typedef std::shared_ptr<AudioIfc> AudioIfcPtr;
37
51 class AudioIfc {
52 protected:
53 /*
54 * constructor
55 * @param sample_rate in Hz -- 48000 is a good choice
56 * @param _sample_count_hint -- the size of the buffers passed to
57 * and from the audio device (in samples)
58 */
59 AudioIfc(unsigned int _sample_rate,
60 unsigned int _sample_count_hint,
61 const std::string & name = "AudioIfc") {
62 sample_rate = _sample_rate;
63 sample_count_hint = _sample_count_hint;
64 datatype_size = sizeof(float);
65 }
66
67 public:
77 virtual int send(void * buf, unsigned int len, bool when_ready = false) = 0;
78
85 virtual bool sendBufferReady(unsigned int len) = 0;
86
87
95 virtual int recv(std::vector<float> & buf, bool when_ready = false) = 0;
96
103 virtual bool recvBufferReady(unsigned int len) = 0;
104
105
111 virtual bool setOutGain(float gain) {
112 out_gain = gain;
113 return true;
114 }
115
121 virtual bool setInGain(float gain) {
122 in_gain = gain;
123 return true;
124 }
125
130 virtual float getOutGain() { return out_gain; }
131
136 virtual float getInGain() { return in_gain; }
137
142 virtual void sleepOut() = 0;
146 virtual void wakeOut() = 0;
147
153 virtual void sleepIn() = 0;
157 virtual void wakeIn() = 0;
158
159
160 virtual std::string currentPlaybackState() { return std::string("UNKNOWN"); }
161 virtual std::string currentCaptureState() { return std::string("UNKNOWN"); }
162
163 protected:
164 unsigned int sample_rate;
165 unsigned int sample_count_hint;
166
167 float in_gain;
168 float out_gain;
169
171 };
172}
173
The Baseclass for all SoDa objects, and useful commonly used classes.
Generic Audio Interface Class.
Definition AudioIfc.hxx:51
virtual bool sendBufferReady(unsigned int len)=0
sendBufferReady – is there enough space in the audio device send buffer for a call from send?
virtual bool setOutGain(float gain)
set the gain for the output device.
Definition AudioIfc.hxx:111
unsigned int sample_rate
Definition AudioIfc.hxx:164
virtual bool setInGain(float gain)
set the gain for the input device.
Definition AudioIfc.hxx:121
virtual void wakeIn()=0
start the input stream
virtual void wakeOut()=0
start the output stream
virtual int send(void *buf, unsigned int len, bool when_ready=false)=0
send – send a buffer to the audio output
virtual void sleepOut()=0
stop the output stream so that we don't encounter a buffer underflow while the reciever is muted.
virtual float getOutGain()
get the gain for the output device.
Definition AudioIfc.hxx:130
virtual std::string currentPlaybackState()
Definition AudioIfc.hxx:160
virtual void sleepIn()=0
stop the input stream so that we don't encounter a buffer overflow while the transmitter is inactive.
virtual float getInGain()
get the gain for the input device.
Definition AudioIfc.hxx:136
AudioIfc(unsigned int _sample_rate, unsigned int _sample_count_hint, const std::string &name="AudioIfc")
Definition AudioIfc.hxx:59
unsigned int sample_count_hint
Definition AudioIfc.hxx:165
virtual bool recvBufferReady(unsigned int len)=0
recvBufferReady – is there enough space in the audio device recv buffer for a call from recv?
virtual std::string currentCaptureState()
Definition AudioIfc.hxx:161
virtual int recv(std::vector< float > &buf, bool when_ready=false)=0
recv – get a buffer of data from the audio input
std::shared_ptr< AudioIfc > AudioIfcPtr
Definition AudioIfc.hxx:36