unit Unit1;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes,
  System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, System.IOUtils,
  FMX.Controls.Presentation, FMX.StdCtrls,

  FMX.BASS,
  BASSMix;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }

  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  Channel0: HSTREAM;
  Channel1: HSTREAM;
  Floatsupport: DWORD;
  ChannelMix: HSTREAM;

implementation

{$R *.fmx}



function ProgDir: string;
begin
  Result := ExtractFilePath(ParamStr(0));
end;

procedure Error(msg: string);
begin
  ShowMessage(msg + #13#10 + #13#10 + '(error code: ' + (BASS_ErrorGetCode).ToString + ')');
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  if not BASS_Init(-1, 44100, 0, handle, nil) then
    Error('Bass Init Error');

  ChannelMix := BASS_Mixer_StreamCreate(44100, 2,0);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  file1, file2: string;
begin

  file1 := ProgDir + '80s-KICK.wav';
  file2 := ProgDir + '80s-SNARE.wav';

  { will work }

  if Channel0 <> 0 then
    Bass_StreamFree(Channel0); // Check if still the Channel exist if yes free it

  Channel0 := BASS_StreamCreateFile(false, pchar(file1), 0, 0, BASS_STREAM_DECODE or Bass_Unicode); // ! BASS_UNICODE
  BASS_Mixer_StreamAddChannel(ChannelMix, Channel0, 0);

  if Channel1 <> 0 then
    Bass_StreamFree(Channel1);
  Channel1 := BASS_StreamCreateFile(false, pchar(file2), 0, 0, BASS_STREAM_DECODE or Bass_Unicode);
  BASS_Mixer_StreamAddChannel(ChannelMix, Channel1, 0);

  BASS_ChannelPlay(ChannelMix, false);

end;

end.
