Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

The Ultimate ████ Mix

Name: Anonymous 2011-11-14 3:59

Compile the following program with: gcc -Os -s -std=gnu99 -Wno-trigraphs -lm -o progmix progmix.c
Pipe the output from the program into an audio playback device as unsigned 8-bit mono PCM @ 8000hz: ./progmix | aplay OR ./progmix | /dev/dsp

Brought to you by ``StrawberryShake''

P.S. - [spoiler]tdavis can't generate music for shit[/code]

//progmix.c
#include <math.h>
#include <stdint.h>
#include <stdio.h>

int main(void) {
    const char melody_notes[] = "IQNNNN!!]]!Q!IWJWQNN??!!W]WQNNN?";
    const double bass_notes[4] = { 3.0, 3.0, 4.75, 2.0 };
    double a, d, m, b, drum, melody, bass, sample;
    uint32_t t, w, v, p;
    for (t = 0; ; t++) {
        w = t >> 9;
        v = w >> 7;
        p = (w >> 5) & 0x03;
        a = 1.0 - fmod(t / 2048.0, 1.0);
        b = bass_notes[p] * t / 4.0;
        d = a * fmod((14 * t * t) ^ t, 2048.0);
        m = (melody_notes[((w >> 1) & 0x0F) | ((p / 3) << 4)] / 33.0 * t) - t;
        bass = fmod(b * 0.98, 80.0) + fmod(b, 80.0);
        drum = (((uint32_t)(fmod(5.0 * t, 2048.0) * a) & 128) * ((0x53232323 >> (w / 4)) & 1)) + (((uint32_t)d & 127) * ((0xA444C444 >> (w / 4)) & 1)) + ((uint32_t)(d * w) & 1);
        melody = (fmod(m, 32.0) + fmod(m * 1.99, 32.0) + fmod(m * 0.49, 32.0) + fmod(m * 0.97, 32.0) - 64.0) * (4.0 - a - a - a);
        sample = bass + (a * ((v ? drum : 0.0) + (v > 1 ? melody : 0.0)));
        sample = (sample >= 0.0) ? sample : 0.0;
        putchar(((uint32_t)(sample * sample) >> 14) ? 127 : (int)sample);
    }
    return 0;
}

Name: Anonymous 2011-11-14 4:03

And I can't close my spoiler tags for shit.

Name: Anonymous 2011-11-14 6:07

>>1

import pyaudio
from math import fmod

def generator():
    melody_notes = 'IQNNNN!!]]!Q!IWJWQNN??!!W]WQNNN?'
    bass_notes = [3.0, 3.0, 4.75, 2.0]
    for t in xrange(2**30):
        w = t >> 9
        v = w >> 7
        p = (w >> 5) & 0x03
        a = 1.0 - fmod(t / 2048.0, 1.0)
        b = bass_notes[p] * t / 4.0
        d = a * fmod((14 * t * t) ^ t, 2048.0)
        m = (ord(melody_notes[((w >> 1) & 0x0F) | ((p / 3) << 4)]) / 33.0 * t) - t
        bass = fmod(b * 0.98, 80.0) + fmod(b, 80.0)
        drum = ((int(fmod(5.0 * t, 2048.0) * a) & 128) * ((0x53232323 >> ((w / 4) % 32)) & 1)) + ((int(d) & 127) * ((0xA444C444 >> ((w / 4) % 32)) & 1)) + (int(d * w) & 1)
        melody = (fmod(m, 32.0) + fmod(m * 1.99, 32.0) + fmod(m * 0.49, 32.0) + fmod(m * 0.97, 32.0) - 64.0) * (4.0 - a - a - a)
        sample = bass + (a * ((drum if v else 0.0) + (melody if v > 1 else 0.0)))
        sample = min(127, int(sample)) if sample >= 0.0 else 0
        yield sample

if __name__ == '__main__':
    device = pyaudio.PyAudio()
    stream = device.open(format = pyaudio.paInt8, channels = 1, rate = 8000, output = True)
    for sample in generator():
        stream.write(chr(sample))


Does it sound the same? I almost fucked up the drums for instance...

Name: Anonymous 2011-11-14 6:13

>>1
Also, tattoo this on the inside of your eyelids, please: §6.5.7.3: if the value of the right operand is negative or is greater than or equal to the width of the promoted left operand, the behavior is undefined.

Name: Anonymous 2011-11-14 6:39

This is some epic shit. Made my day, thanks

Name: Anonymous 2011-11-14 7:51

I'm having a good time! Yeah!
This is good, good shit!

Name: Anonymous 2011-11-14 8:12

I just came up with another one. I call it ``Unrelenting Shit-Poster Onslaught''.

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

int main(void) {
    int melody_notes[32] = { 80,80,80,80,97,97,75,75,70,70,70,69,75,80,'!','!',80,80,80,80,97,97,75,75,93,93,93,98,110,100,'!','!' };
    double m, melody, sample, beat;
    int t, w;
    for (t = 0; ; t++) {
        w = t >> 11;
        m = (melody_notes[((w >> 1) & 0x0F) | ((((w >> 5) & 0x03) / 3) << 4)] / 40.0 * t) - t;
        melody = (((w >> 5) > 1) && !((w >> 7) & 1)) ? (fmod(m + 10.0, 64.0) * fmod(m * 1.01, 64.0) * fmod(m * 0.49, 32.0) / 450.0) : 0.0;
        beat = (t & ((t >> 5)) + (t & (t >> 4))) & 0xFF;
        sample = beat + melody;
        if (sample > 255.0)
            sample = 255.0;
        else if (sample < 0.0)
            sample = 0.0;
        putchar((int)sample);
    }
    return 0;
}

Name: Anonymous 2011-11-14 8:20

>>4
I assume two's complement notation for signed integers and truncation during promotion. If your platform/compiler doesn't do that, it's shit.

Name: Anonymous 2011-11-14 8:43

``Retort of the Ultra-Finitist'' turned out pretty decent, despite it's compact form.

#include <stdio.h>

int main(void) {
    int t;
    for (t = 0; ; t++)
        putchar((((t & ((t >> 5)) | (t & (t * 2))) << 2)) - ((t >> 13) & (t ^ (t - 1))));
    return 0;
}

Name: Anonymous 2011-11-14 9:22

Name: Anonymous 2011-11-14 9:27

Why not use fwrite and write the actual 32 bits?

Name: Anonymous 2011-11-14 10:04

>>8
You also assume that shifts only use lower bits of their second operand, and that, my friend, is inexcusable. It's the only piece of your code that didn't work out of the box in Python.

Name: Anonymous 2011-11-14 10:17

>>8
Also, by the way, s/\?\?!/?" "?!/ instead of requiring a compiler flag.
Also, s/melody_notes[32]/melody_notes[]/.

>>7 putchar(((int)sample - 128) & 0xFF);, the stuff you have is just pointlessly noisy. PCM works with signed bytes, yo.

Name: masterKderz 2011-11-14 14:22

yes | aplay

wrote it in 1 hour and 25 cents

enjoy

Name: Anonymous 2011-11-14 22:05

>>14

this is interesting

yes | cat -n | aplay

Don't change these.
Name: Email:
Entire Thread Thread List