You are not logged in.

#1 2021-06-23 18:16:19

aymenb
Member
Registered: 2021-01-25
Posts: 5

[SOLVED] Pulseaudio, output at full volume

Hello,

I don't have my input device (for clarity i'll call it device 0) at full volume, but I wish to have my output device recording desktop audio at full volume via parec, could you direct me towards a pulseaudio module maybe that I could use please?
I have tried already to create a remapped input device (device 1), redirect parec to device 0 (at 100% volume) for recording while i set device 1 as default in pavucontrol and reduced its volume, but the output was still low.
here's what i get when i list sinks with pactl

Sink #0
        State: RUNNING
        Name: alsa_output.usb-iFi__by_AMR__iFi__by_AMR__HD_USB_Audio_00000000-00.analog-stereo
        Description: iFi (by AMR) HD USB Audio Analog Stereo
        Driver: module-alsa-card.c
        Sample Specification: s32le 2ch 44100Hz
        Channel Map: front-left,front-right
        Owner Module: 6
        Mute: no
        Volume: front-left: 19661 /  30% / -31.37 dB,   front-right: 19661 /  30% / -31.37 dB
                balance 0.00
        Base Volume: 65536 / 100% / 0.00 dB
        Monitor Source: alsa_output.usb-iFi__by_AMR__iFi__by_AMR__HD_USB_Audio_00000000-00.analog-stereo.monitor
        Latency: 22352 usec, configured 23220 usec
        Flags: HARDWARE DECIBEL_VOLUME LATENCY
        Properties:
                alsa.resolution_bits = "32"
                device.api = "alsa"
                device.class = "sound"
                alsa.class = "generic"
                alsa.subclass = "generic-mix"
                alsa.name = "USB Audio"
                alsa.id = "USB Audio"
                alsa.subdevice = "0"
                alsa.subdevice_name = "subdevice #0"
                alsa.device = "0"
                alsa.card = "1"
                alsa.card_name = "iFi (by AMR) HD USB Audio"
                alsa.long_card_name = "iFi (by AMR) iFi (by AMR) HD USB Audio at usb-0000:00:14.0-9, high speed"
                alsa.driver_name = "snd_usb_audio"
                device.bus_path = "pci-0000:00:14.0-usb-0:9:1.0"
                sysfs.path = "/devices/pci0000:00/0000:00:14.0/usb1/1-9/1-9:1.0/sound/card1"
                udev.id = "usb-iFi__by_AMR__iFi__by_AMR__HD_USB_Audio_00000000-00"
                device.bus = "usb"
                device.vendor.id = "20b1"
                device.vendor.name = "XMOS Ltd"
                device.product.id = "3008"
                device.product.name = "iFi (by AMR) HD USB Audio"
                device.serial = "iFi__by_AMR__iFi__by_AMR__HD_USB_Audio_00000000"
                device.string = "front:1"
                device.buffering.buffer_size = "705600"
                device.buffering.fragment_size = "352800"
                device.access_mode = "mmap+timer"
                device.profile.name = "analog-stereo"
                device.profile.description = "Analog Stereo"
                device.description = "iFi (by AMR) HD USB Audio Analog Stereo"
                module-udev-detect.discovered = "1"
                device.icon_name = "audio-card-usb"
        Ports:
                analog-output: Analog Output (type: Analog, priority: 9900, availability unknown)
        Active Port: analog-output
        Formats:
                pcm 

also the script i use for recording

#!/bin/sh

# This script records audio played by you computer as saves it in a folder
# specified by the OUTPUT variable.
# It is designed to work with Anki and any window manager.
# Dependencies: xclip, arecord (ALSA), parec(Pulseaudio)
# Optionally, you may use ffmpeg, sox and a notification-daemon.

# The name of your file contains a timestamp.
# You may change the path or extension as you wish.
# 'arecord' works with .wav only
FORMAT='wav'
OUTPUT="/tmp/record_$(date +%F_%T).$FORMAT"
PID_FILE='/tmp/recordPID'
# Elapsed seconds to automatically stop recording.
MAX_RECORD_TIME=600
CURRENT_RECORD_TIME=0

# Your recording device.
# Consult the appropriate one by using the command 'aplay -l'(ALSA) or
# the file '$HOME/.asoundrc' (ALSA)
ALSA_RECORDING_DEVICE=pulse

# Get sources list by running 'pactl list short sources' and choose the 'output'
# one in order to record playback audio
PULSEAUDIO_RECORDING_DEVICE=alsa_output.usb-iFi__by_AMR__iFi__by_AMR__HD_USB_Audio_00000000-00.analog-stereo.monitor
# May alse be written as the index number shown
#PULSEAUDIO_RECORDING_DEVICE=1

recordWithALSA () {
        if [ $FORMAT = 'wav' ]; then
            arecord -f cd -D "$ALSA_RECORDING_DEVICE" "$OUTPUT" &
            echo "$!" > $PID_FILE
        else
            ffmpeg -f alsa -i "$ALSA_RECORDING_DEVICE" "$OUTPUT" &
            echo "$!" > $PID_FILE
        fi
}

recordWithPulseaudio () {
        if isSupportedByPulseaudio $FORMAT ; then
            parec --file-format=$FORMAT -d "$PULSEAUDIO_RECORDING_DEVICE" "$OUTPUT" &
            echo "$!" > $PID_FILE
        else
            ffmpeg -f pulse -i "$PULSEAUDIO_RECORDING_DEVICE" "$OUTPUT" &
            echo "$!" > $PID_FILE
        fi
}

isSupportedByPulseaudio () {
        if [ $(parec --list-file-formats | cut -f1 | grep -co "$@" ) -gt 0 ]
        then return 0
        else return 1
        fi
}

# Program used for recording; 'ffmpeg' (works for both Alsa and Pulseaudio) or
# 'arecord' (ALSA) or 'parec' (Pulseaudio)

# If it's already recording, finish recording.
if [ -f $PID_FILE ];then
        echo "Stopping recording audio."
        kill $(cat $PID_FILE) && rm $PID_FILE
        exit 0
else
        notify-send "Recording audio." &
        echo "Recording audio.\n"
        pulseaudio --check && recordWithPulseaudio || recordWithALSA
fi

while [ -f $PID_FILE -a $MAX_RECORD_TIME -gt $CURRENT_RECORD_TIME ];do
        CURRENT_RECORD_TIME=$(ps -o etimes= -p $(cat $PID_FILE) \
                | tr -dc [:digit:])
        sleep 1
done

if [ -f $PID_FILE ]; then
        echo "$MAX_RECORD_TIME seconds have elapsed since the start of the\
        recording. Finishing the recording process."

        notify-send "$MAX_RECORD_TIME seconds have elapsed since the start of the recording." "Finishing the recording process." &

        kill $(cat $PID_FILE) && rm $PID_FILE
fi

# Check if SOX is installed and remove silence at the beginning and end.
if [ $(which sox) -a -f "$OUTPUT" ];then
    echo "Removing silence at both ends."
    DESTPATH=$(dirname "$OUTPUT")
    TEMP_INPUT="$DESTPATH"/input."$FORMAT"
    mv "$OUTPUT" "$TEMP_INPUT"
    sox "$TEMP_INPUT" "$OUTPUT" silence 1 0.1 0.1% reverse silence 1 0.1 0.1% reverse
    rm "$TEMP_INPUT"
fi

# Send the audio file's path to your clipboard, so that you can paste with
# Ctrl+v in Anki.
echo "file://$OUTPUT" | xclip -i -selection clipboard -t "text/uri-list"
echo "Copied $OUTPUT to the clipboard."
notify-send "Copied $OUTPUT to the clipboard." &
exit 0

Thank you for having taken time to read through this, I'm really grateful to be a part of this community!

Last edited by aymenb (2021-06-23 22:21:38)

Offline

#2 2021-06-23 18:20:13

aymenb
Member
Registered: 2021-01-25
Posts: 5

Re: [SOLVED] Pulseaudio, output at full volume

I am not sure I was clear in my message.
What I meant is that I wished to have input at any volume without it influencing on the recorded file, but I haven't found a way to do so and the documentation is a bit hard for pulseaudio for a newbie.

Offline

#3 2021-06-23 22:03:44

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 25,331

Re: [SOLVED] Pulseaudio, output at full volume

pactl load-module module-virtual-sink sink_name=VirtualOut master=alsa_output.usb-iFi__by_AMR__iFi__by_AMR__HD_USB_Audio_00000000-00.analog-stereo use_volume_sharing=no

shove things you want to record on the VirtualOut sink and record the VirtualOut.monitor

Offline

#4 2021-06-23 22:14:16

aymenb
Member
Registered: 2021-01-25
Posts: 5

Re: [SOLVED] Pulseaudio, output at full volume

V1del wrote:
pactl load-module module-virtual-sink sink_name=VirtualOut master=alsa_output.usb-iFi__by_AMR__iFi__by_AMR__HD_USB_Audio_00000000-00.analog-stereo use_volume_sharing=no

shove things you want to record on the VirtualOut sink and record the VirtualOut.monitor

Thanks!
I would like to record all desktops sounds, is there a command to do so with the virtual sink and shove them all in? on pavucontrol I cannot seem to make it work
Also, it seems that the virtual sink is subordinated to device 0 (ifi dac), that should mean that if I lower the volume on the computer the virtual sink's volume will also be lowered? i tried it with an example and it worked great!

Last edited by aymenb (2021-06-23 22:16:42)

Offline

Board footer

Powered by FluxBB