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

Pages: 1-4041-

/prog/ AUDIO THREAD PART III

Name: Anonymous 2008-05-24 3:21

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

main() {
 int i,j,k,l;
 while(1) {
  l=rand()%100;
  for(k=0;k<l;k++) {
   for(i=0;i<255;i+=128)
    for(j=0;j<k;j++)
     putchar(i);
   for(;i;i-=128)
    for(j=0;j<k;j++)
     putchar(i);
  }
 }
}


gcc -o lolsound lolsound.c
./lolsound > /dev/dsp


First one to hack this into saying "Have you read your SICP today?" gets an internet.

Name: Anonymous 2008-05-24 4:01

how would I do this on Windows?

Name: Anonymous 2008-05-24 4:29

First one to ask how to get this working on Windows gets laughed and pointed at.

Name: Anonymous 2008-05-24 5:15

>>2
Step 1. Read SICP.
Step 2. Install (Linux|Plan9|Solaris|BSD).
Step 3. ???
Step 4. Achieve Satori.

Name: Anonymous 2008-05-24 5:23


#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#define DO   262
#define RE   294
#define MI   330
#define FA   349
#define SOL  392
#define LA   440
#define SI   494
#define DO2  523
#define RE2  587
#define MI2  660
#define FA2  698
#define SOL2 784
#define LA2  880

#define RATE 8000
#define SIZE 8
#define LENGTH 0.3

char *buf;
int satori[] = {FA, SOL, LA, DO2, SI, SI, RE2, DO2, DO2, FA2, MI2, FA2, DO2, LA, FA, SOL, LA, SI, DO2, RE2, DO2, SI, LA, SOL, LA, FA, MI, FA, SOL, DO, MI, FA, 0};

int main(void){

  int i,j,k;
  int dsp;
  int len = RATE*LENGTH;

  buf = (char*)malloc(sizeof(char)*len);

  dsp = open("/dev/dsp", O_RDWR);
  if(dsp < 0){
    fprintf(stderr, "lol\n");
    exit(1);
  }

  printf("HAVE YOU READ YOUR SICP TODAY ?\n");

  for(j=0; satori[j] != 0; j++){

    for(i=0; i<len; i++){
      buf[i] = 127*sin(satori[j]*2*M_PI*(i)/RATE)+127;
    }
   
    write(dsp, buf, len);
  }
  return 0;
}

Name: Anonymous 2008-05-24 7:08

>>2
Now you have 2 problems.

Name: Anonymous 2008-05-24 9:27

>>5
Nice. Now make it actually say the phrase.

Name: Anonymous 2008-05-24 9:54

I can hax it to say: hax my anus.

Name: Anonymous 2008-05-24 13:53

Yay, another dsp thread. PROTIP for >>5: write to stdout, it's better. That way some of us can do | aplay instead of enabling OSS emulation. And your code becomes so much simpler.

Name: Anonymous 2008-05-24 14:07

Can someone be kind enough to explain the PCM format read by /dev/dsp? The meaning of this 8000hz, how endianness affects interpretation of sound, what does each byte (in 8bit pcm) mean, etc

Name: Anonymous 2008-05-24 14:11

>>8
Prove it by actually writing it, smartass

Name: Anonymous 2008-05-24 14:11

>>10
The meaning of this 8000hz
Number of samples read per second.
how endianness affects interpretation of sound
Each sample is one byte in this format, so it doesn't matter.
what does each byte (in 8bit pcm) mean
Simply the attenuation, 127 is 0, 0 is negative maximum, and 255 maximum.

For a pure tone, use a sine wave scaled to 0-255.  Figure out a way of calculating the frequency (it has to do with 8000Hz) and you can generate any tone.

Name: Anonymous 2008-05-24 14:12

* Not attenuation, damn it... hm, what is the term...

Name: Anonymous 2008-05-24 14:14

>>12
So each second is 8000 bytes, where each byte means something like the "volume" of the tone corresponding to that frequency? Am I enlightened?

Name: Anonymous 2008-05-24 14:17

>>14
Well, just use a sine wave and change the frequency of it.  Longer waves for lower frequency sounds, and shorter waves for higher frequency (perhaps up to 8000Hz, or half of that).  You might want to scale the amplitude down a bit though, as that seems to improve sound quality a bit.

Name: Anonymous 2008-05-24 14:18

>>14
Am I enlightened?
Absolutely not.

Name: Anonymous 2008-05-24 14:31

>>16
fuuuuuuuuuck

Name: Anonymous 2008-05-24 14:54

>>5,9
sed -n '4,7d;35,44d; s/buf\[i\] = \(.*\);$/putchar(\1);/g; 52d; p' satori5.c > satori9.c

Will work only if $ sed -n '54p' satori1.c displays   return 0;

Name: Anonymous 2008-05-24 14:55

>>18
s/satori1.c/satori5.c/, since >>1 is not satori.

Name: Anonymous 2008-05-24 16:23

>Figure out a way of calculating the frequency (it has to do with 8000Hz) and you can generate any tone.

Help.

Name: Anonymous 2008-05-24 16:31

>>20
buf[i] = 127*sin(satori[j]*2*M_PI*(i)/RATE)+127;
or in Haskell
makeU8 x freq = (((sin (x * (2 * pi) * (freq / 8000))) + 1) * 128.0)

Name: Anonymous 2008-05-24 17:46

>>4
How would I do this on HP-UX/AIX?

Name: Anonymous 2008-05-24 17:52

>>22
DRRRRRRRRRRRRRRRRR

Nah, I'll help you:  Hire a handful $1000/h consultants and let them work at it for a few months.

Name: Anonymous 2008-05-24 20:53

>>23
            /⌒ヽ
           /(●)(●)   excuse me may i pass through here
           | トェェェイ/
           | /`ニニ´
           // | |
          U  .U

Name: Anonymous 2008-05-25 21:05

This thread had potential.

Name: Anonymous 2008-05-25 21:26

#!/bin/bash
say -v Ralph "Have you read your SICP today?"

Name: >>4 2008-05-25 22:39

>>22
Funny you should ask that; I had to rewrite some software that was running on one of our old AIX machines last week. And not only was it AIX, but it was an ungodly old version of AIX (5.2). It was funny finding out things like, hey, grep back then didn't support recursive searches.

> uname -a
AIX harper 2 5 000B423C4C00


As such, my advice is to take an axe to any monstrosity HP-UX/AIX machine you have the misfortune to come across.

Name: Anonymous 2008-05-25 22:50

I think I've finally understood[1] how basic sound works. It's like a digital raw description of actual analogic sound. But, damn, that imples that i must build the waves myself with sin(). What if i want to play two different tones simultaneously?

Does anyone know a good introduction to ``sound theory''? Because I'd prefer reading something myself than filling this thread with questions. Due to geographical conditions i'm unable to buy books, so links are preferred. But I don't know what to search.

[1]Being the faggot I am, I had to do this:

$ ./satori.o | od -tu1 -w7 | head
0000000 127 161 193 220 239 251 253
0000007 246 230 206 176 143 108  75
0000016  45  22   6   0   3  15  35
0000025  63  95 129 163 195 221 241
0000034 251 253 245 228 204 174 140
0000043 105  72  43  20   5   0   3
0000052  16  37  65  97 132 166 197
0000061 223 242 252 253 244 226 202
0000070 171 137 103  70  41  19   5
0000077   0   4  17  39  67 100 135

Name: 28 2008-05-25 22:52

Being the enormous faggot I am, I did this before posting that:


#include <stdio.h>

int main() {
    unsigned char buf;
    while ((buf = getchar()) != EOF) {
        printf("%3u: %*c\n", buf, buf / 5, '#');
    }
    return 0;
}


Enjoy

Name: Anonymous 2008-05-25 23:09

>>28
Well, what happens if you were to set up two speakers in the same room playing two different tones? The instantaneous pressure from the two would be added together. If you want to mix two sound waves, you just need to add their amplitudes for that sample together.

Name: Anonymous 2008-05-25 23:23

>>30
You mean that adding up both lineally would work? Taking two parts of the wave from the od output above:


0000000 127 161 193 220 239 251 253
...
0000016  45  22   6   0   3  15  35


I make them signed, and then add up:

0000000   0  34  66  93 112 124 126
0000016 -82-105-121-127-124-112 -92
        ----------------------------
        -82 -71 -55 -34 -12  12  34


Which makes me really think there's something wrong. I'm not sure. Maybe I can't believe that it would be that easy.

Name: Anonymous 2008-05-26 0:02

OP sounds like the beginning of one of the LOLI RIPE songs (except the latter has some /dev/urandom mixed in)

Name: Anonymous 2008-05-26 1:05

Name: Anonymous 2008-05-26 1:28

I'm not going to decipher your graph, but

Wave 1: 0  1  2  3  4  5  4  3  2  1  0 -1 -2
Wave 2: 0  2  4  2  0 -2 -4 -2  0  2  4  2  0
Combo : 0  3  6  5  4  3  0  1  2  3  4  1 -2

is how it works. The only thing to watch out for is that exceeding your maximum amplitude is very likely, and will result in distorted output. You can just let the numbers overflow if you want, or you can clip the waveform, what audio software usually dies. In my example, if the maximum amplitude is 5, that six needs to be made into a 5. This will also result in distorted output, but that's just how it is. If you're trying to produce nice sound, it's a matter of carefully picking levels that won't clip given the material you are mixing.

Name: Anonymous 2008-05-26 1:29

>>34
Corrections: I'm responding to >>31, "dies" should be "does".

Name: Anonymous 2008-05-26 18:14

>>34
I'm not going to decipher your graph
lol'd

Ok, so it is as simple as I thought. Now the challenge is only generating the voice.

Name: Anonymous 2008-05-26 22:53

>>31
Superposition: do you speak it?

Name: Anonymous 2008-05-26 23:00

>>34
exceeding your maximum amplitude is very likely, and will result in distorted output. [...] that six needs to be made into a 5. This will also result in distorted output, but that's just how it is.
God, you're a fucking emo. Crrrawwwwwling in my skiiiinnnnnnnn...

Name: Anonymous 2008-05-26 23:11

>>38
Is that even relevant to the topic, or is it just your way of saying ``I thought we were speaking of mainstream music for faggots''

Name: Anonymous 2008-05-27 1:00

>>39
Whatever you do, you'll get distorted output. You cannot win.

Name: Anonymous 2008-05-27 1:13

>>40
You just have to teach your computer to speak softly. Or you could technically program a compressor, but screw that. A little distortion adds life.

Name: Anonymous 2008-05-27 1:23

>>38
Is that just your way of saying,``I've read Linkin Park lyrics''?

Name: Anonymous 2009-03-06 8:55


Compile LISP in their   laughter I began   changeing the code   that deals with   the user input   was correct return.

Name: Anonymous 2009-08-16 23:49

Lain.

Name: ​​​​​​​​​​ 2010-10-23 22:21

Name: Anonymous 2011-02-03 1:01

Name: Anonymous 2011-02-03 2:11

Name: Sgt.Kabukiman氹衑 2012-05-23 6:13

All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy

Name: bampu pantsu 2012-05-29 3:35

bampu pantsu

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