This commit is contained in:
Bruno Rybársky 2022-03-19 13:03:00 +01:00
parent 4ef6d72b7c
commit 72dfafbc1c
5 changed files with 54 additions and 40 deletions

3
.gitignore vendored Normal file

@ -0,0 +1,3 @@
.vscode
out.ogg
randMus

@ -1,4 +1,16 @@
all: .DEFAULT_GOAL := all
gcc -o randMus randMus.c
run: clean:
rm -f randMus
compile: clean
gcc -o randMus -ggdb randMus.c
run: compile
./randMus | aplay ./randMus | aplay
record: compile
rm -f out.ogg
./randMus|ffmpeg -f u16le -ar 8000 -ac 1 -i - out.ogg
all: compile run

@ -1,3 +1,4 @@
RandMus RandMus
======= =======
@ -12,12 +13,10 @@ Instructions:
cd into the RandMus directory cd into the RandMus directory
type "make" to compile type "make" to compile and run(play)
type "make run" to run the program type "make clean" to remove the compiled files
type "make record" to record a random tune
to quit the program type ctrl-c to quit the program type ctrl-c
to view the random values for the current or last song, first open another terminal window, cd to the RandMus directory, and run the command "cat lastSong.txt"
spend hours messing around with it (in a good way)

@ -1,6 +0,0 @@
a[0]: 12
a[1]: 29
a[2]: 17
a[3]: 2
a[4]: 28
a[5]: 42

@ -1,28 +1,34 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h> #include <time.h>
int main()
{ const int num_samples = 6;
//create data file const int num_sample_repeats = 1;
FILE *f = fopen("lastSong.txt", "w");
if(f==NULL) int main() {
return 0; srand(time(NULL)); // seed random number generator
int num = 6; int a[num_samples]; // array of random numbers
srand(time(NULL)); int i; // loop counter
int a[num]; int c; // out character
int i; int tmp; // temp character
for(i=0;i<num;i++) int x; // loop counter
{ int y; // loop counter
a[i] = rand() % 50 + 1; while (1){
//since all output is piped into another program to make the sound, regular printf won't work for (x = 0; x < num_samples; x++) {
//instead we need to write to a file that can be read in another terminal instance a[x] = rand() % 20 + 1; // set a[x] to a random number between 1 and 50
fprintf(f,"a[%d]: %d\n", i, a[i]); }
for (y = 0; y < num_sample_repeats; y++) {
for (i = 0;i<32000; i++) { // loop forever
c = i >> a[0]; // shift right i by a[0]
c = c | i >> a[1]; // or c by i shifted right by a[1]
c = c + (i * 1.5); // multiply c by i
c = c & a[2]; // and c by a[2]
c = c | i >> a[3]; // or c by i shifted right by a[3]
tmp = i & i >> a[4]; // and i by i shifted right by a[4]
tmp = tmp | i >> a[5]; // or tmp by i shifted right by a[5]
c = c ^ tmp; // xor c by tmp
putchar(c); // print c
}
} }
fclose(f);
for(i=0;;i++)
{
//this is where all the magic happens
putchar(((i*(i>>a[0]|i>>a[1])&a[2]&i>>a[3]))^(i&i>>a[4]|i>>a[5]));
} }
return 0;
} }