shithub: snippets

Download patch

ref: 4b95f4f4f1f3caae8e09e16f9bcd4af303a33a8b
parent: b5485070f68da54643f4a69f156390409947a054
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Tue May 4 19:16:24 EDT 2021

add st-xx-lha-convert

--- a/README.md
+++ b/README.md
@@ -14,3 +14,4 @@
 * `clear` removes all program output from the terminal, leaving only commands used
 * `helpmeport` generates files needed to port a Unix library or a binary
 * `watch` watch-like tool, imagine
+* `st-xx-lha-convert` extract `*.lha` archives and convert samples to WAV, on UNIX
--- /dev/null
+++ b/st-xx-lha-convert
@@ -1,0 +1,20 @@
+#!/bin/sh
+
+for f in $*; do
+	lha -x $f >/dev/null
+done
+
+find . -type f -exec sh -c 'mv "{}" $(echo "{}" | sed "s/ /_/g") 2>/dev/null' \;
+
+find . -type f | while read f; do
+	grep -q FORM "$f"
+	if [ $? -eq 0 ]; then
+		sox -t 8svx -b 8 -c 1 "$f" "$f.wav" 2>/dev/null && \
+			rm "$f"
+	fi
+	if [ -f "$f" ]; then
+		sox -t raw -r 8363 -e signed -b 8 -c 1 "$f" "$f.wav" && \
+			rm "$f"
+	fi
+	test -f "$f" && echo "failed: $f"
+done