-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fef40d8
commit 81341f1
Showing
4 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>BellChoir</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |