Skip to content

Commit

Permalink
first commit'
Browse files Browse the repository at this point in the history
  • Loading branch information
phillyslick committed May 1, 2012
0 parents commit 91ccca1
Show file tree
Hide file tree
Showing 22 changed files with 535 additions and 0 deletions.
Empty file added README
Empty file.
Binary file added ch1/ex
Binary file not shown.
27 changes: 27 additions & 0 deletions ch1/exc2_13.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <stdio.h>

int main (int argc, char const *argv[])
{
int int_tester;
char char_tester;
short short_tester;
long long_tester;
float float_tester;
double double_tester;
int the_answer;

the_answer = sizeof(int_tester);
printf("The size of an int in bytes is: %d\n", the_answer);
the_answer = sizeof(char_tester);
printf("The size of a char in bytes is: %d\n", the_answer);
the_answer = sizeof(short_tester);
printf("The size of a short in bytes is: %d\n", the_answer);
the_answer = sizeof(short_tester);
printf("The size of a long in bytes is: %d\n", the_answer);
the_answer = sizeof(long_tester);
printf("The size of a float in bytes is: %d\n", the_answer);
the_answer = sizeof(float_tester);
printf("The size of a double in bytes is: %d\n", the_answer);

return 0;
}
Binary file added ch1/freq2midi
Binary file not shown.
75 changes: 75 additions & 0 deletions ch1/freq2midi.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/* 1.2 MOD - Find nearest MIDI note for given frequency in Hz */

/*
For more on this check out: http://oakroadsystems.com/math/loglaws.htm
LOG RULE:
log_a(N) = log_b(N) / log_b(a) to find the log of a value to base 'semitone_ratio'.
TODO: Pitchbend INFO!
"We define pitchbend as a percentage deviation half a semitone above or below a MIDI note."
"Maximum deviation is therfore + or - 50 percent."
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main (int argc, char const *argv[])
{
double semitone_ratio = pow(2, 1/12.0); /* approx 1.0594631 */
double c5 = 220.0 * pow(semitone_ratio, 3); // frequency of Middle C
double c0 = c5 * pow(0.5, 5); // frequency of MIDI note 0
double frequency;

int midinote; //the note we're outputting

if(argc != 2){
printf("\n %s: Converts a Frequency in hz (440.00) to a corresponding MIDI note. \n",argv[0]);
printf("If frequency does not correspond exactly with a midi note, pitch bend information is given as well.\n\n");
printf("Usage: %s FREQUENCY\n\n", argv[0] );
return 1;
}

//assign the input to the double frequency
frequency = atof(argv[1]);

if(frequency < 0){
printf("Ah, please enter a position frequency!");
}

/* Calculate a the midi note from the given frequency */
double frac_midi = log(frequency / c0) / log(semitone_ratio);
int low_side = (int) floor(frac_midi);
int high_side = (int) ceil(frac_midi);


/*Round frac_midi to the nearest whole number*/
midinote = (int) (frac_midi + 0.5);

//need to get the low and high side frequency

double low_frequency = c0 * pow(semitone_ratio, low_side);
double high_frequency = c0 * pow(semitone_ratio, high_side);

//determine pitchbend
int pitch_bend;
double difference;
char* sign;

if(low_side == midinote)
{
difference = frequency - low_frequency;
sign = "+";
}
else
{
difference = high_frequency - frequency;
sign = "-";
}
difference = difference / (high_frequency - low_frequency);
pitch_bend = (int) (difference * 100 + 0.5);

printf("The nearest midinote to the frequency %f is %d\n", frequency, midinote);

printf("The pitch bend = %s%d%%\n", sign,pitch_bend );
return 0;
}
8 changes: 8 additions & 0 deletions ch1/hello.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* wonder.c: displays 'hello world' in the terminal */
#include <stdio.h>

int main (int argc, char const *argv[])
{
printf("What a Wonderful Workd\n");
return 0;
}
Binary file added ch1/midi2freq
Binary file not shown.
47 changes: 47 additions & 0 deletions ch1/midi2freq.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* 1.2 - Caluclate frequency of a MIDI note number
Takes command line input!
*/

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

int main (int argc, char const *argv[])
{
double semitone_ratio = pow(2, 1.0/12); /* approx 1.0594631 */
double c5 = 220.0 * pow(semitone_ratio, 3); // frequency of Middle C
double c0 = c5 * pow(0.5, 5); // frequency of MIDI note 0

double frequency = 440.0; //what we want to find
int midinote; //the note we're given

char message[256]; //char array for input

if(argc != 2)
{
printf("%s : converts MIDI note to frequency. \n", argv[0]);
printf("Usage: %s MIDInote\n", argv[0]);
printf("Range: 0 <= MIDInote <= 127 \n");
return 1;
}



//convert char array to interger
midinote = atoi(argv[1]);
if(midinote < 0)
{
printf("Sorry - %s is a bad MIDI note number\n",message );
}

if(midinote > 127)
{
printf("Sorry - %s is a out of the MIDI range!\n",message );
}


/* Calculate a frequency for a given note number */
frequency = c0 * pow(semitone_ratio, midinote);
printf("frequency of MIDI note %d = %f\n",midinote, frequency);
return 0;
}
Binary file added ch1/music
Binary file not shown.
12 changes: 12 additions & 0 deletions ch1/music.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
Just a simple excercise to print out a musical message
Here's we got some dope original nas lyrics.
*/

