Skip to content

Instantly share code, notes, and snippets.

Avatar

Oona Räisänen windytan

View GitHub Profile
@windytan
windytan / bitit.pl
Last active Oct 11, 2015
Perl script to read an image of digits
View bitit.pl
#!/usr/bin/perl
use feature "switch";
open(S,"convert bitit.png gray:-|");
for $y (0..434) {
for $x (0..699) {
read(S,$a,1);
$b[int($x / 27)][int($y / 27)] ++ if (ord($a) < 127);
}
}
@windytan
windytan / muta.pl
Created Oct 13, 2012
Evoluution simulointia sanoilla
View muta.pl
use utf8;
use warnings;
@kirjaimet = ( "a" .. "z", "å", "ä", "ö" );
$alkutilanne = "aaaaaaaaaaaaaaa";
$valintapaine = "kehitysoppi";
# Elinkelpoisuutta simuloidaan ns. Levenšteinin etäisyydellä, joka sopii esimerkkiimme
use Text::Levenshtein qw(fastdistance);
View sigint-to-csv.pl
while(not eof(STDIN)) {
read(STDIN,$a,2);
$a = unpack("s",$a);
print $a."\n";
}
View fsk.pl
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;
View delta.pl
$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;
}
View mod.pl
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);
}
View fm.c
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <fftw3.h>
#define FFTLEN 2048
#define SRATE 22050
// Return sinusoid power from complex DFT coefficients
double power (fftw_complex coeff) {
View deco.pl
$|++;
use warnings;
use Text::LevenshteinXS qw(distance);
for (qx!cat nappis.txt!) {
$merkki{$2} = $1 if (/^(.+) ([01]+)/);
}
while (<>) {
chomp();
View oscillo.pl
use warnings;
use Getopt::Std;
getopt('xytGgwsf',\%opts);
# pcm file = $opts{f}
# samples per pixel x
$xscale = $opts{x} // 1200;
View deinvert-easy.pl
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;
}