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.