#!/bin/sh # # "Free Software Song" player # # Copyright (C) 2016 Patrick "P. J." McDermott # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . play() { local octave_shift="${1}" local note_length="${2}" shift 2 local note= local octave= local length= local freq= while [ ${#} -gt 0 ]; do note="${1%_*}" octave="${1%:*}" octave="${octave#*_}" length="${1#*:}" shift 1 case "${note}" in C) note=-9;; Cs|Df) note=-8;; D) note=-7;; Ds|Ef) note=-6;; E) note=-5;; F) note=-4;; Fs|Gf) note=-3;; G) note=-2;; Gs|Af) note=-1;; A) note=0;; As|Bf) note=1;; B) note=2;; esac # A note's frequency is: # n/12 # f = 2 * 440 Hz # where n is the distance from A4. freq=$(awk -v octave_shift=${octave_shift} -v octave=${octave} \ -v note=${note} ' BEGIN { octaves = octave_shift + octave - 4 + note / 12; freq = 2 ^ octaves * 440; print(int(freq + 0.5)); } ') length=$(($length * $note_length)) beep -f ${freq} -l ${length} done } # "Free Software Song" # # Time signature: 7/8 # Octaves: 4, 5 # Tempo: 252 BPM # Duration: 0:20 # # The notation for the "Free Software Song" is from # . play 4 238 \ D_1:2 C_1:1 B_0:2 A_0:2 \ B_0:2 C_1:1 B_0:1 A_0:1 G_0:2 \ G_0:3 A_0:3 B_0:1 \ C_1:3 B_0:2 B_0:1 D_1:1 \ A_0:3 A_0:4 \ D_1:2 C_1:1 B_0:4 \ \ D_1:2 C_1:1 B_0:2 A_0:2 \ B_0:2 C_1:1 B_0:1 A_0:1 G_0:2 \ G_0:3 A_0:3 B_0:1 \ C_1:3 B_0:2 B_0:1 D_1:1 \ A_0:3 A_0:4 \ A_0:7