Skip to content

Instantly share code, notes, and snippets.

@windytan
Created June 8, 2014 23:17
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save windytan/08650f1c7e84c7370130 to your computer and use it in GitHub Desktop.
use warnings;
use DateTime;
$snum = 0;
$writing = 0;
open OUT, "|sox -t .raw -e signed-integer -b 16 -r 44100 ".
"-c 1 - stamped.wav";
while (not eof STDIN) {
read STDIN, $sample, 2;
$sample = unpack "s", $sample;
$ms = 0;
if ($writing) {
if ($mnum >= scalar @msamples) {
$writing = 0;
} else {
$ms = $msamples[$mnum];
$mnum ++;
}
} elsif ($snum++ % 44100 == 0) {
$writing = 1;
@msamples = ();
$mnum = 0;
$code = DateTime->now()->iso8601();
`echo $code |minimodem --tx --mark 11000 --space 13000 --file - 1200 >stamp.wav`;
open(MODEM, "sox stamp.wav -r 44100 -e signed -c 1 -t .raw -|");
while (not eof MODEM) {
read MODEM, $s, 2;
push(@msamples, unpack("s",$s));
}
close MODEM;
}
print OUT pack("s", $sample + 0.1 * $ms);
}
close OUT;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment