unit uNoiseTest;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ExtCtrls,
Bass;
type
TForm1 = class(TForm)
BitBtn2: TBitBtn;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
private
{ Private declarations }
NoiseStream : HSTREAM;
Toggle : boolean;
public
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses Math;
function MakeNoise(
handle: HSTREAM; buffer: Pointer; length: DWORD; user: Pointer): DWORD; stdcall;
var
buf : ^word;
i, len : Integer;
begin
buf := buffer;
len := length div 2;
for i := 0 to len - 1 do
begin
buf^ := 65538 - trunc(random(32767)); // Werte sind 'SIGNED'
inc(buf);
end;
result := length;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
// check the correct BASS was loaded
if (HIWORD(BASS_GetVersion) <> BASSVERSION) then
begin
MessageBox(0,'An incorrect version of BASS.DLL was loaded',0,MB_ICONERROR);
exit;
end;
// Initialize BASS with the default device
if NOT BASS_Init(-1, 44100, 0,
Handle, nil) then
begin
MessageBox(0,'Could not initialize BASS',0,MB_ICONERROR);
exit;
end;
Toggle := false;
Randomize;
NoiseStream := BASS_StreamCreate(44100, 2, 0, @MakeNoise, 0);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
BASS_ChannelStop(NoiseStream);
BASS_StreamFree(NoiseStream);
Bass_Free;
end;
procedure TForm1.BitBtn2Click(Sender: TObject);
begin
if not Toggle then
begin
if not BASS_ChannelPlay(NoiseStream, true) then
begin
MessageBox(0,'Could not start stream playback',0,MB_ICONERROR);
Exit;
end;
BitBtn2.Caption := 'STOP';
Toggle := true;
end
else
begin
BASS_ChannelStop(NoiseStream);
BitBtn2.Caption := 'START';
Toggle := false;
end;
end;
end.