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

#include <audiocompressor.h>

Public Member Functions

 AudioCompressor ()
 
 ~AudioCompressor ()
 
void fillLUT ()
 4 bands More...
 
void fillLUT2 ()
 8 bands (default) More...
 
void fillALaw ()
 A-law compression to 8 bits. More...
 
void fillULaw ()
 u-law compression to 8 bits More...
 
int16_t compress (int16_t sample)
 
int8_t compress8 (int16_t sample)
 

Private Member Functions

int8_t ALaw_Encode (int16_t number)
 
int8_t MuLaw_Encode (int16_t number)
 

Private Attributes

int16_t m_lut [32768]
 

Static Private Attributes

static const uint16_t ALAW_MAX = 0xFFF
 
static const uint16_t MULAW_MAX = 0x1FFF
 
static const uint16_t MULAW_BIAS = 33
 

Detailed Description

Definition at line 25 of file audiocompressor.h.

Constructor & Destructor Documentation

◆ AudioCompressor()

AudioCompressor::AudioCompressor ( )

Definition at line 26 of file audiocompressor.cpp.

References fillLUT2().

27 {
28  fillLUT2();
29 }
void fillLUT2()
8 bands (default)
+ Here is the call graph for this function:

◆ ~AudioCompressor()

AudioCompressor::~AudioCompressor ( )

Definition at line 31 of file audiocompressor.cpp.

32 {}

Member Function Documentation

◆ ALaw_Encode()

int8_t AudioCompressor::ALaw_Encode ( int16_t  number)
private

Definition at line 139 of file audiocompressor.cpp.

References ALAW_MAX.

Referenced by fillALaw().

140 {
141  uint16_t mask = 0x800;
142  uint8_t sign = 0;
143  uint8_t position = 11;
144  uint8_t lsb = 0;
145 
146  if (number < 0)
147  {
148  number = -number;
149  sign = 0x80;
150  }
151 
152  if (number > ALAW_MAX) {
153  number = ALAW_MAX;
154  }
155 
156  for (; ((number & mask) != mask && position >= 5); mask >>= 1, position--) {
157  }
158 
159  lsb = (number >> ((position == 4) ? (1) : (position - 4))) & 0x0f;
160 
161  return (sign | ((position - 4) << 4) | lsb) ^ 0x55;
162 }
unsigned char uint8_t
Definition: rtptypes_win.h:42
unsigned short uint16_t
Definition: rtptypes_win.h:44
static const uint16_t ALAW_MAX
+ Here is the caller graph for this function:

◆ compress()

int16_t AudioCompressor::compress ( int16_t  sample)

Definition at line 102 of file audiocompressor.cpp.

References abs(), and m_lut.

Referenced by AMBEWorker::upsample().

103 {
104  int16_t sign = sample < 0 ? -1 : 1;
105  int16_t abs = sample < 0 ? -sample : sample;
106  return sign * m_lut[abs];
107 }
short int16_t
Definition: rtptypes_win.h:43
Fixed< IntType, IntBits > abs(Fixed< IntType, IntBits > const &x)
Definition: fixed.h:2313
int16_t m_lut[32768]
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ compress8()

int8_t AudioCompressor::compress8 ( int16_t  sample)

Definition at line 109 of file audiocompressor.cpp.

References m_lut.

Referenced by AudioNetSink::write().

110 {
111  return m_lut[sample/2 + 16384];
112 }
int16_t m_lut[32768]
+ Here is the caller graph for this function:

◆ fillALaw()

void AudioCompressor::fillALaw ( )

A-law compression to 8 bits.

Definition at line 88 of file audiocompressor.cpp.

References ALaw_Encode(), i, and m_lut.

Referenced by AudioNetSink::setParameters().

89 {
90  for (int i=-16384; i<16384; i++) {
91  m_lut[i+16384] = ALaw_Encode(2*i);
92  }
93 }
int16_t m_lut[32768]
int32_t i
Definition: decimators.h:244
int8_t ALaw_Encode(int16_t number)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fillLUT()

void AudioCompressor::fillLUT ( )

4 bands

Definition at line 34 of file audiocompressor.cpp.

References i, and m_lut.

35 {
36  for (int i=0; i<8192; i++) {
37  m_lut[i] = (24576/8192)*i;
38  }
39 
40  for (int i=8192; i<2*8192; i++) {
41  m_lut[i] = 24576 + 0.5f*(i-8192);
42  }
43 
44  for (int i=2*8192; i<3*8192; i++) {
45  m_lut[i] = 24576 + 4096 + 0.25f*(i-2*8192);
46  }
47 
48  for (int i=3*8192; i<4*8192; i++) {
49  m_lut[i] = 24576 + 4096 + 2048 + 0.125f*(i-3*8192);
50  }
51 }
int16_t m_lut[32768]
int32_t i
Definition: decimators.h:244

◆ fillLUT2()

void AudioCompressor::fillLUT2 ( )

8 bands (default)

Definition at line 53 of file audiocompressor.cpp.

References i, and m_lut.

Referenced by AudioCompressor().

54 {
55  for (int i=0; i<4096; i++) {
56  m_lut[i] = (24576/4096)*i;
57  }
58 
59  for (int i=4096; i<2*4096; i++) {
60  m_lut[i] = 24576 + 0.5f*(i-4096);
61  }
62 
63  for (int i=2*4096; i<3*4096; i++) {
64  m_lut[i] = 24576 + 2048 + 0.25f*(i-2*4096);
65  }
66 
67  for (int i=3*4096; i<4*4096; i++) {
68  m_lut[i] = 24576 + 2048 + 1024 + 0.125f*(i-3*4096);
69  }
70 
71  for (int i=4*4096; i<5*4096; i++) {
72  m_lut[i] = 24576 + 2048 + 1024 + 512 + 0.0625f*(i-4*4096);
73  }
74 
75  for (int i=5*4096; i<6*4096; i++) {
76  m_lut[i] = 24576 + 2048 + 1024 + 512 + 256 + 0.03125f*(i-5*4096);
77  }
78 
79  for (int i=6*4096; i<7*4096; i++) {
80  m_lut[i] = 24576 + 2048 + 1024 + 512 + 256 + 128 + 0.015625f*(i-6*4096);
81  }
82 
83  for (int i=7*4096; i<8*4096; i++) {
84  m_lut[i] = 24576 + 2048 + 1024 + 512 + 256 + 128 + 64 + 0.0078125f*(i-7*4096);
85  }
86 }
int16_t m_lut[32768]
int32_t i
Definition: decimators.h:244
+ Here is the caller graph for this function:

◆ fillULaw()

void AudioCompressor::fillULaw ( )

u-law compression to 8 bits

Definition at line 95 of file audiocompressor.cpp.

References i, m_lut, and MuLaw_Encode().

Referenced by AudioNetSink::setParameters().

96 {
97  for (int i=-16384; i<16384; i++) {
98  m_lut[i+16384] = MuLaw_Encode(2*i);
99  }
100 }
int8_t MuLaw_Encode(int16_t number)
int16_t m_lut[32768]
int32_t i
Definition: decimators.h:244
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ MuLaw_Encode()

int8_t AudioCompressor::MuLaw_Encode ( int16_t  number)
private

Definition at line 175 of file audiocompressor.cpp.

References MULAW_BIAS, and MULAW_MAX.

Referenced by fillULaw().

176 {
177  uint16_t mask = 0x1000;
178  uint8_t sign = 0;
179  uint8_t position = 12;
180  uint8_t lsb = 0;
181 
182  if (number < 0)
183  {
184  number = -number;
185  sign = 0x80;
186  }
187 
188  number += MULAW_BIAS;
189 
190  if (number > MULAW_MAX) {
191  number = MULAW_MAX;
192  }
193 
194  for (; ((number & mask) != mask && position >= 5); mask >>= 1, position--) {
195  }
196 
197  lsb = (number >> (position - 4)) & 0x0f;
198 
199  return (~(sign | ((position - 5) << 4) | lsb));
200 }
static const uint16_t MULAW_MAX
static const uint16_t MULAW_BIAS
unsigned char uint8_t
Definition: rtptypes_win.h:42
unsigned short uint16_t
Definition: rtptypes_win.h:44
+ Here is the caller graph for this function:

Member Data Documentation

◆ ALAW_MAX

const uint16_t AudioCompressor::ALAW_MAX = 0xFFF
staticprivate

Definition at line 42 of file audiocompressor.h.

Referenced by ALaw_Encode().

◆ m_lut

int16_t AudioCompressor::m_lut[32768]
private

Definition at line 41 of file audiocompressor.h.

Referenced by compress(), compress8(), fillALaw(), fillLUT(), fillLUT2(), and fillULaw().

◆ MULAW_BIAS

const uint16_t AudioCompressor::MULAW_BIAS = 33
staticprivate

Definition at line 44 of file audiocompressor.h.

Referenced by MuLaw_Encode().

◆ MULAW_MAX

const uint16_t AudioCompressor::MULAW_MAX = 0x1FFF
staticprivate

Definition at line 43 of file audiocompressor.h.

Referenced by MuLaw_Encode().


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