3 {$INCLUDE ../shared/a_modes.inc}
8 LCLIntf
, LCLType
, LMessages
, Classes
, Controls
, Graphics
9 {$IFNDEF NOSOUND}, fmod
, fmodtypes
;{$ELSE};{$ENDIF}
12 N_SPECTRUM_VALUES
= 512;
18 FMOD_CHANNEL
= Pointer;
19 FMOD_RESULT
= Integer;
23 TSpectrumStyle
= (ssSmooth
, ssBlock
);
25 TMiniSpectrum
= class (TGraphicControl
)
30 FStyle
: TSpectrumStyle
;
31 FValues
: array [0..N_SPECTRUM_VALUES
-1] of Single;
33 FChannel
: FMOD_CHANNEL
;
34 FRawData
: System
.PSingle;
36 procedure SetStyle(const Value
: TSpectrumStyle
);
39 procedure Paint(); override;
40 procedure Resize(); override;
41 procedure SetEnabled(Value
: Boolean); override;
44 constructor Create(AOwner
: TComponent
); override;
45 destructor Destroy
; override;
47 procedure SetChannel(ch
: FMOD_CHANNEL
);
51 property Scale
: Single read FScale write FScale
;
52 property Style
: TSpectrumStyle read FStyle write SetStyle
;
59 BinEditor
, g_language
;
63 constructor TMiniSpectrum
.Create(AOwner
: TComponent
);
73 Parent
:= AOwner
as TWinControl
;
74 Width
:= Parent
.Width
;
75 Height
:= Parent
.Height
;
80 GetMem(FRawData
, N_SPECTRUM_VALUES
* SizeOf(Single));
82 // Create draw buffer:
83 FBuffer
:= TBitmap
.Create();
84 FBuffer
.PixelFormat
:= pf32bit
;
85 FBuffer
.Width
:= Width
;
86 FBuffer
.Height
:= Height
;
88 // Create gradient bitmap:
90 FGradient
:= TBitmap
.Create();
91 FGradient
.PixelFormat
:= pf32bit
;
92 FGradient
.Width
:= Width
div FGradientCount
;
93 FGradient
.Height
:= Height
;
99 for Y
:= 0 to Height
-1 do
101 if Y
> (Height
div 2)-1 then
109 C
:= TColor(RGB(R
, G
, B
));
110 for X
:= 0 to Width
-2 do
111 FGradient
.Canvas
.Pixels
[X
, Y
] := C
;
112 FGradient
.Canvas
.Pixels
[Width
-1, Y
] := TColor(0);
116 destructor TMiniSpectrum
.Destroy
;
126 PSingleArray
= ^TSingleArray
;
127 TSingleArray
= array [0..0] of Single;
129 procedure TMiniSpectrum
.Draw();
133 X
, Y
, a
, nGC
: Integer;
139 FBuffer
.Canvas
.Brush
.Color
:= Color
;
140 FBuffer
.Canvas
.FillRect(BoundsRect
);
144 if FChannel
<> nil then
146 res
:= FMOD_Channel_GetSpectrum(FChannel
, FRawData
,
147 N_SPECTRUM_VALUES
, 0, FMOD_DSP_FFT_WINDOW_MAX
);
148 if res
<> FMOD_OK
then
150 ZeroMemory(@FValues
, SizeOf(FValues
));
154 Data
:= PSingleArray(FRawData
);
155 for X
:= 0 to High(FValues
) do
157 FValues
[X
] := Data
^[X
] * FScale
;
158 if FValues
[X
] > 1.0 then
165 ZeroMemory(@FValues
, SizeOf(FValues
));
173 nGC
:= N_SPECTRUM_VALUES
div FGradientCount
;
175 for X
:= 0 to FGradientCount
do
177 for a
:= X
*nGC
to (X
+1)*nGC
-1 do
178 if PeakData
< FValues
[a
] then
179 PeakData
:= FValues
[a
];
181 if PeakData
> 0.0 then
183 Y
:= Height
- Trunc(PeakData
*Height
);
185 FBuffer
.Canvas
.CopyRect(Rect(X
*FGradient
.Width
+1, Y
, (X
+1)*FGradient
.Width
, Height
),
186 FGradient
.Canvas
, Rect(0, Y
, FGradient
.Width
, FGradient
.Height
));
192 else // if Enabled ...
195 FBuffer
.Canvas
.Font
.Color
:= clWhite
;
197 DrawText(FBuffer
.Canvas
.Handle
, PChar(MsgLabSpectrum
), -1, ARect
,
198 DT_WORDBREAK
or DT_NOPREFIX
or DT_VCENTER
or DT_CENTER
);
201 Canvas
.Draw(0, 0, FBuffer
);
205 procedure TMiniSpectrum
.SetChannel(ch
: FMOD_CHANNEL
);
210 procedure TMiniSpectrum
.Paint
;
215 procedure TMiniSpectrum
.Resize
;
219 if Assigned(FBuffer
) then
221 FBuffer
.Width
:= Width
;
222 FBuffer
.Height
:= Height
;
226 procedure TMiniSpectrum
.SetEnabled(Value
: Boolean);
230 //FSOUND_DSP_SetActive(FSOUND_DSP_GetFFTUnit, Value);
233 procedure TMiniSpectrum
.SetStyle(const Value
: TSpectrumStyle
);
235 if FStyle
<> Value
then
238 ZeroMemory(@FValues
, SizeOf(FValues
));