# Audio problems

**URL:** <https://forum.juce.com/t/audio-problems/1323>\
**Category:** Linux\
**Created:** [December 29, 2006, 2:01am UTC](https://forum.juce.com/t/audio-problems/1323 "2006-12-29T02:01:45Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![ptomaine](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/ptomaine/32/245_2.png) [@ptomaine](https://forum.juce.com/u/ptomaine)\
**Post date:** [December 29, 2006, 2:01am UTC](https://forum.juce.com/t/audio-problems/1323/1 "2006-12-29T02:01:45Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [December 29, 2006, 10:51am UTC](https://forum.juce.com/t/audio-problems/1323/2 "2006-12-29T10:51:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ptomaine](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/ptomaine/32/245_2.png) [@ptomaine](https://forum.juce.com/u/ptomaine)\
**Post date:** [December 30, 2006, 10:38am UTC](https://forum.juce.com/t/audio-problems/1323/3 "2006-12-30T10:38:52Z")

</div>

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

```auto
        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]

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [December 30, 2006, 12:25pm UTC](https://forum.juce.com/t/audio-problems/1323/4 "2006-12-30T12:25:44Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ptomaine](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/ptomaine/32/245_2.png) [@ptomaine](https://forum.juce.com/u/ptomaine)\
**Post date:** [January 3, 2007, 3:37pm UTC](https://forum.juce.com/t/audio-problems/1323/5 "2007-01-03T15:37:49Z")

</div>

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

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

```auto

```

…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/](http://www.music.mcgill.ca/~gary/rtaudio/) or here [https://gna.org/projects/mhwaveedit/](https://gna.org/projects/mhwaveedit/).

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [January 3, 2007, 4:38pm UTC](https://forum.juce.com/t/audio-problems/1323/6 "2007-01-03T16:38:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ptomaine](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/ptomaine/32/245_2.png) [@ptomaine](https://forum.juce.com/u/ptomaine)\
**Post date:** [January 4, 2007, 8:44am UTC](https://forum.juce.com/t/audio-problems/1323/7 "2007-01-04T08:44:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [January 4, 2007, 11:54am UTC](https://forum.juce.com/t/audio-problems/1323/8 "2007-01-04T11:54:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![kjetil](https://avatars.discourse-cdn.com/v4/letter/k/bc8723/32.png) [@kjetil](https://forum.juce.com/u/kjetil)\
**Post date:** [January 17, 2007, 3:02pm UTC](https://forum.juce.com/t/audio-problems/1323/9 "2007-01-17T15:02:15Z")

</div>

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.

```auto
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,

```

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [January 17, 2007, 3:16pm UTC](https://forum.juce.com/t/audio-problems/1323/10 "2007-01-17T15:16:11Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![kjetil](https://avatars.discourse-cdn.com/v4/letter/k/bc8723/32.png) [@kjetil](https://forum.juce.com/u/kjetil)\
**Post date:** [January 17, 2007, 3:57pm UTC](https://forum.juce.com/t/audio-problems/1323/11 "2007-01-17T15:57:47Z")

</div>

[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.

---

<div class="post-metadata">

**Author:** ![kjetil](https://avatars.discourse-cdn.com/v4/letter/k/bc8723/32.png) [@kjetil](https://forum.juce.com/u/kjetil)\
**Post date:** [January 17, 2007, 4:52pm UTC](https://forum.juce.com/t/audio-problems/1323/12 "2007-01-17T16:52:34Z")

</div>

[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.

---

<div class="post-metadata">

**Author:** ![kjetil](https://avatars.discourse-cdn.com/v4/letter/k/bc8723/32.png) [@kjetil](https://forum.juce.com/u/kjetil)\
**Post date:** [January 22, 2007, 3:33pm UTC](https://forum.juce.com/t/audio-problems/1323/13 "2007-01-22T15:33:33Z")

</div>

[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

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

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

```auto
    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.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [January 22, 2007, 3:51pm UTC](https://forum.juce.com/t/audio-problems/1323/14 "2007-01-22T15:51:00Z")

</div>

Hmm - not a bad idea, that…

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [January 22, 2007, 4:43pm UTC](https://forum.juce.com/t/audio-problems/1323/15 "2007-01-22T16:43:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kjetil](https://avatars.discourse-cdn.com/v4/letter/k/bc8723/32.png) [@kjetil](https://forum.juce.com/u/kjetil)\
**Post date:** [January 23, 2007, 3:16pm UTC](https://forum.juce.com/t/audio-problems/1323/16 "2007-01-23T15:16:18Z")

</div>

> [@jules](#):
>
> …but unfortunately “default” doesn’t work at all on my machine!

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. 🙂

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [January 23, 2007, 3:32pm UTC](https://forum.juce.com/t/audio-problems/1323/17 "2007-01-23T15:32:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![tesuji](https://avatars.discourse-cdn.com/v4/letter/t/85e7bf/32.png) [@tesuji](https://forum.juce.com/u/tesuji)\
**Post date:** [January 4, 2008, 10:53pm UTC](https://forum.juce.com/t/audio-problems/1323/18 "2008-01-04T22:53:52Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![kunitoki](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/kunitoki/32/15_2.png) [@kunitoki](https://forum.juce.com/u/kunitoki)\
**Post date:** [January 5, 2008, 12:26am UTC](https://forum.juce.com/t/audio-problems/1323/19 "2008-01-05T00:26:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tesuji](https://avatars.discourse-cdn.com/v4/letter/t/85e7bf/32.png) [@tesuji](https://forum.juce.com/u/tesuji)\
**Post date:** [January 5, 2008, 2:08pm UTC](https://forum.juce.com/t/audio-problems/1323/20 "2008-01-05T14:08:20Z")

</div>

That’s great news, thank you very much!

[Next page](https://forum.juce.com/t/audio-problems/1323.md?page=2)
