1 // Copyright (c) Charles J. Cliffe
2 // SPDX-License-Identifier: GPL-2.0+
3
4 #include "ModemUSB.h"
5
ModemUSB()6 ModemUSB::ModemUSB() : ModemAnalog() {
7 // half band filter used for side-band elimination
8 ssbFilt = iirfilt_crcf_create_lowpass(6, 0.25);
9 ssbShift = nco_crcf_create(LIQUID_NCO);
10 nco_crcf_set_frequency(ssbShift, (float)((2.0 * M_PI) * 0.25));
11 c2rFilt = firhilbf_create(5, 90.0);
12 useSignalOutput(true);
13 }
14
factory()15 ModemBase *ModemUSB::factory() {
16 return new ModemUSB;
17 }
18
getName()19 std::string ModemUSB::getName() {
20 return "USB";
21 }
22
~ModemUSB()23 ModemUSB::~ModemUSB() {
24 iirfilt_crcf_destroy(ssbFilt);
25 nco_crcf_destroy(ssbShift);
26 firhilbf_destroy(c2rFilt);
27 }
28
checkSampleRate(long long sampleRate,int)29 int ModemUSB::checkSampleRate(long long sampleRate, int /* audioSampleRate */) {
30 if (sampleRate < MIN_BANDWIDTH) {
31 return MIN_BANDWIDTH;
32 }
33 if (sampleRate % 2 == 0) {
34 return (int)sampleRate;
35 }
36 return (int)(sampleRate+1);
37 }
38
getDefaultSampleRate()39 int ModemUSB::getDefaultSampleRate() {
40 return 5400;
41 }
42
demodulate(ModemKit * kit,ModemIQData * input,AudioThreadInput * audioOut)43 void ModemUSB::demodulate(ModemKit *kit, ModemIQData *input, AudioThreadInput *audioOut) {
44 auto *akit = (ModemKitAnalog *)kit;
45
46 initOutputBuffers(akit,input);
47
48 if (!bufSize) {
49
50 return;
51 }
52
53 liquid_float_complex x, y;
54 for (size_t i = 0; i < bufSize; i++) { // Reject lower band
55 nco_crcf_step(ssbShift);
56 nco_crcf_mix_down(ssbShift, input->data[i], &x);
57 iirfilt_crcf_execute(ssbFilt, x, &y);
58 nco_crcf_mix_up(ssbShift, y, &x);
59 float lsb_discard;
60 firhilbf_c2r_execute(c2rFilt, x, &lsb_discard, &demodOutputData[i]);
61 }
62
63 buildAudioOutput(akit, audioOut, true);
64 }
65
66