SoDaRadio-12.2.0-cut_dependencies:6c82803
Loading...
Searching...
No Matches
AudioQt.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 "SoDaThread.hxx"
33#include "AudioIfc.hxx"
34#include "UDSockets.hxx"
35#include "../common/CircularBuffer.hxx"
36#include <string>
37#include <mutex>
38#include <iostream>
39#include <stdexcept>
40#include <memory>
41#include <tuple>
42
43namespace SoDa {
44
45 class AudioQt;
46 typedef std::shared_ptr<AudioQt> AudioQtPtr;
47
48
75 class AudioQt : public AudioIfc, public Thread {
76 protected:
86 AudioQt(unsigned int _sample_rate,
87 unsigned int _sample_count_hint = 1024,
88 std::string audio_sock_basename = std::string("soda_"));
89
90 public:
91 static AudioQtPtr make(unsigned int _sample_rate,
92 unsigned int _sample_count_hint = 1024,
93 std::string audio_sock_basename = std::string("soda_")) {
94 auto ret = std::shared_ptr<AudioQt>(new AudioQt(_sample_rate,
95 _sample_count_hint,
96 audio_sock_basename));
97 ret->registerThread(ret);
98 return ret;
99 }
100
102 }
103
112 int send(void * buf, unsigned int len, bool when_ready = false);
113
120 bool sendBufferReady(unsigned int len);
121
130 virtual int recv(std::vector<float> & buf, bool when_ready = false);
131
138 bool recvBufferReady(unsigned int len);
139
144 void sleepOut() {
145 }
146
149 void wakeOut() {
150 }
151
157 virtual void sleepIn();
161 virtual void wakeIn();
162
163 std::string currentPlaybackState() {
164 return std::string("Fabulous");
165 }
166
167 virtual std::string currentCaptureState() {
168 return std::string("NOT IMPLEMENTED");
169 }
170
173 void run();
174
175 void subscribeToMailBoxes(const std::vector<MailBoxBasePtr> & mailboxes);
176
177 protected:
181 void setupNetwork(std::string audio_sock_basename) ;
182
183 private:
184 std::shared_ptr<SoDa::UD::ServerSocket> audio_rx_socket;
185 std::shared_ptr<SoDa::UD::ServerSocket> audio_tx_socket;
186
187 // the TX process monitors the command bus for TX on/off.
189 CmdMBox::Subscription cmd_subs;
190
192
193 // Incoming TX audio ring buffer: absorbs bursts from QAudioSource and
194 // feeds BaseBandTX at a steady rate, analogous to AudioRXListener's
195 // audio_cbuffer_p on the RX side.
196 SoDa::CircularBuffer<char> * audio_cbuffer_p;
197
198 // debug assistance
199 float ang;
200 float ang_incr;
201
202 };
203}
204
The Baseclass for all SoDa objects, and useful commonly used classes.
The Baseclass for all SoDa thread objects.
AudioIfc(unsigned int _sample_rate, unsigned int _sample_count_hint, const std::string &name="AudioIfc")
Definition AudioIfc.hxx:59
Qt audio interface class.
Definition AudioQt.hxx:75
virtual std::string currentCaptureState()
Definition AudioQt.hxx:167
void sleepOut()
stop the output stream so that we don't encounter a buffer underflow while the reciever is muted.
Definition AudioQt.hxx:144
bool ignore_tx_data
Definition AudioQt.hxx:191
void subscribeToMailBoxes(const std::vector< MailBoxBasePtr > &mailboxes)
the creator of this thread may offer one or more mailboxes to this object.
std::shared_ptr< SoDa::UD::ServerSocket > audio_tx_socket
Definition AudioQt.hxx:185
std::shared_ptr< SoDa::UD::ServerSocket > audio_rx_socket
Definition AudioQt.hxx:184
bool recvBufferReady(unsigned int len)
recvBufferReady – are there samples waiting in the audio device?
static AudioQtPtr make(unsigned int _sample_rate, unsigned int _sample_count_hint=1024, std::string audio_sock_basename=std::string("soda_"))
Definition AudioQt.hxx:91
std::string currentPlaybackState()
Definition AudioQt.hxx:163
void run()
the run method – maintains incoming audio sample buffers
SoDa::CircularBuffer< char > * audio_cbuffer_p
Definition AudioQt.hxx:196
int send(void *buf, unsigned int len, bool when_ready=false)
send – send a buffer to the audio output
bool sendBufferReady(unsigned int len)
sendBufferReady – is there enough space in the audio device send buffer for a call from send?
AudioQt(unsigned int _sample_rate, unsigned int _sample_count_hint=1024, std::string audio_sock_basename=std::string("soda_"))
constructor
void wakeOut()
start the output stream
Definition AudioQt.hxx:149
virtual void sleepIn()
stop the input stream so that we don't encounter a buffer overflow while the transmitter is inactive.
CmdMBoxPtr cmd_stream
command stream from UI and other units
Definition AudioQt.hxx:188
virtual void wakeIn()
start the input stream
CmdMBox::Subscription cmd_subs
subscription ID for command stream
Definition AudioQt.hxx:189
virtual int recv(std::vector< float > &buf, bool when_ready=false)
recv – get a buffer of data from the audio input
void setupNetwork(std::string audio_sock_basename)
setup the network sockets for the audio link to the user interface.
Thread(const std::string &oname, const std::string &version=std::string("12.2.0"))
make the thread object.
std::shared_ptr< AudioQt > AudioQtPtr
Definition AudioQt.hxx:46
std::shared_ptr< CmdMBox > CmdMBoxPtr
Definition SoDaBase.hxx:79