komh / ksoftseq

K Soft Sequencer
3 stars 1 forks source link

ksoftseq does not follow if the default audio device is changed #12

Closed lerdmann closed 1 year ago

lerdmann commented 1 year ago

ksoftseq seems to have some problems in finding the default audio device: If I play via USB first and then, I switch the default device (I am delivering a utility with the USB audio drivers that does that and AN has also their own solution to switch the default audio device), I cannot switch to UNIAUD: if I do, ksoftseq will still continue to play on the USB device, if I remove the USB audio device, ksoftseq will refuse to play even if have switched over the default audio device to UNIAUD.

lerdmann commented 1 year ago

Just as a note since this is what we found out when updating SDL2: the default audio device can always be selected when you open a device via device type id and a device number of 0 (in parameter "pszDeviceType"). This is true, regardless if a device has been specifically selected as a default (via additional entries in MMPM2.INI) or not (in the latter case, MMPM2 will pick the first device in the device list of that device type).

komh commented 1 year ago

How about adding set KAI_NOSOFTMIXER=1 to config.sys ?

lerdmann commented 1 year ago

What does that do ? How does that influence selection of the default device ? Where is that documented ?

komh commented 1 year ago

It's an option for libkai not for ksoftseq itself, and it disables soft mixer mode of libkai. See https://github.com/komh/kai/blob/master/libkai.txt.

If soft mixer mode is disabled, libkai communicates with DART APIs directly, then this problem may be solved.

lerdmann commented 1 year ago

Yes, that fixes the problem, thank you very much for that information. I still do not understand how the soft mixer comes into play. Why is that needed at all ? I certainly cannot mix multiple sound streams. Only one Midi file can ever be selected. Can the soft mixer (in libkai) be made to honour the default device selection ?

komh commented 1 year ago

The soft mixer is used to mix multiple streams when a sound card or a driver does not support to play multiple streams simultaneously. In case of ksoftseq, it may support to play multiple midi files although it's not working yet.

The soft mixer should consider the default device selection. However, currently it converts a default index to a real index manually at init because I didn't consider sound cards may be inserted and/or removed dynamically. Of course, converting a default index to a real index dynamically when opening a device may improve this situation. I'm considering this way although it has a few problems to solve.

And I want to know that indexes of audio devices may change when an audio card is inserted and/or removed. Would you mind helping this?

lerdmann commented 1 year ago

Indexes of audio cards (or rather: audio drivers) will never change because drivers are loaded statically on system start by OS/2.

It is very simple: the list of say waveaudio devices in MMPM2.INI can be read from left to right: mostleft = 1, next to mostleft = 2 etc., example from MMPM2.INI:

[Drivers] Digitalvideo=IBMDIGVIDPLAYER01,IBMMPEGPLAYER01 Speaker=SPEAKER Headphone=HEADPHONE Microphone=MICROPHONE Filter=IBMFILTER01,IBMFILTER02,IBMFILTER03 Waveaudio=UNIAUDWAVE01,WMBWAVEUSB01,WMBWAVE2USB01 Ampmix=UNIAUDAMPMIX01,WMBAMPMIXUSB01,WMBAMPMIX2USB01 CDaudio=IBMCDAUDIO01,IBMCDAUDIO02 Sequencer=KSOFTSEQ01

So, UNIAUDWAVE01 would be device with index = 1, WMBWAVEUSB01 would be device with index = 2, WMBWAVE2USB01 would be device with index = 3

UNIAUDWAVE01 would also be device with index = 0 because it is the default device as it appears first in the list, unless you find this section in MMPM2.INI:

[defaultnames] Digitalvideo=IBMDIGVIDPLAYER01 Waveaudio=WMBWAVEUSB01 Ampmix=WMBAMPMIXUSB01 Sequencer=KSOFTSEQ01

in which case the default wave device (device index = 0) would be WMBWAVEUSB01.

In short: if you always want to use the "default device" (you do not want to involve the user in selecting a specific device), you can always go with device index = 0.

komh commented 1 year ago

Good!

And there are more things I want to know. So I wrote a simple test program. Attach the output of the following program, please.

cardlist.zip

  1. Output when Non-USB audio(default), USB audio in order
  2. Output when a default device is switched to USB audio
  3. Output when USB audio(default) is removed
  4. Output when USB audio(default), Non-USB audio in order
  5. Output when USB audio(default) is removed

Thanks!

lerdmann commented 1 year ago

cardlist.txt

komh commented 1 year ago

Great!

I could know that

  1. index of an audio device does not change even if the audio device is removed
  2. the default index does not change even if a default audio device is removed

In case of 4., I want to know whether or not indexes of audio devices are reordered if an audio device with a lower index is removed. And I could guess it will not.

I'll try to fix this problem, soon.

Thanks a lot!

komh commented 1 year ago

ksoftseq.zip

Test, please...

lerdmann commented 1 year ago

Yes, that works as expected. I can now swap back and forth between UNIAUD and USB audio and the sound will always play on the default device selected. And the good news is: it also works without setting KAI_NOSOFTMIXER at all. Thank you very much !

komh commented 1 year ago

Good!

Working without KAI_NOSOFTMIXER was the purpose.

Thanks for your help!!!

komh commented 1 year ago

Fixed by commit https://github.com/komh/kai/commit/ba691cacc7fc48169e2f2a9b07f18994aebc8827