Skip to content

Instantly share code, notes, and snippets.

View windytan's full-sized avatar
💭
I may be slow to respond.

Oona Räisänen windytan

💭
I may be slow to respond.
View GitHub Profile
@windytan
windytan / markov-tavut.pl
Last active October 24, 2017 10:26
Markov-ketjuilla uusia sanoja suomenkielisestä lähdetekstistä
#!/usr/bin/perl
#
# Markov-tavutin
#
# (c) Oona Räisänen
# MIT license
#
use strict;
use warnings;
#!/usr/bin/perl
# windytan 2017, public domain
use warnings;
use strict;
my $img_width = 1200;
my $img_height = 900;
my $yscale = 0.6;
my $xscale = 0.13;
my $rowheight = 5;
use warnings;
my $snum = 0;
my $reading = 0;
open my $in, '-|', 'sox stamped.wav -e unsigned-integer -t .raw -';
while (read $in, $sample, 2) {
$bit = (unpack "S", $sample) & 1;
if (/^\.ninja (.+)/) {
$irivi = lc($1);
$irivi =~ tr/ÅÄÖ/åäö/;
$irivi =~ tr/åäöéèü/aaoeeu/;
$irivi =~ s/[^a-z\- ]//g;
$irivi =~ s/\s+$//;
$irivi =~ s/\s\s/ /g;
%ninjanames = qw( a KA b ZU c MI d TE e KU f LU g JI h RI i KI j ZU
k ME l TA m RIN n TO o MO p NO q KE r SHI s ARI
t CHI u DO v RU w MEI x NA y FU z ZI );
@windytan
windytan / bpm.pl
Last active September 14, 2016 05:48
Count newlines per minute. Press enter for beat. Useful for music, heart rate, etc.
#!/usr/bin/perl
#
# bpm.pl - count newlines per minute
#
# Oona Räisänen 2012
# Public domain
#
# Usage: ./bpm [-n SAMPLES] [-p DECIMALS] [-s]
#
# -n SECONDS: average over SECONDS seconds (default 5)
$fs = 48000; # sample rate
$fc = 3729; # carrier frequency
$filter = " sinc -$fc"; # optional LP filter
$fc = freq($fc);
open(IN, "sox scrambled.wav -c 1 -b 16 -e signed -t .raw -|");
open(OUT,"|sox -r $fs -c 1 -b 16 -e signed -t .raw - descrambled.wav".
$filter);
open(IN, "sox scrambled.wav -r 8600 -c 1 -t .s16 -|");
open(OUT,"|sox -r 8600 -c 1 -t .s16 - descrambled.wav");
$n = 1;
while (not eof IN) {
read IN, $a, 2;
print OUT pack("s",unpack("s",$a) * $n);
$n *= -1;
}
open(S,"sox salakalastaja.wav -t .raw -e signed -|");
open(U,"|sox -b 16 -c 1 -e signed -t .raw -r 44100 ".
"- ssb.wav sinc 6000 -n 4096");
while(not eof(S)) {
read(S,$a,2);
print U pack("s",unpack("s",$a) *
cos(($n++ * 2 * 3.141592653589793 * 6000) / 44100);
}
$prevbit = 0;
$n=0;
for (qx!cat ddtaa.asc!) {
chomp($a = $_);
if ($n >= 2300) {
if (($n - 2300) % 80 == 0) {
$bit = ($a > 0) ? 1 : 0;
print (($bit != $prevbit) ? "1" : "0");
$prevbit = $bit;
}
use constant BPS => 300;
use constant SRATE => 44100;
$dur = 0;
for (qx!cat olddata.asc!) {
chomp($a = $_);
if ($a * $preva < 0) {
$nbits = int($dur / (SRATE/BPS) + .5);
print ((($preva < 0) ? 1 : 0) x $nbits);
$dur = 0;