From 4db3c97ab8a76bd28dc737755c331e89a671d162 Mon Sep 17 00:00:00 2001 From: makefu Date: Mon, 30 Dec 2013 03:09:34 +0100 Subject: krebsuino -> god --- "Cancer/K\303\274belwagen/Makefile" | 14 +++ "Cancer/K\303\274belwagen/alarm" | 27 +++++ "Cancer/K\303\274belwagen/index.c" | 206 +++++++++++++++++++++++++++++++++++ "Cancer/K\303\274belwagen/playmobil" | 12 ++ "Cancer/K\303\274belwagen/sin.js" | 37 +++++++ "K\303\274belwagen/Makefile" | 14 --- "K\303\274belwagen/alarm" | 27 ----- "K\303\274belwagen/index.c" | 206 ----------------------------------- "K\303\274belwagen/playmobil" | 12 -- "K\303\274belwagen/sin.js" | 37 ------- god/uino/morse/morse.pde | 164 ++++++++++++++++++++++++++++ uino/morse/morse.pde | 164 ---------------------------- 12 files changed, 460 insertions(+), 460 deletions(-) create mode 100644 "Cancer/K\303\274belwagen/Makefile" create mode 100755 "Cancer/K\303\274belwagen/alarm" create mode 100644 "Cancer/K\303\274belwagen/index.c" create mode 100755 "Cancer/K\303\274belwagen/playmobil" create mode 100644 "Cancer/K\303\274belwagen/sin.js" delete mode 100644 "K\303\274belwagen/Makefile" delete mode 100755 "K\303\274belwagen/alarm" delete mode 100644 "K\303\274belwagen/index.c" delete mode 100755 "K\303\274belwagen/playmobil" delete mode 100644 "K\303\274belwagen/sin.js" create mode 100644 god/uino/morse/morse.pde delete mode 100644 uino/morse/morse.pde diff --git "a/Cancer/K\303\274belwagen/Makefile" "b/Cancer/K\303\274belwagen/Makefile" new file mode 100644 index 00000000..9be84e13 --- /dev/null +++ "b/Cancer/K\303\274belwagen/Makefile" @@ -0,0 +1,14 @@ + +CC := gcc -std=c99 +CFLAGS := -D_XOPEN_SOURCE=500 +LIBS := $(shell pkg-config --cflags --libs jack) -lm + +.PHONY: all clean + +all: a.out + +clean: + rm -f a.out + +a.out: index.c + $(CC) $(CFLAGS) -o $@ $^ $(LIBS) diff --git "a/Cancer/K\303\274belwagen/alarm" "b/Cancer/K\303\274belwagen/alarm" new file mode 100755 index 00000000..a117c433 --- /dev/null +++ "b/Cancer/K\303\274belwagen/alarm" @@ -0,0 +1,27 @@ +#! /bin/sh +# +# //Kübelwagen/alarm SLEEPARGS... +# +# where SLEEPARGS are passed to sleep(3) +# +set -euf +cd $(dirname $(readlink -f $0)) +exec >&2 + +make + +jackd -d alsa & +trap "kill -0 $! && kill $!" EXIT INT + +for i in `seq 8000 1000 10000`; do + echo $i 100 +done | ./a.out 1 +echo 'if you heard that sound, then goto sleep..^_^' + +echo sleep "$@" +sleep "$@" + +echo 'wake up!' +while :; do + echo $(echo "($(od -tu -An -N 2 /dev/urandom)%1000)+500"|bc) $(echo "($(od -tu -An -N 2 /dev/urandom)%500)+100"|bc) +done | ./a.out 1 diff --git "a/Cancer/K\303\274belwagen/index.c" "b/Cancer/K\303\274belwagen/index.c" new file mode 100644 index 00000000..9a15c7c3 --- /dev/null +++ "b/Cancer/K\303\274belwagen/index.c" @@ -0,0 +1,206 @@ +#include +#include +#include +#include +#include + +#include + +const double PI = 3.14; + +/*Our output port*/ +jack_port_t *output_port; + +typedef jack_default_audio_sample_t sample_t; + +/*The current sample rate*/ +jack_nframes_t sr; + +/*samples in cycle*/ +jack_nframes_t samincy; +/*the current offset*/ +long offset=0; + +/*frequency of our sound*/ +int tone = 262; +int length = 1000000; + +char const *name = ""; + +int process (jack_nframes_t nframes, void *arg){ + /*grab our output buffer*/ + sample_t *out = (sample_t *) jack_port_get_buffer + (output_port, nframes); + + int _tone = tone > 0 ? tone : 1; + + /*For each required sample*/ + for(jack_nframes_t i=0;i < nframes;i++){ + /*Copy the sample at the current position in the cycle to the buffer*/ + + jack_nframes_t samincy = sr / _tone; + sample_t scale = 2 * PI / samincy; + out[i] = sin(offset * scale); + + /*and increment the offset, wrapping to 0 if needed*/ + /*(Dumb increment fixed thanks to Jussi Sainio)*/ + offset++; + if(offset >= samincy) + offset = 0; + } + + return 0; +} + +int srate (jack_nframes_t nframes, void *arg){ + printf ("the sample rate is now %lu/sec\n", nframes); + sr=nframes; + return 0; +} + +void error (const char *desc){ + fprintf (stderr, "JACK error: %s\n", desc); +} + +void jack_shutdown (void *arg){ + exit (1); +} + +void usage(void) { + fprintf (stderr, "usage: %s [Hz [ms]]\n", name); +} + +int main (int argc, char *argv[]){ + jack_client_t *client; + const char **ports; + + name = argv[0]; + + if (argc < 2) { + usage(); + return 1; + } + if (argc >= 2) { + tone = atoi(argv[1]); + if (tone == 0) { + usage(); + return 1; + } + fprintf(stderr, "tone: %dHz\n", tone); + if (argc >= 3) { + length = atoi(argv[2]) * 1000; + if (length == 0) { + usage(); + return 1; + } + fprintf(stderr, "length: %dms\n", length/1000); + } + } + + /* tell the JACK server to call error() whenever it + experiences an error. Notice that this callback is + global to this process, not specific to each client. + + This is set here so that it can catch errors in the + connection process + */ + jack_set_error_function (error); + + /* try to become a client of the JACK server */ + + if ((client = jack_client_open(argv[0], JackNullOption, NULL)) == 0) { + fprintf (stderr, "jack server not running?\n"); + return 1; + } + + /* tell the JACK server to call `process()' whenever + there is work to be done. + */ + + jack_set_process_callback (client, process, 0); + + /* tell the JACK server to call `srate()' whenever + the sample rate of the system changes. + */ + + + jack_set_sample_rate_callback (client, srate, 0); + + /* tell the JACK server to call `jack_shutdown()' if + it ever shuts down, either entirely, or if it + just decides to stop calling us. + */ + + jack_on_shutdown (client, jack_shutdown, 0); + + /* display the current sample rate. once the client is activated + (see below), you should rely on your own sample rate + callback (see above) for this value. + */ + printf ("engine sample rate: %lu\n", jack_get_sample_rate (client)); + + + sr=jack_get_sample_rate (client); + + /* create two ports */ + + + output_port = jack_port_register (client, "output", + JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); + + /* tell the JACK server that we are ready to roll */ + + if (jack_activate (client)) { + fprintf (stderr, "cannot activate client"); + return 1; + } + + /* connect the ports*/ + if ((ports = jack_get_ports (client, NULL, NULL, + JackPortIsPhysical|JackPortIsInput)) == NULL) { + fprintf(stderr, "Cannot find any physical playback ports\n"); + exit(1); + } + + int i=0; + while(ports[i]!=NULL){ + if (jack_connect (client, jack_port_name (output_port), ports[i])) { + fprintf (stderr, "cannot connect output ports\n"); + } + i++; + } + + free (ports); + + //while (1) { //scanf("%i %i", &tone, &length) == 2) { + char buf[BUFSIZ]; + while (fgets(buf, BUFSIZ, stdin) == buf) { + //if (strstr(buf, "Hz\n")) { + // sscanf(buf, "%i", &tone); + // fprintf(stderr, "%dHz\n", tone); + //} + //if (strstr(buf, "us\n")) { + // sscanf(buf, "%i", &length); + // fprintf(stderr, "%dus\n", length); + //} + + int length = 0; + int c; + int pos = 0, n; + while ((c = sscanf(buf + pos, "%i%i%n", &tone, &length, &n)) == 2) { + + if (length > 0) { + usleep(length * 1000); + } + + pos += n; + + fprintf(stderr, "%dHz %dms\n", tone, length); + } + } + ///* 3 seconds of bleep is plenty*/ + ///usleep(length); + jack_client_close(client); + + exit(0); +} diff --git "a/Cancer/K\303\274belwagen/playmobil" "b/Cancer/K\303\274belwagen/playmobil" new file mode 100755 index 00000000..51ed70d6 --- /dev/null +++ "b/Cancer/K\303\274belwagen/playmobil" @@ -0,0 +1,12 @@ +#! /bin/sh +file=`mktemp` +trap "rm -f $file" EXIT INT TERM + +gcc -xc -lm -o $file - < +main(t) { + for (t=${2-0};;++t) putchar($1); +} +EOF + +$file | aplay diff --git "a/Cancer/K\303\274belwagen/sin.js" "b/Cancer/K\303\274belwagen/sin.js" new file mode 100644 index 00000000..0f472715 --- /dev/null +++ "b/Cancer/K\303\274belwagen/sin.js" @@ -0,0 +1,37 @@ + + + +var x = 3000; + +var t = 0; +var i = 0; +var j = 0.00001; +var t0 = new Date(); +(function rec () { + + var t1 = new Date(); + console.error('dt = ' + (t1 - t0)); + t0 = t1; + + if (x === 3000) { + x = 1000; + } else { + x = 3000; + }; + + console.log('2000 50 0 50 2000 50 0 50 ' + x + ' 100 0 0'); + return setTimeout(rec, 1000); + + i += 0.01; + console.log((2000 + Math.sin(i) * 1000 | 0) + ' 0'); + return setTimeout(rec, 1); + + var f = Math.abs(1000 + 500 * Math.tan( t )); + var scale = 1; + + console.log(((f * scale)|0) + ' 0'); + + t++; + setTimeout(rec, 100); + //process.nextTick(rec); +})(); diff --git "a/K\303\274belwagen/Makefile" "b/K\303\274belwagen/Makefile" deleted file mode 100644 index 9be84e13..00000000 --- "a/K\303\274belwagen/Makefile" +++ /dev/null @@ -1,14 +0,0 @@ - -CC := gcc -std=c99 -CFLAGS := -D_XOPEN_SOURCE=500 -LIBS := $(shell pkg-config --cflags --libs jack) -lm - -.PHONY: all clean - -all: a.out - -clean: - rm -f a.out - -a.out: index.c - $(CC) $(CFLAGS) -o $@ $^ $(LIBS) diff --git "a/K\303\274belwagen/alarm" "b/K\303\274belwagen/alarm" deleted file mode 100755 index a117c433..00000000 --- "a/K\303\274belwagen/alarm" +++ /dev/null @@ -1,27 +0,0 @@ -#! /bin/sh -# -# //Kübelwagen/alarm SLEEPARGS... -# -# where SLEEPARGS are passed to sleep(3) -# -set -euf -cd $(dirname $(readlink -f $0)) -exec >&2 - -make - -jackd -d alsa & -trap "kill -0 $! && kill $!" EXIT INT - -for i in `seq 8000 1000 10000`; do - echo $i 100 -done | ./a.out 1 -echo 'if you heard that sound, then goto sleep..^_^' - -echo sleep "$@" -sleep "$@" - -echo 'wake up!' -while :; do - echo $(echo "($(od -tu -An -N 2 /dev/urandom)%1000)+500"|bc) $(echo "($(od -tu -An -N 2 /dev/urandom)%500)+100"|bc) -done | ./a.out 1 diff --git "a/K\303\274belwagen/index.c" "b/K\303\274belwagen/index.c" deleted file mode 100644 index 9a15c7c3..00000000 --- "a/K\303\274belwagen/index.c" +++ /dev/null @@ -1,206 +0,0 @@ -#include -#include -#include -#include -#include - -#include - -const double PI = 3.14; - -/*Our output port*/ -jack_port_t *output_port; - -typedef jack_default_audio_sample_t sample_t; - -/*The current sample rate*/ -jack_nframes_t sr; - -/*samples in cycle*/ -jack_nframes_t samincy; -/*the current offset*/ -long offset=0; - -/*frequency of our sound*/ -int tone = 262; -int length = 1000000; - -char const *name = ""; - -int process (jack_nframes_t nframes, void *arg){ - /*grab our output buffer*/ - sample_t *out = (sample_t *) jack_port_get_buffer - (output_port, nframes); - - int _tone = tone > 0 ? tone : 1; - - /*For each required sample*/ - for(jack_nframes_t i=0;i < nframes;i++){ - /*Copy the sample at the current position in the cycle to the buffer*/ - - jack_nframes_t samincy = sr / _tone; - sample_t scale = 2 * PI / samincy; - out[i] = sin(offset * scale); - - /*and increment the offset, wrapping to 0 if needed*/ - /*(Dumb increment fixed thanks to Jussi Sainio)*/ - offset++; - if(offset >= samincy) - offset = 0; - } - - return 0; -} - -int srate (jack_nframes_t nframes, void *arg){ - printf ("the sample rate is now %lu/sec\n", nframes); - sr=nframes; - return 0; -} - -void error (const char *desc){ - fprintf (stderr, "JACK error: %s\n", desc); -} - -void jack_shutdown (void *arg){ - exit (1); -} - -void usage(void) { - fprintf (stderr, "usage: %s [Hz [ms]]\n", name); -} - -int main (int argc, char *argv[]){ - jack_client_t *client; - const char **ports; - - name = argv[0]; - - if (argc < 2) { - usage(); - return 1; - } - if (argc >= 2) { - tone = atoi(argv[1]); - if (tone == 0) { - usage(); - return 1; - } - fprintf(stderr, "tone: %dHz\n", tone); - if (argc >= 3) { - length = atoi(argv[2]) * 1000; - if (length == 0) { - usage(); - return 1; - } - fprintf(stderr, "length: %dms\n", length/1000); - } - } - - /* tell the JACK server to call error() whenever it - experiences an error. Notice that this callback is - global to this process, not specific to each client. - - This is set here so that it can catch errors in the - connection process - */ - jack_set_error_function (error); - - /* try to become a client of the JACK server */ - - if ((client = jack_client_open(argv[0], JackNullOption, NULL)) == 0) { - fprintf (stderr, "jack server not running?\n"); - return 1; - } - - /* tell the JACK server to call `process()' whenever - there is work to be done. - */ - - jack_set_process_callback (client, process, 0); - - /* tell the JACK server to call `srate()' whenever - the sample rate of the system changes. - */ - - - jack_set_sample_rate_callback (client, srate, 0); - - /* tell the JACK server to call `jack_shutdown()' if - it ever shuts down, either entirely, or if it - just decides to stop calling us. - */ - - jack_on_shutdown (client, jack_shutdown, 0); - - /* display the current sample rate. once the client is activated - (see below), you should rely on your own sample rate - callback (see above) for this value. - */ - printf ("engine sample rate: %lu\n", jack_get_sample_rate (client)); - - - sr=jack_get_sample_rate (client); - - /* create two ports */ - - - output_port = jack_port_register (client, "output", - JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); - - /* tell the JACK server that we are ready to roll */ - - if (jack_activate (client)) { - fprintf (stderr, "cannot activate client"); - return 1; - } - - /* connect the ports*/ - if ((ports = jack_get_ports (client, NULL, NULL, - JackPortIsPhysical|JackPortIsInput)) == NULL) { - fprintf(stderr, "Cannot find any physical playback ports\n"); - exit(1); - } - - int i=0; - while(ports[i]!=NULL){ - if (jack_connect (client, jack_port_name (output_port), ports[i])) { - fprintf (stderr, "cannot connect output ports\n"); - } - i++; - } - - free (ports); - - //while (1) { //scanf("%i %i", &tone, &length) == 2) { - char buf[BUFSIZ]; - while (fgets(buf, BUFSIZ, stdin) == buf) { - //if (strstr(buf, "Hz\n")) { - // sscanf(buf, "%i", &tone); - // fprintf(stderr, "%dHz\n", tone); - //} - //if (strstr(buf, "us\n")) { - // sscanf(buf, "%i", &length); - // fprintf(stderr, "%dus\n", length); - //} - - int length = 0; - int c; - int pos = 0, n; - while ((c = sscanf(buf + pos, "%i%i%n", &tone, &length, &n)) == 2) { - - if (length > 0) { - usleep(length * 1000); - } - - pos += n; - - fprintf(stderr, "%dHz %dms\n", tone, length); - } - } - ///* 3 seconds of bleep is plenty*/ - ///usleep(length); - jack_client_close(client); - - exit(0); -} diff --git "a/K\303\274belwagen/playmobil" "b/K\303\274belwagen/playmobil" deleted file mode 100755 index 51ed70d6..00000000 --- "a/K\303\274belwagen/playmobil" +++ /dev/null @@ -1,12 +0,0 @@ -#! /bin/sh -file=`mktemp` -trap "rm -f $file" EXIT INT TERM - -gcc -xc -lm -o $file - < -main(t) { - for (t=${2-0};;++t) putchar($1); -} -EOF - -$file | aplay diff --git "a/K\303\274belwagen/sin.js" "b/K\303\274belwagen/sin.js" deleted file mode 100644 index 0f472715..00000000 --- "a/K\303\274belwagen/sin.js" +++ /dev/null @@ -1,37 +0,0 @@ - - - -var x = 3000; - -var t = 0; -var i = 0; -var j = 0.00001; -var t0 = new Date(); -(function rec () { - - var t1 = new Date(); - console.error('dt = ' + (t1 - t0)); - t0 = t1; - - if (x === 3000) { - x = 1000; - } else { - x = 3000; - }; - - console.log('2000 50 0 50 2000 50 0 50 ' + x + ' 100 0 0'); - return setTimeout(rec, 1000); - - i += 0.01; - console.log((2000 + Math.sin(i) * 1000 | 0) + ' 0'); - return setTimeout(rec, 1); - - var f = Math.abs(1000 + 500 * Math.tan( t )); - var scale = 1; - - console.log(((f * scale)|0) + ' 0'); - - t++; - setTimeout(rec, 100); - //process.nextTick(rec); -})(); diff --git a/god/uino/morse/morse.pde b/god/uino/morse/morse.pde new file mode 100644 index 00000000..685f5092 --- /dev/null +++ b/god/uino/morse/morse.pde @@ -0,0 +1,164 @@ +#include + +/* + Implementes the Morse algorithm for a simple speaker + + @author Felix + @date 07.05.2011 + */ +int inByte = 0; +int i = 0; +int j = 0; +int char_avail = 0; + +/* You can touch this: */ +#define DIT_DELAY 50 + + +/* But you cannot touch this: */ +#define WORD_DELAY (DIT_DELAY * 7) +#define DIT_CYCLES (DIT_DELAY/2) +#define CHAR_DELAY (DIT_DELAY * 3) + +#define dsym() delay(DIT_DELAY); +#define char_delay() delay(CHAR_DELAY); +#define word_delay() delay(WORD_DELAY); + + +static char* latin_upper[] = { + ". -\0" , /* A */ + "- . . .\0" + "- . . .\0", + "- . - .\0", + "- . .\0", + ".\0", + ". . - .\0", + "- - .\0", + ". . . .\0", + ". .\0", + ". - - -\0", + "- . -\0", + ". - . .\0", + "- -\0", + "- .\0", + "- - -\0", + ". - - .\0", + "- - . -\0", + ". - .\0", + ". . .\0", + "-\0", + ". . -\0", + ". . . -\0", + ". - -\0", + "- . . -\0", + "- . - -\0", + "- - . .\0" /* Z */ +}; +static char* numbers[] = { + "- - - - -\0", /* 0 */ + ". - - - -\0", + ". . - - -\0", + ". . . - -\0", + ". . . . -\0", + ". . . . .\0", + "- . . . .\0", + "- - . . .\0", + "- - - . .\0", + "- - - - .\0" /* 9 */ +}; + +void setup() { + // initialize the digital pin as an output. + // Pin 13 has an LED connected on most Arduino boards: + pinMode(13, OUTPUT); + Serial.begin(9600); +} + + + +void loop() { + char_avail = Serial.available(); + + if(char_avail > 0) { + for (j = 0; j < char_avail;j++) + { + char on_line = Serial.read(); + to_beep(on_line); + char_delay(); + } + } +} + +void to_beep(char data) +{ + char* mdata; + if (data == ' ') + { + word_delay(); + Serial.println("word end"); + return; + } + else{ + if (data == '\n') { + word_delay(); + Serial.println("EOL"); + return; + } else + if (data >= 'A' && data <= 'Z' ) + mdata = latin_upper[data-'A']; + else + if (data >= 'a' && data <= 'z' ) + mdata = latin_upper[data-'a']; + else + if (data >= '0' && data <= '9') + mdata = numbers[data-'0']; + else + { + Serial.print(data); + Serial.println(": not implemented"); + return; + } + } + + Serial.println(mdata); + int sdata = strlen( mdata); + for( char i = 0; i < sdata; i ++) + { + + char token = mdata[i]; + if (token == '.') + { + dit(); + } + if (token == '-') + { + dah(); + } + if (token == ' ') + { + dsym(); + } + + } + +} +void dah() { + for (int i=0;i<3;i++) + { + dit(); + } +} + +void dit(){ + + for (int i=0;i - -/* - Implementes the Morse algorithm for a simple speaker - - @author Felix - @date 07.05.2011 - */ -int inByte = 0; -int i = 0; -int j = 0; -int char_avail = 0; - -/* You can touch this: */ -#define DIT_DELAY 50 - - -/* But you cannot touch this: */ -#define WORD_DELAY (DIT_DELAY * 7) -#define DIT_CYCLES (DIT_DELAY/2) -#define CHAR_DELAY (DIT_DELAY * 3) - -#define dsym() delay(DIT_DELAY); -#define char_delay() delay(CHAR_DELAY); -#define word_delay() delay(WORD_DELAY); - - -static char* latin_upper[] = { - ". -\0" , /* A */ - "- . . .\0" - "- . . .\0", - "- . - .\0", - "- . .\0", - ".\0", - ". . - .\0", - "- - .\0", - ". . . .\0", - ". .\0", - ". - - -\0", - "- . -\0", - ". - . .\0", - "- -\0", - "- .\0", - "- - -\0", - ". - - .\0", - "- - . -\0", - ". - .\0", - ". . .\0", - "-\0", - ". . -\0", - ". . . -\0", - ". - -\0", - "- . . -\0", - "- . - -\0", - "- - . .\0" /* Z */ -}; -static char* numbers[] = { - "- - - - -\0", /* 0 */ - ". - - - -\0", - ". . - - -\0", - ". . . - -\0", - ". . . . -\0", - ". . . . .\0", - "- . . . .\0", - "- - . . .\0", - "- - - . .\0", - "- - - - .\0" /* 9 */ -}; - -void setup() { - // initialize the digital pin as an output. - // Pin 13 has an LED connected on most Arduino boards: - pinMode(13, OUTPUT); - Serial.begin(9600); -} - - - -void loop() { - char_avail = Serial.available(); - - if(char_avail > 0) { - for (j = 0; j < char_avail;j++) - { - char on_line = Serial.read(); - to_beep(on_line); - char_delay(); - } - } -} - -void to_beep(char data) -{ - char* mdata; - if (data == ' ') - { - word_delay(); - Serial.println("word end"); - return; - } - else{ - if (data == '\n') { - word_delay(); - Serial.println("EOL"); - return; - } else - if (data >= 'A' && data <= 'Z' ) - mdata = latin_upper[data-'A']; - else - if (data >= 'a' && data <= 'z' ) - mdata = latin_upper[data-'a']; - else - if (data >= '0' && data <= '9') - mdata = numbers[data-'0']; - else - { - Serial.print(data); - Serial.println(": not implemented"); - return; - } - } - - Serial.println(mdata); - int sdata = strlen( mdata); - for( char i = 0; i < sdata; i ++) - { - - char token = mdata[i]; - if (token == '.') - { - dit(); - } - if (token == '-') - { - dah(); - } - if (token == ' ') - { - dsym(); - } - - } - -} -void dah() { - for (int i=0;i<3;i++) - { - dit(); - } -} - -void dit(){ - - for (int i=0;i