Thank you for your donation!


Hardware Mixer with Fifopi and Soekris 1941
#1
I would like to control the volume of my DAC through the DAC (using the Moode Gui, so only Ipad as remote) and not use software as a Mixer, but hardware or master (see example below) as my impression is that software mixer degrates the sound.

The Dac is a Soekris DAM1941 which come with a rx tx serial interface allowing to talk with the RP4 over its rx tx serial pins...

I have read here that it should be in theory possible:

http://moodeaudio.org/forum/printthread.php?tid=861

, but not sure if this has been done finally or is there is a DAC selection in Moode which enables al the necessary changes.

I am as well happy to get my fingers dirty, even though I am not a linux or mpd expert...but figured that the normal pi user cant access /etc/mpd.conf...are there credentials for root ?
Reply
#2
(05-01-2020, 01:52 PM)multiblitz Wrote: I would like to control the volume of my DAC through the DAC (using the Moode Gui, so only Ipad as remote) and not use software as a Mixer, but hardware or master (see example below) as my impression is that software mixer degrates the sound.

The Dac is a Soekris DAM1941 which come with a rx tx serial interface allowing to talk with the RP4 over its rx tx serial pins...

I have read here that it should be in theory possible:

http://moodeaudio.org/forum/printthread.php?tid=861

, but not sure if this has been done finally or is there is a DAC selection in Moode which enables al the necessary changes.

I am as well happy to get my fingers dirty, even though I am not a linux or mpd expert...but figured that the normal pi user cant access /etc/mpd.conf...are there credentials for root ?

There's a fair number of moving parts here which must be connected together. It looks doable as-is, although were I doing it I'd really want to update all the code to Python3 for longevity. Basically the technique is to use Python modules to drive GPIO pins as the serial interface to the DAM1021.

In moOde the user 'pi' already has sudoer permission, which means that (almost) any command you would normally perform as root can be done by 'pi' using sudo.

Regards,
Kent
Reply
#3
Is the proposal to use the utility at the link below as an optional replacement for MPD volume?
https://github.com/fortaa/dam1021

If so then someone needs to first explain:
1. How to map the utilities volume range into moOde's 0 - 100 knob range or some other 0 - N range.
2. How to perform mute

-Tim
Reply
#4
I am quite happy with my dam1941 and moode 6.4.2. A proper integration of the hardware volume control in combination with lirc would be great.

At the moment i change the volume with lirc over the serial port connected with the raspberry pi.
The big advantage of this setup is, to control the preamp, the dam1941 and the mpd with one single remote control.



How to use the serial connection with the dam1941:

First moode has to be installed and also lirc .

Step1

Disable the serial console.
Code:
sudo raspi-config

Go to "Interfacing Options"
Select "P6 Serial"
Select "No"  Would you like a login shell to be accessible over serial?
Select "Yes" Would you like the serial port hardware to be enabled?

If you do not disable the serial console the frontend of the dam1941 will get stuck and you have to powercycle the dam.

Step2

Set the correct baudrate for the dam.
Code:
/bin/stty -F /dev/serial0 115200
The best way is to create a systemd service to set this parameter. There are many tutorials out there how to do this.

Step 3

play with the serial commands....
Code:
# Set volume $LEVEL is a variable with a value from 0 to 100

sudo echo -ne "V-$((100 - $LEVEL))\r\n" > /dev/serial0

The mehod with the echo commands is much faster than the python lib from https://github.com/fortaa/dam1021 .
Speed is important because of the repeat function when the rc-buttons are pushed long.

Also i changed the "vol.sh" for my needs:

Code:
#!/bin/bash
#
# volume switcher for dam1941
#
#
#
# http://moodeaudio.org
# moOde audio player (C) 2014 Tim Curtis
#
# This Program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# This Program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# 2019-01-31 initial version
#

VER="0.1"

SQLDB=/var/local/www/db/moode-sqlite3.db

testfile=/tmp/level.tmp

if [ ! -e "$testfile" ] ; then
   touch "$testfile"
    echo "50" > $testfile
fi

if [ ! -w "$testfile" ] ; then
   echo cannot write to $testfile
   exit 1
fi

if [[ -z $1 ]]; then #if no option is selected then print last volume
    cat $testfile
    echo "is the last volume stored in /tmp/level.tmp"
    exit 0
fi

if [[ $1 = "--help" ]]; then
echo -e "Usage: vol.sh [OPTION] [VOLUME]
Change the volume and update the knob.

With no OPTION or VOLUME, print the current volume.
With just VOLUME, set current volume to VOLUME.

-up\t\tVOLUME    value between 1 and 100
-dn\t\tVOLUME    value between 1 and 100
--version\tprint the program version
--help\t\tprint this help text"

    exit 1
fi

if [[ $1 = "--version" ]]; then
    echo "Version: "$VER
    exit 1
fi

# get config settings
while [ "$OLD" = '' ]
 do
   OLD=$(cat $testfile)
 done

# echo $OLD
# friendly names

REGEX='^[0-9]+$'

# parse OPTIONS
if [[ $1 = "-up" || $1 = "up" ]]; then
        if ! [[ $2 =~ $REGEX ]]; then
            echo "VOLUME must only contain digits 0-9"
            exit 1
        else
            LEVEL=$(($OLD + $2))
        fi
elif [[ $1 = "-dn" || $1 = "dn" ]]; then
        # volume down step
        if ! [[ $2 =~ $REGEX ]]; then
            echo "VOLUME must only contain digits 0-9"
            exit 1
        else
            LEVEL=$(($OLD - $2))
        fi
else
        LEVEL=$1
fi

    # numeric check
    if ! [[ $LEVEL =~ $REGEX ]]; then
        echo "Invalid OPTION or VOLUME not numeric"
        exit 1
    fi
    
    # range check
    if (( $LEVEL < 30 )); then
        LEVEL=30
    elif (( $LEVEL > 100 )); then
        LEVEL=100
    fi

echo $LEVEL > $testfile
sudo echo -ne "V-$((100 - $LEVEL))\r\n" > /dev/serial0
sqlite3 $SQLDB "update cfg_system set value=$LEVEL where id='32'"


This works fast enough for me. The volume change is not perfect smooth but not bad.
I made the workaround with the "/tmp/level.tmp" to store the volume because the sqlite command sometimes returns "0" when the script will be started often because of the "repeat" from the remote control.



Question: Is there a way to enable the volume knob when the "SOEKRIS dam1021/dam1121" dac has been selected?
Reply
#5
This is a fantastic way of changing the volume level on the DAM1121. I was going with the https://github.com/fortaa/dam1021 approach but found the integration with LIRC is challenging.

Other than changing some file access attributes to get Tonno's script to work on my end, it is indeed easier. Thanks Tonno.
Reply
#6
How do you prevent the system from resetting the attributes of level.tmp file? I have to apply the chmod to it else the /var/www/volume.sh will not run correctly.
Reply
#7
The /tmp/level.tmp file will be generated automatically, if it not exists. I never had to chmod the file.
My voltest.sh has 775 permissions.


here is my /home/pi/.lircrc if you want to know how to change inputs and filters too.

Code:
# lirc definition for moode and dam1941 control
begin
prog = irexec
button = DAC_VOL+
config = /var/www/voltest.sh up 1
repeat = 1
end

begin
prog = irexec
button = DAC_VOL-
config = /var/www/voltest.sh dn 1
repeat = 1
end

begin
prog = irexec
button = CD_PLAY
config = mpc toggle
repeat = 0
end

begin
prog = irexec
button = CD_STOP
config = mpc stop
repeat = 0
end

begin
prog = irexec
button = CD_PAUSE
config = mpc toggle
repeat = 0
end

begin
prog = irexec
button = CD_PREV
config = mpc prev
repeat = 0
end

begin
prog = irexec
button = CD_NEXT
config = mpc next
repeat = 0
end

begin
prog = irexec
button = CD_RWND
config = mpc seek -5%
repeat = 1
end

begin
prog = irexec
button = CD_FWD
config = mpc seek +5%
repeat = 1
end

begin
prog = irexec
button = CD_LEFT
config = mpc seek -00:00:05
repeat = 1
end

begin
prog = irexec
button = CD_RIGHT
config = mpc seek +00:00:05
repeat = 1
end

# dam1941 ir commands
# input selector
# 0=USB, 1=AES/EBU, 2=BNC, 3=RCA, 4=TOSLINK, 5=I2S, 7=Auto(not used)

begin
prog = irexec
button = TUNER_CHAN-
config = sudo echo -ne "I5\r\n" > /dev/serial0
repeat = 0
end

begin
prog = irexec
button = TUNER_CHAN+
config = sudo echo -ne "I4\r\n" > /dev/serial0
repeat = 0
end

begin
prog = irexec
button = TUNER_POWER
config = sudo echo -ne "I0\r\n" > /dev/serial0
repeat = 0
end

begin
prog = irexec
button = TUNER_SCAN-
config = sudo echo -ne "I1\r\n" > /dev/serial0
repeat = 0
end

begin
prog = irexec
button = TUNER_SCAN+
config = sudo echo -ne "I2\r\n" > /dev/serial0
repeat = 0
end

begin
prog = irexec
button = TUNER_MEM
config = sudo echo -ne "I3\r\n" > /dev/serial0
repeat = 0
end


# filter control on  dam1941
# 4=linear, 5=mixed, 6=minimum, 7=soft
begin
prog = irexec
button = CD_REPEAT
config = sudo echo -ne "F4\r\n" > /dev/serial0
repeat = 0
end

begin
prog = irexec
button = CD_TIME
config = sudo echo -ne "F5\r\n" > /dev/serial0
repeat = 0
end

begin
prog = irexec
button = CD_PROG
config = sudo echo -ne "F6\r\n" > /dev/serial0
repeat = 0
end

begin
prog = irexec
button = CD_SHUF
config = sudo echo -ne "F7\r\n" > /dev/serial0
repeat = 0
end

As you see in the .lircrc file, i called my script for the volume change /var/www/voltest.sh , so it will not be overwriten by any in-place-udates.
Reply
#8
Thanks Tonno.

I fixed the issue by moving the level.tmp file to /home/pi.
Reply
#9
(05-03-2020, 06:03 PM)tonno Wrote: The /tmp/level.tmp file will be generated automatically, if it not exists. I never had to chmod the file.
My voltest.sh has 775 permissions.


here is my /home/pi/.lircrc if you want to know how to change inputs and filters too.

Code:
# lirc definition for moode and dam1941 control
begin
prog = irexec
button = DAC_VOL+
config = /var/www/voltest.sh up 1
repeat = 1
end

begin
prog = irexec
button = DAC_VOL-
config = /var/www/voltest.sh dn 1
repeat = 1
end

begin
prog = irexec
button = CD_PLAY
config = mpc toggle
repeat = 0
end

begin
prog = irexec
button = CD_STOP
config = mpc stop
repeat = 0
end

begin
prog = irexec
button = CD_PAUSE
config = mpc toggle
repeat = 0
end

begin
prog = irexec
button = CD_PREV
config = mpc prev
repeat = 0
end

begin
prog = irexec
button = CD_NEXT
config = mpc next
repeat = 0
end

begin
prog = irexec
button = CD_RWND
config = mpc seek -5%
repeat = 1
end

begin
prog = irexec
button = CD_FWD
config = mpc seek +5%
repeat = 1
end

begin
prog = irexec
button = CD_LEFT
config = mpc seek -00:00:05
repeat = 1
end

begin
prog = irexec
button = CD_RIGHT
config = mpc seek +00:00:05
repeat = 1
end

# dam1941 ir commands
# input selector
# 0=USB, 1=AES/EBU, 2=BNC, 3=RCA, 4=TOSLINK, 5=I2S, 7=Auto(not used)

begin
prog = irexec
button = TUNER_CHAN-
config = sudo echo -ne "I5\r\n" > /dev/serial0
repeat = 0
end

begin
prog = irexec
button = TUNER_CHAN+
config = sudo echo -ne "I4\r\n" > /dev/serial0
repeat = 0
end

begin
prog = irexec
button = TUNER_POWER
config = sudo echo -ne "I0\r\n" > /dev/serial0
repeat = 0
end

begin
prog = irexec
button = TUNER_SCAN-
config = sudo echo -ne "I1\r\n" > /dev/serial0
repeat = 0
end

begin
prog = irexec
button = TUNER_SCAN+
config = sudo echo -ne "I2\r\n" > /dev/serial0
repeat = 0
end

begin
prog = irexec
button = TUNER_MEM
config = sudo echo -ne "I3\r\n" > /dev/serial0
repeat = 0
end


# filter control on  dam1941
# 4=linear, 5=mixed, 6=minimum, 7=soft
begin
prog = irexec
button = CD_REPEAT
config = sudo echo -ne "F4\r\n" > /dev/serial0
repeat = 0
end

begin
prog = irexec
button = CD_TIME
config = sudo echo -ne "F5\r\n" > /dev/serial0
repeat = 0
end

begin
prog = irexec
button = CD_PROG
config = sudo echo -ne "F6\r\n" > /dev/serial0
repeat = 0
end

begin
prog = irexec
button = CD_SHUF
config = sudo echo -ne "F7\r\n" > /dev/serial0
repeat = 0
end

As you see in the .lircrc file, i called my script for the volume change /var/www/voltest.sh , so it will not be overwriten by any in-place-udates.
That ks great stuff, thanks so much...as I not yet fully understand everything, may I ask if this is a solution which works only with moode or any mpd distro ?

Thanks so much again !
Reply
#10
I came from the Volumio world and stayed with MoOde since release v3.8.x.

You will have to try it out yourself to confirm as I don't run both distributions.
Reply


Forum Jump: