Author Topic: Playback stops random  (Read 436 times)

Gerjan

  • Guest
Playback stops random
« on: 4 May '18 - 10:57 »
I have a strange problem with using BASS.DLL in our application.
The problem is that playback stops random after a few hours playing on certain multichannel soundcards.
The device isn't accessible anymore until we restart the application. restarting windows isn't needed.

We don't use ASIO btw!

at startup we use this:
Code: [Select]
  try
    if lbsounddev.Items.Count > 1 then begin
      for device:=0 to lbsounddev.Items.count-1 do begin
        outdev[device]:=device+1;
        BASS_Init(outdev[device], 44100, 0, Handle, nil);
      end;
    end;
  except
    Log(FLM(8, stinitsnddeb+inttostr(device)+ IntToStr(BASS_ErrorGetCode)));
  end;

Our application has 4 players. they all use a different function, but the code is the same.
Here is some code from one player which is used during playback:



Code: [Select]
procedure Tmainform.player1(FileName,loc,img: String);
var
  dir:single;
begin
  try
    if ch[1] <> 0 Then
    begin
      BASS_ChannelStop(ch[1]);
      BASS_StreamFree(ch[1]);
      ch[1]:=0;
    End;

    try
      if not(BASS_SetDevice(initfrm.outdev[pl1device])) then begin
        Log(FLM(8, 'Error player1: ' + IntToStr(BASS_ErrorGetCode())));
      end;
    except
      Log(FLM(8, 'Error player1x: ' + IntToStr(BASS_ErrorGetCode())));
    end;

    try
      if (magwel1=true) then
        ch[1] := BASS_StreamCreateFile(true,pl1memstream1.memory,0, pl1memstream1.size, BASS_STREAM_DECODE or BASS_SAMPLE_LOOP or BASS_SAMPLE_SOFTWARE {$IFDEF UNICODE} or BASS_UNICODE {$ENDIF});
    except
      Log(FLM(8, 'Error ch[1]: ' + IntToStr(BASS_ErrorGetCode())));
    end;

    if (ch[1] <> 0) then
    begin
      try
        playtime1 := BASS_ChannelGetLength(ch[1], BASS_POS_BYTE);
...
        bpp := BASS_ChannelGetLength(ch[1], BASS_POS_BYTE) div 1023;
        if (bpp < BASS_ChannelSeconds2Bytes(ch[1], 0.02)) then
          bpp := BASS_ChannelSeconds2Bytes(ch[1], 0.02);
      except
        Log(FLM(8, 'Error playtime1'));
      end;

      try
        ch[16] := BASS_StreamCreateFile(true,pl1memstream1.memory,0, pl1memstream1.size, BASS_STREAM_DECODE {$IFDEF UNICODE} or BASS_UNICODE {$ENDIF});
        TScanThread.Create(ch[16]); // start scanning peaks in a new thread}
      except
        Log(FLM(8, 'Error TScanThread1'));
      end;

      try
        //2 seconden scanning
        ch[1] := BASS_FX_ReverseCreate(ch[1], 0.25, BASS_STREAM_DECODE or BASS_FX_FREESOURCE);

        ch[1] := BASS_FX_TempoCreate(ch[1],BASS_SAMPLE_LOOP or BASS_FX_FREESOURCE);
        tbpl1tempo.Position:=0;

        BASS_ChannelGetAttribute(BASS_FX_TempoGetSource(ch[1]), BASS_ATTRIB_REVERSE_DIR, &dir);

        if (dir<0) then
          BASS_ChannelSetAttribute(BASS_FX_TempoGetSource(ch[1]), BASS_ATTRIB_REVERSE_DIR, BASS_FX_RVS_FORWARD)
        else
          BASS_ChannelSetAttribute(BASS_FX_TempoGetSource(ch[1]), BASS_ATTRIB_REVERSE_DIR, BASS_FX_RVS_REVERSE);

        BASS_ChannelGetAttribute(ch[1], BASS_ATTRIB_FREQ, freqpl1);
      except
        Log(FLM(8, 'Error FX1'));
      end;
    end;
  except
    Log(FLM(8, 'player1 error met: '+filename));
  end;
end;

Is it necessary to call BASS_SetDevice on each stream or only on the BASS_init?

Ian @ un4seen

  • Administrator
  • Posts: 21379
Re: Playback stops random
« Reply #1 on: 4 May '18 - 14:15 »
Your usage of BASS_SetDevice looks fine in that code, ie. just before the BASS_StreamCreateFile call.

Does your app lock up when the sound stops, or is it still responsive? If it locks up then it is probably caused by a deadlock between the BASS update thread and another thread (probably the main thread). In that case, check that any callback functions (eg. DSPPROC/STREAMPROC) aren't doing anything that needs to wait for another thread, eg. UI updates. If a callback function is doing that then you could modify it to just post a message to the main thread and have the message handler do the UI update.

If it isn't a deadlock, does calling BASS_Stop and BASS_Start get the sound going again? If not, what about BASS_Free and BASS_Init? Note you should use BASS_SetDevice before BASS_Stop/Start/Free to set the target device.

Also confirm what BASS.DLL version you are using; you can use BASS_GetVersion to check that. If it isn't the latest, please try that, and if the problem still happens, try adding the BASS_DEVICE_DSOUND flag to the BASS_Init calls (for DirectSound output) and see if that makes any difference.

Gerjan

  • Guest
Re: Playback stops random
« Reply #2 on: 4 May '18 - 16:08 »
Hello Ian,

When it happens the app is still responsive. the strange thing is that the other channels are still available and playing.
To explain shortly: We use the ESI Maya 44 USB+ soundcard. So the application sees 2 output devices at startup.
When it occurs on output 1, the other output is still playing.

Bass_channelstop and start doesn't solve the problem. it still can't be started.
And loading a new track doesn't work either.
What works, very strange though, is that if we change the soundcard samplerate settings in the windows sound settings in the controlpanel, it's possible to play it immediately.

We use the latest version of BASS from your site.

We're can try to init the devices as follows, but are a little bit confused because we didn't changed the procedures and there was nothing wrong until a few months ago.
Therefor we also think it could be an issue which is related to Windows 10 in combination with BASS

We did update the BASS.dll and BASS_FX.dll recently to the latest version after getting the issue. Our dll was from 2011 and a bit outdated :)


Code: [Select]
BASS_Init(outdev[device], 44100, 0, Handle, BASS_DEVICE_DSOUND);

Ian @ un4seen

  • Administrator
  • Posts: 21379
Re: Playback stops random
« Reply #3 on: 4 May '18 - 17:04 »
Did the problem begin when you upgraded the BASS version, or did it also happen before that? To check whether it only happens when using WASAPI output, please try using the BASS_DEVICE_DSOUND flag in the BASS_Init calls. Note that should be used in the 3rd parameter.

Please also check whether calling BASS_Stop and BASS_Start (rather than BASS_ChannelStop/Play) gets the sound going again. Be sure to use BASS_SetDevice before that to set the target device, ie. the device that has stopped working.

Gerjan

  • Guest
Re: Playback stops random
« Reply #4 on: 8 May '18 - 11:06 »
The problem did occur before upgrade. We thought an upgrade should help, but we've noticed in the meantime that with Windows 7 there's no problem at all. ::)

We look into your this by adding the flag on a windows 10 computer to check if that's the solution.
and even make a button to check BASS_Stop and BASS_Start

thanks again

Xire

  • Posts: 279
Re: Playback stops random
« Reply #5 on: 11 May '18 - 17:16 »
Hi Gerjan,

Just some remarks after seeing your code:

- You are putting calls to BASS functions in try/except blocks, which is not needed, as BASS does not rise any exceptions. If you get exception by calling them, it's most likely because you are passing invalid data.
- You are not checking result for all calls, where it's needed, e.g. BASS_ChannelStop, BASS_StreamFree,  BASS_ChannelGetAttribute - they might return false and you're not checking that. Missing the check might lead to some issues later.
- Also, what exactly Log(FLM(8, .... does? If it logs and stops the program, then it's OK, otherwise you're just masking the error and proceeding.

I've dealt with BASS for a long time and know for sure, that function, which you assume will always work, might return false for some reason, which (in almost all cases) was caused by bugs in my own code :) You just must check the result of all functions.

Xire