#include <stdio.h>

int main (int argc, char const *argv[])
{
printf("I rap for listeners.\nBlunt heads, fly ladies and prisoners.\n");
return 0;
}
Binary file added dodeca
Binary file not shown.
113 changes: 113 additions & 0 deletions dodeca.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#include <stdio.h>
#include <stdlib.h>

class Dodecaphonic {
protected:
int series[12]; // the tone row, hidden from outside

// modulus as in internal method
int mod12(int note){
while (note >= 12) note -= 12;
while (note < 0) note += 12;
return note;
}

public:
Dodecaphonic() { // default constructor
for(int i = 0; i < 12; ++i) series[i] = 0;
}

Dodecaphonic(int *notes) { // constuctor from an array
for(int i = 0; i < 12; ++i) series[i] = mod12(notes[i]);
}

// get and set notes
int get(int index){
return series[mod12(index)];
}

void set(int note, int index){
series[mod12(index)] = mod12(note);
}

// three base operations
Dodecaphonic transpose(int interval);
Dodecaphonic invert();
Dodecaphonic retrograde();
};

/*So Now, We can define the above base operations from outside the class (we could have done it inside as well)
All of them return a Dodecaphonic */

Dodecaphonic Dodecaphonic::transpose(int interval){
Dodecaphonic transp;
for(int i=0; i < 12; ++i) transp.set(mod12(series[i] + interval), i);
return transp;
}

Dodecaphonic Dodecaphonic::invert(){
Dodecaphonic inv;
inv.set(series[0],0);
for(int i=1; i < 12; ++i) inv.set(mod12(inv.get(i-1) + series[i-1] - series[i]), i);
return inv;
}

Dodecaphonic Dodecaphonic::retrograde(){
Dodecaphonic retr;
for(int i=0; i < 12; ++i) retr.set(series[i], 11-i);
return retr;
}

int main (int argc, char const *argv[])
{
Dodecaphonic row, res;
int interval, n;

if(argc != 14 || argv[1][0] != '-')
{
printf("usage: %s [-oN | -rN | -iN | -irN] " "note1 note2 ... note12\n", argv[0]);
return -1;
}

/* Initialize the row object */
for(n = 0; n < 12; ++n)
{
row.set(atoi(argv[n+2]), n);
}

switch(argv[1][1]){
// original transposed
case 'o':
interval = atoi(argv[1]+2);
res = row.transpose(interval);
break;

// retrograde
case 'r':
interval = atoi(argv[1]+2);
res = row.retrograde().transpose(interval);
break;

// inverted
case 'i':
if(argv[1][2] != 'r')
{
interval = atoi(argv[1] + 2);
res = row.invert().retrograde().transpose(interval);
}
// inverted retrograde
else{
interval = atoi(argv[1] + 3);
res = row.invert().retrograde().transpose(interval);
}
break;

default:
printf("unrecognized option \n");
return -1;
}
for(n=0; n<12; ++n) printf("%d ", res.get(n));
printf("\n");
return 0;

}
12 changes: 12 additions & 0 deletions first.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <stdio.h> /* header file */
int main (int argc, char const *argv[])
{
int a,b,c;
printf("\nPlease Enter A Number: ");
scanf("%d", &a);
printf(" Please Enter A Second Number: ");
scanf("%d", &b);
c=a+b;
printf("%d + %d = %d \n", a,b,c);
return 0; //function returns 0 (ok)
}
Binary file added interval_basic
Binary file not shown.
Binary file added major_better
Binary file not shown.
Binary file added major_scale
Binary file not shown.
42 changes: 42 additions & 0 deletions major_scale.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include <stdio.h>
#include <string.h>

int main (int argc, char const *argv[])
{
int note, i;
char key[3];
char* scale[12] = {"C","Db","D","Eb","E","F","Gb","G","Ab","A","Bb","B"};

printf("Please enter the key (CAPITALS only, use b for flats, e.g. Eb): ");
scanf("%s", key);

//use table to translate name to pitch class
for(i = 0; i < 12; ++i)
{
if(strcmp(scale[i], key) == 0) // that means we've found the note
{
note = i;
printf("== %s major scale ==\n", key);
break;
}
else note = -1; //note not found!
}

if(note >= 0)
{
for(i = 0; i < 7; ++i)
{
//use table to translate pitch class to note name
printf("%s ",scale[note%12]);
if(i != 2) note += 2;
else note++;
}
printf("\n");
return 0;
}
else{
printf("%s: invalid key\n", key);
return 1;
}

}
Binary file added matrix
Binary file not shown.
Loading

0 comments on commit 91ccca1

Please sign in to comment.