Author Topic: Conflict between the FFT and dataname?  (Read 307 times)

terry_zhou82

  • Posts: 21
Conflict between the FFT and dataname?
« on: 24 Feb '18 - 14:39 »
Dear boy
I met some conflict between the FFT and dataname? ,I use two timers Component,one is show the radioname,other one is show the FFT
Timer1. interval:1000  //it's show correct
case BASS_ChannelIsActive(chan) of
    BASS_ACTIVE_STOPPED:str:= 'stop ';
    BASS_ACTIVE_PLAYING:str:= 'play ';
    label.caption:=clientdateset1.fielbyname('name').asstring;

Timer2: interval:30
procedure TForm1.FFT;
const
  w = 8;
var
  i,di: Integer;
begin
  if BASS_ChannelIsActive(chan) <> BASS_ACTIVE_PLAYING then Exit;

  BASS_ChannelGetData(chan, @FFTData, BASS_DATA_FFT1024);

  bit.Width := PaintBox1.Width;
  bit.Height := PaintBox1.Height;
  bit.Canvas.Brush.Color := clWhite;
  bit.Canvas.FillRect(Rect(0, 0, bit.Width, bit.Height));

  bit.Canvas.Pen.Color := $00F4D214;
  for i := 0 to Length(FFTData) - 1 do
  begin
    di := Trunc(Abs(FFTData) * 500);

    if di > bit.Height then di := bit.Height;
    if di >= FFTPeacks then FFTPeacks := di else FFTPeacks := FFTPeacks - 1;
    if di >= FFTFallOff then FFTFallOff := di else FFTFallOff := FFTFallOff - 3;
    if (bit.Height - FFTPeacks) > bit.Height then FFTPeacks := 0;
    if (bit.Height - FFTFallOff) > bit.Height then FFTFallOff := 0;

    bit.Canvas.Pen.Color := bit.Canvas.Pen.Color;
    bit.Canvas.MoveTo(i * (w + 1), bit.Height - FFTPeacks);
    bit.Canvas.LineTo(i * (w + 1) + w, bit.Height - FFTPeacks);

    bit.Canvas.Pen.Color := bit.Canvas.Pen.Color;
    bit.Canvas.Brush.Color := bit.Canvas.Pen.Color;
    bit.Canvas.Rectangle(i * (w + 1), bit.Height - FFTFallOff, i * (w + 1) + w, bit.Height);
  end;

  BitBlt(PaintBox1.Canvas.Handle, 0, 0, PaintBox1.Width, PaintBox1.Height, bit.Canvas.Handle, 0, 0, SRCCOPY);

end;


the question is if both timer1 and timer1 works .some times the label1.visible maybe disappear. if I adjust the timer2.interval to 1000.Both of them worked. Can someone help me ?
   

terry_zhou82

  • Posts: 21
Re: Conflict between the FFT and dataname?
« Reply #1 on: 10 Mar '18 - 13:35 »
anyone knows ? :o

Chris

  • Posts: 1854
Re: Conflict between the FFT and dataname?
« Reply #2 on: 10 Mar '18 - 21:25 »
Hi,
 it is possible that the Timer2 procedure is not finished and starting the next Cyclus to early so
try something like this.

Code: [Select]
procedure TForm1.FFT;
const
  w = 8;
var
  i,di: Integer;
begin
  if BASS_ChannelIsActive(chan) <> BASS_ACTIVE_PLAYING then Exit;
  try
 
  BASS_ChannelGetData(chan, @FFTData, BASS_DATA_FFT1024);

  bit.Width := PaintBox1.Width;
  bit.Height := PaintBox1.Height;
  bit.Canvas.Brush.Color := clWhite;
  bit.Canvas.FillRect(Rect(0, 0, bit.Width, bit.Height));

  bit.Canvas.Pen.Color := $00F4D214;
  for i := 0 to Length(FFTData) - 1 do
  begin
    di := Trunc(Abs(FFTData) * 500);

    if di > bit.Height then di := bit.Height;
    if di >= FFTPeacks then FFTPeacks := di else FFTPeacks := FFTPeacks - 1;
    if di >= FFTFallOff then FFTFallOff := di else FFTFallOff := FFTFallOff - 3;
    if (bit.Height - FFTPeacks) > bit.Height then FFTPeacks := 0;
    if (bit.Height - FFTFallOff) > bit.Height then FFTFallOff := 0;

    bit.Canvas.Pen.Color := bit.Canvas.Pen.Color;
    bit.Canvas.MoveTo(i * (w + 1), bit.Height - FFTPeacks);
    bit.Canvas.LineTo(i * (w + 1) + w, bit.Height - FFTPeacks);

    bit.Canvas.Pen.Color := bit.Canvas.Pen.Color;
    bit.Canvas.Brush.Color := bit.Canvas.Pen.Color;
    bit.Canvas.Rectangle(i * (w + 1), bit.Height - FFTFallOff, i * (w + 1) + w, bit.Height);
  end;

  BitBlt(PaintBox1.Canvas.Handle, 0, 0, PaintBox1.Width, PaintBox1.Height, bit.Canvas.Handle, 0, 0, SRCCOPY);
  finally
   Timer2.enabled := true;
  end;
end;


Code: [Select]
procedure TForm.Timer2.OnTimer(Sender:TObject);
begin
   Timer2.enabled := false; // to be shure that the Timer will wait til the complete procedure has fine end
   FFT;// at the end of the FFT procedure we will activate the timer
end;
« Last Edit: 10 Mar '18 - 21:29 by Chris »