Last active
August 29, 2015 14:04
-
-
Save windytan/73c827addedf8e703ea0 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
#!/usr/bin/perl | |
# Oona Räisänen 2014 | |
use warnings; | |
$fs = 48000; | |
$f = 200; | |
$pi = 3.141592653589793238; | |
open(U,"|sox -t .raw -c 1 -r $fs -b 16 -e signed - sines.wav"); | |
$p = 0; | |
for $step (1,1,1,1..120,120,120,120,120,120,120) { | |
$n = 0; | |
$steplen = 0.5*$fs * (1-$step/131); | |
while ($n < $steplen) { | |
$a = 0; | |
$a += harmo($_, $p) for (1..$step-1); | |
if ($n < 400 && ($prevstep // 0) != $step) { | |
$a += harmo($step, $p) * ($n/400); | |
} else { | |
$a += harmo($step, $p); | |
} | |
$n++; | |
$p++; | |
print U pack("s",$a); | |
} | |
$prevstep = $step; | |
} | |
close(U); | |
sub harmo { | |
($ord,$ph) = @_; | |
my $ampf = .5 * -(2/($ord*$pi))* (-1)**$ord; | |
$ampf * 32000 * sin ( $ph / $fs * ($ord*$f) * 2 * $pi); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment