Created
March 13, 2016 13:01
-
-
Save jonathanstowe/5e430da80882c2166a52 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
#!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