Audio problems


#1

Hi Julian!

I’ve compiled JUCE demo and couldn’t run audio demo because of the following error: “Couldn’t open an output device! - Invalid argument”. I ran Helix Banshee player after that and it plays songs normally. What’s wrong with JUCE?


#2

Must just be an alsa problem - try debugging it to see which stage of the alsa code it gets to before it gives up.


#3

…while debugging I discovered that ALSADevice.setParameters(…) function fails on the last “if” statement:

        if (failed (snd_pcm_hw_params_set_rate_near (handle, hwParams, &sampleRate, 0))
            || failed (snd_pcm_hw_params_set_channels (handle, hwParams, numChannels))
            || failed (snd_pcm_hw_params_set_periods_near (handle, hwParams, &periods, &dir))
            || failed (snd_pcm_hw_params_set_period_size_near (handle, hwParams, &samplesPerPeriod, &dir))
            || failed (snd_pcm_hw_params (handle, hwParams)))
        {
            return false;
        }

…with the following error string: [color=red]“Attempt to extract a component of a value that is not a structure.”[/color]


#4

Great. Exactly the sort of helpful error message that I’ve come to expect from linux code. I guess it’d be slightly more useful to know which of those calls was the one that failed.


#5

…it is funny but the debugging has shown the following:

the ALSADevice.setParameters(…) function fails on the following check:

…and returns the next error string: [color=red]“Invalid argument”[/color]

When removing this function call, the initialization goes Ok but no sounds are played than. Have no idea why.

A good example of how to init ALSA driver can be found at http://www.music.mcgill.ca/~gary/rtaudio/ or here https://gna.org/projects/mhwaveedit/.


#6

That’s odd. Have you tried it with a big number instead of INT_MAX? Maybe 0x10000000 or something like that?


#7

The only acceptable value is zero. The error occurs on any positive or negative values except for the zero. It looks like something is not initialized prior to this function call.

Anyway, no sounds play even if I point the zero as the parameter. Demo page says it’s Ok but .wav files does not play and MIDI does not produce any sounds.


#8

Very odd. It’s pretty straightforward stuff, I don’t see how a driver could be getting it wrong. I’ll have a think about this one, but let me know if you spot any more clues.


#9

Alsa is just too complicated, or at least undocumented. In my opinion, it would be better if people only used alsa for implementing low latency sound servers like jack, and used OSS for the rest.

(Theres also this misunderstanding that the OSS API is deprecated, which is wrong. Its only the OSS drivers that are deprecated, but that doesn’t matter because alsa emulates OSS perfectly.)

Anyway, here are my hacks to make sound with juce. I’ll add jack support to the program I’m working on later, and post the code in the forum.

kjetil@ttleush ~/juce/build/linux/platform_specific_code $ diff juce_linux_Audio.cpp~ juce_linux_Audio.cpp |more
52a53
> #define DD "default"
105c106
<             if (snd_pcm_open (&pcmHandle, id, SND_PCM_STREAM_PLAYBACK, SND_PCM_ASYNC | SND_PCM_NONBLOCK ) >= 0)
---
>             if (snd_pcm_open (&pcmHandle, DD, SND_PCM_STREAM_PLAYBACK, SND_PCM_ASYNC | SND_PCM_NONBLOCK ) >= 0)
119c120
<             if (snd_pcm_open (&pcmHandle, id, SND_PCM_STREAM_CAPTURE, SND_PCM_ASYNC | SND_PCM_NONBLOCK ) >= 0)
---
>             if (snd_pcm_open (&pcmHandle, DD, SND_PCM_STREAM_CAPTURE, SND_PCM_ASYNC | SND_PCM_NONBLOCK ) >= 0)
146c147
<         failed (snd_pcm_open (&handle, deviceName,
---
>       failed (snd_pcm_open (&handle, DD, //deviceName,

#10

Yes, a jack implementation has been on my to-do-list for a while now.

(Not sure how useful that hack is - it’ll just hard-wire it to always open the default device, regardless of which one you actually try to open).


#11

[quote=“jules”]Yes, a jack implementation has been on my to-do-list for a while now.

(Not sure how useful that hack is - it’ll just hard-wire it to always open the default device, regardless of which one you actually try to open).[/quote]

Oh, well, it works for me. Without this hack, I just get a message about invalid parameters.


#12

[quote=“kjetil”][quote=“jules”]Yes, a jack implementation has been on my to-do-list for a while now.

(Not sure how useful that hack is - it’ll just hard-wire it to always open the default device, regardless of which one you actually try to open).[/quote]

Oh, well, it works for me. Without this hack, I just get a message about invalid parameters.[/quote]

And I’m sorry that I was not giving information about what happens in my system in my first posting. I don’t know very much about alsa, and trying to use “default” was just something I found after a quick google.

Please let me know if there is anything you want me to try out. I get the same error (“invalid parameter”) on two machines I have tested, both using the ice1712 driver.


#13

[quote=“jules”]
(Not sure how useful that hack is - it’ll just hard-wire it to always open the default device, regardless of which one you actually try to open).[/quote]

Trying some more, just adding

	names.add(T("default"));
	ids.add(T("default"));

at the top of ALSAAudioIODeviceType::scanForDevice plus changing
ALSAAudioIODeviceType::getDefaultDeviceName into

    const String getDefaultDeviceName (const bool /*preferInputNames*/) const
    {
        jassert (hasScanned); // need to call scanForDevices() before doing this

        return "default";
    }

is enough.

I also think this may be a proper solution. Theres still the problem that the specific device (in my case “hw:M2496,0”) refuses to open, but at least alsa’s “default” device works.


#14

Hmm - not a bad idea, that…


#15

…but unfortunately “default” doesn’t work at all on my machine!


#16

Hmm, its actually a bit tempting to suggest to just forget about alsa, and only support OSS and jack instead? OSS is more compatible than alsa anyway, and can be used on systems such as *bsd and solaris (I think).

Well, there I suggested it. Nah, in case you don’t fix it, hopefully someone with lots of alsa experience steps up and fix things really soon. :slight_smile:


#17

Yes, hopefully someone who actually understands it will help out!

And hopefully I’ll soon have chance to try hacking together a Jack audio device too.


#18

Is there anything new about this issue? I just found out about JUCE and I’m very excited especially about its Audio/Midi features, but sadly I experienced that problem with ALSA (on Gentoo/AMD64) which was discussed here one year ago…


#19

i’ve started the jack audio device. next week it will be complete.


#20

That’s great news, thank you very much!