<html>
    <head>
      <base href="https://bugs.freedesktop.org/" />
    </head>
    <body>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - LFE channel not synthesized properly"
   href="https://bugs.freedesktop.org/show_bug.cgi?id=95021#c3">Comment # 3</a>
              on <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - LFE channel not synthesized properly"
   href="https://bugs.freedesktop.org/show_bug.cgi?id=95021">bug 95021</a>
              from <span class="vcard"><a class="email" href="mailto:darwish.07@gmail.com" title="Ahmed S. Darwish <darwish.07@gmail.com>"> <span class="fn">Ahmed S. Darwish</span></a>
</span></b>
        <pre>#!/bin/bash

#
# generate_waveform.sh - Record from a PulseAudio sink monitor and
# plot the resulting waveform using sox and gnuplot
#
# usage:
#   - generate_waveform.sh alsa - Plot from ALSA sink monitor
#   - generate_waveform.sh null - Plot from NULL sink monitor
#
# notes:
#   - Before usage, set ALSA_SINK_NAME to system-appropriate value
#   - If not available, a NULL_5.1 sink is automatically created
#

set -o errexit
set -o nounset

PACTL=pactl
PACAT=pacat
PAREC=parec

NULL_SINK_NAME=NULL_5.1
NULL_SINK_MONITOR=${NULL_SINK_NAME}.monitor

ALSA_SINK_NAME=alsa_output.pci-0000_00_14.2.analog-stereo
ALSA_SINK_MONITOR=${ALSA_SINK_NAME}.monitor

OUTPUT_WAV_FILE=audio.wav
OUTPUT_DAT_FILE=audio.dat
OUTPUT_PLOT_FILE=audio.plot
OUTPUT_PNG_FILE=audio.png
GNUPLOT_SCRIPT=plot_audio.gp

RECORD_PERIOD=10s

usage() {
    echo "usage: $0 [null|alsa]" >& 2
    exit -1
}

[[ "$#" != "1" ]] && usage
case "$1" in
    "null") RECORD_SINK_MONITOR=$NULL_SINK_MONITOR;;
    "alsa") RECORD_SINK_MONITOR=$ALSA_SINK_MONITOR;;
    *) usage
esac

null_sink_exists() {
    $PACTL list sinks | grep --silent $NULL_SINK_NAME
}

create_null_sink() {
    echo "Creating NULL sink $NULL_SINK_NAME"
    $PACTL load-module module-null-sink sink_name=$NULL_SINK_NAME  \
         channels=6                                                \
        
channel_map=front-left,front-right,rear-left,rear-right,front-center,lfe    
}

null_sink_exists || create_null_sink

$PAREC -d $RECORD_SINK_MONITOR --file-format=wav $OUTPUT_WAV_FILE &
_pid=$!

echo "Recording audio, from $RECORD_SINK_MONITOR, for ${RECORD_PERIOD} .."
sleep $RECORD_PERIOD
kill $_pid

echo "Generating signal amplitude values .."
sox $OUTPUT_WAV_FILE $OUTPUT_DAT_FILE
tail -n+3 $OUTPUT_DAT_FILE > $OUTPUT_PLOT_FILE    # Remove comments

cat > $GNUPLOT_SCRIPT <<EOF
set terminal pngcairo enhanced size 640,480 font 'Verdana,10'
set output "$OUTPUT_PNG_FILE"
set yrange [-1:1]
set ytics -1,0.1,1        # 0.1 jumps
plot "$OUTPUT_PLOT_FILE" with lines
EOF

echo "Plotting audio .."
gnuplot $GNUPLOT_SCRIPT

echo "Success! .. please check audio waveform at $OUTPUT_PNG_FILE"</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are the assignee for the bug.</li>
          <li>You are the QA Contact for the bug.</li>
      </ul>
    </body>
</html>