1 // Copyright (c) Charles J. Cliffe
2 // SPDX-License-Identifier: GPL-2.0+
3
4 #include "ModemAM.h"
5
ModemAM()6 ModemAM::ModemAM() : ModemAnalog() {
7 // Create a DC blocker using 25 samples wide window
8 // and 30dB reduction of the DC level.
9 mDCBlock = firfilt_rrrf_create_dc_blocker (25,30.0f);
10 useSignalOutput(true);
11 }
12
~ModemAM()13 ModemAM::~ModemAM() {
14 firfilt_rrrf_destroy(mDCBlock);
15 }
16
factory()17 ModemBase *ModemAM::factory() {
18 return new ModemAM;
19 }
20
getName()21 std::string ModemAM::getName() {
22 return "AM";
23 }
24
getDefaultSampleRate()25 int ModemAM::getDefaultSampleRate() {
26 return 6000;
27 }
28
demodulate(ModemKit * kit,ModemIQData * input,AudioThreadInput * audioOut)29 void ModemAM::demodulate(ModemKit *kit, ModemIQData *input, AudioThreadInput* audioOut) {
30 auto *amkit = (ModemKitAnalog *)kit;
31
32 initOutputBuffers(amkit,input);
33
34 if (!bufSize) {
35
36 return;
37 }
38
39 // Implement an AM demodulator. Compute signal
40 // amplitude followed by a DC blocker to remove
41 // the DC offset.
42 for (size_t i = 0; i < bufSize; i++) {
43 float I = input->data[i].real;
44 float Q = input->data[i].imag;
45 firfilt_rrrf_push (mDCBlock,sqrt(I*I+Q*Q));
46 firfilt_rrrf_execute (mDCBlock,&demodOutputData[i]);
47 }
48
49 buildAudioOutput(amkit,audioOut,true);
50 }
51