Author Topic: Create Stream issues  (Read 70 times)

RicardoC

  • Guest
Create Stream issues
« on: 8 Jun '21 - 16:32 »
Hello, I'm exploring ManagedBass wrapper and have got a song playing and stopping.

I want to have 15 seconds of the song loop, not the entire song.
Tried using the create stream and change offset and length parameters but if i change either of them CreateStream returns 0!
if i change the parameters back to 0,0 then the song plays and loops.

Does anyone know what the problem may be? Am I overlooking something?

Code: [Select]
if ((_chan = Bass.CreateStream(song, 0, 0, BassFlags.Loop | BassFlags.Float)) == 0)

Ian @ un4seen

  • Administrator
  • Posts: 23619
Re: Create Stream issues
« Reply #1 on: 9 Jun '21 - 15:53 »
The BASS_StreamCreateFile "offset" and "length" parameters deal in file positions, rather than decoded data positions, so they cannot usually be used for what you want to do, eg. if "offset" isn't 0 then BASS won't see the file's headers. You can instead do it by setting a "mixtime" BASS_SYNC_POS sync at 15 seconds via BASS_ChannelSetSync and then have the callback function seek back to the start. I'm not a .Net/ManagedBass user myself, but in C/C++ the code could look like this:

Code: [Select]
BASS_ChannelSetSync(stream, BASS_SYNC_POS | BASS_SYNC_MIXTIME, BASS_ChannelSeconds2Bytes(stream, 15), LoopSyncProc, 0); // set a mixtime sync at 15s

...

void CALLBACK LoopSyncProc(HSYNC handle, DWORD channel, DWORD data, void *user)
{
BASS_ChannelSetPosition(channel, 0, BASS_POS_BYTE); // rewind the stream
}

The next BASS release (due soon) will have an even simpler way to do this, without requiring a sync.

David_AVD

  • Posts: 45
Re: Create Stream issues
« Reply #2 on: 9 Jun '21 - 22:18 »
The next BASS release (due soon) will have an even simpler way to do this, without requiring a sync.

Ooh... I'm interested in that.

Ian @ un4seen

  • Administrator
  • Posts: 23619
Re: Create Stream issues
« Reply #3 on: 10 Jun '21 - 15:22 »
If you would like to try it now, it's in this latest build:

   www.un4seen.com/stuff/bass.zip

The new feature of interest is the BASS_POS_END (0x10) option for use with BASS_ChannelSetPosition, which allows you to set a reduced length (0=normal length). For example:

Code: [Select]
BASS_ChannelSetPosition(stream, BASS_ChannelSeconds2Bytes(stream, 15), BASS_POS_END); // limit the length to 15s

If looping is enabled (BASS_SAMPLE_LOOP flag set) then that becomes the loop end position. If you would also like to customise the loop start position, there's a new BASS_POS_LOOP (0x11) option for that too.

RicardoC

  • Guest
Re: Create Stream issues
« Reply #4 on: 11 Jun '21 - 11:08 »
Thanks for the reply.
If i got it right this sample code makes a 15s loop from the start of the song.
How would i go about changing the start of this loop so that, for example, it loops from second 15 to 30.

Code: [Select]
BASS_ChannelSetSync(stream, BASS_SYNC_POS | BASS_SYNC_MIXTIME, BASS_ChannelSeconds2Bytes(stream, 15), LoopSyncProc, 0); // set a mixtime sync at 15s

...

void CALLBACK LoopSyncProc(HSYNC handle, DWORD channel, DWORD data, void *user)
{
BASS_ChannelSetPosition(channel, 0, BASS_POS_BYTE); // rewind the stream
}

RicardoC

  • Posts: 1
Re: Create Stream issues
« Reply #5 on: 11 Jun '21 - 11:48 »
Nevermind i solved my issue!
I was using BASS_ChannelSetPosition but it doesn't take seconds and i was completely ignoring BASS_ChannelSeconds2Bytes.

Thanks for the help!