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 Member Functions | Static Public Attributes | Private Attributes | List of all members
AudioOpus Class Reference

#include <audioopus.h>

Public Member Functions

 AudioOpus ()
 
 ~AudioOpus ()
 
void setEncoder (int32_t fs, int nChannels)
 
int encode (int frameSize, int16_t *in, uint8_t *out)
 

Static Public Attributes

static const int m_bitrate = 64000
 Fixed 64kb/s bitrate (8kB/s) More...
 
static const int m_maxPacketSize = 3*1276
 

Private Attributes

OpusEncoder * m_encoderState
 
bool m_encoderOK
 
QMutex m_mutex
 

Detailed Description

Definition at line 28 of file audioopus.h.

Constructor & Destructor Documentation

◆ AudioOpus()

AudioOpus::AudioOpus ( )

Definition at line 28 of file audioopus.cpp.

28  :
29  m_encoderState(0),
30  m_encoderOK(false),
31  m_mutex(QMutex::Recursive)
32 {
33  qDebug("AudioOpus::AudioOpus: libopus version %s", opus_get_version_string());
34 }
bool m_encoderOK
Definition: audioopus.h:42
QMutex m_mutex
Definition: audioopus.h:43
OpusEncoder * m_encoderState
Definition: audioopus.h:41

◆ ~AudioOpus()

AudioOpus::~AudioOpus ( )

Definition at line 36 of file audioopus.cpp.

References m_encoderState.

37 {
38  if (m_encoderState) {
39  opus_encoder_destroy(m_encoderState);
40  }
41 }
OpusEncoder * m_encoderState
Definition: audioopus.h:41

Member Function Documentation

◆ encode()

int AudioOpus::encode ( int  frameSize,
int16_t in,
uint8_t out 
)

Definition at line 86 of file audioopus.cpp.

References m_encoderOK, m_encoderState, m_maxPacketSize, and m_mutex.

Referenced by AudioNetSink::write().

87 {
88  QMutexLocker mutexLocker(&m_mutex);
89 
90  if (!m_encoderOK)
91  {
92  qWarning("AudioOpus::encode: encoder not initialized");
93  return 0;
94  }
95 
96  int nbBytes = opus_encode(m_encoderState, in, frameSize, out, m_maxPacketSize);
97 
98  if (nbBytes < 0)
99  {
100  qWarning("AudioOpus::encode failed: %s", opus_strerror(nbBytes));
101  return 0;
102  }
103  else
104  {
105  return nbBytes;
106  }
107 }
static const int m_maxPacketSize
Definition: audioopus.h:38
bool m_encoderOK
Definition: audioopus.h:42
QMutex m_mutex
Definition: audioopus.h:43
OpusEncoder * m_encoderState
Definition: audioopus.h:41
+ Here is the caller graph for this function:

◆ setEncoder()

void AudioOpus::setEncoder ( int32_t  fs,
int  nChannels 
)

Definition at line 43 of file audioopus.cpp.

References m_bitrate, m_encoderOK, m_encoderState, and m_mutex.

Referenced by AudioNetSink::setNewCodecData().

44 {
45  int error;
46  bool newInstance = true;
47  QMutexLocker mutexLocker(&m_mutex);
48 
49  if (m_encoderState) {
50  opus_encoder_destroy(m_encoderState);
51  }
52 
53  m_encoderState = opus_encoder_create(fs, nChannels, OPUS_APPLICATION_AUDIO, &error);
54 
55  if (error != OPUS_OK)
56  {
57  qWarning("AudioOpus::setEncoder: error: %s", opus_strerror(error));
58  m_encoderOK = false;
59  return;
60  }
61  else
62  {
63  qDebug("AudioOpus::setEncoder: fs: %d, nChannels: %d", fs, nChannels);
64  m_encoderOK = true;
65  }
66 
67  error = opus_encoder_ctl(m_encoderState, OPUS_SET_BITRATE(m_bitrate));
68 
69  if (error != OPUS_OK)
70  {
71  qWarning("AudioOpus::setEncoder: set bitrate error: %s", opus_strerror(error));
72  m_encoderOK = false;
73  return;
74  }
75 
76  error = opus_encoder_ctl(m_encoderState, OPUS_SET_VBR(0)); // force constant bit rate
77 
78  if (error != OPUS_OK)
79  {
80  qWarning("AudioOpus::setEncoder: set constant bitrate error: %s", opus_strerror(error));
81  m_encoderOK = false;
82  return;
83  }
84 }
static const int m_bitrate
Fixed 64kb/s bitrate (8kB/s)
Definition: audioopus.h:37
bool m_encoderOK
Definition: audioopus.h:42
QMutex m_mutex
Definition: audioopus.h:43
OpusEncoder * m_encoderState
Definition: audioopus.h:41
+ Here is the caller graph for this function:

Member Data Documentation

◆ m_bitrate

const int AudioOpus::m_bitrate = 64000
static

Fixed 64kb/s bitrate (8kB/s)

Definition at line 37 of file audioopus.h.

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

◆ m_encoderOK

bool AudioOpus::m_encoderOK
private

Definition at line 42 of file audioopus.h.

Referenced by encode(), and setEncoder().

◆ m_encoderState

OpusEncoder* AudioOpus::m_encoderState
private

Definition at line 41 of file audioopus.h.

Referenced by encode(), setEncoder(), and ~AudioOpus().

◆ m_maxPacketSize

const int AudioOpus::m_maxPacketSize = 3*1276
static

Definition at line 38 of file audioopus.h.

Referenced by encode().

◆ m_mutex

QMutex AudioOpus::m_mutex
private

Definition at line 43 of file audioopus.h.

Referenced by encode(), and setEncoder().


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