ref: 4028a0b5f197066ef36281f45c8efbaaaf3dbe37
parent: e38100c90d38ced7099be43743c0afdaabd2634f
author: qwx <qwx@sciops.net>
date: Sat Jul 22 04:07:34 EDT 2023
add tune: tune up/down by semitone and/or speed up/down using audio/stretch
--- /dev/null
+++ b/bin/tune
@@ -1,0 +1,55 @@
+#!/bin/rc
+fn usage{
+ echo usage: $0 '[-p NSEMITONE]' '[-t PERCENT]'
+ exit usage
+}
+
+p=0
+t=100
+while(~ $1 -?){
+ switch($1){
+ case -p
+ p=$2
+ shift
+ case -t
+ t=$2
+ shift
+ case *
+ usage
+ }
+ shift
+}
+if(~ $#p 0 && ~ $#t 0)
+ usage
+eval `{awk -v p'='^$p -v t'='^$t '
+BEGIN{
+ c = ""
+ if(p != 0){
+ if(p < 0)
+ p = 1.0 / (1.0594631 ^ -p)
+ else if(p > 0){
+ p = 1.0594631 ^ p
+ if(p > 4.0)
+ p = 4.0
+ }
+ c = "audio/stretch -s -r " p
+ if(t != 100)
+ c = c " | "
+ }
+ if(t != 100){
+ if(t < 0)
+ t = 1
+ else if(t <= 100){
+ t = 1.0 + (1 - t / 100)
+ if(t > 4.0)
+ t = 4.0
+ }else{
+ t = 1 - t / 100
+ if(t < 0.25)
+ t = 0.25
+ }
+ c = c "audio/stretch -r " t
+ }
+ print c
+}
+'}