Author Topic: fade out with delay without sleep  (Read 109 times)

johnvantelli

  • Posts: 93
fade out with delay without sleep
« on: 6 Sep '24 - 20:29 »
Hi, I need to apply a fade out effect after X secs delay.
Is it possible in any way with bass? Is there a way to do that without using Sleep() function or other similar
but using bass infrastructure?

my goal is to start a fade out after 5 seconds and than a fade in.
I've tried to use priority but I understand that that's not the right way...


Code: [Select]
procedure TSong.FadeOut(anFxDuration: single; aDelay: single);
var
  lVolFxOut: DWORD;
  lParOut: BASS_FX_VOLUME_PARAM;
begin

  if aDelay > 0 then
    sleep(round(aDelay*1000));   <------------------- this lock user interface

  lVolFxOut := BASS_ChannelSetFX(AudioStream, BASS_FX_VOLUME, 0);

  lParOut.fCurrent := 1;
  lParOut.fTarget := 0;
  lParOut.fTime := aSec;
  lParOut.lCurve := 0;

  BASS_FXSetParameters(lVolFxOut, @lParOut);

end;

johnvantelli

  • Posts: 93
Re: fade out with delay without sleep
« Reply #1 on: 9 Sep '24 - 06:45 »
self solved with BASS_ChannelSlideAttribute and a callback...
 ;D

Ian @ un4seen

  • Administrator
  • Posts: 26077
Re: fade out with delay without sleep
« Reply #2 on: 9 Sep '24 - 16:34 »
Another way you could implement a delayed fade-out is with an envelope, eg. the BASS_FX add-on's BASS_FX_BFX_VOLUME_ENV effect. It could look something like this:

Code: [Select]
lVolFxOut = BASS_ChannelSetFX(AudioStream, BASS_FX_BFX_VOLUME_ENV, 0);
BASS_BFX_VOLUME_ENV param;
BASS_BFX_ENV_NODE nodes[3];
param.lChannel = -1;
param.lNodeCount = 3;
param.pNodes = nodes;
param.bFollow = false;
nodes[0].pos = 0;
nodes[0].val = 1;
nodes[1].pos = aDelay;
nodes[1].val = 1;
nodes[2].pos = aDelay + aSec;
nodes[2].val = 0;
BASS_FXSetParameters(lVolFxOut, param);

Note that the BASS_FX add-on needs to be loaded before you use any effects from it. You can force it to be linked/loaded by calling a function from it, eg. BASS_FX_GetVersion during initialization.

If you're using BASSmix to play the stream then another option is to use BASS_Mixer_ChannelSetEnvelope instead.