Write the prettiest bytebeat composition

24

11

Bytebeat is a style of music one can compose by writing a simple C program that's output is piped to aplay or /dev/dsp.

main(t){for(;;t++)putchar(((t<<1)^((t<<1)+(t>>7)&t>>12))|t>>(4-(1^7&(t>>19)))|t>>7);}

There is a good deal of information on the bytebeat site, a javascript implementation, and more demos and example compositions in this thread.

Very simple rules : Try to write a pretty sounding composition. Most up votes wins since that's obviously subjective, although not that subjective considering the usual results.

Jeff Burdges

Posted 2012-01-24T04:28:07.670

Reputation: 445

Something like this maybe? It states that there is a correlation between our enjoyment of music and how much it can be compressed. I doubt it is reliable in any way but it is an objective winning criteria

– Aaron – 2016-07-21T13:10:28.063

4Useful blog article – JiminP – 2012-01-24T06:28:58.413

Are you holding this to strict bytebeat (i.e. no buffers)? – Peter Taylor – 2012-01-24T12:43:46.720

4Why is it restricted to C? – user unknown – 2012-01-24T15:04:49.643

There isn't afaik any intrinsic reason to restrict using buffers or other languages, but usually bytebeat means that particular C loop with the output defined by a formula. I voted up Joey Adams answer even thought rand() is non-standard. – Jeff Burdges – 2012-01-24T15:51:53.090

While I like this idea, the FAQ calls for an objective winning criteria (it's too easy to get trapped in calculations or ASCII art). Can we look for something better defined than "pretty"? – dmckee --- ex-moderator kitten – 2012-01-24T16:44:53.090

Also it should be tagged with one of [code-golf], [code-challenge], [king-of-the-hill], etc. I assume that you want [code-challenge] for this one. – dmckee --- ex-moderator kitten – 2012-01-24T16:46:55.347

Any suggestions? I donno much music theory, but melodic or harmonic might be over specified. How about "Write a bytebeat composition that doesn't sound too computer generated", not necessarily more objective, but specificity often yields objectivity in practice. I doubt you want the up votes by March 1st precedent – Jeff Burdges – 2012-01-24T19:20:40.007

Answers

16

(Signed 16-bit little endian, 8000Hz mono (--format=S16_LE))

Music

Much better than before! (although it's quite long)

main(t){for(;;t++)putchar(((7&(((t>>17)+1)>>2)+((t>>10)&1+2*(t>>18&1))*(("23468643"[7&t>>12]-48)+(3&t>>11))+((3&t>>17)>0)*(3&t>>9)*!(1&t>>10)*(((2+t>>10&3)^(2+t>>11&3))))*t*"@06+"[3&t>>15]/32));}

(You can listen this at here)

I wrote this, but even I don't know how some part works, like >0 and (especially) the first 7&.

Change for loop to for(;!(t>>22);t++)... to listen it 'once'. I don't know whether it "loops" exactly the same way, however.

Melody (base of above music)

I love this melody I made (C-G-A-F ftw), but it's too 'plain'...

main(t){for(;;t++)putchar(((t>>10)&1)*(t*("23468643"[7&t>>12]-48)+t*(3&t>>11))*"@06+"[3&t>>15]/32);}

Simple music (which I made before)

main(t){for(;;t++)putchar(t*(3&t>>11)+(t&t>>11)*4*!((t>>11)%3));}

JiminP

Posted 2012-01-24T04:28:07.670

Reputation: 3 264

If you click the above bytebeat link, you'll see a sox command line to convert it to a .wav file, and an odd compressor command line. – Jeff Burdges – 2012-01-24T15:57:47.293

3+1 Amazing! A few bits (e.g. 1:30 - 1:40) sound kind of "stuttering", but then again, much of the very charm of bytebeat is in these odd and unconventional rhythms and melodies, and the overall effect is excellent. (Ps. I accidentally played this at 8 bits per sample, and I sounds surprisingly good that way too. Sort of like playing a 45 rpm vinyl at 33.3 rpm.) – Ilmari Karonen – 2012-01-25T19:14:17.420

3

The ruler function in C minor:

#include <math.h>
#include <stdio.h>

#define PI 3.14159265358979323846

#define step(freq, n) ((freq) * pow(2, (n) / 12.0))
#define note(n)       step(440, n)
#define MIDDLE_C      note(-9)

int count_zeros(unsigned int n)
{
    int count = 0;
    for (; (n & 1) == 0; n >>= 1)
        count++;
    return count;
}

int minor_note(int note)
{
    int octave = note / 7;
    int scale[] = {0, 2, 3, 5, 7, 8, 10};

    note %= 7;
    if (note < 0) {
        note += 7;
        octave--;
    }

    return scale[note] + octave*12;
}

int main(void) {
    double t = 0.0;
    double freq = MIDDLE_C * 2;
    double step = PI * 2 / 8192;
    int n = 0;
    int i = 0;

    for (i = 1;; t += step, i++) {
        if (i == 1024) {
            i = 0;
            n++;
            freq = step(MIDDLE_C, minor_note(count_zeros(n)));
        }

        putchar(sin(t * freq) * 50.0 + 128.0);
    }

    return 0;
}

Joey Adams

Posted 2012-01-24T04:28:07.670

Reputation: 9 929

Nice melody, but to be a "composition" this IMO needs something more... – Ilmari Karonen – 2012-01-25T19:20:01.610

3

main(t){for(;;t+=(t%6)?1:2)putchar((((t<<t^(t>>8))|(t<<7))*((t<<t&(t>>12))|(t<<10))));}

Pubby

Posted 2012-01-24T04:28:07.670

Reputation: 1 239

Very classic bytebeat, if that's not an oxymoron. +1 from me. – Ilmari Karonen – 2012-01-25T19:27:33.630

3

Emphasising "beat" over "byte":

#include<math.h>

double s(double,double);double r(double,double);double d(double);double f(double);

char bytebeat(int t){return (d(f(t/4000.)/3) + 1) * 63;}
double f(double t){
  double sn=s(1./2,t-1); sn*=(sn*sn);
  return 3*s(1./4,1/s(1,t))+3*s(4,1/sn)/2+s(4,1/(sn*sn*sn*sn*sn))/4
       +2*s(55+18.3*r(1./2,t),t)+s(110+s(5,t)/4000,t)*s(1,t)+s(220+110*r(1,t)+55*r(3,t),t)/5
       +s(880+440*r(1./2,t)-220*r(1,t)+110*r(2,t)+s(5,t)/4000,t)
       *(2+s(1760+438*r(3./2,t)-1234*r(2,t)+423*r(5,t),t))/9
       +s(s(1,t)+s(1./2,t)+s(1./4,t)+s(1./8,t),t)*s(s(1,t)+s(1./2,t)+s(1./4,t)+s(1./8,t)+1,t)
       +r(264+11*r(1./20,t),t)*s(1./20,t);
}
double s(double f,double t){return d(sin(f*3.14159265*(t+999)));}
double r(double f,double t){return s(f,t)<0;}
double d(double a){return tanh(a+a*a/4);}

main(t){for(;;++t)putchar(bytebeat(t));}

To be used at 8 kHz, uint8 mono. Sounds best over decently bass-capable loudspeakers.

ceased to turn counterclockwis

Posted 2012-01-24T04:28:07.670

Reputation: 5 200

2

main(){for(;;)putchar(rand());}

Sounds like the ocean ;-)

Joey Adams

Posted 2012-01-24T04:28:07.670

Reputation: 9 929

2@B1KMusic much more simple: aplay /dev/urandom – minmaxavg – 2015-05-01T07:04:41.180

3easier way: $ cat /dev/urandom | aplay – Braden Best – 2014-05-25T01:46:09.170

1More like a really busy railway crossing to me. :) – Ilmari Karonen – 2012-01-25T19:23:44.450

5Protip: if it sounds like a continuous tone, your RNG is broke. – Mr. Llama – 2012-01-25T23:15:33.840

0

Combined melody and harmony:

r=3,
r=3,
m=(t*(t>>12|t>>13|t>>14|t>>15|t>>16|t>>17|t>>18))&63,

h= ((t&t>>7&t>>6)|t*5&t>>8-c^t*6&t>>9-c|t*7&t>>12-c^t*9&t>>11-c^t*11&t>>22^t*19&t>>20^t*14&t>>20|t*23&t>>15-c|t*12&t>>9|t*30&t>>30|t>>5|t>>4)-31, m|h

Kenn Downey

Posted 2012-01-24T04:28:07.670

Reputation: 1