#!/usr/bin/perl

use warnings;
use strict;

undef $/; #= 0777;

my @inp = split(/,|\\n/, <>);

my @freqs = (
    1,      # pause, 1Hz kann niemand abspielen
    262,    # 1   c    
    277,    # 2   cis
    294,    # 3   d
    311,    # 4   dis
    330,    # 5   e
    349,    # 6   f
    370,    # 7   fis
    392,    # 8   g
    416,    # 9   gis
    440,    # 10  a
    466,    # 11  ais
    495,    # 12  b
    524,    # 13  c'
    554,    # 14  cis'
    588,    # 15  d'
    622,    # 16  dis'
    660,    # 17  e'
    698,    # 18  f'
    740,    # 19  fis'
    784,    # 20  g'
    831,    # 21  gis'
    880,    # 22  a'
    929,    # 23  ais'
    992,    # 24  b'
    1050,   # 25  c''
    1106,   # 26  cis''
    1179,   # 27  d''
    1244,   # 28  dis''
    1316,   # 29  e'
    1397,   # 30  f''
    1562,   # 31  g'' auf position von fis'' verschoben
);

my $songlength = shift @inp;
my $songspeed =  shift @inp;

# empty first tone
my @beepargv = ("-f", "1", "-l", "1");

foreach(@inp) {
    chomp;
    # printf("%2x\n", $_);
    my $freq = $freqs[ $_ & 0x1F ];
    my $length = ($_ >> 5)*20*$songspeed;
    push @beepargv, "-n", "-f", $freq, "-l", $length, "-D", "20";
    # print "$length: $freq\n";
}


my @args = ("/usr/bin/beep", @beepargv);
# print join(" ", @args, "\n");
system(@args) == 0 or die "system @args failed: $?"
