Author Topic: Unusual looping problem  (Read 120 times)

frytech

  • Posts: 17
Unusual looping problem
« on: 29 Jul '18 - 06:14 »
In my program I define 3 steaming channels ... chan(0) chan(1) and chan(2) . The first 2 are for music playback. As chan(0) is finishing up chan(1) starts playing.  My solution for gapless playback. I use chan(2) for pre-processing only and use the BASS_STREAM_DECODE flag when creating the stream.

What is happening on occasion is that the song that is ending and is supposed to stop will loop. I then have 2 songs playing at once.  When I send a stop command (to all 3 channels) the looping song still continues to play. Everything else in the program continues to operate normally.

Running Windows 7 x64, Directsound BASS 2.4.8 no other libraries.

Chris

  • Posts: 1851
Re: Unusual looping problem
« Reply #1 on: 29 Jul '18 - 23:32 »
Hi
with which Flags  do you create the streams ?
So if you want automatically that the stream will freed after its end then just add BASS_STREAM_AUTOFREE as Flag.
2  :) How do you detected that One Stream has stop and the other should be start? Inside a BASS_SYNC_END Sync?
Are your sure you do not create the Stream with the BASS_SAMPLE_LOOP Flag?
Show the Source how you create the stream.....

frytech

  • Posts: 17
Re: Unusual looping problem
« Reply #2 on: 30 Jul '18 - 02:53 »
My programming language is VB6 btw - any help is greatly appreciated

Direct from my source code:

chan(Index) = BASS_StreamCreateFile(BASSFALSE, StrPtr(MusicFile), 0, 0, BASS_STREAM_PRESCAN And BASS_STREAM_AUTOFREE)

and for checking if the file has ended:

lngPtr = BASS_ChannelIsActive(chan(Index))
Select Case lngPtr
    Case Is = BASS_ACTIVE_PLAYING
        MusicPlaying = 0
    Case Is = BASS_ACTIVE_STOPPED ' I want to know if the file has Ended
        flength = BASS_ChannelGetLength(chan(Index), BASS_POS_BYTE)
        fPosition = BASS_ChannelGetPosition(chan(Index), BASS_POS_BYTE)
        If (flength = fPosition) And (fPosition <> -1) Then
            ' debuglog "BASS Active Stop"
            MusicPlaying = 1
            Exit Function
        End If
    Case Is = BASS_ACTIVE_PAUSED
        MusicPlaying = 2
    Case Is = BASS_ACTIVE_STALLED
        MusicPlaying = 3
    Case Else
        MusicPlaying = -1
End Select


Ian @ un4seen

  • Administrator
  • Posts: 21020
Re: Unusual looping problem
« Reply #3 on: 30 Jul '18 - 14:32 »
In my program I define 3 steaming channels ... chan(0) chan(1) and chan(2) . The first 2 are for music playback. As chan(0) is finishing up chan(1) starts playing.  My solution for gapless playback. I use chan(2) for pre-processing only and use the BASS_STREAM_DECODE flag when creating the stream.

What is happening on occasion is that the song that is ending and is supposed to stop will loop. I then have 2 songs playing at once.

Have you set the BASS_SAMPLE_LOOP flag on the looping stream? If not, are you calling BASS_ChannelSetPosition on the stream in a BASS_SYNC_END sync callback? If you're not doing that either, how much of the file is being looped, ie. the entire file or a small piece at the end?

When I send a stop command (to all 3 channels) the looping song still continues to play. Everything else in the program continues to operate normally.

Perhaps you have overwritten one of the stream handle variables? That could explain one of the streams not stopping, ie. BASS_ChannelStop is never actually called on it. You could try logging the handles and function calls to check that.

Running Windows 7 x64, Directsound BASS 2.4.8 no other libraries.

BASS 2.4.8 is pretty old now. You could try upgrading to the latest version.

My programming language is VB6 btw - any help is greatly appreciated

Direct from my source code:

chan(Index) = BASS_StreamCreateFile(BASSFALSE, StrPtr(MusicFile), 0, 0, BASS_STREAM_PRESCAN And BASS_STREAM_AUTOFREE)

and for checking if the file has ended:

lngPtr = BASS_ChannelIsActive(chan(Index))
Select Case lngPtr
    Case Is = BASS_ACTIVE_PLAYING
        MusicPlaying = 0
    Case Is = BASS_ACTIVE_STOPPED ' I want to know if the file has Ended
        flength = BASS_ChannelGetLength(chan(Index), BASS_POS_BYTE)
        fPosition = BASS_ChannelGetPosition(chan(Index), BASS_POS_BYTE)
        If (flength = fPosition) And (fPosition <> -1) Then
            ' debuglog "BASS Active Stop"
            MusicPlaying = 1
            Exit Function
        End If
    Case Is = BASS_ACTIVE_PAUSED
        MusicPlaying = 2
    Case Is = BASS_ACTIVE_STALLED
        MusicPlaying = 3
    Case Else
        MusicPlaying = -1
End Select

Please clarify why you are checking the position when BASS_ChannelIsActive returns BASS_ACTIVE_STOPPED. It seems unnecessary and could potentially leave "MusicPlaying" undefined if playback stops earlier than expected.

frytech

  • Posts: 17
Re: Unusual looping problem
« Reply #4 on: 30 Jul '18 - 15:54 »


What is happening on occasion is that the song that is ending and is supposed to stop will loop. I then have 2 songs playing at once.
[/quote]

Have you set the BASS_SAMPLE_LOOP flag on the looping stream? If not, are you calling BASS_ChannelSetPosition on the stream in a BASS_SYNC_END sync callback? If you're not doing that either, how much of the file is being looped, ie. the entire file or a small piece at the end?

The entire file loops once then stops ... in normal operation, player(0) finishes as player(1) starts, player(0) gets pre-loaded, player(1) finishes as player(0) starts ... wash rinse repeat.

What is happening is player(0) comes to the point where player(1) starts, player(0) -should- stop and get preloaded but it starts playing again and plays the entire file 1 additional time.

When I send a stop command (to all 3 channels) the looping song still continues to play. Everything else in the program continues to operate normally.

Perhaps you have overwritten one of the stream handle variables? That could explain one of the streams not stopping, ie. BASS_ChannelStop is never actually called on it. You could try logging the handles and function calls to check that.

Running Windows 7 x64, Directsound BASS 2.4.8 no other libraries.

BASS 2.4.8 is pretty old now. You could try upgrading to the latest version.

I meant to say 2.4.13.8

lngPtr = BASS_ChannelIsActive(chan(Index))
Select Case lngPtr
    Case Is = BASS_ACTIVE_PLAYING
        MusicPlaying = 0
    Case Is = BASS_ACTIVE_STOPPED ' I want to know if the file has Ended
        flength = BASS_ChannelGetLength(chan(Index), BASS_POS_BYTE)
        fPosition = BASS_ChannelGetPosition(chan(Index), BASS_POS_BYTE)
        If (flength = fPosition) And (fPosition <> -1) Then
            ' debuglog "BASS Active Stop"
            MusicPlaying = 1
            Exit Function
        End If
    Case Is = BASS_ACTIVE_PAUSED
        MusicPlaying = 2
    Case Is = BASS_ACTIVE_STALLED
        MusicPlaying = 3
    Case Else
        MusicPlaying = -1
End Select
[/quote]

Please clarify why you are checking the position when BASS_ChannelIsActive returns BASS_ACTIVE_STOPPED. It seems unnecessary and could potentially leave "MusicPlaying" undefined if playback stops earlier than expected.
[/quote]

That is where I have been checking to see if I am at the end of the file or if stopped for some other reason, just part of my own debugging attempts.  It would be nice if there were a 'file is done' flag <grin>

Chris

  • Posts: 1851
Re: Unusual looping problem
« Reply #5 on: 30 Jul '18 - 21:59 »
hi
Quote
chan(Index) = BASS_StreamCreateFile(BASSFALSE, StrPtr(MusicFile), 0, 0, BASS_STREAM_PRESCAN And BASS_STREAM_AUTOFREE)
must be
chan(Index) = BASS_StreamCreateFile(BASSFALSE, StrPtr(MusicFile), 0, 0, BASS_STREAM_PRESCAN or BASS_STREAM_AUTOFREE)

Quote
and for checking if the file has ended:
its better to do that inside a Bass_Sync (BASS_SYNC_END)
« Last Edit: 30 Jul '18 - 22:16 by Chris »

frytech

  • Posts: 17
Re: Unusual looping problem
« Reply #6 on: 31 Jul '18 - 06:15 »
hi
Quote
chan(Index) = BASS_StreamCreateFile(BASSFALSE, StrPtr(MusicFile), 0, 0, BASS_STREAM_PRESCAN And BASS_STREAM_AUTOFREE)
must be
chan(Index) = BASS_StreamCreateFile(BASSFALSE, StrPtr(MusicFile), 0, 0, BASS_STREAM_PRESCAN or BASS_STREAM_AUTOFREE)

Noted, thank you.

Quote
and for checking if the file has ended:
its better to do that inside a Bass_Sync (BASS_SYNC_END)

I have not done anything with callbacks or syncs so I am unfamiliar with the structure and syntax.  Could you provide me with a little pseudo code of how that would work? In a VB6 flavor if possible.


Ian @ un4seen

  • Administrator
  • Posts: 21020
Re: Unusual looping problem
« Reply #7 on: 31 Jul '18 - 14:40 »
The entire file loops once then stops ... in normal operation, player(0) finishes as player(1) starts, player(0) gets pre-loaded, player(1) finishes as player(0) starts ... wash rinse repeat.

What is happening is player(0) comes to the point where player(1) starts, player(0) -should- stop and get preloaded but it starts playing again and plays the entire file 1 additional time.

What does that code look like? Are you using the BASS_SAMPLE_LOOP flag? If not, I see 2 possible causes for the loop: either you call BASS_ChannelSetPosition to rewind player(0) before it ends, or you call BASS_ChannelPlay to restart it after it has ended. Check the code for either of those.

I have not done anything with callbacks or syncs so I am unfamiliar with the structure and syntax.  Could you provide me with a little pseudo code of how that would work? In a VB6 flavor if possible.

Callbacks can be troublesome in VB6 because VB6 doesn't really support multi-threading. If you don't use any VB stuff in the callbacks (eg. stick to BASS or Win32 APIs) then they should be OK, but if possible, I would suggest switching to VB.Net (or perhaps another Basic that does support multi-threading).

frytech

  • Posts: 17
Re: Unusual looping problem
« Reply #8 on: 1 Aug '18 - 08:26 »
The entire file loops once then stops ... in normal operation, player(0) finishes as player(1) starts, player(0) gets pre-loaded, player(1) finishes as player(0) starts ... wash rinse repeat.

What is happening is player(0) comes to the point where player(1) starts, player(0) -should- stop and get preloaded but it starts playing again and plays the entire file 1 additional time.

What does that code look like? Are you using the BASS_SAMPLE_LOOP flag? If not, I see 2 possible causes for the loop: either you call BASS_ChannelSetPosition to rewind player(0) before it ends, or you call BASS_ChannelPlay to restart it after it has ended. Check the code for either of those.

All of my calls for creating the stream, telling the stream to play or stop etc, are done in a small module and nowhere else, a quick check shows none of the above is the case.  I don't know yet why it is looping but I did discover why it was not stopping when it should. I was using the CALL keyword eg Call BASS_ChannelStop(chan(index)) instead of int = BASS_ChannelStop(chan(index))
The problem is very intermittent so I have not been able to see a pattern.

Callbacks can be troublesome in VB6 because VB6 doesn't really support multi-threading. If you don't use any VB stuff in the callbacks (eg. stick to BASS or Win32 APIs) then they should be OK, but if possible, I would suggest switching to VB.Net (or perhaps another Basic that does support multi-threading).

I'll keep hammering on it. I'm just a hobby programmer so I'll stick to VB6, too many intuitive things in VB6 were done away with in VB.Net and I just don't have the patience anymore for learning a new language.  You can see how well I do at quoting messages as an example :)