Skip to content

Instantly share code, notes, and snippets.

@windytan
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save windytan/73c827addedf8e703ea0 to your computer and use it in GitHub Desktop.
Save windytan/73c827addedf8e703ea0 to your computer and use it in GitHub Desktop.
#!/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