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.
Public Types | Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
AudioNetSink Class Reference

#include <audionetsink.h>

+ Collaboration diagram for AudioNetSink:

Public Types

enum  SinkType { SinkUDP, SinkRTP }
 
enum  Codec {
  CodecL16, CodecL8, CodecPCMA, CodecPCMU,
  CodecG722, CodecOpus
}
 

Public Member Functions

 AudioNetSink (QObject *parent)
 without RTP More...
 
 AudioNetSink (QObject *parent, int sampleRate, bool stereo)
 with RTP More...
 
 ~AudioNetSink ()
 
void setDestination (const QString &address, uint16_t port)
 
void addDestination (const QString &address, uint16_t port)
 
void deleteDestination (const QString &address, uint16_t port)
 
void setParameters (Codec codec, bool stereo, int sampleRate)
 
void setDecimation (uint32_t decimation)
 
void write (qint16 sample)
 
void write (qint16 lSample, qint16 rSample)
 
bool isRTPCapable () const
 
bool selectType (SinkType type)
 
void moveToThread (QThread *thread)
 

Static Public Attributes

static const int m_udpBlockSize = 512
 
static const int m_dataBlockSize = 65536
 
static const int m_g722BlockSize = 12800
 
static const int m_opusBlockSize = 960*2
 
static const int m_opusOutputSize = 160
 

Protected Member Functions

void setNewCodecData ()
 
void setDecimationFilters ()
 

Protected Attributes

SinkType m_type
 
Codec m_codec
 
QUdpSocket * m_udpSocket
 
RTPSinkm_rtpBufferAudio
 
AudioCompressor m_audioCompressor
 
AudioG722 m_g722
 
AudioOpus m_opus
 
AudioFilter m_audioFilter
 
int m_sampleRate
 
bool m_stereo
 
uint32_t m_decimation
 
uint32_t m_decimationCount
 
char m_data [m_dataBlockSize]
 
int16_t m_opusIn [m_opusBlockSize]
 
int m_codecInputSize
 
int m_codecInputIndex
 
int m_codecRatio
 
unsigned int m_bufferIndex
 
QHostAddress m_address
 
unsigned int m_port
 

Detailed Description

Definition at line 37 of file audionetsink.h.

Member Enumeration Documentation

◆ Codec

Enumerator
CodecL16 

Linear 16 bit samples (no formatting)

CodecL8 

Linear 8 bit samples.

CodecPCMA 

PCM A-law 8 bit samples.

CodecPCMU 

PCM Mu-law 8 bit samples.

CodecG722 

G722 compressed 8 bit samples 16kS/s in 8kS/s out.

CodecOpus 

Opus compressed 8 bit samples at 64kbits/s (8kS/s out). Various input sample rates.

Definition at line 45 of file audionetsink.h.

46  {
47  CodecL16,
48  CodecL8,
49  CodecPCMA,
50  CodecPCMU,
51  CodecG722,
52  CodecOpus
53  } Codec;
Linear 16 bit samples (no formatting)
Definition: audionetsink.h:47
PCM Mu-law 8 bit samples.
Definition: audionetsink.h:50
PCM A-law 8 bit samples.
Definition: audionetsink.h:49
Linear 8 bit samples.
Definition: audionetsink.h:48
Opus compressed 8 bit samples at 64kbits/s (8kS/s out). Various input sample rates.
Definition: audionetsink.h:52
G722 compressed 8 bit samples 16kS/s in 8kS/s out.
Definition: audionetsink.h:51

◆ SinkType

Enumerator
SinkUDP 
SinkRTP 

Definition at line 39 of file audionetsink.h.

Constructor & Destructor Documentation

◆ AudioNetSink() [1/2]

AudioNetSink::AudioNetSink ( QObject *  parent)

without RTP

Definition at line 29 of file audionetsink.cpp.

References AudioOpus::m_bitrate, m_codecRatio, m_data, m_dataBlockSize, m_decimation, m_opusBlockSize, m_opusIn, m_sampleRate, and m_udpSocket.

29  :
30  m_type(SinkUDP),
33  m_sampleRate(48000),
34  m_stereo(false),
35  m_decimation(1),
37  m_codecInputSize(960),
39  m_bufferIndex(0),
40  m_port(9998)
41 {
42  std::fill(m_data, m_data+m_dataBlockSize, 0);
43  std::fill(m_opusIn, m_opusIn+m_opusBlockSize, 0);
44  m_codecRatio = (m_sampleRate / m_decimation) / (AudioOpus::m_bitrate / 8); // compressor ratio
45  m_udpSocket = new QUdpSocket(parent);
46 }
Linear 16 bit samples (no formatting)
Definition: audionetsink.h:47
RTPSink * m_rtpBufferAudio
Definition: audionetsink.h:86
uint32_t m_decimation
Definition: audionetsink.h:93
static const int m_bitrate
Fixed 64kb/s bitrate (8kB/s)
Definition: audioopus.h:37
char m_data[m_dataBlockSize]
Definition: audionetsink.h:95
int16_t m_opusIn[m_opusBlockSize]
Definition: audionetsink.h:96
unsigned int m_bufferIndex
Definition: audionetsink.h:100
int m_codecInputIndex
Definition: audionetsink.h:98
unsigned int m_port
Definition: audionetsink.h:102
static const int m_dataBlockSize
Definition: audionetsink.h:74
QUdpSocket * m_udpSocket
Definition: audionetsink.h:85
uint32_t m_decimationCount
Definition: audionetsink.h:94
int m_codecInputSize
Definition: audionetsink.h:97
SinkType m_type
Definition: audionetsink.h:83
static const int m_opusBlockSize
Definition: audionetsink.h:76

◆ AudioNetSink() [2/2]

AudioNetSink::AudioNetSink ( QObject *  parent,
int  sampleRate,
bool  stereo 
)

with RTP

Definition at line 48 of file audionetsink.cpp.

References AudioOpus::m_bitrate, m_codecRatio, m_data, m_dataBlockSize, m_decimation, m_opusBlockSize, m_opusIn, m_rtpBufferAudio, m_sampleRate, and m_udpSocket.

48  :
49  m_type(SinkUDP),
52  m_sampleRate(48000),
53  m_stereo(false),
54  m_decimation(1),
56  m_codecInputSize(960),
58  m_bufferIndex(0),
59  m_port(9998)
60 {
61  std::fill(m_data, m_data+m_dataBlockSize, 0);
62  std::fill(m_opusIn, m_opusIn+m_opusBlockSize, 0);
63  m_codecRatio = (m_sampleRate / m_decimation) / (AudioOpus::m_bitrate / 8); // compressor ratio
64  m_udpSocket = new QUdpSocket(parent);
65  m_rtpBufferAudio = new RTPSink(m_udpSocket, sampleRate, stereo);
66 }
Linear 16 bit samples (no formatting)
Definition: audionetsink.h:47
RTPSink * m_rtpBufferAudio
Definition: audionetsink.h:86
uint32_t m_decimation
Definition: audionetsink.h:93
static const int m_bitrate
Fixed 64kb/s bitrate (8kB/s)
Definition: audioopus.h:37
char m_data[m_dataBlockSize]
Definition: audionetsink.h:95
int16_t m_opusIn[m_opusBlockSize]
Definition: audionetsink.h:96
unsigned int m_bufferIndex
Definition: audionetsink.h:100
int m_codecInputIndex
Definition: audionetsink.h:98
unsigned int m_port
Definition: audionetsink.h:102
static const int m_dataBlockSize
Definition: audionetsink.h:74
QUdpSocket * m_udpSocket
Definition: audionetsink.h:85
uint32_t m_decimationCount
Definition: audionetsink.h:94
int m_codecInputSize
Definition: audionetsink.h:97
SinkType m_type
Definition: audionetsink.h:83
static const int m_opusBlockSize
Definition: audionetsink.h:76

◆ ~AudioNetSink()

AudioNetSink::~AudioNetSink ( )

Definition at line 68 of file audionetsink.cpp.

References m_rtpBufferAudio, and m_udpSocket.

69 {
70  if (m_rtpBufferAudio) {
71  delete m_rtpBufferAudio;
72  }
73 
74  m_udpSocket->deleteLater(); // this thread is not the owner thread (was moved)
75 }
RTPSink * m_rtpBufferAudio
Definition: audionetsink.h:86
QUdpSocket * m_udpSocket
Definition: audionetsink.h:85

Member Function Documentation

◆ addDestination()

void AudioNetSink::addDestination ( const QString &  address,
uint16_t  port 
)

Definition at line 106 of file audionetsink.cpp.

References RTPSink::addDestination(), and m_rtpBufferAudio.

107 {
108  if (m_rtpBufferAudio) {
109  m_rtpBufferAudio->addDestination(address, port);
110  }
111 }
RTPSink * m_rtpBufferAudio
Definition: audionetsink.h:86
void addDestination(const QString &address, uint16_t port)
Definition: rtpsink.cpp:205
+ Here is the call graph for this function:

◆ deleteDestination()

void AudioNetSink::deleteDestination ( const QString &  address,
uint16_t  port 
)

Definition at line 113 of file audionetsink.cpp.

References RTPSink::deleteDestination(), and m_rtpBufferAudio.

114 {
115  if (m_rtpBufferAudio) {
116  m_rtpBufferAudio->deleteDestination(address, port);
117  }
118 }
RTPSink * m_rtpBufferAudio
Definition: audionetsink.h:86
void deleteDestination(const QString &address, uint16_t port)
Definition: rtpsink.cpp:194
+ Here is the call graph for this function:

◆ isRTPCapable()

bool AudioNetSink::isRTPCapable ( ) const

Definition at line 77 of file audionetsink.cpp.

References RTPSink::isValid(), and m_rtpBufferAudio.

78 {
80 }
RTPSink * m_rtpBufferAudio
Definition: audionetsink.h:86
bool isValid() const
Definition: rtpsink.h:56
+ Here is the call graph for this function:

◆ moveToThread()

void AudioNetSink::moveToThread ( QThread *  thread)

Definition at line 483 of file audionetsink.cpp.

References m_udpSocket.

484 {
485  m_udpSocket->moveToThread(thread);
486 }
QUdpSocket * m_udpSocket
Definition: audionetsink.h:85

◆ selectType()

bool AudioNetSink::selectType ( SinkType  type)

Definition at line 82 of file audionetsink.cpp.

References m_type, SinkRTP, and SinkUDP.

Referenced by AudioOutput::setUdpUseRTP().

83 {
84  if (type == SinkUDP)
85  {
86  m_type = SinkUDP;
87  }
88  else // this is SinkRTP
89  {
90  m_type = SinkRTP;
91  }
92 
93  return true;
94 }
SinkType m_type
Definition: audionetsink.h:83
+ Here is the caller graph for this function:

◆ setDecimation()

void AudioNetSink::setDecimation ( uint32_t  decimation)

Definition at line 162 of file audionetsink.cpp.

References decimation(), m_decimation, m_decimationCount, and setNewCodecData().

Referenced by AudioOutput::setUdpDecimation().

163 {
164  m_decimation = decimation < 1 ? 1 : decimation > 6 ? 6 : decimation;
165  qDebug() << "AudioNetSink::setDecimation: " << m_decimation << " from: " << decimation;
166  setNewCodecData();
167  m_decimationCount = 0;
168 }
int decimation(float Fin, float Fout)
Definition: datvdemod.h:66
uint32_t m_decimation
Definition: audionetsink.h:93
uint32_t m_decimationCount
Definition: audionetsink.h:94
void setNewCodecData()
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setDecimationFilters()

void AudioNetSink::setDecimationFilters ( )
protected

Definition at line 190 of file audionetsink.cpp.

References CodecG722, CodecL16, CodecL8, CodecOpus, CodecPCMA, CodecPCMU, m_audioFilter, m_codec, m_decimation, m_sampleRate, and AudioFilter::setDecimFilters().

Referenced by setNewCodecData().

191 {
192  int decimatedSampleRate = m_sampleRate / m_decimation;
193 
194  switch (m_codec)
195  {
196  case CodecPCMA:
197  case CodecPCMU:
198  m_audioFilter.setDecimFilters(m_sampleRate, decimatedSampleRate, 3300.0, 300.0);
199  break;
200  case CodecG722:
201  m_audioFilter.setDecimFilters(m_sampleRate, decimatedSampleRate, 7000.0, 50.0);
202  break;
203  case CodecOpus:
204  case CodecL8:
205  case CodecL16:
206  default:
207  m_audioFilter.setDecimFilters(m_sampleRate, decimatedSampleRate, 0.45*decimatedSampleRate, 50.0);
208  break;
209  }
210 }
Linear 16 bit samples (no formatting)
Definition: audionetsink.h:47
PCM Mu-law 8 bit samples.
Definition: audionetsink.h:50
PCM A-law 8 bit samples.
Definition: audionetsink.h:49
uint32_t m_decimation
Definition: audionetsink.h:93
Linear 8 bit samples.
Definition: audionetsink.h:48
Opus compressed 8 bit samples at 64kbits/s (8kS/s out). Various input sample rates.
Definition: audionetsink.h:52
G722 compressed 8 bit samples 16kS/s in 8kS/s out.
Definition: audionetsink.h:51
AudioFilter m_audioFilter
Definition: audionetsink.h:90
void setDecimFilters(int srHigh, int srLow, float fcHigh, float fcLow, float gain=1.0f)
Definition: audiofilter.cpp:42
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setDestination()

void AudioNetSink::setDestination ( const QString &  address,
uint16_t  port 
)

Definition at line 96 of file audionetsink.cpp.

References m_address, m_port, m_rtpBufferAudio, and RTPSink::setDestination().

Referenced by AudioOutput::setUdpDestination().

97 {
98  m_address.setAddress(const_cast<QString&>(address));
99  m_port = port;
100 
101  if (m_rtpBufferAudio) {
102  m_rtpBufferAudio->setDestination(address, port);
103  }
104 }
void setDestination(const QString &address, uint16_t port)
Definition: rtpsink.cpp:180
RTPSink * m_rtpBufferAudio
Definition: audionetsink.h:86
unsigned int m_port
Definition: audionetsink.h:102
QHostAddress m_address
Definition: audionetsink.h:101
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setNewCodecData()

void AudioNetSink::setNewCodecData ( )
protected

Definition at line 170 of file audionetsink.cpp.

References CodecOpus, AudioOpus::m_bitrate, m_bufferIndex, m_codec, m_codecInputIndex, m_codecInputSize, m_codecRatio, m_decimation, m_opus, m_sampleRate, m_stereo, setDecimationFilters(), and AudioOpus::setEncoder().

Referenced by setDecimation(), and setParameters().

171 {
172  if (m_codec == CodecOpus)
173  {
174  m_codecInputSize = m_sampleRate / (m_decimation * 50); // 20ms = 1/50s - size is per channel
175  m_codecInputSize = m_codecInputSize > 960 ? 960 : m_codecInputSize; // hard limit of 48 kS/s
176  m_codecRatio = (m_sampleRate / m_decimation) / (AudioOpus::m_bitrate / 8); // compressor ratio
177  qDebug() << "AudioNetSink::setNewCodecData: CodecOpus:"
178  << " m_codecInputSize: " << m_codecInputSize
179  << " m_codecRatio: " << m_codecRatio
180  << " Fs: " << m_sampleRate/m_decimation
181  << " stereo: " << m_stereo;
182  m_opus.setEncoder(m_sampleRate/m_decimation, m_stereo ? 2 : 1);
183  m_codecInputIndex = 0;
184  m_bufferIndex = 0;
185  }
186 
188 }
uint32_t m_decimation
Definition: audionetsink.h:93
static const int m_bitrate
Fixed 64kb/s bitrate (8kB/s)
Definition: audioopus.h:37
unsigned int m_bufferIndex
Definition: audionetsink.h:100
int m_codecInputIndex
Definition: audionetsink.h:98
void setEncoder(int32_t fs, int nChannels)
Definition: audioopus.cpp:43
Opus compressed 8 bit samples at 64kbits/s (8kS/s out). Various input sample rates.
Definition: audionetsink.h:52
void setDecimationFilters()
AudioOpus m_opus
Definition: audionetsink.h:89
int m_codecInputSize
Definition: audionetsink.h:97
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setParameters()

void AudioNetSink::setParameters ( Codec  codec,
bool  stereo,
int  sampleRate 
)

Definition at line 120 of file audionetsink.cpp.

References CodecG722, CodecL16, CodecL8, CodecOpus, CodecPCMA, CodecPCMU, AudioCompressor::fillALaw(), AudioCompressor::fillULaw(), m_audioCompressor, m_codec, m_rtpBufferAudio, m_sampleRate, m_stereo, RTPSink::PayloadG722, RTPSink::PayloadL16Mono, RTPSink::PayloadL16Stereo, RTPSink::PayloadL8, RTPSink::PayloadOpus, RTPSink::PayloadPCMA8, RTPSink::PayloadPCMU8, setNewCodecData(), and RTPSink::setPayloadInformation().

Referenced by AudioOutput::setUdpChannelFormat().

121 {
122  qDebug() << "AudioNetSink::setParameters:"
123  << " codec: " << codec
124  << " stereo: " << stereo
125  << " sampleRate: " << sampleRate;
126 
127  m_codec = codec;
128  m_stereo = stereo;
129  m_sampleRate = sampleRate;
130 
131  setNewCodecData();
132 
133  if (m_rtpBufferAudio)
134  {
135  switch (m_codec)
136  {
137  case CodecPCMA:
140  break;
141  case CodecPCMU:
144  break;
145  case CodecL8:
147  break;
148  case CodecG722:
150  break;
151  case CodecOpus:
153  break;
154  case CodecL16: // actually no codec
155  default:
157  break;
158  }
159  }
160 }
Linear 16 bit samples (no formatting)
Definition: audionetsink.h:47
PCM Mu-law 8 bit samples.
Definition: audionetsink.h:50
RTPSink * m_rtpBufferAudio
Definition: audionetsink.h:86
AudioCompressor m_audioCompressor
Definition: audionetsink.h:87
PCM A-law 8 bit samples.
Definition: audionetsink.h:49
Linear 8 bit samples.
Definition: audionetsink.h:48
Opus compressed 8 bit samples at 64kbits/s (8kS/s out). Various input sample rates.
Definition: audionetsink.h:52
G722 compressed 8 bit samples 16kS/s in 8kS/s out.
Definition: audionetsink.h:51
void fillALaw()
A-law compression to 8 bits.
void fillULaw()
u-law compression to 8 bits
void setNewCodecData()
void setPayloadInformation(PayloadType payloadType, int sampleRate)
Definition: rtpsink.cpp:75
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ write() [1/2]

void AudioNetSink::write ( qint16  sample)

Definition at line 212 of file audionetsink.cpp.

References CodecG722, CodecL16, CodecL8, CodecOpus, CodecPCMA, CodecPCMU, AudioCompressor::compress8(), AudioG722::encode(), AudioOpus::encode(), m_address, m_audioCompressor, m_audioFilter, AudioOpus::m_bitrate, m_bufferIndex, m_codec, m_codecInputIndex, m_codecInputSize, m_codecRatio, m_data, m_decimation, m_decimationCount, m_g722, m_g722BlockSize, m_opus, m_opusIn, m_port, m_rtpBufferAudio, m_type, m_udpBlockSize, m_udpSocket, AudioFilter::run(), SinkRTP, SinkUDP, and RTPSink::write().

Referenced by AudioOutput::readData().

213 {
214  qint16& sample = isample;
215 
216  if (m_decimation > 1)
217  {
218  float lpSample = m_audioFilter.run(sample / 32768.0f);
219 
220  if (m_decimationCount >= m_decimation - 1)
221  {
222  sample = lpSample * 32768.0f;
223  m_decimationCount = 0;
224  }
225  else
226  {
228  return;
229  }
230  }
231 
232  if (m_type == SinkUDP)
233  {
234  if (m_codec == CodecG722)
235  {
236  if (m_bufferIndex >= 2*m_udpBlockSize)
237  {
238  m_udpSocket->writeDatagram((const char*) m_data, (qint64 ) m_udpBlockSize, m_address, m_port);
239  m_bufferIndex = 0;
240  }
241  }
242  else
243  {
245  {
246  m_udpSocket->writeDatagram((const char*) m_data, (qint64 ) m_udpBlockSize, m_address, m_port);
247  m_bufferIndex = 0;
248  }
249  }
250 
251  switch(m_codec)
252  {
253  case CodecPCMA:
254  case CodecPCMU:
255  {
256  qint8 *p = (qint8*) &m_data[m_bufferIndex];
257  *p = m_audioCompressor.compress8(sample);
258  m_bufferIndex += sizeof(qint8);
259  }
260  break;
261  case CodecL8:
262  {
263  qint8 *p = (qint8*) &m_data[m_bufferIndex];
264  *p = sample / 256;
265  m_bufferIndex += sizeof(qint8);
266  }
267  break;
268  case CodecG722:
269  {
270  qint16 *p = (qint16*) &m_data[m_udpBlockSize + 2*m_bufferIndex];
271  *p = sample;
272  m_bufferIndex += 1;
273 
274  if (m_bufferIndex == 2*m_udpBlockSize) {
275  m_g722.encode((uint8_t *) m_data, (const int16_t*) &m_data[m_udpBlockSize], 2*m_udpBlockSize);
276  }
277  }
278  break;
279  case CodecOpus:
280  {
282  {
283  int nbBytes = m_opus.encode(m_codecInputSize, m_opusIn, (uint8_t *) m_data);
284  nbBytes = nbBytes > m_udpBlockSize ? m_udpBlockSize : nbBytes;
285  m_udpSocket->writeDatagram((const char*) m_data, (qint64 ) nbBytes, m_address, m_port);
286  m_codecInputIndex = 0;
287  }
288 
289  m_opusIn[m_codecInputIndex++] = sample;
290  }
291  break;
292  case CodecL16:
293  default:
294  {
295  qint16 *p = (qint16*) &m_data[m_bufferIndex];
296  *p = sample;
297  m_bufferIndex += sizeof(qint16);
298  }
299  break;
300  }
301  }
302  else if (m_type == SinkRTP)
303  {
304  switch(m_codec)
305  {
306  case CodecPCMA:
307  case CodecPCMU:
308  {
309  qint8 p = m_audioCompressor.compress8(sample);
310  m_rtpBufferAudio->write((uint8_t *) &p);
311  }
312  break;
313  case CodecL8:
314  {
315  qint8 p = sample / 256;
316  m_rtpBufferAudio->write((uint8_t *) &p);
317  }
318  break;
319  case CodecG722:
320  {
321 
323  {
324  m_g722.encode((uint8_t *) m_data, (const int16_t*) &m_data[m_g722BlockSize], 2*m_g722BlockSize);
325  m_bufferIndex = 0;
326  }
327 
328  if (m_bufferIndex % 2 == 0) {
329  m_rtpBufferAudio->write((uint8_t *) &m_data[m_bufferIndex/2]);
330  }
331 
332  qint16 *p = (qint16*) &m_data[m_g722BlockSize + 2*m_bufferIndex];
333  *p = sample;
334  m_bufferIndex += 1;
335  }
336  break;
337  case CodecOpus:
338  {
340  {
341  int nbBytes = m_opus.encode(m_codecInputSize, m_opusIn, (uint8_t *) m_data);
342  if (nbBytes != AudioOpus::m_bitrate/400) { // 8 bits for 1/50s (20ms)
343  qWarning("AudioNetSink::write: CodecOpus mono: unexpected output frame size: %d bytes", nbBytes);
344  }
345  m_bufferIndex = 0;
346  m_codecInputIndex = 0;
347  }
348 
349  if (m_codecInputIndex % m_codecRatio == 0) {
350  m_rtpBufferAudio->write((uint8_t *) &m_data[m_bufferIndex++]);
351  }
352 
353  m_opusIn[m_codecInputIndex++] = sample;
354  }
355  break;
356  case CodecL16:
357  default:
358  m_rtpBufferAudio->write((uint8_t *) &sample);
359  break;
360  }
361  }
362 }
short int16_t
Definition: rtptypes_win.h:43
Linear 16 bit samples (no formatting)
Definition: audionetsink.h:47
PCM Mu-law 8 bit samples.
Definition: audionetsink.h:50
RTPSink * m_rtpBufferAudio
Definition: audionetsink.h:86
AudioCompressor m_audioCompressor
Definition: audionetsink.h:87
PCM A-law 8 bit samples.
Definition: audionetsink.h:49
uint32_t m_decimation
Definition: audionetsink.h:93
static const int m_bitrate
Fixed 64kb/s bitrate (8kB/s)
Definition: audioopus.h:37
Linear 8 bit samples.
Definition: audionetsink.h:48
char m_data[m_dataBlockSize]
Definition: audionetsink.h:95
int16_t m_opusIn[m_opusBlockSize]
Definition: audionetsink.h:96
unsigned int m_bufferIndex
Definition: audionetsink.h:100
int m_codecInputIndex
Definition: audionetsink.h:98
int8_t compress8(int16_t sample)
static const int m_udpBlockSize
Definition: audionetsink.h:73
int encode(int frameSize, int16_t *in, uint8_t *out)
Definition: audioopus.cpp:86
unsigned int m_port
Definition: audionetsink.h:102
unsigned char uint8_t
Definition: rtptypes_win.h:42
QHostAddress m_address
Definition: audionetsink.h:101
AudioG722 m_g722
Definition: audionetsink.h:88
Opus compressed 8 bit samples at 64kbits/s (8kS/s out). Various input sample rates.
Definition: audionetsink.h:52
G722 compressed 8 bit samples 16kS/s in 8kS/s out.
Definition: audionetsink.h:51
QUdpSocket * m_udpSocket
Definition: audionetsink.h:85
void write(const uint8_t *sampleByte)
Definition: rtpsink.cpp:221
AudioOpus m_opus
Definition: audionetsink.h:89
float run(const float &sample)
int encode(uint8_t g722_data[], const int16_t amp[], int len)
Definition: audiog722.cpp:236
uint32_t m_decimationCount
Definition: audionetsink.h:94
AudioFilter m_audioFilter
Definition: audionetsink.h:90
int m_codecInputSize
Definition: audionetsink.h:97
SinkType m_type
Definition: audionetsink.h:83
static const int m_g722BlockSize
Definition: audionetsink.h:75
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ write() [2/2]

void AudioNetSink::write ( qint16  lSample,
qint16  rSample 
)

Definition at line 364 of file audionetsink.cpp.

References CodecG722, CodecL16, CodecL8, CodecOpus, CodecPCMA, CodecPCMU, AudioOpus::encode(), m_address, m_audioFilter, AudioOpus::m_bitrate, m_bufferIndex, m_codec, m_codecInputIndex, m_codecInputSize, m_codecRatio, m_data, m_decimation, m_decimationCount, m_opus, m_opusIn, m_port, m_rtpBufferAudio, m_type, m_udpBlockSize, m_udpSocket, AudioFilter::runLP(), SinkRTP, SinkUDP, and RTPSink::write().

365 {
366  qint16& lSample = ilSample;
367  qint16& rSample = irSample;
368 
369  if (m_decimation > 1)
370  {
371  float lpLSample = m_audioFilter.runLP(lSample / 32768.0f);
372  float lpRSample = m_audioFilter.runLP(rSample / 32768.0f);
373 
374  if (m_decimationCount >= m_decimation - 1)
375  {
376  lSample = lpLSample * 32768.0f;
377  rSample = lpRSample * 32768.0f;
378  m_decimationCount = 0;
379  }
380  else
381  {
383  return;
384  }
385  }
386 
387  if (m_type == SinkUDP)
388  {
390  {
391  m_udpSocket->writeDatagram((const char*) m_data, (qint64 ) m_udpBlockSize, m_address, m_port);
392  m_bufferIndex = 0;
393  }
394 
395  switch(m_codec)
396  {
397  case CodecPCMA:
398  case CodecPCMU:
399  case CodecG722:
400  break; // mono modes - do nothing
401  case CodecOpus:
402  {
404  {
405  int nbBytes = m_opus.encode(m_codecInputSize, m_opusIn, (uint8_t *) m_data);
406  nbBytes = nbBytes > m_udpBlockSize ? m_udpBlockSize : nbBytes;
407  m_udpSocket->writeDatagram((const char*) m_data, (qint64 ) nbBytes, m_address, m_port);
408  m_codecInputIndex = 0;
409  }
410 
411  m_opusIn[2*m_codecInputIndex] = lSample;
412  m_opusIn[2*m_codecInputIndex+1] = rSample;
414  }
415  break;
416  case CodecL8:
417  {
418  qint8 *p = (qint8*) &m_data[m_bufferIndex];
419  *p = lSample / 256;
420  m_bufferIndex += sizeof(qint8);
421  p = (qint8*) &m_data[m_bufferIndex];
422  *p = rSample / 256;
423  m_bufferIndex += sizeof(qint8);
424  }
425  break;
426  case CodecL16:
427  default:
428  {
429  qint16 *p = (qint16*) &m_data[m_bufferIndex];
430  *p = lSample;
431  m_bufferIndex += sizeof(qint16);
432  p = (qint16*) &m_data[m_bufferIndex];
433  *p = rSample;
434  m_bufferIndex += sizeof(qint16);
435  }
436  break;
437  }
438  }
439  else if (m_type == SinkRTP)
440  {
441  switch(m_codec)
442  {
443  case CodecPCMA:
444  case CodecPCMU:
445  case CodecG722:
446  break; // mono modes - do nothing
447  case CodecOpus:
448  {
450  {
451  int nbBytes = m_opus.encode(m_codecInputSize, m_opusIn, (uint8_t *) m_data);
452  if (nbBytes != AudioOpus::m_bitrate/400) { // 8 bits for 1/50s (20ms)
453  qWarning("AudioNetSink::write: CodecOpus stereo: unexpected output frame size: %d bytes", nbBytes);
454  }
455  m_bufferIndex = 0;
456  m_codecInputIndex = 0;
457  }
458 
459  if (m_codecInputIndex % m_codecRatio == 0) {
460  m_rtpBufferAudio->write((uint8_t *) &m_data[m_bufferIndex++]);
461  }
462 
463  m_opusIn[2*m_codecInputIndex] = lSample;
464  m_opusIn[2*m_codecInputIndex+1] = rSample;
466  }
467  break;
468  case CodecL8:
469  {
470  qint8 pl = lSample / 256;
471  qint8 pr = rSample / 256;
472  m_rtpBufferAudio->write((uint8_t *) &pl, (uint8_t *) &pr);
473  }
474  break;
475  case CodecL16:
476  default:
477  m_rtpBufferAudio->write((uint8_t *) &lSample, (uint8_t *) &rSample);
478  break;
479  }
480  }
481 }
Linear 16 bit samples (no formatting)
Definition: audionetsink.h:47
PCM Mu-law 8 bit samples.
Definition: audionetsink.h:50
RTPSink * m_rtpBufferAudio
Definition: audionetsink.h:86
PCM A-law 8 bit samples.
Definition: audionetsink.h:49
uint32_t m_decimation
Definition: audionetsink.h:93
static const int m_bitrate
Fixed 64kb/s bitrate (8kB/s)
Definition: audioopus.h:37
Linear 8 bit samples.
Definition: audionetsink.h:48
char m_data[m_dataBlockSize]
Definition: audionetsink.h:95
int16_t m_opusIn[m_opusBlockSize]
Definition: audionetsink.h:96
unsigned int m_bufferIndex
Definition: audionetsink.h:100
int m_codecInputIndex
Definition: audionetsink.h:98
static const int m_udpBlockSize
Definition: audionetsink.h:73
int encode(int frameSize, int16_t *in, uint8_t *out)
Definition: audioopus.cpp:86
unsigned int m_port
Definition: audionetsink.h:102
unsigned char uint8_t
Definition: rtptypes_win.h:42
QHostAddress m_address
Definition: audionetsink.h:101
Opus compressed 8 bit samples at 64kbits/s (8kS/s out). Various input sample rates.
Definition: audionetsink.h:52
G722 compressed 8 bit samples 16kS/s in 8kS/s out.
Definition: audionetsink.h:51
QUdpSocket * m_udpSocket
Definition: audionetsink.h:85
void write(const uint8_t *sampleByte)
Definition: rtpsink.cpp:221
AudioOpus m_opus
Definition: audionetsink.h:89
float runLP(const float &sample)
uint32_t m_decimationCount
Definition: audionetsink.h:94
AudioFilter m_audioFilter
Definition: audionetsink.h:90
int m_codecInputSize
Definition: audionetsink.h:97
SinkType m_type
Definition: audionetsink.h:83
+ Here is the call graph for this function:

Member Data Documentation

◆ m_address

QHostAddress AudioNetSink::m_address
protected

Definition at line 101 of file audionetsink.h.

Referenced by setDestination(), and write().

◆ m_audioCompressor

AudioCompressor AudioNetSink::m_audioCompressor
protected

Definition at line 87 of file audionetsink.h.

Referenced by setParameters(), and write().

◆ m_audioFilter

AudioFilter AudioNetSink::m_audioFilter
protected

Definition at line 90 of file audionetsink.h.

Referenced by setDecimationFilters(), and write().

◆ m_bufferIndex

unsigned int AudioNetSink::m_bufferIndex
protected

Definition at line 100 of file audionetsink.h.

Referenced by setNewCodecData(), and write().

◆ m_codec

Codec AudioNetSink::m_codec
protected

Definition at line 84 of file audionetsink.h.

Referenced by setDecimationFilters(), setNewCodecData(), setParameters(), and write().

◆ m_codecInputIndex

int AudioNetSink::m_codecInputIndex
protected

Definition at line 98 of file audionetsink.h.

Referenced by setNewCodecData(), and write().

◆ m_codecInputSize

int AudioNetSink::m_codecInputSize
protected

Definition at line 97 of file audionetsink.h.

Referenced by setNewCodecData(), and write().

