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 / bitit.pl
Last active October 11, 2015 10:28
Perl script to read an image of digits
#!/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 October 13, 2012 15:03
Evoluution simulointia sanoilla
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);
while(not eof(STDIN)) {
read(STDIN,$a,2);
$a = unpack("s",$a);
print $a."\n";
}
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;
$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;
}
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);
}
@windytan
windytan / fm.c
Last active August 26, 2019 03:49
#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) {
$|++;
use warnings;
use Text::LevenshteinXS qw(distance);
for (qx!cat nappis.txt!) {
$merkki{$2} = $1 if (/^(.+) ([01]+)/);
}
while (<>) {
chomp();
use warnings;
use Getopt::Std;
getopt('xytGgwsf',\%opts);
# pcm file = $opts{f}
# samples per pixel x
$xscale = $opts{x} // 1200;
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;
}