home *** CD-ROM | disk | FTP | other *** search
/ Chip 2005 November / CDVD1105.ISO / Software / Freeware / programare / bass / Delphi / SampleVis / osc_vis.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2002-12-15  |  3.6 KB  |  109 lines

  1. unit osc_vis;
  2. { Oscilloscope Visualyzation by Alessandro Cappellozza
  3.   version 0.8 05/2002
  4.   http://digilander.iol.it/Kappe/audioobject
  5. }
  6.  
  7. interface
  8.   uses Windows, Dialogs, Graphics, SysUtils, CommonTypes, Classes;
  9.  
  10.  type TOcilloScope = Class(TObject)
  11.     private
  12.       VisBuff : TBitmap;
  13.       BackBmp : TBitmap;
  14.  
  15.       BkgColor : TColor;
  16.       ScopeOff : Integer;
  17.       PenColor : TColor;
  18.       DrawType : Integer;
  19.       DrawRes  : Integer;
  20.       FrmClear : Boolean;
  21.       UseBkg   : Boolean;
  22.  
  23.     public
  24.      Constructor Create (Width, Height : Integer);
  25.      procedure Draw(HWND : THandle; WaveData : TWaveData; X, Y : Integer);
  26.      procedure SetBackGround (Active : Boolean; BkgCanvas : TGraphic);
  27.  
  28.      property BackColor : TColor read BkgColor write BkgColor;
  29.      property Offset : Integer read ScopeOff write ScopeOff;
  30.      property Pen  : TColor read PenColor write PenColor;
  31.      property Mode : Integer read DrawType write DrawType;
  32.      property Res  : Integer read DrawRes write DrawRes;
  33.      property FrameClear : Boolean read FrmClear write FrmClear;
  34.   end;
  35.  
  36.  var OcilloScope : TOcilloScope;
  37.  
  38. implementation
  39.  
  40.      Constructor TOcilloScope.Create(Width, Height : Integer);
  41.       begin
  42.         VisBuff := TBitmap.Create;
  43.         BackBmp := TBitmap.Create;
  44.  
  45.           VisBuff.Width := Width;
  46.           VisBuff.Height := Height;
  47.           BackBmp.Width := Width;
  48.           BackBmp.Height := Height;
  49.  
  50.           BkgColor := clBlack;
  51.           ScopeOff := 50;
  52.           PenColor := clWhite;
  53.           DrawType := 0;
  54.           DrawRes  := 1;
  55.           FrmClear := True;
  56.           UseBkg := False;
  57.       end;
  58.  
  59.      procedure TOcilloScope.SetBackGround (Active : Boolean; BkgCanvas : TGraphic);
  60.       begin
  61.         UseBkg := Active;
  62.         BackBmp.Canvas.Draw(0, 0, BkgCanvas);
  63.       end;
  64.  
  65.      procedure TOcilloScope.Draw(HWND : THandle; WaveData : TWaveData; X, Y : Integer);
  66.         var i, YPos : LongInt; R, L : SmallInt;
  67.        begin
  68.        if FrmClear then begin
  69.          VisBuff.Canvas.Pen.Color := BkgColor;
  70.          VisBuff.Canvas.Brush.Color := BkgColor;
  71.          if UseBkg then
  72.            BitBlt(VisBuff.Canvas.Handle,         // Destination
  73.                   0, 0,                          // X, Y (target pos)
  74.                   VisBuff.Width, VisBuff.Height, // Size to copy
  75.                   BackBmp.Canvas.handle,         // Source
  76.                   0, 0,                          // X, Y (source pos)
  77.                   SrcCopy)                       // plain copy
  78.          else
  79.            VisBuff.Canvas.Rectangle(0, 0, VisBuff.Width, VisBuff.Height) // only if no background
  80.        end;
  81.  
  82.         VisBuff.Canvas.Pen.Color := PenColor;
  83.             R :=  SmallInt(LOWORD(WaveData[0]));
  84.             L := SmallInt(HIWORD(WaveData[0]));
  85.             YPos := Trunc(((R + L) / (2 * 65535)) * ScopeOff) ;
  86.             VisBuff.Canvas.MoveTo(X , Y + YPos);
  87.  
  88.          for i := 1 to 256 do begin
  89.             R := SmallInt(Loword(WaveData[i * DrawRes]));
  90.             L := SmallInt(HIword(WaveData[i * DrawRes]));
  91.             YPos := Trunc(((R + L) / (2 * 65535)) * ScopeOff) ;
  92.  
  93.               case DrawType of
  94.                 0 : VisBuff.Canvas.lineto(X + i, Y + YPos);
  95.  
  96.                 1 : begin
  97.                       VisBuff.Canvas.MoveTo(X + i, Y);
  98.                       VisBuff.Canvas.lineto(X + i, Y + YPos);
  99.                     end;
  100.  
  101.                 2 : VisBuff.Canvas.Pixels[X + i,  Y + YPos] := PenColor;
  102.               end;
  103.          end;
  104.  
  105.           BitBlt(HWND, 0, 0, VisBuff.Width, VisBuff.Height, VisBuff.Canvas.Handle, 0, 0, srccopy)
  106.        end;
  107. end.
  108.  
  109.