◆ m_codecRatio

int AudioNetSink::m_codecRatio
protected

Definition at line 99 of file audionetsink.h.

Referenced by AudioNetSink(), setNewCodecData(), and write().

◆ m_data

char AudioNetSink::m_data[m_dataBlockSize]
protected

Definition at line 95 of file audionetsink.h.

Referenced by AudioNetSink(), and write().

◆ m_dataBlockSize

const int AudioNetSink::m_dataBlockSize = 65536
static

Definition at line 74 of file audionetsink.h.

Referenced by AudioNetSink().

◆ m_decimation

uint32_t AudioNetSink::m_decimation
protected

◆ m_decimationCount

uint32_t AudioNetSink::m_decimationCount
protected

Definition at line 94 of file audionetsink.h.

Referenced by setDecimation(), and write().

◆ m_g722

AudioG722 AudioNetSink::m_g722
protected

Definition at line 88 of file audionetsink.h.

Referenced by write().

◆ m_g722BlockSize

const int AudioNetSink::m_g722BlockSize = 12800
static

Definition at line 75 of file audionetsink.h.

Referenced by write().

◆ m_opus

AudioOpus AudioNetSink::m_opus
protected

Definition at line 89 of file audionetsink.h.

Referenced by setNewCodecData(), and write().

◆ m_opusBlockSize

const int AudioNetSink::m_opusBlockSize = 960*2
static

Definition at line 76 of file audionetsink.h.

Referenced by AudioNetSink().

◆ m_opusIn

int16_t AudioNetSink::m_opusIn[m_opusBlockSize]
protected

Definition at line 96 of file audionetsink.h.

Referenced by AudioNetSink(), and write().

◆ m_opusOutputSize

const int AudioNetSink::m_opusOutputSize = 160
static

Definition at line 77 of file audionetsink.h.

◆ m_port

unsigned int AudioNetSink::m_port
protected

Definition at line 102 of file audionetsink.h.

Referenced by setDestination(), and write().

◆ m_rtpBufferAudio

RTPSink* AudioNetSink::m_rtpBufferAudio
protected

◆ m_sampleRate

int AudioNetSink::m_sampleRate
protected

Definition at line 91 of file audionetsink.h.

Referenced by AudioNetSink(), setDecimationFilters(), setNewCodecData(), and setParameters().

◆ m_stereo

bool AudioNetSink::m_stereo
protected

Definition at line 92 of file audionetsink.h.

Referenced by setNewCodecData(), and setParameters().

◆ m_type

SinkType AudioNetSink::m_type
protected

Definition at line 83 of file audionetsink.h.

Referenced by selectType(), and write().

◆ m_udpBlockSize

const int AudioNetSink::m_udpBlockSize = 512
static

Definition at line 73 of file audionetsink.h.

Referenced by write().

◆ m_udpSocket

QUdpSocket* AudioNetSink::m_udpSocket
protected

Definition at line 85 of file audionetsink.h.

Referenced by AudioNetSink(), moveToThread(), write(), and ~AudioNetSink().


The documentation for this class was generated from the following files: