Created
April 12, 2023 18:36
-
-
Save HaraldJoerg/7b6efc314718a0f69c971232ac118653 to your computer and use it in GitHub Desktop.
(Linux) sound with Perl and a few lines of PDL
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
use PDL; | |
my $freq = 440; | |
my $rate = 8000; # default for aplay | |
my $samples = pdl[0..$rate-1]; | |
open (my $aplay,'|-','aplay'); | |
my $raw_sound = byte(zeroes($rate)); | |
my $amplitude = 64; | |
for (1..5) { | |
$raw_sound += byte($amplitude*(1+sin($samples*$_*$freq*6.28/$rate))); | |
$amplitude /= 2; | |
print $aplay $raw_sound->get_dataref->$*; | |
} | |
close $aplay; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment