Last active
February 12, 2017 10:36
-
-
Save windytan/3fdd4c7b19d262402e5e to your computer and use it in GitHub Desktop.
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
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