Am I loading this Song correctly with Bass.dll?

Asked

Viewed 469 times

5

Based on documentation from Bass, i am trying to upload a common ogg file, with the following code:

var
  FFile : string;
  Music: HSAMPLE; 
  ch: HCHANNEL;
  OpenDialog1 : TOpenDialog;
begin
  Dynamic_Bass.Load_BASSDLL('Library/Bass.dll');
  Dynamic_Bass.BASS_Init(1,44000,Bass_DEVICE_SPEAKERS,0,nil);  
  OpenDialog1 := TOpenDialog.Create(nil);
  if not OpenDialog1.Execute then
    Exit;
  ffile := OpenDialog1.FileName;
  Music := BASS_SampleLoad(FALSE, PChar(ffile), 0, 0, 3, BASS_SAMPLE_OVER_POS);
  ch := BASS_SampleGetChannel(Music, False);
  BASS_ChannelSetAttribute(ch, BASS_ATTRIB_PAN, 0);
  BASS_ChannelSetAttribute(ch, BASS_ATTRIB_VOL, 1);
  BASS_ChannelPlay(ch, False);
  ShowMessage(IntToStr(BASS_ErrorGetCode));
end;

It shows the number 5 which according to the documentation, is an error in the Handle, in this case, in my variable music. If I comment on these lines below BASS_SampleLoad, the code changes to 2, which means the file cannot be loaded. This is ordinary file and it is not corrupted so my question: I am doing something wrong?

  • I think only one link to what BASS is or its documentation is missing. At least for those who do not know, it would be difficult to help.

  • @Embarrassment: That’s why I added the link in my reply

  • @whosrdaddy I noticed. I just thought I should be on the question instead of being on the answer. Anyway, good job on detecting the problem.

1 answer

5


I do not speak Portuguese natively, I used Google Translator to create my answer.

Original English Question

Your code seems to be correct, just make sure there are errors in each call.

Corrected code:

var
  ffile : string;
  music: HSAMPLE; 
  ch: HCHANNEL;
  opendialog1 : topendialog;

begin 
 if not Dynamic_Bass.Load_BASSDLL('Library/Bass.dll') then
  Exit;
 // change device to -1 which is the default device
 if Dynamic_Bass.BASS_Init(-1,44000,Bass_DEVICE_SPEAKERS,0,nil) then
  begin
   opendialog1 := topendialog.Create(nil);
   try
    if OpenDialog1.Execute then
     begin
      ffile := OpenDialog1.FileName;
      music := BASS_SampleLoad(FALSE, PChar(ffile), 0, 0, 3, BASS_SAMPLE_OVER_POS);
      if music <> 0 then
       begin
        ch := BASS_SampleGetChannel(music, False);
        if ch <> 0 then
         begin
          // omitted, see if the basics work   
          // BASS_ChannelSetAttribute(ch, BASS_ATTRIB_PAN, 0);
          // BASS_ChannelSetAttribute(ch, BASS_ATTRIB_VOL, 1);
          if not BASS_ChannelPlay(ch, False) then
           ShowMessage(inttostr(bass_errorgetcode));
         end
        else
         ShowMessage(inttostr(bass_errorgetcode));
       end
      else
       ShowMessage(inttostr(bass_errorgetcode));
     end;
   finally  
    OpenDialog1.Free;
   end;
  end
 else
  ShowMessage(inttostr(bass_errorgetcode));
end;

UPDATING

I should have seen this before, your fault code because BASS_SampleLoad expects the file name to be in ANSI format, the documentation clearly mentions this, once you use Delphi XE3 and the strings are Unicode, you must provide the flag BASS_UNICODE to indicate this.

Thus, the line Bass_SampleLoad becomes:

music := BASS_SampleLoad(FALSE, PChar(ffile), 0, 0, 3, BASS_SAMPLE_OVER_POS 
          or BASS_UNICODE);
  • I don’t have much knowledge about text formats. Better study a little. But anyway, thank you!

  • for nothing, please accept my reply on the English site too :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.