#!/usr/bin/perl # Micro Sizzle # by Jacob Joaquin # http://jacobjoaquin.tumblr.com my @bins; # Stores information for each PVS bin my $numberOfBins = 1; # Stores the number of total bins # Open Csound generated data file for reading open( DATA, "< sizzleData.txt" ) || die "Can't read file sizzleData.txt: $!"; # Parse sizzle data while() { if ($_ =~ m/\[(\d+)\s(\d+)\s(\S+)\s(\S+)\s(\S+)\]/) { $bins[$1] .= "$2:$3:$4:$5::"; # Check for higher bin index if ($1 > $numberOfBins) { $numberOfBins = $1; } }; } close DATA; # Print the number of bins present print "\n\nNumber of Bins: $numberOfBins\n\n"; # Create/overwrite Csound score file for processed score data open( OUT, "> MicroSizzle.sco" ) || die "Can't read file MicroSizzle.sco: $!"; # Credits print OUT "/* Micro Sizzle\n"; print OUT " * by Jacob Joaquin\n"; print OUT " * http://jacobjoaquin.tumblr.com/\n"; print OUT " */\n\n"; my $duration = 0.125; # Duration of each sine grain my $ampLimit = 1000; # Amp limit for determining attack my $ampScale = 0.6788; # Rescale amplitude to avoid clipping # Process each bin for ($thisBin = 1; $thisBin <= $numberOfBins; $thisBin++ ) { # Split into separate events @thisPacket = split(/::/, $bins[$thisBin]); for ($i = 0; $i < scalar(@thisPacket); $i++) { $event = ""; # To store i-event # Parse current packet @thisData = split(/:/, $thisPacket[$i]); $time = $thisData[0] / 4410; $amp = $thisData[1]; $freq = $thisData[2]; $pan = $thisData[3]; # Determine attack time based on amplitude $modAmp = $amp; if ($modAmp > $ampLimit) { $modAmp = $ampLimit; } $modAmp = $ampLimit - $modAmp; $attack = $modAmp / $ampLimit * $duration / 2; $attack += 0.05; # Generate i-event if ($amp > 1 && $freq > 50) { $event .= "i 1 "; # instrument 1 $event .= "$time "; # start time $event .= "$duration "; # duration $event .= $amp * $ampScale . " "; # amp $event .= "$freq "; # start frequency $event .= "$freq "; # end frequency $event .= $attack * $duration . " "; # attack $event .= "$pan "; # pan start $event .= "$pan\n"; # pan end } # Print to file print OUT $event; } } close OUT;