Author Topic: [Delphi]Problems switching Mutil audio device【Sincere thanks】  (Read 231 times)

dreamnyj

  • Posts: 12
Hi, friends, hello everyone.



I am using bass.dll in Delphi and want to switch sound cards through the Tcombox dropdown method.



But it's useless for me to use the following code. I have tried using bass_ It is possible to directly initialize init to the specified device ID.



But this is clearly not elegant enough.



At the same time, I have also looked at a similar issue recently and tried to solve it according to that, but it still hasn't improved.



I saw Mutil's DEMO in the demo and it worked normally. That DEMO is more similar to VC style message programming,



So I want to ask, if there are multiple sound cards on a computer, I want to play different content on different devices simultaneously,

Is it necessary to use message based programming, or is it possible to use single threading, but is my code incorrect?

Code: [Select]
function TBass.test(DeviceIndex: Integer; ssFileName: string): Boolean;
var
    hs: HSTREAM;       
begin

  BASS_StreamFree(hs);

 
  BASS_SetDevice(DeviceIndex);

  hs := BASS_StreamCreateFile(False, PAnsiChar(Ansistring(ssFileName)), 0, 0, 0);

  if not BASS_ChannelPlay(hs, False) then
  begin
    result := False;
  end
  else
  begin
    result := true;
  end;

end;

David_AVD

  • Posts: 74
Are you initialising all of the devices you want to use before you try and use them?

dreamnyj

  • Posts: 12
Code: [Select]

  GetDeviceAvailableInfoToStringList(AudioDevStrList);

  for i := 1 to AudioDevStrList.Count - 1 do
  begin

    ShowMessage('init:' + inttostr(i));

    if not BASS_Init(1, 44100, 0, 0, nil) then
      begin
      Showmessage('Bass.dll initialization error NYJ');
    end;

  end;



I found out that only the last one was  by Bass_ Init's device is valid.

That friend knows, give me a hint.
« Last Edit: 9 May '23 - 08:46 by dreamnyj »

Chris

  • Posts: 2148
Code: [Select]

  GetDeviceAvailableInfoToStringList(AudioDevStrList);

  for i := 1 to AudioDevStrList.Count - 1 do
  begin

    ShowMessage('init:' + inttostr(i));

    if not BASS_Init(1, 44100, 0, 0, nil) then
      begin
      Showmessage('Bass.dll initialization error NYJ');
    end;

  end;



try this

Code: [Select]
  GetDeviceAvailableInfoToStringList(AudioDevStrList);

  for i := 1 to AudioDevStrList.Count - 1 do
  begin

 //   ShowMessage('init:' + inttostr(i));

   // if not BASS_Init(1, 44100, 0, 0, nil) then
       if not BASS_Init(i, 44100, 0, 0, nil) then // i and not 1
      begin
      Showmessage('initialization error with ID '+ i.tostring+#13#10+ 'ErrorCode : '+(Bass_ErrorGetCode()).tostring); 

  end;


« Last Edit: 9 May '23 - 12:44 by Chris »

dreamnyj

  • Posts: 12

First of all, thank you very much for your reply. Your reply has opened up my mind.

Now I have successfully switched between different sound cards.

I will place my success code, which may be helpful for friends who search for this issue in the future.

Thank you again for your guidance.

Code: [Select]
function TBass.test(DeviceIndex: Integer; ssFileName: string): Boolean;
begin

  BASS_StreamFree(hs);         

  BASS_SetDevice(DeviceIndex);             

  hs := BASS_StreamCreateFile(False, PAnsiChar(Ansistring(ssFileName)), 0, 0, 0); 


  if hs = 0 then
  begin
    result := False;
    exit;
  end;


  if not BASS_ChannelPlay(hs, False) then
  begin
    result := False;
  end
  else
  begin
    result := true;
  end;

end;

Chris

  • Posts: 2148
some small suggestion .
Code: [Select]
function TBass.test(DeviceIndex: Integer; ssFileName: string): Boolean;
begin
   BASS_StreamFree(hs);         
   if  not  BASS_SetDevice(DeviceIndex) then
       ShowMessage('Can not set the Device , Error  Nr'+(Bass_ErrorGetCode().tostring);   
    hs := BASS_StreamCreateFile(False, PAnsiChar(Ansistring(ssFileName)), 0, 0, BASS_SAMPLE_FLOAT); // Floating Point Channels are better for clipping
    if hs <>  0 then
    begin
        BASS_ChannelPlay(hs, False);
     end else
   begin
      ShowMessage('The Stream Creation has failed, Error  Nr'+(Bass_ErrorGetCode().tostring);
   end;
end;

dreamnyj

  • Posts: 12

I have been taught, thank you very much。