SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
audiodevicemanager.h
Go to the documentation of this file.
1 // Copyright (C) 2017 F4EXB //
3 // written by Edouard Griffiths //
4 // //
5 // This program is free software; you can redistribute it and/or modify //
6 // it under the terms of the GNU General Public License as published by //
7 // the Free Software Foundation as version 3 of the License, or //
8 // (at your option) any later version. //
9 // //
10 // This program is distributed in the hope that it will be useful, //
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
13 // GNU General Public License V3 for more details. //
14 // //
15 // You should have received a copy of the GNU General Public License //
16 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
18 
19 #ifndef INCLUDE_AUDIODEVICEMANGER_H
20 #define INCLUDE_AUDIODEVICEMANGER_H
21 
22 #include <QStringList>
23 #include <QList>
24 #include <QMap>
25 #include <QAudioDeviceInfo>
26 
27 #include "audio/audioinput.h"
28 #include "audio/audiooutput.h"
29 #include "export.h"
30 
31 class QDataStream;
32 class AudioFifo;
33 class MessageQueue;
34 
36 public:
38  {
39  public:
41  sampleRate(m_defaultAudioSampleRate),
42  volume(m_defaultAudioInputVolume)
43  {}
44  void resetToDefaults() {
45  sampleRate = m_defaultAudioSampleRate;
46  volume = m_defaultAudioInputVolume;
47  }
48  unsigned int sampleRate;
49  float volume;
50  friend QDataStream& operator<<(QDataStream& ds, const InputDeviceInfo& info);
51  friend QDataStream& operator>>(QDataStream& ds, InputDeviceInfo& info);
52  };
53 
55  {
56  public:
58  sampleRate(m_defaultAudioSampleRate),
59  udpAddress(m_defaultUDPAddress),
60  udpPort(m_defaultUDPPort),
61  copyToUDP(false),
62  udpUseRTP(false),
63  udpChannelMode(AudioOutput::UDPChannelLeft),
64  udpChannelCodec(AudioOutput::UDPCodecL16),
65  udpDecimationFactor(1)
66  {}
67  void resetToDefaults() {
68  sampleRate = m_defaultAudioSampleRate;
69  udpAddress = m_defaultUDPAddress;
70  udpPort = m_defaultUDPPort;
71  copyToUDP = false;
72  udpUseRTP = false;
73  udpChannelMode = AudioOutput::UDPChannelLeft;
74  udpChannelCodec = AudioOutput::UDPCodecL16;
75  udpDecimationFactor = 1;
76  }
77  unsigned int sampleRate;
78  QString udpAddress;
79  quint16 udpPort;
80  bool copyToUDP;
81  bool udpUseRTP;
85  friend QDataStream& operator<<(QDataStream& ds, const OutputDeviceInfo& info);
86  friend QDataStream& operator>>(QDataStream& ds, OutputDeviceInfo& info);
87  };
88 
91 
92  const QList<QAudioDeviceInfo>& getInputDevices() const { return m_inputDevicesInfo; }
93  const QList<QAudioDeviceInfo>& getOutputDevices() const { return m_outputDevicesInfo; }
94 
95  bool getOutputDeviceName(int outputDeviceIndex, QString &deviceName) const;
96  bool getInputDeviceName(int inputDeviceIndex, QString &deviceName) const;
97  int getOutputDeviceIndex(const QString &deviceName) const;
98  int getInputDeviceIndex(const QString &deviceName) const;
99 
100  void addAudioSink(AudioFifo* audioFifo, MessageQueue *sampleSinkMessageQueue, int outputDeviceIndex = -1);
101  void removeAudioSink(AudioFifo* audioFifo);
102 
103  void addAudioSource(AudioFifo* audioFifo, MessageQueue *sampleSourceMessageQueue, int inputDeviceIndex = -1);
104  void removeAudioSource(AudioFifo* audioFifo);
105 
106  bool getInputDeviceInfo(const QString& deviceName, InputDeviceInfo& deviceInfo) const;
107  bool getOutputDeviceInfo(const QString& deviceName, OutputDeviceInfo& deviceInfo) const;
108  int getInputSampleRate(int inputDeviceIndex = -1);
109  int getOutputSampleRate(int outputDeviceIndex = -1);
110  void setInputDeviceInfo(int inputDeviceIndex, const InputDeviceInfo& deviceInfo);
111  void setOutputDeviceInfo(int outputDeviceIndex, const OutputDeviceInfo& deviceInfo);
112  void unsetInputDeviceInfo(int inputDeviceIndex);
113  void unsetOutputDeviceInfo(int outputDeviceIndex);
114  void inputInfosCleanup();
115  void outputInfosCleanup();
116 
117  static const unsigned int m_defaultAudioSampleRate = 48000;
118  static const float m_defaultAudioInputVolume;
119  static const QString m_defaultUDPAddress;
120  static const quint16 m_defaultUDPPort = 9998;
121  static const QString m_defaultDeviceName;
122 
123 private:
124  QList<QAudioDeviceInfo> m_inputDevicesInfo;
125  QList<QAudioDeviceInfo> m_outputDevicesInfo;
126 
127  QMap<AudioFifo*, int> m_audioSinkFifos; //< audio sink FIFO to audio output device index-1 map
128  QMap<AudioFifo*, MessageQueue*> m_audioFifoToSinkMessageQueues;
129  QMap<int, QList<MessageQueue*> > m_outputDeviceSinkMessageQueues;
130  QMap<int, AudioOutput*> m_audioOutputs;
131  QMap<QString, OutputDeviceInfo> m_audioOutputInfos;
132 
133  QMap<AudioFifo*, int> m_audioSourceFifos; //< audio source FIFO to audio input device index-1 map
134  QMap<AudioFifo*, MessageQueue*> m_audioFifoToSourceMessageQueues;
135  QMap<int, QList<MessageQueue*> > m_inputDeviceSourceMessageQueues;
136  QMap<int, AudioInput*> m_audioInputs;
137  QMap<QString, InputDeviceInfo> m_audioInputInfos;
138 
139  void resetToDefaults();
140  QByteArray serialize() const;
141  bool deserialize(const QByteArray& data);
142 
143  void startAudioOutput(int outputDeviceIndex);
144  void stopAudioOutput(int outputDeviceIndex);
145  void startAudioInput(int inputDeviceIndex);
146  void stopAudioInput(int inputDeviceIndex);
147 
148  void serializeInputMap(QByteArray& data) const;
149  void deserializeInputMap(QByteArray& data);
150  void debugAudioInputInfos() const;
151 
152  void serializeOutputMap(QByteArray& data) const;
153  void deserializeOutputMap(QByteArray& data);
154  void debugAudioOutputInfos() const;
155 
156  friend class MainSettings;
157 };
158 
159 QDataStream& operator<<(QDataStream& ds, const AudioDeviceManager::InputDeviceInfo& info);
160 QDataStream& operator>>(QDataStream& ds, AudioDeviceManager::InputDeviceInfo& info);
161 
162 QDataStream& operator<<(QDataStream& ds, const AudioDeviceManager::OutputDeviceInfo& info);
163 QDataStream& operator>>(QDataStream& ds, AudioDeviceManager::OutputDeviceInfo& info);
164 
165 #endif // INCLUDE_AUDIODEVICEMANGER_H
static const QString m_defaultDeviceName
QList< QAudioDeviceInfo > m_inputDevicesInfo
const QList< QAudioDeviceInfo > & getInputDevices() const
QMap< QString, InputDeviceInfo > m_audioInputInfos
audio device name to audio input device info
static const QString m_defaultUDPAddress
QMap< int, QList< MessageQueue * > > m_inputDeviceSourceMessageQueues
sink message queues attached to device
AudioOutput::UDPChannelCodec udpChannelCodec
unsigned int uint32_t
Definition: rtptypes_win.h:46
QMap< int, AudioInput * > m_audioInputs
audio device index to audio input map (index -1 is default device)
QMap< int, QList< MessageQueue * > > m_outputDeviceSinkMessageQueues
sink message queues attached to device
QDataStream & operator>>(QDataStream &ds, AudioDeviceManager::InputDeviceInfo &info)
QMap< AudioFifo *, MessageQueue * > m_audioFifoToSinkMessageQueues
audio sink FIFO to attached sink message queue
QDataStream & operator<<(QDataStream &ds, const AudioDeviceManager::InputDeviceInfo &info)
Linear 16 bit (no codec)
Definition: audiooutput.h:47
const QList< QAudioDeviceInfo > & getOutputDevices() const
QMap< AudioFifo *, MessageQueue * > m_audioFifoToSourceMessageQueues
audio source FIFO to attached source message queue
QMap< AudioFifo *, int > m_audioSinkFifos
AudioOutput::UDPChannelMode udpChannelMode
QMap< AudioFifo *, int > m_audioSourceFifos
QMap< int, AudioOutput * > m_audioOutputs
audio device index to audio output map (index -1 is default device)
#define SDRBASE_API
Definition: export.h:40
static const float m_defaultAudioInputVolume
QMap< QString, OutputDeviceInfo > m_audioOutputInfos
audio device name to audio output info
QList< QAudioDeviceInfo > m_outputDevicesInfo