-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSpectrumVis3D.pas
More file actions
executable file
·136 lines (112 loc) · 4.74 KB
/
SpectrumVis3D.pas
File metadata and controls
executable file
·136 lines (112 loc) · 4.74 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
unit SpectrumVis3D;
{ Spectrum Visualyzation by Alessandro Cappellozza
version 0.8 05/2002
http://digilander.iol.it/Kappe/audioobject
}
interface
uses Dialogs, Graphics, SysUtils, Classes;
type
TWaveData = array [0..2048] of DWORD;
TFFTData = array [0..512] of Single;
TSpectrum = Class(TObject)
private
VisBuff : TBitmap;
BackBmp : TBitmap;
BkgColor : TColor;
SpecHeight : Integer;
PenColor : TColor;
PeakColor: TColor;
DrawType : Integer;
DrawRes : Integer;
FrmClear : Boolean;
UseBkg : Boolean;
PeakFall : Integer;
LineFall : Integer;
ColWidth : Integer;
ShowPeak : Boolean;
FFTPeacks : array [0..128] of Integer;
FFTFallOff : array [0..128] of Integer;
public
Constructor Create (Width, Height : Integer);
procedure Draw(Canvas : TCanvas; FFTData : TFFTData; X, Y : Integer);
procedure SetBackGround (Active : Boolean; BkgCanvas : TGraphic);
property BackColor : TColor read BkgColor write BkgColor;
property Height : Integer read SpecHeight write SpecHeight;
property Width : Integer read ColWidth write ColWidth;
property Pen : TColor read PenColor write PenColor;
property Peak : TColor read PeakColor write PeakColor;
property Mode : Integer read DrawType write DrawType;
property Res : Integer read DrawRes write DrawRes;
property FrameClear : Boolean read FrmClear write FrmClear;
property PeakFallOff: Integer read PeakFall write PeakFall;
property LineFallOff: Integer read LineFall write LineFall;
property DrawPeak : Boolean read ShowPeak write ShowPeak;
end;
//var Spectrum : TSpectrum;
implementation
Constructor TSpectrum.Create(Width, Height : Integer);
begin
VisBuff := TBitmap.Create;
BackBmp := TBitmap.Create;
VisBuff.Width := Width;
VisBuff.Height := Height;
BackBmp.Width := Width;
BackBmp.Height := Height;
BkgColor := clBlack;
SpecHeight := 100;
PenColor := clWhite;
PeakColor := clYellow;
DrawType := 1;
DrawRes := 1;
FrmClear := True;
UseBkg := False;
PeakFall := 1;
LineFall := 3;
ColWidth := 5;
ShowPeak := True;
end;
procedure TSpectrum.SetBackGround (Active : Boolean; BkgCanvas : TGraphic);
begin
UseBkg := Active;
BackBmp.Canvas.Draw(0, 0, BkgCanvas);
end;
procedure TSpectrum.Draw(Canvas : TCanvas; FFTData : TFFTData; X, Y : Integer);
var i, YPos : LongInt; YVal : Single;
begin
if FrmClear then begin
VisBuff.Canvas.Pen.Color := BkgColor;
VisBuff.Canvas.Brush.Color := BkgColor;
VisBuff.Canvas.Rectangle(0, 0, VisBuff.Width, VisBuff.Height);
if UseBkg then VisBuff.Canvas.CopyRect(Rect(0, 0, BackBmp.Width, BackBmp.Height), BackBmp.Canvas, Rect(0, 0, BackBmp.Width, BackBmp.Height));
end;
VisBuff.Canvas.Pen.Color := PenColor;
for i := 0 to 128 do begin
YVal := Abs(FFTData[(i * DrawRes) + 5]);
YPos := Trunc((YVal) * 500);
if YPos > Height then YPos := SpecHeight;
if YPos >= FFTPeacks[i] then FFTPeacks[i] := YPos
else FFTPeacks[i] := FFTPeacks[i] - PeakFall;
if YPos >= FFTFallOff[i] then FFTFallOff[i] := YPos
else FFTFallOff[i] := FFTFallOff[i] - LineFall;
if (VisBuff.Height - FFTPeacks[i]) > VisBuff.Height then FFTPeacks[i] := 0;
if (VisBuff.Height - FFTFallOff[i]) > VisBuff.Height then FFTFallOff[i] := 0;
case DrawType of
0 : begin
VisBuff.Canvas.MoveTo(X + i, Y + VisBuff.Height);
VisBuff.Canvas.LineTo(X + i, Y + VisBuff.Height - FFTFallOff[i]);
if ShowPeak then VisBuff.Canvas.Pixels[X + i, Y + VisBuff.Height - FFTPeacks[i]] := Pen;
end;
1 : begin
if ShowPeak then VisBuff.Canvas.Pen.Color := PeakColor;
if ShowPeak then VisBuff.Canvas.MoveTo(X + i * (ColWidth + 1), Y + VisBuff.Height - FFTPeacks[i]);
if ShowPeak then VisBuff.Canvas.LineTo(X + i * (ColWidth + 1) + ColWidth, Y + VisBuff.Height - FFTPeacks[i]);
VisBuff.Canvas.Pen.Color := PenColor;
VisBuff.Canvas.Brush.Color := PenColor;
VisBuff.Canvas.Rectangle(X + i * (ColWidth + 1), Y + VisBuff.Height - FFTFallOff[i],
X + i * (ColWidth + 1) + ColWidth, Y + VisBuff.Height);
end;
end;
end;
Canvas.Draw(0, 0, VisBuff);
end;
end.