From b49f8f730dd32d2d74b3fd7e9023d77c6b159b7e Mon Sep 17 00:00:00 2001 From: Louis Croisez Date: Mon, 3 Oct 2022 16:06:44 +0200 Subject: [PATCH] Bugfixes + added choice between ffmpeg and sox tools --- birdnet.conf-defaults | 14 +++++++++---- scripts/advanced.php | 44 ++++++++++++++++++++++++++++++++++----- scripts/install_config.sh | 14 +++++++++---- scripts/play.php | 40 +++++++++++++++++++++++------------ 4 files changed, 86 insertions(+), 26 deletions(-) diff --git a/birdnet.conf-defaults b/birdnet.conf-defaults index a3dab57..12d81c7 100644 --- a/birdnet.conf-defaults +++ b/birdnet.conf-defaults @@ -116,15 +116,21 @@ CONFIDENCE=0.7 SENSITIVITY=1.25 ## Configuration of the frequency shifting feature, useful for earing impaired people. -## You have to define a freq. shift from HI to LO: + +## FREQSHIFT_TOOL + +FREQSHIFT_TOOL=sox + +## If the tool is ffmpeg, you have to define a freq. shift from HI to LO: ## FREQSHIFT_HI - FREQSHIFT_HI=6000 - ## FREQSHIFT_LO - FREQSHIFT_LO=3000 +## If the tool is sox, you have to define the pitch shift (amount of 100ths of semitone) +## FREQSHIFT_PITCH +FREQSHIFT_PITCH=-1500 + ## CHANNELS holds the variable that corresponds to the number of channels the ## sound card supports. diff --git a/scripts/advanced.php b/scripts/advanced.php index b7f4c49..650cd78 100644 --- a/scripts/advanced.php +++ b/scripts/advanced.php @@ -116,6 +116,22 @@ if(isset($_GET['submit'])) { } } + if(isset($_GET["freqshift_pitch"])) { + $freqshift_pitch = $_GET["freqshift_pitch"]; + if(strcmp($freqshift_pitch,$config['FREQSHIFT_PITCH']) !== 0) { + $contents = preg_replace("/FREQSHIFT_PITCH=.*/", "FREQSHIFT_PITCH=$freqshift_pitch", $contents); + $contents2 = preg_replace("/FREQSHIFT_PITCH=.*/", "FREQSHIFT_PITCH=$freqshift_pitch", $contents2); + } + } + + if(isset($_GET["freqshift_tool"])) { + $freqshift_tool = $_GET["freqshift_tool"]; + if(strcmp($freqshift_tool,$config['FREQSHIFT_TOOL']) !== 0) { + $contents = preg_replace("/FREQSHIFT_TOOL=.*/", "FREQSHIFT_TOOL=$freqshift_tool", $contents); + $contents2 = preg_replace("/FREQSHIFT_TOOL=.*/", "FREQSHIFT_TOOL=$freqshift_tool", $contents2); + } + } + if(isset($_GET["full_disk"])) { $full_disk = $_GET["full_disk"]; if(strcmp($full_disk,$config['FULL_DISK']) !== 0) { @@ -291,12 +307,30 @@ foreach($formats as $format){

Accessibility Settings

Birdsongs Frequency shifting configuration:
-     this can be useful for earing impaired people.
-     e.g. origin=6000, target=4000, performs a shift of 2000 Hz down.
-      + this can be useful for earing impaired people.
+ +

+ Choose here the shifting tool, must be a value in the list { ffmpeg, sox }.
+ +
+

+ +

+ using ffmpeg: + e.g. origin=6000, target=4000, performs a shift of 2000 Hz down.
+
-      -
+ + +

+ +

+ using sox: + e.g. shiftPitch=-1200 performs a shift of 1 octave down. This value is in 100ths of a semitone.
+ +
+

+



