diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..fceb480 --- /dev/null +++ b/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..07584af --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + BellChoir + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/src/ChoirMember.java b/src/ChoirMember.java new file mode 100644 index 0000000..bf535e3 --- /dev/null +++ b/src/ChoirMember.java @@ -0,0 +1,106 @@ + +public class ChoirMember { + private Note noteOne; + private Note noteTwo; + + public ChoirMember() { + //is it my turn? some function associated with the mutex + + //acquire the mutex + //play note + //release the mutex + } +} + + + +//These classes from Nate Williams +/** + * This class defines one bell not with note and length + * + */ +class BellNote { + final Note note; + final NoteLength length; + + BellNote(Note note, NoteLength length) { + this.note = note; + this.length = length; + } +} + + +/** + * This enum defines valid note length for a bellnote. + * + */ +enum NoteLength { + WHOLE(1.0f), + HALF(0.5f), + QUARTER(0.25f), + EIGTH(0.125f); + + private final int timeMs; + + private NoteLength(float length) { + timeMs = (int)(length * Note.MEASURE_LENGTH_SEC * 1000); + } + + public int timeMs() { + return timeMs; + } +} + + +/** + * This enum defines valid notes + * + */ +enum Note { + // REST Must be the first 'Note' + REST, + A4, + A4S, + B4, + C4, + C4S, + D4, + D4S, + E4, + F4, + F4S, + G4, + G4S, + A5; + + public static final int SAMPLE_RATE = 48 * 1024; // ~48KHz + public static final int MEASURE_LENGTH_SEC = 1; + + // Circumference of a circle divided by # of samples + private static final double step_alpha = (2.0d * Math.PI) / SAMPLE_RATE; + + private final double FREQUENCY_A_HZ = 440.0d; + private final double MAX_VOLUME = 127.0d; + + private final byte[] sinSample = new byte[MEASURE_LENGTH_SEC * SAMPLE_RATE]; + + private Note() { + int n = this.ordinal(); + if (n > 0) { + // Calculate the frequency! + final double halfStepUpFromA = n - 1; + final double exp = halfStepUpFromA / 12.0d; + final double freq = FREQUENCY_A_HZ * Math.pow(2.0d, exp); + + // Create sinusoidal data sample for the desired frequency + final double sinStep = freq * step_alpha; + for (int i = 0; i < sinSample.length; i++) { + sinSample[i] = (byte)(Math.sin(i * sinStep) * MAX_VOLUME); + } + } + } + + public byte[] sample() { + return sinSample; + } +} \ No newline at end of file