Skip to content

Instantly share code, notes, and snippets.

@jonathanstowe
Created March 13, 2016 13:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jonathanstowe/5e430da80882c2166a52 to your computer and use it in GitHub Desktop.
Save jonathanstowe/5e430da80882c2166a52 to your computer and use it in GitHub Desktop.
#!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