Skip to content

Instantly share code, notes, and snippets.

@iamahuman
Created March 18, 2017 10:23
Show Gist options
  • Save iamahuman/e2cf8c74cc3caa32e4708afa9cebcdb8 to your computer and use it in GitHub Desktop.
Save iamahuman/e2cf8c74cc3caa32e4708afa9cebcdb8 to your computer and use it in GitHub Desktop.
Stereo audio test (requires PulseAudio and pacat)
#!/usr/bin/perl
use Math::Trig;use IO::Handle;$s=44100;if(@ARGV[0]ne'o'){open($fh,"|pacat --rate=$s --format=s16le --channels=2");}else{$fh=*STDOUT;}$i=0;$d=2;$l=440;$r=880;$j=1;$a=8192;$la=0;$lb=0;$i=$s*$d-1;$n=0;while(1){if(++$i>=$s*$d){while(abs(int($la))>1 or abs(int($lb))>1){print $fh pack "vv",($la*=0.99),($lb*=0.99);}print "\x00"x4;sleep $n;$n=$d;$i=0;$j=!$j;printf STDERR " %5s (%6.1f Hz)\r", ($j?"Right":"Left"), ($j?$r:$l);STDERR->flush();}print $fh pack "vv",($la=$j?0:(sin($i*2*pi*$l/$s)*$a)),($lb=$j?(sin($i*2*pi*$r/$s)*$a):0);}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment