User avatar
TerryC65
Posts: 202
Joined: Sat May 09, 2015 7:50 am
Location: Wimborne, Dorset, UK

Is it possible to O/P 2 independent audio channels from RPi?

Fri Nov 04, 2016 12:00 pm

Hi,

I have a project ongoing to simulate the chimes from a Minster bell tower in the replica Model Town across the road. I have the whole thing working at the moment, using an RPi Zero running Python and playing through mpg321. The sound is picked up from the HDMI connector and amplified before being routed to a couple of speakers. However, the Trustees have just thrown out a challenge.

Currently they use an old CD/MP3 player to play church music inside the Model Minster building. They intended to replace that because it is old and worn out, but everyone thinks it would be better to get the Pi to manage the music as well as the bells. Initially I thought it would be straightforward to fire off two instances of mpg321; one for the bells and one for the music. Unfortunately, that would mean that the music would be played in the bell tower instead of the chancel and they don't think that would sound right (and I agree).

So, can I get two separate mono channels from an RPi? I was hoping to use a pHAT DAC from Pimorini for one of the channels and the HDMI O/P for the other, but the people there do not think I could get simultaneous outputs.

I'm looking for ideas. At the moment, the best idea I have is two Pis, but it would be more elegant if we could do it with one.

User avatar
Burngate
Posts: 6332
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Is it possible to O/P 2 independent audio channels from

Fri Nov 04, 2016 6:35 pm

There's probably a neater way to do it, in software, but my first thought would be to use a relay to switch between speaker-pairs - just so long as you don't want both bells and organ at the same time.

The alternative I can think of is two separate mono files, and mash them together ... too much software is softening my brain ...
... can you create the mp3 files as "stereo", but with one channel of each silent, so "bells" would have sound only on the right, and "organ" would have silence on that side?


Wimborne is a wonderful place. I remember there being a small company there, making cap-gens, 8 inch floppies that never stopped till their bearings died ...
When you've got it set up, let us know - I'd love to come and see it

User avatar
TerryC65
Posts: 202
Joined: Sat May 09, 2015 7:50 am
Location: Wimborne, Dorset, UK

Re: Is it possible to O/P 2 independent audio channels from

Sat Nov 05, 2016 7:34 am

Burngate wrote:There's probably a neater way to do it, in software, but my first thought would be to use a relay to switch between speaker-pairs - just so long as you don't want both bells and organ at the same time.
That's the rub, the chimes will ring all the time, even when there is a service in the Minster.
Burngate wrote:The alternative I can think of is two separate mono files, and mash them together ... too much software is softening my brain ...
... can you create the mp3 files as "stereo", but with one channel of each silent, so "bells" would have sound only on the right, and "organ" would have silence on that side?
I did consider that and I might even go that way. The problem is that out of the 60 + volunteers and staff who maintain and manage the Model Town, only a couple of us are technically oriented. Most of the rest deal with gardening, maintenance of the models, running the cafe and a host of other things. Whatever I come up with, I need to ensure that changing the music (for example) involves nothing more than copying the files into designated folders on a USB stick.
Burngate wrote:Wimborne is a wonderful place. I remember there being a small company there, making cap-gens, 8 inch floppies that never stopped till their bearings died ...
I remember using 8" floppies, but I'm afraid I don't remember that company.
Burngate wrote: When you've got it set up, let us know - I'd love to come and see it
The Model Town is now closed for the Winter Maintenance period and we are committed to completing this project by the re-opening date on 1st April. We are also working on two other projects; to introduce a phone-based audio guide and a phone-based kiddies quiz.

hazza96
Posts: 23
Joined: Sun Oct 23, 2016 1:34 am

Re: Is it possible to O/P 2 independent audio channels from

Sat Nov 05, 2016 1:31 pm

I understand the desire to nut out an innovative solution in the most elegant way.

However I think you are over doing it trying to provide a solution with a single Pi.

Buy another and implement the same solution for the same required result.

User avatar
TerryC65
Posts: 202
Joined: Sat May 09, 2015 7:50 am
Location: Wimborne, Dorset, UK

Re: Is it possible to O/P 2 independent audio channels from

Sat Nov 05, 2016 1:41 pm

hazza96 wrote:I understand the desire to nut out an innovative solution in the most elegant way.

However I think you are over doing it trying to provide a solution with a single Pi.

Buy another and implement the same solution for the same required result.
Can I ask you why (apart from the audio O/P problem) you think I'm overdoing it trying to do it on a single Pi?

This solution will run headless, in a shell, with either the music and chimes or with a quarter peal ringing from one O/P. Do you think a Pi would be unable to play both at the same time?

I have tested this in principle by running two instances of mpg321 (into the same audio channel) and it worked very well. I must admit that I was a bit surprised, given that the pi Zero is single core, but it did work with no stuttering.

All I want to do is the same thing with two separate O/P channels.

User avatar
TerryC65
Posts: 202
Joined: Sat May 09, 2015 7:50 am
Location: Wimborne, Dorset, UK

Re: Is it possible to O/P 2 independent audio channels from

Mon Nov 07, 2016 1:11 pm

OK. Not many responses, so far.

However, a guy on our Linux User Group Mailing List has suggested using two USB Sound Cards, such as: https://www.amazon.co.uk/Sabrent-Extern ... sound+card. I would also need a USB Hub of course, because the Zero only has one USB connector, but it could be the answer.

The Amazon page referenced says that these are OK for Linux, but does anyone know if these will work on a Pi? If so, do the cards map to separate devices, eg in /dev/snd? If they do, I should be able to direct the output of two instances of mpg321 to two devices.

These things aren't expensive, but I'd prefer to have some confidence that they are going to work before I buy two.

tvjon
Posts: 798
Joined: Mon Jan 07, 2013 9:11 am

Re: Is it possible to O/P 2 independent audio channels from

Mon Nov 07, 2016 10:13 pm

People who can help are often busy, & can only read the (many) sub-forums when they have time...


Since you're presently using audio from hdmi, you have another, analogue audio interface available via gpio. Using a pi 0 means buying, or building a simple DAC; details are on the forum.

Instead of a Linux media player, you can use:

omxplayer

& supply a command line argument for which audio interface to play your files.

Just enter

omxplayer

in a terminal for a long list of options. It's very versatile.

User avatar
TerryC65
Posts: 202
Joined: Sat May 09, 2015 7:50 am
Location: Wimborne, Dorset, UK

Re: Is it possible to O/P 2 independent audio channels from

Tue Nov 08, 2016 7:47 am

tvjon wrote:Since you're presently using audio from hdmi, you have another, analogue audio interface available via gpio. Using a pi 0 means buying, or building a simple DAC; details are on the forum.
Unfortunately, I was told that that wouldn't work when I asked Pimoroni (see my first post).

That was my original idea.

User avatar
TerryC65
Posts: 202
Joined: Sat May 09, 2015 7:50 am
Location: Wimborne, Dorset, UK

Re: Is it possible to O/P 2 independent audio channels from

Fri Nov 11, 2016 1:59 pm

I've now got this working with two USB Sound Adapters. In case anyone else ever wants to do this; here is what I did:

I went to the Tutorial on the Pihut's website, see https://thepihut.com/products/usb-audio-adapter.

Having established that my two adapters were Card 3 and Card 4, I used aplay (as per the Tutorial) to get two different wav files playing simultanously. I then did the same using mpg123.

Here is the output of the two commands (you'll need to run them in two shell instances as I did):

Code: Select all

terry@OptiPlex:~/Development/Wimborne_Model_Town/Winter_2016-17_Projects/Code/MP3_Payer/Playlist1$ mpg123 -a hw:4,0 01_Wedding_March.mp3                                   
High Performance MPEG 1.0/2.0/2.5 Audio Player for Layers 1, 2 and 3                                                                                                       
        version 1.22.4; written and copyright by Michael Hipp and others                                                                                                   
        free software (LGPL) without any warranty but with best wishes                                                                                                     
                                                                                                                                                                           
Playing MPEG stream 1 of 1: 01_Wedding_March.mp3 ...                                                                                                                       
                                                                                                                                                                           
MPEG 1.0 layer III, 128 kbit/s, 44100 Hz joint-stereo                                                                                                                      
Title:   CWV10_12                        Artist:                                                                                                                           
Comment:                                 Album:  
Year:                                    Genre:  Unknown


terry@OptiPlex:~/Development/Wimborne_Model_Town/Winter_2016-17_Projects/Code/MP3_Payer/Playlist1$ mpg123 -a hw:3,0 02_Toccata_and_fugue_in_D_minor_\(Bach\).mp3 
High Performance MPEG 1.0/2.0/2.5 Audio Player for Layers 1, 2 and 3
        version 1.22.4; written and copyright by Michael Hipp and others
        free software (LGPL) without any warranty but with best wishes

Playing MPEG stream 1 of 1: 02_Toccata_and_fugue_in_D_minor_(Bach).mp3 ...

MPEG 1.0 layer III, VBR, 44100 Hz joint-stereo
Title:   Toccata and fugue in D minor
Year:    2012
So it can be done :D

Return to “Graphics, sound and multimedia”