Author Topic: Problems switching audio device of mixer channel  (Read 1814 times)

kafffee

  • Posts: 260
Re: Problems switching audio device of mixer channel
« Reply #25 on: 9 May '23 - 13:00 »
Okay:

09.05.2023 01:53:21.849
Bass Version: 33820933
Bass Mixer Version: 33819648
09.05.2023 01:53:21.850
before BASS_ChannelPlay(mixer): ChannelIsActive = 0
09.05.2023 01:53:21.850
after BASS_ChannelPlay(mixer): ChannelIsActive = 1
09.05.2023 01:53:23.909
before BASS_ChannelSetDevice(mixer): ChannelIsActive = 2
error code: 0
return value: True
09.05.2023 01:53:23.910
after BASS_ChannelSetDevice(mixer): ChannelIsActive = 2
09.05.2023 01:53:38.215
before BASS_Mixer_StreamAddChannel(mixer)(Channel 1: ChannelIsActive = 2
error code: 0
return value: True
09.05.2023 01:53:38.215
after BASS_Mixer_StreamAddChannel(mixer)(Channel 1: ChannelIsActive = 2
09.05.2023 01:53:49.062
before BASS_ChannelSetDevice(mixer): ChannelIsActive = 2
error code: 0
return value: True
09.05.2023 01:53:49.062
after BASS_ChannelSetDevice(mixer): ChannelIsActive = 2

Ian @ un4seen

  • Administrator
  • Posts: 26015
Re: Problems switching audio device of mixer channel
« Reply #26 on: 9 May '23 - 13:55 »
That looks like the BASS_Mixer_StreamAddChannel call was successful. If so, the only other possibility that comes to mind is that the source ("Channel 1") has ended, so the mixer still has nothing to play and remains stalled. What does BASS_ChannelIsActive say about the source? If it has ended, you can use BASS_ChannelSetPosition to rewind it.

kafffee

  • Posts: 260
Re: Problems switching audio device of mixer channel
« Reply #27 on: 9 May '23 - 15:13 »
That seems not to be the issue neither:


09.05.2023 03:54:35.848
Bass Version: 33820933
Bass Mixer Version: 33819648
09.05.2023 03:54:35.849
before BASS_ChannelPlay(mixer): ChannelIsActive = 0
09.05.2023 03:54:35.850
after BASS_ChannelPlay(mixer): ChannelIsActive = 1
09.05.2023 03:54:44.317
before BASS_ChannelSetDevice(mixer): ChannelIsActive = 2
error code: 0
return value: True
09.05.2023 03:54:44.318
after BASS_ChannelSetDevice(mixer): ChannelIsActive = 2
09.05.2023 03:55:06.412
before BASS_Mixer_StreamAddChannel(mixer)(Channel 1: ChannelIsActive = 2
SourceChannel Channel 1 ChannelIsActive: 1
error code: 0
return value: True
09.05.2023 03:55:06.412
after BASS_Mixer_StreamAddChannel(mixer)(Channel 1: ChannelIsActive = 2
09.05.2023 03:55:16.439
before BASS_ChannelSetDevice(mixer): ChannelIsActive = 2
error code: 0
return value: True
09.05.2023 03:55:16.439
after BASS_ChannelSetDevice(mixer): ChannelIsActive = 2


Can you exclude a threading issue? I have a WPF MVVM app with a truckload of different ViewModels (code classes) which sometimes show the weirdest behaviors when  being combined. I have had problems with that a bunch of times now and they are very tricky to debug as there is no error being thrown in some of the cases.

Anyways, at this point, it's okay for me to just use BASSCONFIG.BASS_CONFIG_DEV_NONSTOP. It might not be the best idea when it comes to saving resources but the app is not supposed to run idle anyways.
But if you need me there to fix a presumed bug then let me know.

I hope this is okay for you :-)

Ian @ un4seen

  • Administrator
  • Posts: 26015
Re: Problems switching audio device of mixer channel
« Reply #28 on: 9 May '23 - 15:53 »
Very puzzling. To hopefully reveal what's going wrong, can you create a little bare-bones example containing only the calls needed to produce the problem?

kafffee

  • Posts: 260
Re: Problems switching audio device of mixer channel
« Reply #29 on: 12 May '23 - 11:42 »
Okay I sat down for a while and done a test app, see attachment. In order to run it, you need Visual Studio 2019 or later.

What I have now is even weirder:

I can hear the music playing, but ChannelIsActive (mixer) returns that it's stalled when you press "Play".

The relevant code is in the ListBoxRightClickViewModel-project in the file: Main ViewModel.vb and you can display it in normal Text Editor, just in case I made a mistake you might want to take a look at it.

Its not that much of code but let me know when you have any questions... Dont worry about the project Name, I had difficulties opening a project Template, so I chose another project...

PS: You have to add Bass, Bass. Net, bassmix and bassfx to the bin\Debug folder of the App- and ViewModel-project!
« Last Edit: 12 May '23 - 11:50 by kafffee »

Ian @ un4seen

  • Administrator
  • Posts: 26015
Re: Problems switching audio device of mixer channel
« Reply #30 on: 12 May '23 - 13:36 »
I can hear the music playing, but ChannelIsActive (mixer) returns that it's stalled when you press "Play".

That is to be expected when the BASS_MIXER_RESUME flag isn't set because the mixer won't resume until its next update cycle. If you add a Sleep call to wait a bit before calling BASS_ChannelIsActive then you should see it return 1 (BASS_ACTIVE_PLAYING). Please also note that each BASS function call (except GetVersion calls) sets the error code, so your logging here is actually showing the error code from the source's BASS_ChannelIsActive call rather than the BASS_Mixer_StreamAddChannel call:

Code: [Select]
        Output = Output & DateTime.Now.ToString("dd.MM.yyyy hh:mm:ss.fff tt") & Environment.NewLine
        Output = Output & "before BASS_Mixer_StreamAddChannel(streamfx): ChannelIsActive(mixer) = " & CStr(Bass.BASS_ChannelIsActive(mixer)) & Environment.NewLine
        Dim retvalue As Boolean = BassMix.BASS_Mixer_StreamAddChannel(mixer, streamfx, BASSFlag.BASS_MIXER_NORAMPIN Or BASSFlag.BASS_MIXER_BUFFER) ' Or BASSFlag.BASS_STREAM_AUTOFREE
        Output = Output & "SourceChannel ChannelIsActive: " & CStr(Bass.BASS_ChannelIsActive(streamfx)) & Environment.NewLine
        Output = Output & "error code: " & CStr(Bass.BASS_ErrorGetCode) & Environment.NewLine
        Output = Output & "return value: " & CStr(retvalue) & Environment.NewLine
        Output = Output & DateTime.Now.ToString("dd.MM.yyyy hh:mm:ss.fff tt") & Environment.NewLine
        Output = Output & "after BASS_Mixer_StreamAddChannel(streamfx): ChannelIsActive(mixer) = " & CStr(Bass.BASS_ChannelIsActive(mixer)) & Environment.NewLine & Environment.NewLine

You could change that to this:

Code: [Select]
        Output = Output & DateTime.Now.ToString("dd.MM.yyyy hh:mm:ss.fff tt") & Environment.NewLine
        Output = Output & "before BASS_Mixer_StreamAddChannel(streamfx): ChannelIsActive(mixer) = " & CStr(Bass.BASS_ChannelIsActive(mixer)) & Environment.NewLine
        Dim retvalue As Boolean = BassMix.BASS_Mixer_StreamAddChannel(mixer, streamfx, BASSFlag.BASS_MIXER_NORAMPIN Or BASSFlag.BASS_MIXER_BUFFER) ' Or BASSFlag.BASS_STREAM_AUTOFREE
        Output = Output & "error code: " & CStr(Bass.BASS_ErrorGetCode) & Environment.NewLine
        Output = Output & "return value: " & CStr(retvalue) & Environment.NewLine
        Output = Output & "SourceChannel ChannelIsActive: " & CStr(Bass.BASS_ChannelIsActive(streamfx)) & Environment.NewLine
        Thread.Sleep(100) ' wait a bit
        Output = Output & DateTime.Now.ToString("dd.MM.yyyy hh:mm:ss.fff tt") & Environment.NewLine
        Output = Output & "after BASS_Mixer_StreamAddChannel(streamfx): ChannelIsActive(mixer) = " & CStr(Bass.BASS_ChannelIsActive(mixer)) & Environment.NewLine & Environment.NewLine

Let me know if there's still a problem. Note that Sleep is just to confirm that the mixer's status does eventually change to PLAYING in the logging, and you shouldn't include it in your real code.

kafffee

  • Posts: 260
Re: Problems switching audio device of mixer channel
« Reply #31 on: 12 May '23 - 14:24 »
If it's the way its supposed to be then this is fine for me.

So the test program is working, other than my "big" app, but thats okay, I guess the mistake is on my side.

I have been explicitely looking for calls like ChannelStop or ChannelRemove that I might have overlooked but didnt find any... Must be something I cannot find...

So I will just go on using BASSCONFIG.BASS_CONFIG_DEV_NONSTOP...

Have a nice weekend  :)

Ian @ un4seen

  • Administrator
  • Posts: 26015
Re: Problems switching audio device of mixer channel
« Reply #32 on: 12 May '23 - 14:45 »
Another little issue I noticed is that the device selector defaults to the "Default" device but the mixer is actually being created on the last device because that was the most recently initialized one. If you want the mixer created on the "Default" device then you will need a BASS_SetDevice call there:

Code: [Select]
        SpeakerIndex = 1
        BASS.BASS_SetDevice(SpeakerIndex) ' set device for mixer
        mixer = Un4seen.Bass.AddOn.Mix.BassMix.BASS_Mixer_StreamCreate(44100, 2, BASSFlag.BASS_DEFAULT Or BASSFlag.BASS_SAMPLE_FLOAT) ' Or BASSFlag.BASS_MIXER_RESUME)

Perhaps your main app has the same issue?

kafffee

  • Posts: 260
Re: Problems switching audio device of mixer channel
« Reply #33 on: 13 May '23 - 06:49 »
Did you take a look at the setter of SpeakerIndex?

Because when I set SpeakerIndex, ChannelSetDevice is being called as well automatically.

Or does it make any difference to call SetDevice or ChannelSetDevice in this case?

Ian @ un4seen

  • Administrator
  • Posts: 26015
Re: Problems switching audio device of mixer channel
« Reply #34 on: 15 May '23 - 11:28 »
The issue there is that the mixer doesn't exist yet (it's before the BASS_Mixer_StreamCreate call), so that BASS_ChannelSetDevice call will fail. BASS_SetDevice sets what device a new stream (in the same thread) will be created on.

kafffee

  • Posts: 260
Re: Problems switching audio device of mixer channel
« Reply #35 on: 23 May '23 - 04:36 »
In my main project, I call ChannelSetDevice after BASS_Mixer_StreamCreate.

But as I said, it's fine for me.  :)