////////////////////////////////////////////////////////////////////// // // // observerSound.pas: Sound waveform observer // // // // The contents of this file are subject to the Bottled Light // // Public License Version 1.0 (the "License"); you may not use this // // file except in compliance with the License. You may obtain a // // copy of the License at http://www.bottledlight.com/BLPL/ // // // // Software distributed under the License is distributed on an // // "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or // // implied. See the License for the specific language governing // // rights and limitations under the License. // // // // The Original Code is the Mappy VM User Interface, released // // April 1st, 2003. The Initial Developer of the Original Code is // // Bottled Light, Inc. Portions created by Bottled Light, Inc. are // // Copyright (C) 2001-2003 Bottled Light, Inc. All Rights Reserved. // // // // Author(s): // // Michael Noland (joat), michael@bottledlight.com // // // // Changelog: // // 1.0: First public release (April 1st, 2003) // // // // Notes: // // This was intended only for debugging purposes, it is not // // robust enough for production code as-is. // // // ////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// unit observerSound; ////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// interface //////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, CheckLst, cpuObservers, console, ExtCtrls, Math, nexus, platformSound, AddressSpace; ////////////////////////////////////////////////////////////////////// const BUFFER_SIZE = 44100 * 4; type TjdevSoundViewer = class(TCpuObserver) procedure FormCreate(Sender: TObject); procedure FormShow(Sender: TObject); procedure FormPaint(Sender: TObject); procedure FormDestroy(Sender: TObject); private myData: array[0..BUFFER_SIZE-1] of uint8; myDataSize: integer; public procedure UpdateObserver; override; class function OCaption: string; override; procedure OnMoreSound(data: pointer; length: integer); end; ////////////////////////////////////////////////////////////////////// var jdevSoundViewer: TjdevSoundViewer; ////////////////////////////////////////////////////////////////////// implementation /////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// {$R *.DFM} ////////////////////////////////////////////////////////////////////// // TjdevSoundViewer ////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// class function TjdevSoundViewer.OCaption: string; begin Result := 'Sound Viewer'; end; ////////////////////////////////////////////////////////////////////// procedure TjdevSoundViewer.UpdateObserver; var i: integer; s, h: single; begin if (myDataSize > 0) and (ClientWidth > 0) and (ClientHeight > 0) then begin h := -ClientHeight / 256; s := ClientHeight; Canvas.Brush.Color := clBlack; Canvas.FillRect(Rect(0, 0, ClientWidth, ClientHeight)); Canvas.Pen.Color := clBlue; Canvas.MoveTo(0, Trunc(s+h*myData[0])); for i := 0 to ClientWidth - 1 do begin Canvas.LineTo(i, Trunc(s+h*myData[Trunc(i/ClientWidth*myDataSize/2)*2])); end; Canvas.Pen.Color := clGreen; Canvas.MoveTo(0, Trunc(s+h*myData[1])); for i := 0 to ClientWidth - 1 do begin Canvas.LineTo(i, Trunc(s+h*myData[Trunc(i/ClientWidth*myDataSize/2)*2+1])); end; end; myDataSize := 0; end; ////////////////////////////////////////////////////////////////////// procedure TjdevSoundViewer.FormCreate(Sender: TObject); begin HelpContext := LinkHelp('sound_viewer.html'); myDataSize := 0; soundObserverCallback := OnMoreSound; end; ////////////////////////////////////////////////////////////////////// procedure TjdevSoundViewer.FormShow(Sender: TObject); begin // Load the translation LoadTranslation(self, translation); end; ////////////////////////////////////////////////////////////////////// procedure TjdevSoundViewer.FormPaint(Sender: TObject); begin updateObserver; end; ////////////////////////////////////////////////////////////////////// procedure TjdevSoundViewer.OnMoreSound(data: pointer; length: integer); var oldSize: integer; begin oldSize := myDataSize; myDataSize := Min(length*2, BUFFER_SIZE); Move(data^, myData[oldSize], myDataSize-oldSize); end; ////////////////////////////////////////////////////////////////////// procedure TjdevSoundViewer.FormDestroy(Sender: TObject); begin soundObserverCallback := nil; end; ////////////////////////////////////////////////////////////////////// initialization RegisterViewer(TjdevSoundViewer); end. //////////////////////////////////////////////////////////////////////