skjelten / emusc

A software synthesizer emulating the Sound Canvas SC-55 lineup
GNU General Public License v3.0
205 stars 15 forks source link

[ALSA] Can't set interleaved mode #4

Closed Kappa971 closed 1 year ago

Kappa971 commented 2 years ago

On Debian 11 during initialization, it displays:

EmuSC: Configuration file found at /home/*****/.config/emusc/emusc.conf
EmuSC: SC-55 control ROM found [version=1.21 date=91/08]
EmuSC: PCM ROM(s) found and decrypted [version=0.20 date=1990-09-12]
EmuSC: GS mode initialized
EmuSC: MIDI sequencer [ALSA] client started at address 128
EmuSC: Error during initialization:
  -> [ALSA] Can't set interleaved mode. Operation not permitted
skjelten commented 2 years ago

This is a known issue for people using pulseaudio. I believe there are three different ways to fix this:

The last option has been on my wish list for a while, but never been prioritized.

** One way to quickly disable pulseaudio is to select another audio device in the control panel. Pulseaudio only locks one audio device at the time; the one that is active in e.g. gnome control panel. Otherwise you will have to prevent pulseaudio from respawning and kill it.

Kappa971 commented 2 years ago
* Disable pulseaudio for the used audio device as specified by "output_device" in emusc.conf**

Do you mean output = alsa? It is already set up like this.

* Use the "pulse" audio driver ("output" in emusc.conf), but make sure to configure pulseaudio in a way that gives you short latencies

EmuSC is initialized but midi playback is slow.

** One way to quickly disable pulseaudio is to select another audio device in the control panel. Pulseaudio only locks one audio device at the time; the one that is active in e.g. gnome control panel. Otherwise you will have to prevent pulseaudio from respawning and kill it.

I can't understand this. Also I don't use GNOME but Xfce. The only way I've managed to get EmuSC to work is to run it as root (although it shouldn't be necessary).

I can't compile on Windows (I opened another issue) but I'm sure it works them.

skjelten commented 2 years ago
* Disable pulseaudio for the used audio device as specified by "output_device" in emusc.conf**

Do you mean output = alsa? It is already set up like this.

Nope, the 'output = alsa' is correct as long as you want to use alsa. My suggestion was to disable the pulseaudio daemon (see further comments below).

* Use the "pulse" audio driver ("output" in emusc.conf), but make sure to configure pulseaudio in a way that gives you short latencies

EmuSC is initialized but midi playback is slow.

If you by slow mean that there is a noticeable latency from when you play a note to you can hear it, then that is because pulseaudio AFAIK has a pretty high latency in it's default configuration. Google is your friend to figure out how to reduce this latency (I personally have just used alsa in Linux).

** One way to quickly disable pulseaudio is to select another audio device in the control panel. Pulseaudio only locks one audio device at the time; the one that is active in e.g. gnome control panel. Otherwise you will have to prevent pulseaudio from respawning and kill it.

I can't understand this. Also I don't use GNOME but Xfce. The only way I've managed to get EmuSC to work is to run it as root (although it shouldn't be necessary).

Pulseaudio is a daemon that takes control of an audio device and sends data to the device as applications sends audio data to pulseaudio. When you try to use EmuSC with alsa output to an audio device that is already locked by the pulseaudio daemon it will fail. (note that this would probably have worked if EmuSC alsa output was written without using asynchronous callbacks - ref. my 3rd. point in my first reply). The only option you have to use the alsa output now is therefore to disable pulseaudio for the audio device you want to use. There are at least two ways to do this:

My tip for quickly disabling pulseaudio was to configure pulseaudio to just use another audio device. I don't know which GUI applications that exists for this, but I would expect xfce to have some kind of easy way to configure which sound card to use.

PS: Remember to specify the correct alsa device for emusc to use by specifying it in emusc.conf -> "output_device". "default" might not always give the correct result, depending on which audio device you want to use. On my computer I use pulseaudio on my main speakers (line out on the integrated chipset) and configure emusc to use alsa on a USB headset (output_device=hw:2,1).

I can't compile on Windows (I opened another issue) but I'm sure it works them.

There is currently a buffer underrun issue in Windows, so Linux + alsa is the best solution if you can choose.

Kappa971 commented 2 years ago

Thanks for the very detailed answer. I don't think I will start "playing" with the pulseaudio daemon, I will try as advised to choose another audio device (not present) and see if it works, or see if I can reduce the pulseaudio latency. I leave this issue open in case a better solution is found (on the other hand this emulator is still in an "embryonic" state).

rderooy commented 2 years ago

Modern Linux distributions no longer use PulseAudio, but rather use PipeWire. PipeWire is compatible with the PulseAudio API, so existing PulseAudio applications will work with it. In addition, it also supports the low-latency Jack API in addition to applications using ALSA and GStreamer.

skjelten commented 1 year ago

The emusc application has recently been completely rewritten, and in this process the alsa output driver was changed to use direct write transfer instead of asynchronous playback. This should make alsa output friendlier to PulseAudio. A configure dialog has also been added to list all available alsa outputs so that you can more easily test & find a working device id.

Writing a PipeWire output driver is on the TODO-list. It will be the sixth output driver for emusc, so I'm getting a bit tired of writing them :slightly_smiling_face:

I'll close this issue now, but feel free to reopen if you still have issues with alsa output.