Created
July 27, 2010 03:39
-
-
Save encryptio/491687 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
sub read_curve_from { | |
my ($fn) = @_; | |
my $fh; | |
if ( $fn eq "-" ) { | |
$fh = \*STDIN; | |
} else { | |
open $fh, "<", $fn or die "Couldn't open $fn for reading: $!"; | |
} | |
return read_curve_string(do { local $/; <$fh> }); | |
} | |
sub read_curve_string { | |
my ($str) = @_; | |
my $samplerate; | |
my $curve = []; | |
for my $line ( grep { defined and length } split /[\n\r,]/, $str ) { | |
if ( $line =~ /SAMPLERATE=(\d+)/ ) { | |
$samplerate = $1; | |
} | |
next if $line =~ /^[#;]/; | |
$line =~ s/^\s*//; | |
$line =~ s/\s*$//; | |
my ($freq, $power) = split /[=\s]+/, $line; | |
next unless $freq =~ /^\+?\d*(?:\.\d*)?(?:[eE][-+]?\d+)?$/; | |
next unless $power =~ /^\+?\d*(?:\.\d*)?(?:[eE][-+]?\d+)?$/; | |
push @$curve, [$freq, $power]; | |
} | |
return ($curve, $samplerate); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment