-
Notifications
You must be signed in to change notification settings - Fork 7
/
rm_am.pas
95 lines (75 loc) · 2.06 KB
/
rm_am.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
unit rm_am;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, UComplex, RadioMessage, RadioModule, RadioSystem;
type
{ TRadioAMDetector }
TRadioAMDetector = class(TRadioModule)
private
FRegulator: TStreamRegulator;
procedure ReceiveRegulatedData(const P: PComplex; const Len: Integer);
protected
function RMSetFrequency(const Msg: TRadioMessage; const Freq: Cardinal): Integer; override;
function RMSetSampleRate(const Msg: TRadioMessage; const Rate: Cardinal): Integer; override;
public
constructor Create(RunQueue: TRadioRunQueue); override;
destructor Destroy; override;
procedure ReceiveData(const P: PComplex; const Len: Integer); override;
end;
implementation
uses
SignalBasic;
{ TRadioAMDetector }
procedure TRadioAMDetector.ReceiveRegulatedData(const P: PComplex;
const Len: Integer);
var
I: Integer;
J: Integer;
O: PComplex;
begin
O := Alloc(DefOutput, I);
if not Assigned(O) then
begin
TRadioLogger.Report(llWarn, 'TRadioAMDetector.ReceiveRegulatedData: data lost');
Exit;
end;
for J := 0 to Len - 1 do
begin
O[J].im := 0;
O[J].re := cmod(P[I]);
end;
CancelDC(O, Len);
DefOutput.Broadcast(I, FDataListeners);
end;
function TRadioAMDetector.RMSetFrequency(const Msg: TRadioMessage;
const Freq: Cardinal): Integer;
begin
Result := 0;
end;
function TRadioAMDetector.RMSetSampleRate(const Msg: TRadioMessage;
const Rate: Cardinal): Integer;
begin
Result := inherited;
Broadcast(RM_SET_FEATURE, RM_FEATURE_FREQ, 0);
end;
constructor TRadioAMDetector.Create(RunQueue: TRadioRunQueue);
begin
inherited Create(RunQueue);
FRegulator := TStreamRegulator.Create;
FRegulator.Size := DefOutput.BufferSize;
FRegulator.OnRegulatedData := @ReceiveRegulatedData;
FHasConfig := False;
end;
destructor TRadioAMDetector.Destroy;
begin
FRegulator.Free;
inherited Destroy;
end;
procedure TRadioAMDetector.ReceiveData(const P: PComplex; const Len: Integer);
begin
FRegulator.ReceiveData(P, Len);
end;
initialization
RegisterModule(TRadioModuleClass(TRadioAMDetector.ClassType));
end.