Author Topic: Problem with Slide and Free Callback  (Read 145 times)

K Fisher

  • Posts: 2
Problem with Slide and Free Callback
« on: 15 Aug '17 - 02:02 »
I seem to have a problem with slide and free callbacks.
I have two files, Rain and Frog.  Both are mp3.  Rain is 60 seconds, and Frog is 5 seconds.
I start Rain, and slide the volume for 15 seconds.  At the same time I start Frog.
After 5 seconds, I receive the "END" callback for Frog (Which I should)
However I don't receive the "FREE" callback Immediately, I receive it 10 seconds later.  Which is a total of 15 seconds (the slide time for Rain)
If I don't Slide Rain, Everything works as I understand it should (I recieve both END and FREE after 5 seconds)

Here is my Code:
       public static void KPFTester()
        {
            if (_myTestSyncProc == null)
            {
                _myTestSyncProc = new SYNCPROC(EndSyncCallback);
            }

            //  Play Simply-noise-rain - length is about one minute
            string RainFileName = @"http://192.168.1.5:81/sda1/tttt/Simply-noise-rain.mp3";
            int RainStream = Bass.BASS_StreamCreateURL(RainFileName, 0, BASSFlag.BASS_DEFAULT | BASSFlag.BASS_STREAM_AUTOFREE,null, new IntPtr(77)); // | BassFlags.Mono
            //   slide the volume to 50% over 15 seconds
            Bass.BASS_ChannelSlideAttribute(RainStream, BASSAttribute.BASS_ATTRIB_VOL, 0.5f, 15000);
            // set sync for end of slide
            Bass.BASS_ChannelSetSync(RainStream, BASSSync.BASS_SYNC_SLIDE, 0, _myTestSyncProc, new IntPtr(77));
            Bass.BASS_ChannelPlay(RainStream, false);
            SafeAddToListbox(DateTime.Now.ToString("mm:ss") + "  Starting Rain: " + RainStream.ToString());

            //  Play Frog Croaking - length is about 5 seconds    --    note: BASS_STREAM_AUTOFREE
            string FrogFileName = @"d:\etc\sounds\Frog Croaking.mp3";
            int FrogStream = Bass.BASS_StreamCreateFile(FrogFileName, 0L, 0L, BASSFlag.BASS_DEFAULT | BASSFlag.BASS_STREAM_AUTOFREE);
            //  set sync callbacks for both FREE and END
            int sHandle = Bass.BASS_ChannelSetSync(FrogStream, BASSSync.BASS_SYNC_FREE | BASSSync.BASS_SYNC_MIXTIME, 0, _myTestSyncProc, new IntPtr(55));
            int sHandle2 = Bass.BASS_ChannelSetSync(FrogStream, BASSSync.BASS_SYNC_END | BASSSync.BASS_SYNC_MIXTIME, 0, _myTestSyncProc, new IntPtr(166));
            Bass.BASS_ChannelPlay(FrogStream, false);
            SafeAddToListbox(DateTime.Now.ToString("mm:ss") + "  Starting Frog: " + FrogStream.ToString());
        }

        private static void EndSyncCallback(int handle, int channel, int data, IntPtr user)
        {
            int code = (int)user;
            string reason = "???";
            if (code == 55) reason = "FREE";
            if (code == 66) reason = "END";
            if (code == 166) reason = "END";
            if (code == 77) reason = "SLIDE";
            SafeAddToListbox(DateTime.Now.ToString("mm:ss") + " In Callback Reason: " + reason + " Channel = "+channel.ToString());

        }


Here is sample output showing failure:

15:35  Starting Rain: -2147483647 
15:35  Starting Frog: -2147483645 
15:40 In Callback Reason: END Channel = -2147483645 
15:50 In Callback Reason: SLIDE Channel = -2147483647 
15:50 In Callback Reason: FREE Channel = -2147483645 

Ian @ un4seen

  • Administrator
  • Posts: 20400
Re: Problem with Slide and Free Callback
« Reply #1 on: 15 Aug '17 - 15:08 »
Auto-freeing of streams (due to BASS_STREAM_AUTOFREE) may indeed be delayed, and so any BASS_SYNC_FREE syncs set on them will be delayed too. The reason for that is that the same thread that handles attribute sliding also handles auto-freeing (it also handles non-mixtime syncs). If there are any slides active then the stream freeing will be delayed to avoid any chance of delaying the slides.

If you would like to have the stream freed as soon as it reaches the end, you could call BASS_StreamFree in the BASS_SYNC_END sync's callback. You should remove the BASS_SYNC_MIXTIME flag from the BASS_ChannelSetSync call, as the SYNCPROC will otherwise be called before the end is heard (due to buffering) and it is unsafe to free a stream in its own "mixtime" SYNCPROC.
« Last Edit: 16 Aug '17 - 15:35 by Ian @ un4seen »