Created
July 27, 2022 07:49
-
-
Save coderofsalvation/9f6fc6923b0114266b5ebecb85955086 to your computer and use it in GitHub Desktop.
convert wav 2 csound using awk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# usage: ./wav2csound sample.wav >> mysong.csd | |
test -z $1 && { | |
echo "usage: wav2csound sample.wav"; | |
echo " wav2csound sample.wav >> mysong.csd" | |
exit 0; | |
} | |
{ | |
CSD=' | |
<CsoundSynthesizer> | |
<CsInstruments> | |
; example usage: csound --nosound --strset1=sample.wav wav2ft.csd | |
sr = 44100 | |
ksmps = 32 | |
0dbfs = 1 | |
gSin strget 1 ; input file | |
nchnls = filenchnls(gSin) | |
giLen filelen gSin ; length file | |
giDuration = giLen | |
;varname ifn itime isize igen Sfilnam iskip iformat ichn | |
giFile ftgen 101, 0, giLen, 1, gSin, 0, 0, 1 | |
ftsave "/tmp/out.orc", 1, 101 | |
exitnow | |
</CsInstruments> | |
</CsoundSynthesizer> | |
' | |
echo "$CSD" > /tmp/wav2ft.csd | |
out=$(basename "$1").orc | |
csound --nosound --strset1="$1" /tmp/wav2ft.csd | |
len=$(awk '/flen:/ {print $2 }' /tmp/out.orc ) | |
printf "\n==== COPY/PASTE this into your .csd file:\n\n" 1>&2 | |
} 1>&2 | |
# now we print the final csd-code using awk | |
echo "; $(basename "$1")" | |
awk ' | |
BEGIN{ data=-1; printf "giSample ftgen 0, 0, -'$len', "; } | |
/END OF TABLE/ { data=-1; } | |
( data > 0 ) { printf "%s, ",$1 } | |
/END OF HEADER/ { data=NR; } | |
' /tmp/out.orc | |
echo | |
rm /tmp/wav2ft.csd /tmp/out.orc 2>/dev/null # cleanup |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment