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.
audioresampler.cpp
Go to the documentation of this file.
1 // Copyright (C) 2019 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 #include "audioresampler.h"
20 
22  m_decimation(1),
23  m_decimationCount(0)
24 {}
25 
27 {}
28 
30 {
31  m_decimation = decimation == 0 ? 1 : decimation;
32 }
33 
34 void AudioResampler::setAudioFilters(int srHigh, int srLow, int fcLow, int fcHigh, float gain)
35 {
36  srHigh = (srHigh <= 100 ? 100 : srHigh);
37  srLow = (srLow <= 0 ? 1 : srLow);
38  srLow = srLow > srHigh - 50 ? srHigh - 50 : srLow;
39 
40  fcLow = fcLow < 0 ? 0 : fcLow;
41  fcHigh = fcHigh < 100 ? 100 : fcHigh;
42  fcLow = fcLow > fcHigh - 100 ? fcHigh - 100 : fcLow;
43 
44  m_audioFilter.setDecimFilters(srHigh, srLow, fcHigh, fcLow, gain);
45 }
46 
47 bool AudioResampler::downSample(qint16 sampleIn, qint16& sampleOut)
48 {
49  if (m_decimation == 1)
50  {
51  sampleOut = sampleIn;
52  return true;
53  }
54 
56  {
57  float lpSample = m_audioFilter.run(sampleIn / 32768.0f);
58  sampleOut = lpSample * 32768.0f;
60  return true;
61  }
62  else
63  {
65  return false;
66  }
67 }
68 
69 bool AudioResampler::upSample(qint16 sampleIn, qint16& sampleOut)
70 {
71  float lpSample;
72 
73  if (m_decimation == 1)
74  {
75  sampleOut = sampleIn;
76  return true;
77  }
78 
80  {
82  lpSample = m_audioFilter.run(sampleIn / 32768.0f);
83  sampleOut = lpSample * 32768.0f;
84  return true;
85  }
86  else
87  {
89  lpSample = m_audioFilter.run(0.0f);
90  sampleOut = lpSample * 32768.0f;
91  return false;
92  }
93 }
94 
95 
bool upSample(qint16 sampleIn, qint16 &sampleOut)
int decimation(float Fin, float Fout)
Definition: datvdemod.h:66
void setAudioFilters(int srHigh, int srLow, int fcLow, int fcHigh, float gain=1.0f)
void setDecimation(uint32_t decimation)
uint32_t m_decimation
unsigned int uint32_t
Definition: rtptypes_win.h:46
uint32_t m_decimationCount
AudioFilter m_audioFilter
float run(const float &sample)
void setDecimFilters(int srHigh, int srLow, float fcHigh, float fcLow, float gain=1.0f)
Definition: audiofilter.cpp:42
bool downSample(qint16 sampleIn, qint16 &sampleOut)