Created
April 23, 2018 06:21
-
-
Save ivand58/bce190414c0fd1a3e1a188bb718dc301 to your computer and use it in GitHub Desktop.
text to morse and morse to text
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
char X[] = | |
" ETIANMSURWDKGOHVF:L:PJBXCYZQ::54:3:::2&:+::::16=/:::(:7:::8:90" | |
"::::::::::::?_::::\"::.::::@:::'::-::::::::;!:):::::,:::::"; | |
int j,w,h,f,u,d,g,e,n,i,l,a,r,p,c,m,o,t,s,Q=32,T[32],W[32],I=13000; | |
int main(int v, char** b) { | |
for (i=0;v>0&&v<5&&(v*=t=fread(X,1,1,stdin));) | |
for (v-1&&101==*1[b]?++g%1500?u+=(g&1^1)*(*X<0?-*X:*X):(f=e,e=w,w=d,d=u, | |
m=(1 - h%2* 2 )*(d -f)/ (d<f ?d|1 : 1|f) > 5?T[ h%Q] =o+l , l=W[ | |
h++%Q]=o,o=0:m,o++,u=main(0,b)):(c=strrchr(X,~(Q&*X&*X/2)&*X)-X,j=255); | |
v==1&&(c*j||main(*X-Q?8:24,b));j/=2)c<j?0:main(9+(c-j)/(j/2+1)%2*10,b); | |
for (a=u=0;i<=Q*Q&&!v;j>7&&j<13?s=c*s+T[i/Q]/2,s/=++c:0) | |
!(i++%Q)?a=c>a?u=s,c:a,c=s=0:0,j=T[i%Q],j=j?T[i/Q]*10/j:0,j*=(j<5)*2+1; | |
for (r+=(h-r)/Q*Q;i<v/4*I;putchar((i/I<v%4)*i%2*85<<(i%176/88)),i++); | |
for (g*=!!v;r+t!=h+1&&h>5&&!v;r+t!=h+1?(W[r%Q]>2*u||r==h?p=n=n>6?0: | |
putchar(X[p-1+(1<<n)])&0:0,W[r++%Q]>6*u?putchar(Q):0):0) | |
*X=Q,p=r%2?++n,2*p+(W[r++%Q]>2*u):p; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Build
gcc morse.c -o prog
Text to Morse
echo 'No. I want chocolate!' | ./prog | mplayer -demuxer rawaudio -
Convert audio file with Morse signals to text
./prog e < audio_file.raw
or alternatively pass a .wav file as input.