unit Audio;

interface
uses BASS,windows,Messages;
var
  floatable: DWORD; // floating-point channel support?
  chan: array[0..100] of DWORD;     // the channel... HMUSIC or HSTREAM
  rotdsp: HDSP = 0;  // DSP handle
  rotpos: Single;    // cur.pos
  echdsp: HDSP = 0;  // DSP handle
  echpos: Integer;  // cur.pos
  fladsp: HDSP = 0;  // DSP handle
  flapos: Integer;  // cur.pos

procedure play(i: integer);
procedure stop(i: integer);
procedure pause(i: integer);

procedure loadFile(name: string);
procedure load(i: integer; names: string; loop: boolean);
procedure inits(a: HWND);

implementation

procedure play(i: integer);
begin
  BASS_ChannelPlay(chan[i],FALSE);
end;

procedure stop(i: integer);
begin
  BASS.BASS_ChannelStop(chan[i]);
end;

procedure pause(i: integer);
begin
  BASS.BASS_ChannelPause(chan[i]);
end;

procedure loadFile(name: string);
var F: TEXTFILE; nam,s1,s2: string; i,j,k: integer;
begin
  Assign(F,name);
  Reset(F);
    readln(F,k);
    for i:=1 to k do
    begin
      Readln(F,nam);
      s1:=copy(nam,1,pos(' ',nam));
      //writeINI(nam);
      if copy(s2,pos(' ',nam)+1,length(nam))='TRUE' then
      load(i,nam,TRUE) else load(i,nam,FALSE); 
    end;
  Close(F);
end;

procedure load(i: integer; names: string; loop: boolean);
var info: BASS_CHANNELINFO;
bbb: DWORD;   var name: string;
begin
  name:=names;
  BASS_MusicFree(chan[i]);
  BASS_StreamFree(chan[i]);
  if loop then bbb:=BASS_MUSIC_LOOP else bbb:=0;
  chan[i] := BASS_StreamCreateFile(False, PCHAR(name), 0, 0, floatable or bbb {$IFDEF UNICODE} or BASS_UNICODE {$ENDIF});
  if (chan[i] = 0) then
    chan[i] := BASS_MusicLoad(False,PCHAR(name), 0, 0, bbb or BASS_MUSIC_RAMPS or floatable {$IFDEF UNICODE} or BASS_UNICODE {$ENDIF}, 0);
  if (chan[i] = 0) then
  begin
    MessageBox(0, Pchar(' Can''t play the file: '+name+' '), 0, 0);
  end;
end;

procedure inits(a: HWND);
begin
  BASS_SetConfig(BASS_CONFIG_FLOATDSP, 1);
  if not BASS_Init(-1, 44100, 0, a, nil) then
  begin
    MessageBox(0, 'Can''t initialize device', 0, 0);
    Halt;
  end;
  floatable := BASS_StreamCreate(44100,1, BASS_SAMPLE_FLOAT, nil,0);
  if (floatable > 0) then
  begin
    BASS_StreamFree(floatable);
    floatable := BASS_SAMPLE_FLOAT;
  end
end;

end.
