Skip to content

Instantly share code, notes, and snippets.

@windytan
Last active February 12, 2017 10:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save windytan/3fdd4c7b19d262402e5e to your computer and use it in GitHub Desktop.
Save windytan/3fdd4c7b19d262402e5e to your computer and use it in GitHub Desktop.
use warnings;
my $snum = 0;
my $reading = 0;
open my $in, '-|', 'sox stamped.wav -e unsigned-integer -t .raw -';
while (read $in, $sample, 2) {
$bit = (unpack "S", $sample) & 1;
if (!$reading && $bit) {
$byte = 0x00;
$pos = 0;
$reading = 1;
$starts = $snum;
$stamp = "";
} elsif ($reading) {
$byte |= ($bit << $pos);
if (++$pos >= 8) {
if ($byte == 0x00) {
$reading = 0;
print "$starts: $stamp\n";
} else {
$stamp .= chr $byte;
}
$byte = 0x00;
$pos = 0;
}
}
$snum++;
}
close $in;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment