Skip to content

Instantly share code, notes, and snippets.

@windytan
Last active Aug 29, 2015
Embed
What would you like to do?
#!/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