-
-
Save timo/d97a284b884274e9e375 to your computer and use it in GitHub Desktop.
This file contains hidden or 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) { | |
my num $spf = $sample-rate.Num / $frequency.Num; | |
my num $twopi = (2 * pi).Num; | |
my $range = (0..$spf); | |
do loop { | |
slip $range.map({ sin(($_.Num/($spf)) * $twopi) }); | |
} | |
} | |
my $now = now; | |
my $sin-generator = gen-sin($samplerate, $frequency); | |
for $sin-generator.rotor(256) -> @a { | |
my $c = CArray[num32].new(flat @a Z @a); | |
say now - $now; | |
$now = now; | |
last if $++ > 100; | |
} | |
# vim: expandtab shiftwidth=4 ft=perl6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
:) I'll try and plug this in to https://github.com/jonathanstowe/Audio-PortAudio/blob/master/examples/play-sine later to see if it works cheers.