Last active
February 6, 2018 13:18
-
-
Save przemoc/943386 to your computer and use it in GitHub Desktop.
Siemens ringtone converter v. 0.3 // taken from pcspk 0.0.6: http://wiki.przemoc.net/projects/pcspk
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
#!/usr/bin/gawk -f | |
# SPDX-License-Identifier: GPL-2.0-only | |
## (C) Copyright 2007-2008 Przemyslaw Pawelczyk <[email protected]> | |
## | |
## This script is licensed under the terms of the GNU GPL v2 only license. | |
## https://www.gnu.org/licenses/gpl-2.0.html | |
# | |
# Siemens ringtone converter v. 0.3 | |
# | |
# Usage: | |
# siemens.gawk [-v bpm=XXX] [-v oct=Y] siemens_ringtone_file | pcspk -n | |
BEGIN { | |
IGNORECASE = 1 | |
BPM = 100; # default BPM | |
OCT = 2; # default octave shift | |
_ord_init(); | |
is = "CDFGA"; | |
es = "degaB"; | |
ORS = " "; | |
} | |
/^#.*bpm=([0-9]+)/ { | |
match($0, /bpm=([0-9]+)/, b); | |
if ((b[1] > 0) && !(bpm > 0)) | |
bpm = b[1]; | |
} | |
/^#.*oct=([0-9]+)/ { | |
match($0, /oct=([0-9]+)/, b); | |
if ((b[1] > 0) && !(oct > 0)) | |
oct = b[1]; | |
} | |
# _ord_init is taken from | |
# http://www.gnu.org/software/gawk/manual/gawk.html#Ordinal-Functions | |
function _ord_init( low, high, i, t) { | |
low = sprintf("%c", 7); # BEL is ascii 7 | |
if (low == "\a") { # regular ascii | |
low = 0; | |
high = 127; | |
} else if (sprintf("%c", 128 + 7) == "\a") { # ascii, mark parity | |
low = 128; | |
high = 255; | |
} else { # ebcdic(!) | |
low = 0; | |
high = 255; | |
} | |
for (i = low; i <= high; i++) { | |
t = sprintf("%c", i); | |
_ord_[t] = i; | |
} | |
} | |
function parse(input) { | |
split(input, array, "[ \t]+"); | |
for (i = 1; i in array; i++) { | |
if (array[i] !~ /^([CDEFGAHBP](is)?)([0-9])?\(1\/([0-9]+)\)/) | |
continue; | |
match(array[i], /^([CDEFGAHBP])(is)?([0-9])?\(1\/([0-9]+)\)/, s); | |
if (s[2] != "") | |
s[1] = substr(es, index(is, s[1]), 1); | |
else | |
s[1] = toupper(s[1]); | |
s[3] += oct; | |
if (s[3] < 0) | |
s[3] = 0; | |
s[4] = s[4] - 1; | |
if(s[4] >= 10) | |
s[4] = sprintf("%c", _ord_["A"] + s[4] - 10); | |
print s[1] s[3] s[4] | |
} | |
} | |
/^[^#]/ { | |
if (!(notfirst)) { | |
if (!(bpm > 0)) | |
bpm = BPM; | |
if (!(oct > 0)) | |
oct = OCT; | |
printf "%03d%s", bpm, ORS; | |
notfirst = 1; | |
} | |
parse($0); | |
} |
Author
przemoc
commented
Feb 6, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment