Multiple OMXPlayer instances and AudioInjector

Moderator: flatmax

Post Reply
LWesthaver
Posts: 8
Joined: Mon Mar 27, 2017 1:07 pm

Multiple OMXPlayer instances and AudioInjector

Post by LWesthaver » Thu Mar 30, 2017 10:30 am

I got my Audio Injector installed and it sounds good!

But I noticed something odd. I can run multiple instances of OMXPlayer when using the Raspberry Pi's built-in audio hardware but when I try to run more than one instance of OMXPlayer with the Audio Injector the first instance plays and the second instance hangs. It's like the Audio Injector only allows one process to access it at a time.

Unfortunately, I actually need to have two instances of the OMXPlayer running and using the sound system simultaneously. Like I said, the Raspberry Pi's built-in sound system (as bad as it is) allows this but the Audio Injector it appears does not.

As an example, If I open two terminal windows and launch the OMXPlayer from the command line like this:

Terminal #1:

Code: Select all

omxplayer --adev alsa --dbus_name "unique.player.name1" "Key Largo.mp3"
Terminal #2:

Code: Select all

omxplayer --adev alsa --dbus_name "unique.player.name2" "Bang Bang.mp3"
"KeyLargo.mp3" will play but "Bang Bang.mp3" hangs.

The --adev alsa command line option instructs the OMXPlayer to use the ALSA system for audio output rather than accessing the audio hardware directly.
The --dbus_name "unique.player.name1" command line option allows me to give that instance of the OMXPlayer a unique name so that I can control that specific named instance via DBUS commands.

I really need the ability to run two instances of the OMXPlayer. If Audio Injector imposes a single process access rule then this is a show-stopper for me.

Can you advise?

Thanks,
-Wes

flatmax
Posts: 609
Joined: Sat Jul 23, 2016 11:39 pm

Re: Multiple OMXPlayer instances and AudioInjector

Post by flatmax » Thu Mar 30, 2017 10:42 am

Hi there,

I am not sure why this is different for this sound card. I think both cards use the same i2s driver.
Is it possible to instruct the player to use the dmix device ?
Using aplayer it is like so :
aplay -D plug:dmix file.wav

The dmix device mixes down multiple streams to one.

thanks
Matt
Check out our audiophile quality crossovers : https://bit.ly/2kb1nzZ
Please review the Zero sound card on Amazon USA : https://www.amazon.com/dp/B075V1VNDD
---
Check out our new forum on github : https://github.com/Audio-Injector

LWesthaver
Posts: 8
Joined: Mon Mar 27, 2017 1:07 pm

Re: Multiple OMXPlayer instances and AudioInjector

Post by LWesthaver » Fri Mar 31, 2017 2:20 am

Were you able to replicate this?

Maybe it's something wrong with my setup (Raspberry Pi 3 Model B Rev 1.2, Linux version 4.9.17-v7+)

-Wes

LWesthaver
Posts: 8
Joined: Mon Mar 27, 2017 1:07 pm

Re: Multiple OMXPlayer instances and AudioInjector

Post by LWesthaver » Sun Apr 02, 2017 10:50 am

Just in case anyone is questioning why I would need to have multiple instances of OMXPlayer running simultaneously, here's a video that shows the project I'm working on:

https://youtu.be/vxS9QjEUvi4

When switching from the Music panel to the Video panel, I simply pause the OMXPlayer instance so that I can return later and resume at the point the player was paused. I suppose I could store the palyer's state (playing, media position etc.), stop the player, launch the other player etc. but this seems like a lot of trouble when the current method works so easily.

So, hopefully you can see that there is some justification for allowing multiple instances of OMXPlayer to run at the same time. Too bad the Audio Injector doesn't seem to allow it.

By the way, the Audio Injector seen in the video was disabled and the Raspberry Pi's built-in audio was used so that I could demonstrate my use of the OMXPlayer.

-Wes

flatmax
Posts: 609
Joined: Sat Jul 23, 2016 11:39 pm

Re: Multiple OMXPlayer instances and AudioInjector

Post by flatmax » Tue Apr 04, 2017 10:16 am

Sweet product.
I like the fast switching between the video and music player.

Matt
Check out our audiophile quality crossovers : https://bit.ly/2kb1nzZ
Please review the Zero sound card on Amazon USA : https://www.amazon.com/dp/B075V1VNDD
---
Check out our new forum on github : https://github.com/Audio-Injector

LWesthaver
Posts: 8
Joined: Mon Mar 27, 2017 1:07 pm

Re: Multiple OMXPlayer instances and AudioInjector

Post by LWesthaver » Tue Apr 04, 2017 1:13 pm

Hi Matt,

Thanks. I've been spending a lot of time crafting code to drive this system. Just when I thought I had a all the details worked out to control the OMXPlayer it's looking like I may not be able to get this to work with a good sound card. Very frustrating. I shouldn't be surprised. I assumed that a sound card would behave the same way as the built-in sound system on the Raspberry Pi... but sound much better.

When I run the "aplay -l" command, this is what I see when both the Audio Injector and the Raspberry Pi audio hardware are enabled.

Code: Select all

pi@car-pi:~ $ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 1: ALSA [bcm2835 ALSA], device 0: bcm2835 ALSA [bcm2835 ALSA]
  Subdevices: 8/8
  Subdevice #0: subdevice #0
  Subdevice #1: subdevice #1
  Subdevice #2: subdevice #2
  Subdevice #3: subdevice #3
  Subdevice #4: subdevice #4
  Subdevice #5: subdevice #5
  Subdevice #6: subdevice #6
  Subdevice #7: subdevice #7
card 1: ALSA [bcm2835 ALSA], device 1: bcm2835 ALSA [bcm2835 IEC958/HDMI]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 2: audioinjectorpi [audioinjector-pi-soundcard], device 0: AudioInjector audio wm8731-hifi-0 []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
Am I correct in thinking that the reason the built-in Raspberry Pi audio hardware works for me is that it appears to provide 8 possible audio processing channels and this allows multiple instances of OMXPlayer to grab an available audio processing channel?

Whereas it looks like the Audio Injector provides 1 audio processing channel (but a quality one). So, because of this, I need to use the DMIX plugin to provide a software based mixer that will allow multiple audio streams to feed the Audio Injector card?

I'm really new to ALSA and never heard of the DMIX device plugin until you mentioned it. But it sounds like the answer I'm looking for. Can you offer any advice or guidance to help me get this working? I've spent quite a few hours over the last couple of days trying to find something I could understand but ALSA is way over my head.

Thanks,
-Wes

flatmax
Posts: 609
Joined: Sat Jul 23, 2016 11:39 pm

Re: Multiple OMXPlayer instances and AudioInjector

Post by flatmax » Tue Apr 04, 2017 8:17 pm

Yes that is right, you will need to use plug:dmix to allow many applications use the same sound card.

One way to do this is to set the default device to dmix in your .asoundrc, one example of how to write the .asoundrc file is available here and here.

Hope that helps.
Matt
Check out our audiophile quality crossovers : https://bit.ly/2kb1nzZ
Please review the Zero sound card on Amazon USA : https://www.amazon.com/dp/B075V1VNDD
---
Check out our new forum on github : https://github.com/Audio-Injector

LWesthaver
Posts: 8
Joined: Mon Mar 27, 2017 1:07 pm

Re: Multiple OMXPlayer instances and AudioInjector

Post by LWesthaver » Thu Apr 06, 2017 12:57 pm

Well, I'm done. I'm tapping-out. This ALSA/Sound Card stuff is just to damned arcane for me.

What I'm trying to do isn't out of the mainstream and it shouldn't be this difficult. All modern computers allow multiple processes to stream audio to the sound card. Otherwise, when you were playing music you couldn't receive audio notifications of incoming emails, or voice chat while playing music etc.

I'm not knocking the Audio Injector but the software that drives it really needs to be easier to work with or at least documented in such a way that it doesn't require you to already know the answer to the question you are asking...

Are people really only using the Raspberry Pi for dedicated media systems where only one audio output stream is needed???

So frustrating.

-Wes

LWesthaver
Posts: 8
Joined: Mon Mar 27, 2017 1:07 pm

Re: Multiple OMXPlayer instances and AudioInjector

Post by LWesthaver » Wed Apr 12, 2017 8:13 am

Well, after several days of cutting-and-pasting every configuration I could find into my Raspberry Pi I finally found one that allowed me to employ the DMIXER. Unfortunately I ran into another roadblock.

My MP3 files were playing too fast. Everything was pitched up and up tempo. So I discover that the DMIXER has a sampling rate configuration setting which defaults to 48000 bits per second. My MP3 files are all 44100 bits per second. This was causing the problem. So I changed the DMIXER default to 44100. Now my MP3 files played correctly but my MP4 video files were running too slow and the audio was pitched down. Crap!

Another search finally turns up the fact that DMIXER can't effectively mix audio streams having different sampling rates. So, DMIXER is not the answer I was hoping for.

Ultimately, I put the Audio Injector away in my stock of parts for another project and bought two USB audio card dongles that employ the C-Media chipset. These dongles are pretty much plug-and-play. Now I can run two OMXPlayer instances, each having its own sound card running at whatever sampling rate is required. A simple circuit of resistors is used to combine the outputs of the USB dongles together before they hit the output amplifiers.

The sound is great and my need for multiple OMXPlayer instances is satisfied.

This has been a frustrating journey but hopefully if anyone else finds themselves in a similar situation they can learn from my experience.

-Wes

flatmax
Posts: 609
Joined: Sat Jul 23, 2016 11:39 pm

Re: Multiple OMXPlayer instances and AudioInjector

Post by flatmax » Thu Apr 13, 2017 9:42 am

Have you thought about using mplayer ? It allows you to specify an audio resample rate.

Matt
Check out our audiophile quality crossovers : https://bit.ly/2kb1nzZ
Please review the Zero sound card on Amazon USA : https://www.amazon.com/dp/B075V1VNDD
---
Check out our new forum on github : https://github.com/Audio-Injector

Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests