Bytebeat: Difference between revisions

From Noisebridge
Jump to navigation Jump to search
 
(27 intermediate revisions by 19 users not shown)
Line 97: Line 97:
  python -c'import sys;[sys.stdout.write(chr(( t|(((t>>1)%(8+(t>>14)%4))+(t>>6))              )%256)) for t in xrange(2**18)]'|aplay
  python -c'import sys;[sys.stdout.write(chr(( t|(((t>>1)%(8+(t>>14)%4))+(t>>6))              )%256)) for t in xrange(2**18)]'|aplay
  python -c'import sys;[sys.stdout.write(chr(( t*(3+(t>>10)%(4+(t>>11)%8))|(t>>5)            )%256)) for t in xrange(2**20)]'|aplay
  python -c'import sys;[sys.stdout.write(chr(( t*(3+(t>>10)%(4+(t>>11)%8))|(t>>5)            )%256)) for t in xrange(2**20)]'|aplay
python -c'import sys;[sys.stdout.write(chr(( t^(t+(t>>7))|t*((t>>(16-((t>>19)*4)))%8)      )%256)) for t in xrange(2**21)]'|aplay
python -c'import sys;[sys.stdout.write(chr(( t*(((t>>10)*(1+(t>>13)%7)*((t>>11)+(t>>12)+(t>>13)))%8) )%256)) for t in xrange(2**21)]'|aplay
python -c'import sys;[sys.stdout.write(chr(( (1+(t>>10)%7)*((t*(1+(t>>13)%4))%(24+(t>>14)*9%8)&16)*10 )%256))for t in xrange(2**20)]'|aplay
python -c'import sys;[sys.stdout.write(chr(( (((t>>((t>>16)%4))+t)&(t>>8))&(t>>6) )%256)) for t in xrange(2**19+2**18+2**16+2**12)]'|aplay


From @isislovecruft (#FYB):
From @isislovecruft (#FYB):
Line 103: Line 107:
  python -c'import sys;[sys.stdout.write(chr((((t*(t>>13|t>>8))|(t>>16)^t)-64)%256)) for t in xrange(2**18)]'|aplay
  python -c'import sys;[sys.stdout.write(chr((((t*(t>>13|t>>8))|(t>>16)^t)-64)%256)) for t in xrange(2**18)]'|aplay


=== in >140-character command lines, by @wiretapped ===
python -c'import sys;[sys.stdout.write(chr(( t*(1+((t>>10)*(43+(2*(t>>(15-((t>>16)%13)))%8)))%8)*(1+(t>>14)%4) )%256))for t in xrange(2**21)]'|aplay
python -c'import sys;[sys.stdout.write(chr( ((t*(1|(t>>10-((t>>17)%4))%8))&(8<<((t>>13)%4))*((1|(t>>15)%8))) *11*(t>>10) %256))for t in xrange(2**22)]'|aplay
python -c'import sys;[sys.stdout.write(chr(( (((t>>((t>>12)%4))+t*(1+(1+(t>>16)%6)*((t>>10))*(t>>11)%8))^(t>>13))^((t>>6))  )%256)) for t in xrange(2**21)]'|aplay
for OSX
for OSX


Line 109: Line 117:
   sox -r 8000 -c 1 -t u8 out.raw out.wav;
   sox -r 8000 -c 1 -t u8 out.raw out.wav;
   open out.wav
   open out.wav
OSX one-liner
  python -c'import sys; [sys.stdout.write(chr(((t*5&t>>7|t*9&t>>4|t*18&t/1024)|((t|7)>>5|(t|4)>>9))%256))for t in xrange(2**18)]' | sox -traw -r8000 -b8 -e unsigned-integer - -tcoreaudio


=== an attempt with luajit ===
=== an attempt with luajit ===
Line 134: Line 146:
   luajit 8bit.lua | sox -r 8000 -c 1 -t u8 - -d
   luajit 8bit.lua | sox -r 8000 -c 1 -t u8 - -d


=== Busybox Awk ===
=== busybox awk ===
It might work with Gawk, though it hasn't been tested.
gawk might also work.
Other awks don't have bit ops.
other awks lack bitshift operations.
Save and make executable, or call with awk -f
please add below if you test it.
then pipe to /dev/dsp for systems with OSS(BSD/Linux),
to aplay, or to sox for other systems.


     #/usr/bin/awk -f  
put this into your /dev/dsp pipe and smoke it.
 
     #!/bin/busybox awk -f  
     BEGIN{
     BEGIN{
       for (t=0;;t++){
       for (;;t++){
           printf("%c",and(t, rshift(t, 8)));
           printf("%c",and(t, rshift(t, 8)));
       }
       }
     }
     }


This will of course make awk eat your processor alive. And summon Chtulhu.
or @ your shell prompt
 
    seq 11111111 | busybox awk '{printf("%c",and($1,rshift($1,8)))}' > /dev/dsp


=== With Haskell! ===  
=== With Haskell! ===  
Line 158: Line 172:
* https://github.com/kragen/pytebeat - Python Bytebeat livecoding software in SDL
* https://github.com/kragen/pytebeat - Python Bytebeat livecoding software in SDL
* http://music.columbia.edu/~douglas/strange_things/?p=78 - Algorithmic beat rotation with the EchoNest API
* http://music.columbia.edu/~douglas/strange_things/?p=78 - Algorithmic beat rotation with the EchoNest API
[[Category:Python]]
[[Category:Lua]]
[[Category:Assembler]]

Latest revision as of 07:09, 20 November 2020

bytebeat in x86 assembler[edit]


 ; noise.asm -- just fooling around :-)
 ; mct and leif, ; Sun Feb 19 19:08:13 PST 2012
 ; 
 ; Build with:
 ;
 ;       nasm -felf32 noise.asm
 ;       ld -melf_i386 -o noise noise.o
 ;
 ; Run with:
 ;
 ;       ./noise | aplay
 ;
 ; Equivalent to:
 ;        python -c'import sys;[sys.stdout.write(chr((t>>10^t>>(t>>13)%4)%256)) for t in xrange(2**20)]' |aplay

 global _start

 section .data

 section .bss

         var:    resb 1  ; one bye variable

 section .text

         ; f(x) = (x >> 10 ^ x>>((x>>13)%4)) % 256

         _start: mov esi, 0

                 ;int 3

         .loop: 

                 mov edi, esi
                 shr edi, 13 ; edi := x >> 13

                 mov eax, edi
                 cwd
                 mov bx, 4
                 div bx  ; dx := (x >> 13) % 4

                 mov eax, esi
                 mov cx, dx
                 shr eax, cl   ; eax := x >> ((x >> 13) % 4)

                 mov edi, esi
                 shr edi, 10   ; edi := x >> 10

                 xor eax, edi
                 mov [var], al

                 mov eax, 4      ; sys_write
                 mov ebx, 1      ; stdout
                 mov ecx, var    ; buffer
                 mov edx, 1      ; length
                 int 80h         ; syscall

                 inc esi
                 jmp .loop
 

 ### Basic Sierpinski harmony bytebeat t & t >> 8 in as few bytes as possible:
         .globl _start
 _start: inc %ebx             # output fd 1 in %ebx for write()
         inc %edx             # byte count of 1 in %edx for write()
 loop:   inc %eax             # increment t each time through the loop
         push %eax            # save it on the stack
         and %ah, %al         # compute t & t >> 8, our output sample
         push %eax            # store it on the stack for write()
         lea 3(%ebx), %eax    # a three-byte way to set %eax to 4 (__NR_write)
         mov %esp, %ecx       # pass sample pointer to write() (little-endian!)
         int $0x80            # invoke system call
         pop %eax             # discard sample
         pop %eax             # restore t into %eax
         jmp loop             # and repeat
 ### Kragen Javier Sitaker
 ### 2012-01-10

 

Compile with gcc -m32 -nostdlib and pipe the output to aplay. After stripping, the ELF is 240 bytes; size(1) says it has 18 bytes of code.

bytebeat in <140-character command lines with python[edit]

From @wiretapped:

python -c'import sys;[sys.stdout.write(chr(( t^t>>(t>>11)%3^t>>(t>>12)%4                    )%256)) for t in xrange(2**19)]'|aplay
python -c'import sys;[sys.stdout.write(chr(( t>>(t>>11)%4^(t>>10)*(t>>15)                   )%256)) for t in xrange(2**19)]'|aplay
python -c'import sys;[sys.stdout.write(chr(( t<<3+(t>>10)%3^t>>4+(t>>12)%4^t**(2+(t>>13)%8) )%256)) for t in xrange(2**18)]'|aplay
python -c'import sys;[sys.stdout.write(chr(( t^t>>4^(t*((t>>(11+(t>>16)%3))%16))^t*3        )%256)) for t in xrange(2**20)]'|aplay
python -c'import sys;[sys.stdout.write(chr(( t+(t>>(5+(t>>10)%4)^t)                         )%256)) for t in xrange(2**21)]'|aplay
python -c'import sys;[sys.stdout.write(chr(( t+(t>>(5+(t>>10)%8))^t|t>>12                   )%256)) for t in xrange(2**21)]'|aplay
python -c'import sys;[sys.stdout.write(chr(( t|(((t>>1)%(8+(t>>14)%4))+(t>>6))              )%256)) for t in xrange(2**18)]'|aplay
python -c'import sys;[sys.stdout.write(chr(( t*(3+(t>>10)%(4+(t>>11)%8))|(t>>5)             )%256)) for t in xrange(2**20)]'|aplay
python -c'import sys;[sys.stdout.write(chr(( t^(t+(t>>7))|t*((t>>(16-((t>>19)*4)))%8)       )%256)) for t in xrange(2**21)]'|aplay
python -c'import sys;[sys.stdout.write(chr(( t*(((t>>10)*(1+(t>>13)%7)*((t>>11)+(t>>12)+(t>>13)))%8) )%256)) for t in xrange(2**21)]'|aplay
python -c'import sys;[sys.stdout.write(chr(( (1+(t>>10)%7)*((t*(1+(t>>13)%4))%(24+(t>>14)*9%8)&16)*10 )%256))for t in xrange(2**20)]'|aplay
python -c'import sys;[sys.stdout.write(chr(( (((t>>((t>>16)%4))+t)&(t>>8))&(t>>6) )%256)) for t in xrange(2**19+2**18+2**16+2**12)]'|aplay

From @isislovecruft (#FYB):

python -c'import sys;[sys.stdout.write(chr(((~t>>2)*(2+(42&t*((7&t>>10)*2))<(24&t*((3&t>>14)+2))))%256))for t in xrange(2**19)]'|aplay
python -c'import sys;[sys.stdout.write(chr((((t*5&t>>7|t*9&t>>4|t*18&t/1024)|((t|7)>>5|(t|4)>>9))) %256))for t in xrange(2**18)]'|aplay
python -c'import sys;[sys.stdout.write(chr((((t*(t>>13|t>>8))|(t>>16)^t)-64)%256)) for t in xrange(2**18)]'|aplay

in >140-character command lines, by @wiretapped[edit]

python -c'import sys;[sys.stdout.write(chr(( t*(1+((t>>10)*(43+(2*(t>>(15-((t>>16)%13)))%8)))%8)*(1+(t>>14)%4) )%256))for t in xrange(2**21)]'|aplay
python -c'import sys;[sys.stdout.write(chr( ((t*(1|(t>>10-((t>>17)%4))%8))&(8<<((t>>13)%4))*((1|(t>>15)%8))) *11*(t>>10) %256))for t in xrange(2**22)]'|aplay
python -c'import sys;[sys.stdout.write(chr(( (((t>>((t>>12)%4))+t*(1+(1+(t>>16)%6)*((t>>10))*(t>>11)%8))^(t>>13))^((t>>6))   )%256)) for t in xrange(2**21)]'|aplay

for OSX

 brew install sox
 python -c'import sys; [sys.stdout.write(chr(((t*5&t>>7|t*9&t>>4|t*18&t/1024)|((t|7)>>5|(t|4)>>9))%256))for t in xrange(2**18)]' > out.raw; 
 sox -r 8000 -c 1 -t u8 out.raw out.wav;
 open out.wav

OSX one-liner

 python -c'import sys; [sys.stdout.write(chr(((t*5&t>>7|t*9&t>>4|t*18&t/1024)|((t|7)>>5|(t|4)>>9))%256))for t in xrange(2**18)]' | sox -traw -r8000 -b8 -e unsigned-integer - -tcoreaudio

an attempt with luajit[edit]

 local bit = require'bit'
 local ffi = require'ffi'
 
 ffi.cdef[[
   int putchar(int c);
 ]]
 
 local putc = ffi.C.putchar
 local rsh  = bit.rshift
 local lsh  = bit.lshift
 local band = bit.band
 local bor  = bit.bor
 local bxor = bit.bxor
 
 for t=0, math.huge do
   putc( band(t, rsh(t, 8)) )
 end

run it on osx:

 luajit 8bit.lua | sox -r 8000 -c 1 -t u8 - -d

busybox awk[edit]

gawk might also work. other awks lack bitshift operations. please add below if you test it.

put this into your /dev/dsp pipe and smoke it.

   #!/bin/busybox awk -f 
   BEGIN{
      for (;;t++){
         printf("%c",and(t, rshift(t, 8)));
      }
   }

or @ your shell prompt

   seq 11111111 | busybox awk '{printf("%c",and($1,rshift($1,8)))}' > /dev/dsp

With Haskell![edit]

http://yaxu.org/haskell-hack/

links[edit]