unit GSound;

interface
uses
  Bass, LexUtils, Setup;

procedure InitGS;

procedure PlaySound( I : Byte);
procedure StopSound( I : Byte);
procedure TrackPlay(I : Integer);
procedure DJ;

const
  MofTrack = 2;

implementation
const
  MofSound = 4;

const
  NSound : array[1..MofSound ] of string =
  ('4.ogg', 'Ok.ogg', 'b.ogg', 'Click.ogg');

  NTrack : array[1..MofTrack] of string =
  ('1.mp3', '2.mp3');

var
  S_Gn   : array[1..MofSound ] of Cardinal;
  S_Intro,
  S_MZT  : array[1..MofTrack ] of Cardinal;
  NowTrack : Integer = -1;
  WSD    : Boolean;
  
procedure LoadSounds;
var
  I : integer;
begin
  for I := 1 to MofTrack do
    S_MZT[I] := BASS_StreamCreateFile(False, PChar('Data\SD\' + NTrack[I]), 0, 0, BASS_SAMPLE_LOOP);

  for I := 1 to MofSound do
    S_Gn[I] := BASS_StreamCreateFile(False, PChar('Data\SD\' + NSound[I]), 0, 0, 0);

  TrackPlay(2);
end;

procedure DJ;
var
  I : Integer;
begin
 { if  BASS.BASS_ChannelGetPosition(S_MZT[NowTrack],0) >=
      BASS.BASS_ChannelGetLength(S_MZT[NowTrack],0)
  then
  begin
    I := random(MofTrack - NowTrack + 1) + NowTrack + 1;
    if I > MofTrack then
      I := 1;
    TrackPlay(1);
  end; }
end;

procedure TrackPlay(I : Integer);
begin
  if (WSD) then
  if NowTrack <> I then
  begin
    if NowTrack >= 0 then
      BASS_ChannelStop(S_MZT[NowTrack]);
    BASS_ChannelPlay(S_MZT[I], TRUE);
    NowTrack := I;
  end;
end;

procedure InitGS;
begin
  if BASS_Init(-1, 44100, 0, 0, nil) then
  begin
    WSD := true;
    LoadSounds;
  end
  else
    WSD:=false;
end;

procedure PlaySound;
begin
  if (WSD) then
  begin
    BASS_ChannelPlay(S_Gn[I], False);
  end;
end;

procedure StopSound;
begin
  if (WSD) then
  begin
    BASS_ChannelStop(S_Gn[I]);
  end;
end;

end.
