Author Topic: Reverse Stream End Position  (Read 364 times)

rewire07

  • Posts: 12
Reverse Stream End Position
« on: 14 Feb '24 - 16:10 »
Hi, great library!

Is it possible to set the end position for a reversed BASSFX stream? Works fine for a normal stream, but whenever I try setting BASS_POS_END flag of the reversed stream, I get false returned with "NotAvailable" error message. I thought maybe because it was outside the 2 second buffer, but that seems to have no impact either. Just trying to play 1 second of a long WAV in reverse basically...

Code: [Select]
sourceHandle = Bass.CreateStream(fileSelected, 0, 0, BassFlags.Decode | BassFlags.Prescan);
playbackHandle = BassFx.ReverseCreate(sourceHandle, 2f, BassFlags.FxFreeSource);

long bytesIn = Bass.ChannelSeconds2Bytes(playbackHandle, 3.0);
Bass.ChannelSetPosition(playbackHandle, bytesIn);

long bytesOut = Bass.ChannelSeconds2Bytes(playbackHandle, 2.0);
bool b = Bass.ChannelSetPosition(playbackHandle, bytesOut , 16);


Ian @ un4seen

  • Administrator
  • Posts: 25732
Re: Reverse Stream End Position
« Reply #1 on: 14 Feb '24 - 17:48 »
The current BASS_FX release indeed doesn't support the BASS_POS_END (or BASS_POS_LOOP) option, but I think the latest build/beta adds support for it. You can get that here:

   www.un4seen.com/stuff/bass_fx.zip

rewire07

  • Posts: 12
Re: Reverse Stream End Position
« Reply #2 on: 14 Feb '24 - 18:34 »
Thanks for the help! I tried the version you linked, and it no longer errors, but it still doesn't seem to work. If I do ChannelGetPosition with the BASS_POS_END after trying to set it, it returns -1.

Ian @ un4seen

  • Administrator
  • Posts: 25732
Re: Reverse Stream End Position
« Reply #3 on: 15 Feb '24 - 15:03 »
The latest BASS build may also be needed. You can get that from here:

   www.un4seen.com/stuff/bass.zip

Let me know if it still isn't working properly. And if so, please also confirm the BASS_CHANNELINFO "ctype" value of the source stream that you're reversing, as it will need to support BASS_POS_END too.

rewire07

  • Posts: 12
Re: Reverse Stream End Position
« Reply #4 on: 15 Feb '24 - 17:00 »
Thanks! So that did help, but its still not working. Verifying with ChannelGetPosition, the ChannelSetPosition seems to be working correctly now. However, when I begin playback, it immediately jumps to the end position, then continues playing until hitting 0. Maybe its a problem with my code? I will keep looking at it..

I'm using WavePCM files right now for development, but also plan on supporting FLAC and MP3 as well if possible. It's for a free app for working with old samplers like Akai, E-mu, etc. Kind of a digital turntable for cueing up portions of recordings to sample.

Ian @ un4seen

  • Administrator
  • Posts: 25732
Re: Reverse Stream End Position
« Reply #5 on: 16 Feb '24 - 17:11 »
In reverse mode, the BASS_POS_END position is where it starts from. But it currently always ends at 0, so you can't easily loop just a middle part of a file. Here's an update that should end at the BASS_POS_LOOP position when looping is enabled (BASS_SAMPLE_LOOP), so BASS_POS_END/LOOP are basically swapped compared to normal playback.

   www.un4seen.com/stuff/bass_fx.zip

Let me know if you find it still isn't working properly.

rewire07

  • Posts: 12
Re: Reverse Stream End Position
« Reply #6 on: 16 Feb '24 - 18:21 »
OK, got ya. So swapping around the positions and updating to the latest BASS FX DLL, I can confirm looping in reverse is now working for WavePCM files!

The looping is nice for picking out a region to sample, but when you do final playback for recording into sampler, it really needs to be a one-shot and stop playing at the end of the region. I see you're saying its always 0 for the reverse end pos, do you think this will ever change or should I perhaps find another way to stop it?

Ian @ un4seen

  • Administrator
  • Posts: 25732
Re: Reverse Stream End Position
« Reply #7 on: 19 Feb '24 - 17:15 »
With other stream types, it's possible to use a "mixtime" BASS_SYNC_POS sync to end at any position. That isn't currently working on reverse streams, but here's an update that should add support for it:

   www.un4seen.com/stuff/bass_fx.zip

For example, to stop at 1000000, you could do this:

Code: [Select]
BASS_ChannelSetSync(stream, BASS_SYNC_POS | BASS_SYNC_MIXTIME, 1000000, EndSyncProc, 0); // set mixtime sync at end position

...

void CALLBACK EndSyncProc(HSYNC handle, DWORD channel, DWORD data, void *user)
{
BASS_ChannelStop(channel); // end it
}

rewire07

  • Posts: 12
Re: Reverse Stream End Position
« Reply #8 on: 25 Feb '24 - 21:17 »
Finally got around to checking this out. Very cool! I didn't know about the SyncProcedures. I decided to remove all the existing looping and Endposition code, and just try to use these to handle it all.

I added an EndSyncProcedure as you demonstrated and it seems to work, but my issue now is that it sometimes crashes after calling Bass.ChannelPlay with the reverse stream. It seems to be more consistent if I do a ChannelSetPosition to queue up the start position before calling play. I'm using ManagedBass, so maybe it's making the error message less useful:

System.AccessViolationException: 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'

Ian @ un4seen

  • Administrator
  • Posts: 25732
Re: Reverse Stream End Position
« Reply #9 on: 26 Feb '24 - 12:32 »
For more info on the problem, please provide a dump file from the crash. If you catch it in the VS debugger, you can use the "Save Dump As" option to generate a dump file. The dump file can be uploaded here:

   ftp.un4seen.com/incoming/

rewire07

  • Posts: 12
Re: Reverse Stream End Position
« Reply #10 on: 26 Feb '24 - 17:51 »
Thanks, I've uploaded JungleTools.dmp, hope it is of some help.

Ian @ un4seen

  • Administrator
  • Posts: 25732
Re: Reverse Stream End Position
« Reply #11 on: 27 Feb '24 - 12:34 »
It looks like the problem may be related to SkiaSharp.dll? This is the call-stack in the uploaded dump file:

Quote
00000098`2357cef0 00007ffb`5858db44 SkiaSharp!ILStubClass.IL_STUB_PInvoke+0x74
00000098`2357cfb0 00007ffb`5858daa3 JungleTools!JungleTools.Pages.ScrubberPage.StartPlayback+0xd3
00000098`2357d020 00007ffb`5858d992 JungleTools!JungleTools.Pages.ScrubberPage.Play+0x4b2
00000098`2357d140 00007ffb`585a4023 JungleTools!JungleTools.Pages.ScrubberPage.btnPlayRev_Click+0x33
...

What call-stack do you see when you catch the crash in the VS debugger? It should hopefully lead back to a line in your code that you can check.

rewire07

  • Posts: 12
Re: Reverse Stream End Position
« Reply #12 on: 1 Mar '24 - 16:58 »
On my end its pointing to the line Bass.ChannelPlay(playbackHandle) with the following error:

Code: [Select]
System.AccessViolationException
  HResult=0x80004003
  Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
  Source=<Cannot evaluate the exception source>
  StackTrace:
<Cannot evaluate the exception stack trace>

I've tried commenting out the ChannelPlay and no longer receive the error. I've also never gotten it before updating to the last BassFX dll you sent.

Ian @ un4seen

  • Administrator
  • Posts: 25732
Re: Reverse Stream End Position
« Reply #13 on: 1 Mar '24 - 17:21 »
Is there anything above that in the callstack, eg. mentioning BASS or BASS_FX? If not, please check that you have mixed mode debugging enabled, as described here:

   https://learn.microsoft.com/en-us/visualstudio/debugger/how-to-debug-in-mixed-mode

Just in case there happened to be a different crash when you generated the earlier dump file, please also generate and upload a new dump file after confirming the callstack shows it's within BASS_ChannelPlay.

rewire07

  • Posts: 12
Re: Reverse Stream End Position
« Reply #14 on: 3 Mar '24 - 19:27 »
Thanks for sticking with me on this! Looks like I got a real error after enabling the Mixed debugging. Hopefully this is more helpful?


Ian @ un4seen

  • Administrator
  • Posts: 25732
Re: Reverse Stream End Position
« Reply #15 on: 4 Mar '24 - 12:07 »
Yes, that looks more promising. Please generate and upload a dump file from that crash to have a look at.

rewire07

  • Posts: 12
Re: Reverse Stream End Position
« Reply #16 on: 4 Mar '24 - 14:02 »
Uploaded, thanks!

Ian @ un4seen

  • Administrator
  • Posts: 25732
Re: Reverse Stream End Position
« Reply #17 on: 4 Mar '24 - 16:29 »
Here's an update for you to try:

   www.un4seen.com/stuff/bass_fx.zip

Let me know if you still get a crash with it (and upload a new dump file if so).

rewire07

  • Posts: 12
Re: Reverse Stream End Position
« Reply #18 on: 7 Mar '24 - 14:17 »
Working beautifully now! Had to do some more code adjustments to work with the sync calls instead of the endposition and loop flags, but all seems solid. Thanks again for the help on this.

Any idea when these fixes will make it to the public release? I have Mac and Linux versions as well.

Ian @ un4seen

  • Administrator
  • Posts: 25732
Re: Reverse Stream End Position
« Reply #19 on: 7 Mar '24 - 17:38 »
Good to hear that it's working well now. I'm not sure when the next release be. Besides the reverse changes, these betas have some pretty big changes in the tempo processing, which I think still need more testing and perhaps some performance tweaking too. But here are macOS and Linux builds that you can use for now:

   www.un4seen.com/stuff/bass_fx-osx.zip
   www.un4seen.com/stuff/bass_fx-linux.zip

Btw, there was a BASS_SYNC_END sync issue (sometimes not being called) found in the new tempo stuff in the last couple of days, so the Windows version has been updated too. You can get that by re-downloading from the earlier link.