18 May '13 - 10:11 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1]
  Reply  |  Print  
Author Topic: How to Play an audio file using BASSWASAPI  (Read 375 times)
pwatel
Posts: 48


« on: 16 Jan '12 - 16:14 »
Reply with quoteQuote

Hello
Is there somewhere a simple example of sample code on how to play an audio file using ASAPI and Bass in Delphi preferably please
The help is just a collection of function calls but no order on how  to use them
Thank you
PW
Logged
muhahp
Posts: 7


« Reply #1 on: 16 Jan '12 - 16:56 »
Reply with quoteQuote

Here is my code to use WASAPI, enjoy Wink

//Initializing default output device on FormCreate
var
  i, devcount: byte;
  WASAPIDevInfo: BASS_WASAPI_DEVICEINFO;
  music: hstream;
begin
for i := 0 to devcount do
  begin
    if not BASS_WASAPI_GetDeviceInfo(i, WASAPIDevInfo) then
      break;
    if ((WASAPIDevInfo.flags and BASS_DEVICE_DEFAULT) = (BASS_DEVICE_DEFAULT))
      and ((WASAPIDevInfo.flags and BASS_DEVICE_INPUT) <> BASS_DEVICE_INPUT)
      and (WASAPIDevInfo.flags and BASS_DEVICE_ENABLED =
        BASS_DEVICE_ENABLED) then
      break
    else
      Inc(devcount);
  end;
   BASS_SetConfig(BASS_CONFIG_UPDATEPERIOD, 0);
    if not BASS_Init(0, WASAPIDevInfo.mixfreq, 0, 0, nil) then
      Showmessage('Error initializing DS audio!');
    if not BASS_WASAPI_Init(i, WASAPIDevInfo.mixfreq, WASAPIDevInfo.mixchans,
      BASS_WASAPI_BUFFER, 0, 0, @WasapiProc, nil) then
      Showmessage('Error initializing WASAPI!');
  end;
end;
//callback function
function WasapiProc(buffer: pointer; length: dword; user: pointer): dword;
  stdcall;
var
  c: dword;
begin
  c := Bass_ChannelGetData(music, buffer, length);
  if (c = -1) then
    c := 0;
  Result := c;
end;

//opening and playing file
Music := Bass_StreamCreateFile(false, PChar('C:\test.wav'), 0, 0,
      BASS_SAMPLE_FLOAT or BASS_STREAM_DECODE or BASS_UNICODE);
if not BASS_WASAPI_Start then
      Showmessage('Error Playing File');
« Last Edit: 16 Jan '12 - 18:26 by muhahp » Logged
pwatel
Posts: 48


« Reply #2 on: 16 Jan '12 - 17:40 »
Reply with quoteQuote

Thank you so much I will check it out
PW
Logged
Pages: [1]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.18 | SMF © 2013, Simple Machines