shorepine / amy

AMY - the Additive Music synthesizer librarY

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't get `amy-example` to generate audio under Fedora 37 Linux

octetta opened this issue · comments

After making changes mentioned in #18, amy-example emits the message No suitable device format available. regardless of the sound device I specify.

Can AMY use another output format than SoundIoFormatS16NE?

When possible, I'll try changing SoundIoFormatS16NE to SoundIoFormatS16LE and SoundIoFormatS16BE to see if I can get further. I'm just hacking without understanding at the moment.

It certainly can (we render to float32s and emit int16s only at the end to whatever is rendering.)

But i'm curious why libsoundio is not working on your system, it should be able to support converting to whatever sound device you're using.

I've just booted up my Ubuntu 20 VM, and it works for me. Can you show me what ./amy-example -l shows you?

Sure:

$ ./amy-example -l
[0]	Built-in Audio Digital Stereo (HDMI): playback_FL, playback_FR (default)	2 output channels

Additionally, the version of libsoundio installed via Fedora's package manager reports 2.0.0-9. I was able to compile a simple sine wave program from libsoundio's examples and get working audio on this platform.

brew on my mac seems to have installed 2.0.0 as well (but can't see what the '-9') part might be there.

Ah, neat. Can you send me a link to the sine wave program you compiled that does work? I bet i'm not setting something up right in our libsoundio-audio.c file for AMY.

It's on the main page http://libsound.io/ under "Basic Sine Wave Example".

Don't do what I did and change the line:

    outstream->format = SoundIoFormatFloat32NE;

to:

    outstream->format = SoundIoFormatS16NE;

...else your speakers will scare the snot out of everyone in your house ;-) ... I should have know better after hours of blowing up my speakers with PureData (AND Arduinos AND Teensies AND Parallax P1s)... I'm not sure what I expected to happen, LOL...

I'll try to compare/contrast AMY and this example after work today as well.

OK, yes, I'm pretty certain your audio output just doesn't natively support the 16-bit format. I wasn't expecting that to happen, but i bet it's more common than I think.

Can you do me a favor, just clone this repository again or "pull" it to update it, and compile it again, and run ./amy-example -l for me? I added some stuff to debug this (As I don't have any device like yours here.) Let me know what it shows for the supported formats,

If it's the case that your audio out just doesn't support 16-bit out, I can make a secondary path through libsoundio-audio that converts our 16-bit native stream from AMY back to 32-bit. I'm less certain I want to keep native 32-bit everywhere, so we can start here.

Here you go:

$ ./amy-example -l
[0]	Built-in Audio Digital Stereo (HDMI): playback_FL, playback_FR (default) 2 outputs, formats: float 32-bit LE
[1]	Bose bucket speaker: playback_FL, playback_FR 2 outputs, formats: float 32-bit LE

I attached a bluetooth speaker to see if my situation was odd because I was using the HDMI audio path on my laptop, but even the BT speaker seems limited to this format.

One other thing I'll try to look into is if JACK vs ALSA vs PulseAudio might be odd on this system.

Do you know which of the audio subsystems are running on your Ubuntu 20 system?

I have a RPi3 here as well, that I might try to experiment with.

Ultimately, I'm more interested in the ESP32 / tiny embedded devices, but don't have them in reach at the moment.

Is your Ubuntu 20 system 32-bit or 64-bit? Intel or ARM or ???.

This might be in the category of "not helping", but comparing what libsoundio exposes versus what other Linux-ey things report, aplay -l on my Fedora laptop (with the bluetooth device now detached) shows:

$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: PCH [HDA Intel PCH], device 0: ALC298 Analog [ALC298 Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 3: HDMI 0 [DELL UP3017]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 7: HDMI 1 [HDMI 1]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 8: HDMI 2 [HDMI 2]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

and my Fedora desktop shows:

$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: PCH [HDA Intel PCH], device 0: CS4208 Analog [CS4208 Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 1: CS4208 Digital [CS4208 Digital]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: HDMI [HDA ATI HDMI], device 3: HDMI 0 [HDMI 0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: HDMI [HDA ATI HDMI], device 7: HDMI 1 [HDMI 1]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: HDMI [HDA ATI HDMI], device 8: HDMI 2 [HDMI 2]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: HDMI [HDA ATI HDMI], device 9: HDMI 3 [HDMI 3]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: HDMI [HDA ATI HDMI], device 10: HDMI 4 [HDMI 4]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: HDMI [HDA ATI HDMI], device 11: HDMI 5 [HDMI 5]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 2: HDMI_1 [HDA ATI HDMI], device 3: HDMI 0 [HDMI 0 *]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 2: HDMI_1 [HDA ATI HDMI], device 7: HDMI 1 [HDMI 1]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 2: HDMI_1 [HDA ATI HDMI], device 8: HDMI 2 [HDMI 2]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 2: HDMI_1 [HDA ATI HDMI], device 9: HDMI 3 [HDMI 3]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 2: HDMI_1 [HDA ATI HDMI], device 10: HDMI 4 [HDMI 4]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 2: HDMI_1 [HDA ATI HDMI], device 11: HDMI 5 [HDMI 5]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

It appears I have PulseAudio installed on both systems... is the same true for your Ubuntu 20 system?

If so, could you share the output of pactl list for comparison?

Hopefully we can make AMY work smoothly on all kinds of Linux systems.

I certainly want to help if I can, although I'm getting the sneaking feeling we're debugging libsoundio at this point.

Regardless, I'm a big fan of Andrew/Zig and didn't know he had this project (libsoundio) until seeing AMY, so getting this figured out feels good on two fronts.

When possible, I'll try changing SoundIoFormatS16NE to SoundIoFormatS16LE and SoundIoFormatS16BE to see if I can get further. I'm just hacking without understanding at the moment.

Might be obvious, but given what's mentioned in this thread, none of the S16?E formats were available, so this doesn't help.

This I believe is a known bug with libsoundio not being able to select the backend correctly (here's the issue: andrewrk/libsoundio#139) that's existed for a while and is goal for a 2.0.1 release.

I believe this can be worked around by forcing to the PulseAudio backend. I'm trying to see how to do that in AMY...

This I believe is a known bug with libsoundio not being able to select the backend correctly (here's the issue: andrewrk/libsoundio#139) that's existed for a while and is goal for a 2.0.1 release.

I believe this can be worked around by forcing to the PulseAudio backend. I'm trying to see how to do that in AMY...

In libsoundio-audio.c I changed:

int err = soundio_connect(soundio);

to:

int err = soundio_connect_backend(soundio, SoundIoBackendPulseAudio);

and this results in amy-example starting without the output format complaint, but it silently stops after a few seconds without making any sound.

This I believe is a known bug with libsoundio not being able to select the backend correctly (here's the issue: andrewrk/libsoundio#139) that's existed for a while and is goal for a 2.0.1 release.
I believe this can be worked around by forcing to the PulseAudio backend. I'm trying to see how to do that in AMY...

In libsoundio-audio.c I changed:

int err = soundio_connect(soundio);

to:

int err = soundio_connect_backend(soundio, SoundIoBackendPulseAudio);

and this results in amy-example starting without the output format complaint, but it silently stops after a few seconds without making any sound.

Ignore this... my speakers have an auto-power off feature, so the example was playing but I couldn't hear it. This patch indeed works! Maybe the fix is to let the user specify the backend. But also, amy-example should probably exit when it can't find an output format that works. As it stands now, it just stays running.

I think I know how to address this. I'll try to get a PR to you ASAP.

@octetta love this!! I will test your fix on a couple of Linux VMs to ensure the PR works for me and then merge it! This will also help out on Alles and Tulip Desktop, so thank you!!