diff --git a/scripts/install_config.sh b/scripts/install_config.sh index da5f6fb..c71ec48 100755 --- a/scripts/install_config.sh +++ b/scripts/install_config.sh @@ -127,15 +127,21 @@ CONFIDENCE=0.7 SENSITIVITY=1.25 ## Configuration of the frequency shifting feature, useful for earing impaired people. -## You have to define a freq. shift from HI to LO: + +## FREQSHIFT_TOOL + +FREQSHIFT_TOOL=sox + +## If the tool is ffmpeg, you have to define a freq. shift from HI to LO: ## FREQSHIFT_HI - FREQSHIFT_HI=6000 - ## FREQSHIFT_LO - FREQSHIFT_LO=3000 +## If the tool is sox, you have to define the pitch shift (amount of 100ths of semintone) +## FREQSHIFT_PITCH +FREQSHIFT_PITCH=-1500 + ## CHANNELS holds the variable that corresponds to the number of channels the ## sound card supports. diff --git a/scripts/play.php b/scripts/play.php index 020a342..c211840 100644 --- a/scripts/play.php +++ b/scripts/play.php @@ -100,22 +100,36 @@ if(isset($_GET['excludefile'])) { $shifted_path = $home."/BirdSongs/Extracted/By_Date/shifted/"; if(isset($_GET['shiftfile'])) { + $filename = $_GET['shiftfile']; - if(isset($_GET['shiftfreq'])) { - $pp = pathinfo($filename); - $dir = $pp['dirname']; - $fn = $pp['filename']; - $ext = $pp['extension']; - $pi = $home."/BirdSongs/Extracted/By_Date/"; - $cmd = "/usr/bin/nohup /usr/bin/ffmpeg -y -i \"".$pi.$filename."\" -af \"rubberband=pitch=".$config['FREQSHIFT_LO']."/".$config['FREQSHIFT_HI']."\" \"".$shifted_path.$filename."\""; - shell_exec("mkdir -p ".$shifted_path.$dir." && echo \"".$cmd."\" > /tmp/shift.sh && chmod +x /tmp/shift.sh"); + $pp = pathinfo($filename); + $dir = $pp['dirname']; + $fn = $pp['filename']; + $ext = $pp['extension']; + $pi = $home."/BirdSongs/Extracted/By_Date/"; + + if(isset($_GET['doshift'])) { + $freqshift_tool = $config['FREQSHIFT_TOOL']; + + if ($freqshift_tool == "ffmpeg") { + $cmd = "/usr/bin/nohup /usr/bin/ffmpeg -y -i \"".$pi.$filename."\" -af \"rubberband=pitch=".$config['FREQSHIFT_LO']."/".$config['FREQSHIFT_HI']."\" \"".$shifted_path.$filename."\""; + shell_exec("mkdir -p ".$shifted_path.$dir." && echo \"".$cmd."\" > /tmp/shift.sh && chmod +x /tmp/shift.sh"); + + } else if ($freqshift_tool == "sox") { + //linux.die.net/man/1/sox + $soxopt = "-q"; + $soxpitch = $config['FREQSHIFT_PITCH']; + $cmd = "/usr/bin/nohup /usr/bin/sox \"".$pi.$filename."\" \"".$shifted_path.$filename."\" pitch ".$soxopt." ".$soxpitch; + shell_exec("mkdir -p ".$shifted_path.$dir." && echo \"".$cmd."\" > /tmp/shift.sh && chmod +x /tmp/shift.sh"); + } + shell_exec("/tmp/shift.sh"); shell_exec("rm -f /tmp/shift.sh"); } else { - $cmd = "rm -f " . $shifted_path.$dir.$filename; - shell_exec("echo \"".$cmd."\" > /tmp/rmshift.sh && chmod +x /tmp/rmshift.sh"); - shell_exec("/tmp/rmshift.sh"); - shell_exec("rm -f /tmp/rmshift.sh"); + $cmd = "rm -f " . $shifted_path.$filename; + shell_exec("echo \"".$cmd."\" > /tmp/unshift.sh && chmod +x /tmp/unshift.sh"); + shell_exec("/tmp/unshift.sh"); + shell_exec("rm -f /tmp/unshift.sh"); } echo "OK"; @@ -265,7 +279,7 @@ function toggleShiftFreq(filename, shiftAction, elem) { } if(shiftAction == "shift") { console.log("shifting freqs of " + filename); - xhttp.open("GET", "play.php?shiftfile="+filename+"&shiftfreq=true", true); + xhttp.open("GET", "play.php?shiftfile="+filename+"&doshift=true", true); } else { console.log("unshifting freqs of " + filename); xhttp.open("GET", "play.php?shiftfile="+filename, true);