Вот нашел у себя пример на Bass, воспроизводит выбранный муз файл и отображает в спектре, думаю не сложно переделать под вашу синусоиду, главное поймите что к чему, может это вам поможет.
Код:
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.StdCtrls, Bass;
type
TForm1 = class(TForm)
PaintBoxSpectrum: TPaintBox;
OpenDialog1: TOpenDialog;
Button1: TButton;
Timer1: TTimer;
Button2: TButton;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
end;
//тип данных для спектра
type
FFTData = array[0..2048] of Single; // Массив для получения данных звука и работы с данными в спектре
TPeaks = array[0..128] of Integer; //Массив макс. количество полос
var
FData: FFTDATA;
FPeaks: TPeaks;
FLimit: TPeaks;
Form1: TForm1;
PlayChan: DWORD;
implementation
{$R *.dfm}
procedure TForm1.Timer1Timer(Sender: TObject);
var
i, YPos, SpecHeight, ColWidth, BandCount : Integer;
begin
if PlayChan > 0 then
begin
//снимаем данные с канала в буфер для прорисовки
BASS_ChannelGetData(PlayChan, @FData, BASS_DATA_FFT2048);
SpecHeight := PaintBoxSpectrum.Height - 2; //Высота полосы
ColWidth := 4; //ширина полосы спектров
BandCount := 45; //кол-во полос спектров
PaintBoxSpectrum.Canvas.Pen.Color := clWhite; //цвет рамки окна спектра
PaintBoxSpectrum.Canvas.Brush.Color := clBlack; //цвет фона окна спектра
PaintBoxSpectrum.Canvas.Rectangle(0, 0, PaintBoxSpectrum.Width, PaintBoxSpectrum.Height); //Рисует прямоугольник.
for i := 0 to BandCount-1 do
begin // работаем с полученными данными
YPos := Trunc(Abs(FData[i + 5]) * 500);
if YPos > SpecHeight then YPos := SpecHeight;
if YPos >= FPeaks[i] then FPeaks[i] := YPos
else
FPeaks[i] := FPeaks[i] - 1;
if YPos >= FLimit[i] then FLimit[i] := YPos - 1
else
FLimit[i] := FLimit[i] - 3;
if (PaintBoxSpectrum.Height - FPeaks[i]) > PaintBoxSpectrum.Height then
FPeaks[i] := 0;
if (PaintBoxSpectrum.Height - FLimit[i]) > PaintBoxSpectrum.Height then
FLimit[i] := 0;
// рисуем обычные пики
PaintBoxSpectrum.Canvas.Pen.Color := clRed; //Цвет верхних точек Пиков
PaintBoxSpectrum.Canvas.MoveTo(i * (ColWidth + 1), PaintBoxSpectrum.Height - FPeaks[i]); //Пеpемещает текущую позицию в указанную точку
PaintBoxSpectrum.Canvas.LineTo(i * (ColWidth + 1) + ColWidth, PaintBoxSpectrum.Height - FPeaks[i]); //чертит линию от текущей позиции до
// рисуем полосы
PaintBoxSpectrum.Canvas.Pen.Color := clLtGray; //Цвет рамки линий Пиков
PaintBoxSpectrum.Canvas.Brush.Color := clBlue; //Цвет заливки линий Пиков
PaintBoxSpectrum.Canvas.Rectangle(i * (ColWidth + 1), PaintBoxSpectrum.Height - FLimit[i],
i * (ColWidth + 1) + ColWidth, PaintBoxSpectrum.Height); //Рисует прямоугольник.
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if opendialog1.Execute then
begin
Button2Click(nil);
PlayChan:= BASS_StreamCreateFile(false, PAnsiChar(AnsiString(opendialog1.FileName)), 0, 0, 0);
if PlayChan > 0 then
bass_channelplay(PlayChan, true);
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
i: integer;
begin
bass_streamfree(PlayChan);
//чистим спектр
for i := 0 to Length(FData) -1 do
FData[i]:= 0;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
if BASS_Init(-1, 44100, 0, handle, nil) then
begin
BASS_Start;
Timer1.Interval:= 10;
Timer1.Enabled:= true;
end
else
ShowMessage('Error Bass code: ' + SysErrorMessage(BASS_ErrorGetCode));
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
if PlayChan <> 0 then
begin
BASS_ChannelStop(PlayChan);
Bass_StreamFree(PlayChan);
end;
BASS_Free();
end;