Skip to content

Instantly share code, notes, and snippets.

@chezsick
Last active October 28, 2019 19:46
Show Gist options
  • Save chezsick/955cdfcac2a6c84ced8c91eb53b72a9d to your computer and use it in GitHub Desktop.
Save chezsick/955cdfcac2a6c84ced8c91eb53b72a9d to your computer and use it in GitHub Desktop.
Encode/Decode An Video/Photo To Native Flute Sheet ;;; NEW Include Sound Inside Sheet ::::::: filename framerate samplesound imgsize ;;;; With A Sound In Raw Unsigned 8 Bit ;;;;; For Color Render, Please Using With This ::::::::::: https://github.com/kFYatek/color_modem
<?php
$note = [1,3,4,5,7,8,9,0];
while (false !== ($o = fgetc(STDIN)))
{
$gray = intval((ord($o) / 256)*64);
echo $note[intval($gray/8)].$note[intval($gray%8)];
}
<?php
$fs = fopen($argv[1],"rb");
$fps = intval($argv[2]);
$sample = intval($argv[3]);
$size = $argv[4];
$note = [1,3,4,5,7,8,9,0];
$q = $sample/$fps;
$siza = explode("x",$size);
$p = $q/intval($siza[1]);
while ($o = fread(STDIN,intval($siza[0])))
{
for ($n = 0;$n < intval($siza[0]);$n++)
{
$gray = intval((ord($o[$n]) / 256)*64);
echo $note[intval($gray/8)].$note[intval($gray%8)];
}
$e = fread($fs,intval($p));
for ($n = 0;$n < intval($p);$n++)
{
$r = intval((ord($e[$n]) / 256)*64);
echo $note[intval($r/8)].$note[intval($r%8)];
}
}
<?php
$note = [1,3,4,5,7,8,9,0];
while ($o = fread(STDIN,2))
{
$gray = 4*((8*array_search($o[0],$note))+array_search($o[1],$note));
echo chr($gray);
}
<?php
$fs = fopen($argv[1],"wb");
$fps = intval($argv[2]);
$sample = intval($argv[3]);
$size = $argv[4];
$note = [1,3,4,5,7,8,9,0];
$q = $sample/$fps;
$siza = explode("x",$size);
$p = $q/intval($siza[1]);
while ($o = fread(STDIN,(intval($siza[0])+$p)*2))
{
for ($n = 0;$n < intval($siza[0]);$n++)
{
$gray = 4*((8*array_search($o[($n*2)],$note))+array_search($o[($n*2)+1],$note));
echo chr($gray);
}
for ($n = intval($siza[0]);$n < intval($siza[0])+intval($p);$n++)
{
$d = 4*((8*array_search($o[$n*2],$note))+array_search($o[($n*2)+1],$note));
fwrite($fs,chr($d));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment