From b081209514523095ccb05cc5b3afdbb01d48751c Mon Sep 17 00:00:00 2001 From: St33v Date: Wed, 26 Jan 2022 23:10:32 +1100 Subject: rename --- speakerSqeaker.txt | 65 +++++++++++++++++++++++++++++++++++++++++++++++++ speakerSqueaker.service | 13 ++++++++++ speakerSqueaker.sh | 50 +++++++++++++++++++++++++++++++++++++ speakerWatchdog.service | 13 ---------- speakerWatchdog.sh | 50 ------------------------------------- speakerWatchdog.txt | 65 ------------------------------------------------- 6 files changed, 128 insertions(+), 128 deletions(-) create mode 100644 speakerSqeaker.txt create mode 100644 speakerSqueaker.service create mode 100755 speakerSqueaker.sh delete mode 100644 speakerWatchdog.service delete mode 100755 speakerWatchdog.sh delete mode 100644 speakerWatchdog.txt diff --git a/speakerSqeaker.txt b/speakerSqeaker.txt new file mode 100644 index 0000000..d78c40a --- /dev/null +++ b/speakerSqeaker.txt @@ -0,0 +1,65 @@ +#! /bin/bash +# Workaround for stupd 'powersave' 'feature' of Creative Speakers +# +# SJP 11 Dec 2021 +# +# This is just a stub for now + +# Which device is the audio output going to? + +# st33v@cr4y:~$ grep RUNNING /proc/asound/card*/pcm*/sub*/status +# /proc/asound/card2/pcm0p/sub0/status:state: RUNNING + +# That is fine, but the status remains as 'RUNNING' even after the speakers have turned themselves off... +# So I'm going down the track of periodically sending a 'sound' to a loopback device +# sudo modprobe snd-aloop +# Now aply -l shows a new 'card' called Loopback. + + +record one second of default stream: + +$ rec -d -n trim 0 1 stat + + rec sox in record mode + -d default input + -n direct output to /dev/null + trim 0 1 duration 1 second + stat + +Output: + +Input File : 'default' (pulseaudio) +Channels : 2 +Sample Rate : 48000 +Precision : 16-bit +Sample Encoding: 16-bit Signed Integer PCM + +In:0.00% 00:00:01.02 [00:00:00.00] Out:48.0k [ | ] Clip:0 +Samples read: 96000 +Length (seconds): 1.000000 +Scaled by: 2147483647.0 +Maximum amplitude: 0.000000 +Minimum amplitude: 0.000000 +Midline amplitude: 0.000000 +Mean norm: 0.000000 +Mean amplitude: 0.000000 +RMS amplitude: 0.000000 +Maximum delta: 0.000000 +Minimum delta: 0.000000 +Mean delta: 0.000000 +RMS delta: 0.000000 +Rough frequency: -2147483648 +Done. + +So if Max amplitude = 0 then we have silence! + +to generate a tone that is not audible: +play -n synth 1 sine 40 fade .2 0 + + play sox alias + -n dummy input file + synth synthesise a sound + sine sine wave [the default, so not strictly necessary] + 40 Hz + fade fade in from zero volume to max volume over 200 msec. + '0' says fade out at end over same period. diff --git a/speakerSqueaker.service b/speakerSqueaker.service new file mode 100644 index 0000000..8a43108 --- /dev/null +++ b/speakerSqueaker.service @@ -0,0 +1,13 @@ +[Unit] +Description=Make sure the Speakers don't go to sleep +After=sound.target + + +[Service] +Type=oneshot +StandardOutput=journal +ExecStart=-/usr/local/bin/speakerWatchdog.sh + +[Install] +WantedBy=default.target + diff --git a/speakerSqueaker.sh b/speakerSqueaker.sh new file mode 100755 index 0000000..2597eaf --- /dev/null +++ b/speakerSqueaker.sh @@ -0,0 +1,50 @@ +#! /bin/bash +# Workaround for stupid 'powersave' 'feature' of Creative Speakers +# +# SJP 11 Dec 2021 +# +# Record a snippet of default stream: + +# 0 rec -d -n trim 0 .1 stat + +# rec sox in record mode +# -d default input +# -n direct output to /dev/null +# trim 0 .1 duration 0.1 second +# stat write info about the audio stream +# 2>&1 redirect stderr to stdout +# | pipe +# grep finds this line: Minimum amplitude: 0.000000 +# | pipe +# awk ruturns just the third word (the number) +#echo hello $USER | systemd-cat -t AlexySayle -p warning +maxAmp=$(rec -d -c1 -n trim 0 .1 stat 2>&1 | grep 'Maximum amplitude' | awk {'print $3'}) +echo Max Amplitude = $maxAmp +if [ "$maxAmp" == "0.000000" ]; then + # if Max amplitude = 0 then we have silence! + if [ -f "/tmp/silencemarker" ] ; then + # There was silence last time we checked, so play the tone + echo Play the sound + play -nq synth 1 sine 40 fade 0.2 0 + rm /tmp/silencemarker + else + touch /tmp/silencemarker + fi +else + if [ -f "/tmp/silencemarker" ] ; then + rm /tmp/silencemarker + fi +fi + +systemd-run --user --on-active=10m /usr/local/bin/speakerWatchdog.sh + +#to generate a tone that is not audible: +#play -n synth 1 sine 40 fade .2 0 +# +# play sox alias +# -n dummy input file +# synth synthesise a sound +# sine sine wave [the default, so not strictly necessary] +# 40 Hz +# fade fade in from zero volume to max volume over 200 msec. +# '0' says fade out at end over same period. diff --git a/speakerWatchdog.service b/speakerWatchdog.service deleted file mode 100644 index 8a43108..0000000 --- a/speakerWatchdog.service +++ /dev/null @@ -1,13 +0,0 @@ -[Unit] -Description=Make sure the Speakers don't go to sleep -After=sound.target - - -[Service] -Type=oneshot -StandardOutput=journal -ExecStart=-/usr/local/bin/speakerWatchdog.sh - -[Install] -WantedBy=default.target - diff --git a/speakerWatchdog.sh b/speakerWatchdog.sh deleted file mode 100755 index 2597eaf..0000000 --- a/speakerWatchdog.sh +++ /dev/null @@ -1,50 +0,0 @@ -#! /bin/bash -# Workaround for stupid 'powersave' 'feature' of Creative Speakers -# -# SJP 11 Dec 2021 -# -# Record a snippet of default stream: - -# 0 rec -d -n trim 0 .1 stat - -# rec sox in record mode -# -d default input -# -n direct output to /dev/null -# trim 0 .1 duration 0.1 second -# stat write info about the audio stream -# 2>&1 redirect stderr to stdout -# | pipe -# grep finds this line: Minimum amplitude: 0.000000 -# | pipe -# awk ruturns just the third word (the number) -#echo hello $USER | systemd-cat -t AlexySayle -p warning -maxAmp=$(rec -d -c1 -n trim 0 .1 stat 2>&1 | grep 'Maximum amplitude' | awk {'print $3'}) -echo Max Amplitude = $maxAmp -if [ "$maxAmp" == "0.000000" ]; then - # if Max amplitude = 0 then we have silence! - if [ -f "/tmp/silencemarker" ] ; then - # There was silence last time we checked, so play the tone - echo Play the sound - play -nq synth 1 sine 40 fade 0.2 0 - rm /tmp/silencemarker - else - touch /tmp/silencemarker - fi -else - if [ -f "/tmp/silencemarker" ] ; then - rm /tmp/silencemarker - fi -fi - -systemd-run --user --on-active=10m /usr/local/bin/speakerWatchdog.sh - -#to generate a tone that is not audible: -#play -n synth 1 sine 40 fade .2 0 -# -# play sox alias -# -n dummy input file -# synth synthesise a sound -# sine sine wave [the default, so not strictly necessary] -# 40 Hz -# fade fade in from zero volume to max volume over 200 msec. -# '0' says fade out at end over same period. diff --git a/speakerWatchdog.txt b/speakerWatchdog.txt deleted file mode 100644 index d78c40a..0000000 --- a/speakerWatchdog.txt +++ /dev/null @@ -1,65 +0,0 @@ -#! /bin/bash -# Workaround for stupd 'powersave' 'feature' of Creative Speakers -# -# SJP 11 Dec 2021 -# -# This is just a stub for now - -# Which device is the audio output going to? - -# st33v@cr4y:~$ grep RUNNING /proc/asound/card*/pcm*/sub*/status -# /proc/asound/card2/pcm0p/sub0/status:state: RUNNING - -# That is fine, but the status remains as 'RUNNING' even after the speakers have turned themselves off... -# So I'm going down the track of periodically sending a 'sound' to a loopback device -# sudo modprobe snd-aloop -# Now aply -l shows a new 'card' called Loopback. - - -record one second of default stream: - -$ rec -d -n trim 0 1 stat - - rec sox in record mode - -d default input - -n direct output to /dev/null - trim 0 1 duration 1 second - stat - -Output: - -Input File : 'default' (pulseaudio) -Channels : 2 -Sample Rate : 48000 -Precision : 16-bit -Sample Encoding: 16-bit Signed Integer PCM - -In:0.00% 00:00:01.02 [00:00:00.00] Out:48.0k [ | ] Clip:0 -Samples read: 96000 -Length (seconds): 1.000000 -Scaled by: 2147483647.0 -Maximum amplitude: 0.000000 -Minimum amplitude: 0.000000 -Midline amplitude: 0.000000 -Mean norm: 0.000000 -Mean amplitude: 0.000000 -RMS amplitude: 0.000000 -Maximum delta: 0.000000 -Minimum delta: 0.000000 -Mean delta: 0.000000 -RMS delta: 0.000000 -Rough frequency: -2147483648 -Done. - -So if Max amplitude = 0 then we have silence! - -to generate a tone that is not audible: -play -n synth 1 sine 40 fade .2 0 - - play sox alias - -n dummy input file - synth synthesise a sound - sine sine wave [the default, so not strictly necessary] - 40 Hz - fade fade in from zero volume to max volume over 200 msec. - '0' says fade out at end over same period. -- cgit v1.3