Skip to content

ALSA: dedicated devices for HDMI and analog audio #847

Closed

Description

@julianscheel

I wonder if it would be possible to use HDMI and analog audio in parallel via alsa. I think it should be possible as it can be done through OMX, right?
If this should be supported by the vchiq core I might give a try at reworking the alsa driver to support it.

Activity

  1. popcornmix commented on Feb 23, 2015

    @popcornmix
    Collaborator

    Yes, the hardware supports it. (e.g. running two instances of hello_audio in parallel should work).
    I believe the vchiq audio service (used by alsa) supports it - just open two instances and send control messages with different dest values.

    The only thing I'm not sure of is if the alsa driver can switch a single subchannel's dest (e.g. through amixer cset). I think it should be trivial to implement - it's just knowing what the best way of doing it through alsa is.

  2. julianscheel commented on Feb 24, 2015

    @julianscheel
    ContributorAuthor

    @popcornmix Thanks, I'll try to implement this sometime soon.

  3. ashleyw-gh commented on Mar 5, 2015

    @ashleyw-gh

    does this mean that separate audio streams could in theory be directed to both the HDMI and analog audio devices simultaneous? If so, this will be a great fix (I can think of squeezelite/Kodi and a host of other potential uses).

  4. julianscheel commented on Mar 10, 2015

    @julianscheel
    ContributorAuthor

    @popcornmix I implemented this in a proof-of-concept style and it works flawless so far: julianscheel@8b77ad4
    I just create two pcm devices now and split the 8 available substreams to them. Additionally the playback device control is duplicated so that each pcm device can be configured independently. So it allows the user to do things like this:

    amixer cset numid=3 1
    amixer cset numid=4 2
    speaker-test -Dhw:0,0 &
    speaker-test -Dhw:0,1 -t sine
    

    Which would play white noise on analog out and a sine on hdmi out.

    While it works well the design feels not really good, actually I'd prefer something like a static setup with a subdevice per output - but doing this castrates the total number of usable substreams per output. Do you have any thoughts on a proper approach for this?

  5. popcornmix commented on Mar 10, 2015

    @popcornmix
    Collaborator

    I agree allowing hdmi and analogue to be driven independently could be useful, but I'm not sure how it's best to expose this though alsa. It's also nice to support multiple sub-channels, to get mixing "for free".
    Anyone with any better suggestions?

    @pelwell any thoughts?

  6. julianscheel commented on Mar 10, 2015

    @julianscheel
    ContributorAuthor

    Actually after thinking a bit more about it I think it's possible to create both device with 8 substreams (is 8 a hard limit of the hardware, btw?). In the pcm_open we just need to dynamically maintain a pool of total open substreams and abort with EBUSY if all 8 channels are in use. This should be quite straight forward as there is no hard linkage between alsa substreams and vchiq channels anyway, but all is maintained dynamically.
    So we could easily have two pcm devices, one for analog, one for hdmi by default.
    Or we could even create 3 - pcm 0 staying as it is now, so that no userspace change is required for existing applications. pcm 1 could be explicit analog/headphone out and pcm 2 explicit hdmi output.

    What do you think about this? If you think it's sane I'll take a go at implementing it.

  7. popcornmix commented on Mar 10, 2015

    @popcornmix
    Collaborator

    8 sub channels is a software limit - it may handle more, but there is obviously some point where it will fail.
    There is also ~32K per sub channel of (static) GPU memory used (we could possibly trim that), so making it arbitrarily large would be undesirable.

    I could try increasing it in a test build to check it behaves okay with 16 (or more) sub channels.

    I like the idea of keeping backwards compatibility, but do we let all three devices be used together? (i.e. possibly requiring 24 sub-channels)

  8. julianscheel commented on Mar 10, 2015

    @julianscheel
    ContributorAuthor

    I think we can stay with 8 channels - we just dynamically share them between the three pcms. So we'd actually have 24 alsa substreams - but as soon as 8 are used in total (and hence 8 vchiq sub channels are in use) pcm_open would fail with EBUSY.

  9. popcornmix commented on Mar 10, 2015

    @popcornmix
    Collaborator

    Yes, sounds okay. Once the 8 channels are in use you should find:
    https://github.com/raspberrypi/linux/blob/rpi-3.18.y/sound/arm/bcm2835-vchiq.c#L289
    returns a fail, and so bcm2835_audio_open_connection returns a failure, so you may be able to avoid hard coding the number of substreams. That way the firmware could support more subchannels in future.

  10. bigmacattack commented on Dec 28, 2015

    @bigmacattack

    What is the status on this? Has a decision been made on how to handle this in ALSA? I'd love to be able to output audio via HDMI and analog simultaneously using ALSA.

  11. root42 commented on Jul 29, 2016

    @root42

    Same here. I have a RetroPie with a Shairport-Server. I would like the RetroPie to output via HDMI because of image/sound sync and the Shairport to output via analog so I don't have to turn on the TV to hear music.

  12. giddyhup commented on Sep 13, 2016

    @giddyhup

    I second the request. It works with an USB DAC (sound card) and HDMI audio; being able to direct audio to the analog port alternatively makes sense.

  13. JamesH65 commented on May 17, 2017

    @JamesH65
    Contributor

    @popcornmix @julianscheel is there anything to add to this? Close or continue?

  14. julianscheel commented on May 17, 2017

    @julianscheel
    ContributorAuthor

    @JamesH65 I still do have some dirty (outdated) kernel tree lying around somewhere, which implements this... I personally don't currently need this, but if there is someone who really needs it I could take some time and search for that tree and possibly do a bit of cleanup...

  15. added
    Waiting for internal comment
    on May 18, 2017
  16. JamesH65 commented on Jun 27, 2018

    @JamesH65
    Contributor

    @popcornmix @julianscheel is there anything to add to this? Close or continue?

    This issue will be closed within 30 days unless further interactions are posted. If you wish this issue to remain open, please add a comment. A closed issue may be reopened if requested.

  17. Druw2000 commented on Sep 12, 2018

    @Druw2000

    Hello, please keep this issue open. I imagine multi channel PCM is possible with PulseAudio, though?

  18. Holzhaus commented on Nov 29, 2021

    @Holzhaus

    Any news on this? Currently I need to use an additional USB sound card due to this issue.

  19. 6by9 commented on Nov 29, 2021

    @6by9
    Contributor

    HDMI and analogue audio are switched to being independent ALSA devices with 8e6c2ab back in July 2020.

  20. added a commit that references this issue on Apr 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Waiting for internal comment

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions