Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!perl6
use NativeCall;
my $samplerate = 44100;
my $frequency = 440;
sub gen-sin(Int $sample-rate, Int $frequency) {
gather {
loop {
for (0 .. ($samplerate/$frequency)).map({ sin(($_/($samplerate/$frequency)) * (2 * pi))}) -> $val {
take $val;
}
}
}
}
my $now = now;
for gen-sin($samplerate, $frequency).rotor(256) -> @a {
my $c = CArray[num32].new(flat @a Z @a);
say now - $now;
$now = now;
last if $++ == 4;
}
# vim: expandtab shiftwidth=4 ft=perl6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment