26 May '13 - 07:44 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1]
  Reply  |  Print  
Author Topic: Device switching and BASS_ChannelIsActive bug  (Read 428 times)
QuentinC
Posts: 8


« on: 4 Sep '12 - 22:23 »
Reply with quoteQuote

Hello,
I think this is a bug, but I may have missunderstood something.

My original program contains a kind of player that plays a stream. While the sound is playing, a separate thread regularely query the stream to check if it is still playing, its duration, etc. to update a progress bar and other controls. The user can also change the output device on the fly in a combo box.

However, for a strange reason, just after the device has been changed, BASS_ChannelIsActive sometimes returns 0, as if the stream was stopped, allthough it keeps playing fine on the new device set by the user. BASS_ErrorGetCode doesn't return any error code in that case.

I have isolated the problem in  this code :
#include<windows.h>
#include<stdio.h>
#include "bass.h"

DWORD stream = 0;
BOOL running = TRUE;

DWORD CALLBACK threadproc (LPVOID udata) {
printf("Thread is running\r\n");
while (running) {
int state = BASS_ChannelIsActive(stream);
if (state!=1) printf("Channel isn't active ! state=%d, error=%d\r\n", state, BASS_ErrorGetCode());
Sleep(1);
}
return 0;
}

int main (int argc, char** argv) {
!BASS_Init(1, 44100, 0, NULL, NULL);
BASS_SetDevice(1);
stream = BASS_StreamCreateFile(FALSE, "test.ogg", 0, 0, BASS_SAMPLE_LOOP | BASS_SAMPLE_FLOAT);
BASS_ChannelSetAttribute(stream, BASS_ATTRIB_VOL, 0.2);
BASS_ChannelPlay(stream, FALSE);
CreateThread(NULL, 0, threadproc, NULL, 0, NULL);
printf("Press any key when you are ready to switch to device #2\r\n");
getch();
!BASS_Init(2, 44100, 0, NULL, NULL);
BASS_ChannelSetDevice(stream, 2);
BASS_SetDevice(1);
BASS_Free();
BASS_SetDevice(2);
printf("Press any key to quit\r\n");
getch();
running = FALSE;
Sleep(20);
BASS_Free();
return 0;
}

Try multiple times, the problem don't always occurrs. By me it's about 75-80% of the time if you listen to the music more than 5 seconds.

If I remove the first BASS_Free call, then the problem disappears completely. But of course, this is a kind of leak because I'm not freeing a device I'm no longer using.

I'm on windows 7 32 bits. 1st device is an USB headphone+mic, and 2nd device is the speakers, but sometimes this order is reversed.

Thank you for your answer.
« Last Edit: 4 Sep '12 - 22:27 by QuentinC » Logged
Ian @ un4seen
Administrator
Posts: 15276


« Reply #1 on: 5 Sep '12 - 15:39 »
Reply with quoteQuote

There will be a split second where the channel isn't playing, while it is moved to the new device, but it should be resumed on the new device before the BASS_ChannelSetDevice call returns. So the subsequent BASS_Free call shouldn't really affect things; are you sure the problem only ever happen when that call is present?

Here's an update to try, in which BASS_ChannelIsActive should ignore the brief stoppage while the channel is being moved to another device...

   www.un4seen.com/stuff/bass.dll

Let me know if you still see the problem with that.
Logged
QuentinC
Posts: 8


« Reply #2 on: 7 Sep '12 - 17:26 »
Reply with quoteQuote

Thank you, the problem mentionned above as gone away with your patch, BASS_Free has actually nothing to do with it.

However, I had a second problem in my real application. I said by misstake that it was linked to BASS_Free because there's a second reason why my channel stopped prematurely. There was a FX tempo effect on it, and to successfully switch device I must call BASS_SetDevice on both the effect handle and the source stream, otherwise any further call give the error #5 (invalid handle). Normal, the stream has been free by BASS_Free.

That later is therefore not really a bug, but in my opinion, when one change one's device, attached effects and/or sources  should follow automatically. I tried with other effects coming from bass_fx.dll and those works as expected, i.e. they follow, I don't have to set their device explicitely.

Thank you again.
Logged
Ian @ un4seen
Administrator
Posts: 15276


« Reply #3 on: 7 Sep '12 - 17:38 »
Reply with quoteQuote

However, I had a second problem in my real application. I said by misstake that it was linked to BASS_Free because there's a second reason why my channel stopped prematurely. There was a FX tempo effect on it, and to successfully switch device I must call BASS_SetDevice on both the effect handle and the source stream, otherwise any further call give the error #5 (invalid handle). Normal, the stream has been free by BASS_Free.

In that scenario, you could create the decoding channels (eg. a tempo stream source) on the "no sound" device (device number 0) and leave them there while moving the playback channels around. Keeping the "no sound" device initialized won't use up any extra resources, eg. memory or CPU.
Logged
Pages: [1]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.18 | SMF © 2013, Simple Machines