Get max audio channels available from alsasink

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Get max audio channels available from alsasink

moritz.vieli
Hi there

I am letting the user decide, how many audio channels he wants to to play on
an alsasink. However, if he configures more channels than available on the
specified audio interface, my complete app gets wiped from the memory
(because of some illegal memory access form Gstreamer/ALSA i suppose).

Now, is there a possibility to find out the maximum available channels on an
audio interface? It would be nice with Gstreamer of course, but a command
line solution would also be sufficient. I tried querying the negotiated
caps, allowed caps and so on, but it's always returning the configured
channels, not the possible available channels. I couldn't figure out a
solution.

Thanks a lot and best,
Moritz



--
Sent from: http://gstreamer-devel.966125.n4.nabble.com/
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: Get max audio channels available from alsasink

Nicolas Dufresne-5
Le lundi 28 janvier 2019 à 12:15 -0600, moritz.vieli a écrit :
> Hi there
>
> I am letting the user decide, how many audio channels he wants to to play on
> an alsasink. However, if he configures more channels than available on the
> specified audio interface, my complete app gets wiped from the memory
> (because of some illegal memory access form Gstreamer/ALSA i suppose).

Sounds like a driver bug, normally you'd get an "not-negotaited" error
on the bus and adding audioconvert element before alsasink would handle
the required up/down-mixing for you.

>
> Now, is there a possibility to find out the maximum available channels on an
> audio interface? It would be nice with Gstreamer of course, but a command
> line solution would also be sufficient. I tried querying the negotiated
> caps, allowed caps and so on, but it's always returning the configured
> channels, not the possible available channels. I couldn't figure out a
> solution.


It can all be done grammatically of course, the number of channels will
depend on the selected output. But as an example, my laptop have two
physical speaker, if I use amixer, I can read this:

  amixer -c 0
  . . .
  Simple mixer control 'Speaker',0
    Capabilities: pvolume pswitch
    Playback channels: Front Left - Front Right
    Limits: Playback 0 - 87
    Mono:
      Front Left: Playback 87 [100%] [0.00dB] [on]
      Front Right: Playback 87 [100%] [0.00dB] [on]
  Simple mixer control 'PCM',0
    Capabilities: pvolume
    Playback channels: Front Left - Front Right
    Limits: Playback 0 - 255
    Mono:
      Front Left: Playback 255 [100%] [0.00dB]
      Front Right: Playback 255 [100%] [0.00dB]
    Simple mixer control 'Mic',0

You can see that "Playback channels:" give me both how many channels I
got and what these channels are mapped to.

Nicolas


>
> Thanks a lot and best,
> Moritz
>
>
>
> --
> Sent from: http://gstreamer-devel.966125.n4.nabble.com/
> _______________________________________________
> gstreamer-devel mailing list
> [hidden email]
> https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel

_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel

signature.asc (201 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Get max audio channels available from alsasink

moritz.vieli
Hi Nicolas

Thanks a lot for your quick response! Unfortunately, amixer does not return
all available channels for my sound interfaces (tested with different ones).
This one should have 6, but the following is returned:

$ amixer -c K6
Simple mixer control 'Audio Input Terminal',0
  Capabilities: volume volume-joined
  Playback channels: Mono
  Capture channels: Mono
  Limits: 0 - 1
  Mono: 0 [0%]
Simple mixer control 'Audio Input Terminal',1
  Capabilities: volume
  Playback channels: Front Left - Front Right
  Capture channels: Front Left - Front Right
  Limits: 0 - 1
  Front Left: 0 [0%]
  Front Right: 0 [0%]
Simple mixer control 'Audio Input Terminal',2
  Capabilities: volume
  Playback channels: Front Left - Front Right
  Capture channels: Front Left - Front Right
  Limits: 0 - 1
  Front Left: 0 [0%]
  Front Right: 0 [0%]
Simple mixer control 'Audio Output Terminal Clock Source',0
  Capabilities: enum
  Items: 'Internal Clock' 'External Clock (S/PDIF)'
  Item0: 'Internal Clock'
Simple mixer control 'External Clock (S/PDIF) Validity',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [on]
Simple mixer control 'Internal Clock Validity',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [on]
Simple mixer control 'Monitor Control',0
  Capabilities: pswitch
  Playback channels: Front Left - Front Right - Rear Left - Rear Right
  Mono:
  Front Left: Playback [off]
  Front Right: Playback [off]
  Rear Left: Playback [off]
  Rear Right: Playback [off]
Simple mixer control 'Monitor Control',1
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [off]

I also tried different amixer options (info, scontents and so on), but I
cannot get the information.

Best,
Moritz



--
Sent from: http://gstreamer-devel.966125.n4.nabble.com/
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: Get max audio channels available from alsasink

Pavel Hofman
Hi,

> Thanks a lot for your quick response! Unfortunately, amixer does not return
> all available channels for my sound interfaces (tested with different ones).

Amixer lists controls provided by the driver and alsa-lib stack above it.

Hardware capabilities of your soundcard can be listed e.g. with

aplay --dump-hw-params -D hw:3 /usr/share/sounds/alsa/Front_Center.wav
Playing WAVE '/usr/share/./sounds/alsa/Front_Center.wav' : Signed 16 bit
Little Endian, Rate 48000 Hz, Mono
HW Params of device "hw:3":
--------------------
ACCESS:  MMAP_INTERLEAVED RW_INTERLEAVED
FORMAT:  S32_LE
SUBFORMAT:  STD
SAMPLE_BITS: 32
FRAME_BITS: 64
CHANNELS: 2
RATE: [44100 192000]
PERIOD_TIME: (41 371520)
PERIOD_SIZE: [8 16384]
PERIOD_BYTES: [64 131072]
PERIODS: [2 1024]
BUFFER_TIME: (83 743039)
BUFFER_SIZE: [16 32768]
BUFFER_BYTES: [128 262144]
TICK_TIME: ALL


The dump is provided by snd_pcm_hw_params_dump of alsa-lib.

Best regards,

Pavel.
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: Get max audio channels available from alsasink

moritz.vieli
Hi Pavel

You. Are. The. Man! This really works!

It correctly shows the 6 available channels. There is even more information,
like buffer sizes, available audio rates and so on.

Only downside: You have to provide a file (not even an audio file), which
makes the usage a little bit strange. But it seems to work well.

Thanks a lot!

Best,
Moritz



--
Sent from: http://gstreamer-devel.966125.n4.nabble.com/
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: Get max audio channels available from alsasink

Pavel Hofman

Dne 02. 02. 19 v 14:10 moritz.vieli napsal(a):
> Hi Pavel
>
>
> Only downside: You have to provide a file (not even an audio file), which
> makes the usage a little bit strange.

Actually I had the very same need to learn details of my soundcard a few
years ago and adding that option to aplay.c was the easiest way.

Good luck with your endeavor.

Pavel.
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: Get max audio channels available from alsasink

Antonio Ospite-2
In reply to this post by moritz.vieli
On Sat, 2 Feb 2019 07:10:43 -0600 (CST)
"moritz.vieli" <[hidden email]> wrote:

> Hi Pavel
>
> You. Are. The. Man! This really works!
>
> It correctly shows the 6 available channels. There is even more information,
> like buffer sizes, available audio rates and so on.

Useful info indeed, thanks Pavel.
 
> Only downside: You have to provide a file (not even an audio file), which
> makes the usage a little bit strange. But it seems to work well.

If you don't want an extra file on the filesystem you could provide a
fake header on the standard input, the minimal accepted header for
non-raw formats seems to be 26 bytes:

  printf "\x00%.0s" {1..26} | aplay --dump-hw-params -D hw:0 -

or

  head -c 26 /dev/zero | aplay --dump-hw-params -D hw:0 -

or even better, use the raw format and /dev/null:

  aplay --dump-hw-params -D hw:0 -t raw /dev/null

Ciao,
   Antonio

--
Antonio Ospite
https://ao2.it
https://twitter.com/ao2it

A: Because it messes up the order in which people normally read text.
   See http://en.wikipedia.org/wiki/Posting_style
Q: Why is top-posting such a bad thing?
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel