This forum is in permanent archive mode. Our new active community can be found here.

Programming Challenge - save an episode of GeekNights

2»

Comments

  • Wow, honorary asshole judge? Never thought I'd live to see the day.

    For reward, can you hook up me with a PAX Prime Sunday badge? (I already have the other three.) Also, if you could shout out to your friends to see if anyone needs another hotel roommate, that'd be great. (I know pence and Ro are already full up.)

    In case anyone cares, here's the script. It's very simple and not super efficient (string operations on raw bytes! keeping the entire wave in memory!), but it does work.

    #!/usr/bin/env perl

    use warnings;
    use strict;

    use Audio::Wav;

    die "missing file" unless @ARGV;

    my $wav = new Audio::Wav;
    my $in = $wav->read($ARGV[0]);
    my $details = $in->details();
    my $out = $wav->write("fixed-$ARGV[0]",
    {
    'bits_sample' => $details->{bits_sample},
    'channels' => $details->{channels},
    'sample_rate' => $details->{sample_rate},
    }
    );
    print "input is ", $in->length_seconds(), "\n";
    my $raw = $in->read_raw($details->{total_length});
    print "length of raw is ", length($raw), "\n";

    my %bad =
    (
    "\0\0\0" => 1,
    "\1\0\0" => 1,
    "\x{ff}\x{ff}\x{ff}" => 1,
    );

    # read triple.
    # if bad, add to bad buffer and increment bad count.
    # if not bad, output bad buffer (unless its size is 71!) and this not bad triple.

    my $badcount = 0;
    my $badbuffer = '';
    my $output = '';
    for (my $i = 0; $i < length $raw; $i += 3) {
    my $sample = substr $raw, $i, 3;
    if($bad{$sample}) {
    $badcount++;
    $badbuffer .= $sample;
    } else {
    if($badcount == 71) {
    print "*";
    $output .= $sample;
    $badcount = 0;
    $badbuffer = '';
    } else {
    # spurious sample. dump badbuffer and it.
    $output .= $badbuffer;
    $output .= $sample;
    $badcount = 0;
    $badbuffer = '';
    }
    }
    }

    $out->write_raw($output);
  • edited July 2015
    Edit: ignore meeee
    Post edited by Linkigi(Link-ee-jee) on
  • If any of our panels is accepted, I'll have one full set of 1-day passes to get rid of.
  • I have a four-day pass I will also be able to give away if we get our panels.
  • edited July 2015
    .
    Post edited by Matt on
  • okeefe said:

    Wow, honorary asshole judge? Never thought I'd live to see the day.

    For reward, can you hook up me with a PAX Prime Sunday badge? (I already have the other three.) Also, if you could shout out to your friends to see if anyone needs another hotel roommate, that'd be great. (I know pence and Ro are already full up.)

    In case anyone cares, here's the script. It's very simple and not super efficient (string operations on raw bytes! keeping the entire wave in memory!), but it does work.

    Dude you should have told me. I could have grabbed you one when they released more passes the other day. I grabbed one for my friend. :/
  • I tried interpolating with third order polynomials. I thought it might fill the gaps smoothly. I think it's actually worse somehow.

    edited file
    scilab script
Sign In or Register to comment.