* Cast floats (from double) everywhere.

* Reference parent methods for Processing-specific functions like round(), ceil() and map().
* Suppress warnings about usage of parent.println()
* Build .jar
This commit is contained in:
litter 2019-10-29 00:16:51 -04:00
parent de7d47a69e
commit 5240530cac
2 changed files with 66 additions and 47 deletions

Binary file not shown.

113
src/soundtrack/optical/SoundtrackOptical.java Normal file → Executable file
View File

@ -1,25 +1,25 @@
package soundtrack.optical; package soundtrack.optical;
import processing.sound.*;
import processing.core.*; import processing.core.*;
import processing.sound.*;
public class SoundtrackOptical { public class SoundtrackOptical {
String TYPE = "dual variable area"; //type of soundtrack String TYPE = "dual variable area"; //type of soundtrack
int DPI = 2880; //dots/in int DPI = 2880; //dots/in
boolean POSITIVE = true; boolean POSITIVE = true;
float VOLUME = 1.0; float VOLUME = (float) 1.0;
String pitch = "long"; String pitch = "long";
//String filePath = "wavTones.com.unregistred.sweep_100Hz_6000Hz_-3dBFS_5s.wav"; //String filePath = "wavTones.com.unregistred.sweep_100Hz_6000Hz_-3dBFS_5s.wav";
String FILEPATH = "barking.wav"; String FILEPATH;
float IN = 25.4; //mm/in float IN = (float) 25.4; //mm/in
float FRAME_H = 7.62; //mm float FRAME_H = (float) 7.62; //mm
float FRAME_W = 12.52 - 10.26;; //mm float FRAME_W = (float) (12.52 - 10.26);; //mm
float DPMM = DPI / IN; float DPMM = (float) (DPI / IN);
int FRAME_H_PIXELS = round(DPMM * FRAME_H); int FRAME_H_PIXELS = (int) Math.round(DPMM * FRAME_H);
int SAMPLE_RATE = FRAME_H_PIXELS * 24; int SAMPLE_RATE = FRAME_H_PIXELS * 24;
int DEPTH = round(DPMM * FRAME_W); int DEPTH = (int) Math.round(DPMM * FRAME_W);
int LINE_W = 0; int LINE_W = 0;
float DENSITY = 0; float DENSITY = 0;
@ -35,78 +35,97 @@ public class SoundtrackOptical {
AudioSample sample; AudioSample sample;
float[] frameSample = new float[FRAME_H_PIXELS]; float[] frameSample = new float[FRAME_H_PIXELS];
SoundFile soundfile; SoundFile soundfile;
PApplet parent;
Soundtrack (PApplet parent, String soundtrackFile, int dpi, float volume, String type, String pitch, boolean positive ) { @SuppressWarnings("static-access")
FILEPATH = soundtrackFile; public SoundtrackOptical (PApplet parent, String soundtrackFile, int dpi, float volume, String type, String pitch, boolean positive ) {
this.parent = parent;
FILEPATH = soundtrackFile;
TYPE = type; TYPE = type;
DPI = dpi; DPI = dpi;
VOLUME = volume; VOLUME = volume;
POSITIVE = positive; POSITIVE = positive;
FRAME_H = pitch == "long" ? 7.62 : 7.605; FRAME_H = (float) ((pitch == "long") ? 7.62 : 7.605);
DPMM = DPI / IN; DPMM = DPI / IN;
FRAME_H_PIXELS = round(DPMM * FRAME_H); FRAME_H_PIXELS = (int) Math.round(DPMM * FRAME_H);
SAMPLE_RATE = FRAME_H_PIXELS * 24; SAMPLE_RATE = FRAME_H_PIXELS * 24;
DEPTH = floor(DPMM * FRAME_W); DEPTH = (int) Math.floor(DPMM * FRAME_W);
soundfile = new SoundFile(parent, FILEPATH); soundfile = new SoundFile(parent, FILEPATH);
soundfile.rate(SAMPLE_RATE); soundfile.rate(SAMPLE_RATE);
FRAMES = ceil(soundfile.frames() / FRAME_H_PIXELS); FRAMES = (int) Math.ceil(soundfile.frames() / FRAME_H_PIXELS);
/* parent.println(FRAMES);
println("SAMPLE RATE "); parent.println(DEPTH);
println(SAMPLE_RATE); parent.println(FRAME_H_PIXELS);
println("FRAME_H");
println(FRAME_H_PIXELS); for (int x = 0; x < soundfile.frames(); x++) {
println("DEPTH "); compare = soundfile.read(x);
println(DEPTH); if (compare > max) {
println("FRAMES"); max = compare;
println(FRAMES); }
*/ if (compare < min) {
min = compare;
}
}
parent.println(min);
parent.println(max);
} }
@SuppressWarnings("static-access")
public void frame(int X, int Y) { public void frame(int X, int Y) {
if (i >= FRAMES) { if (i >= FRAMES) {
return; return;
} }
if (POSITIVE) { //draw bg
background(0); parent.noStroke();
stroke(255); if (POSITIVE) {
parent.fill(0);
} else { } else {
background(255); parent.fill(255);
stroke(0); }
if (TYPE != "variable density") {
parent.rect(X, Y, DEPTH, FRAME_H_PIXELS);
}
//draw top
if (POSITIVE) {
parent.stroke(255);
} else {
parent.stroke(0);
} }
soundfile.read(i * FRAME_H_PIXELS, frameSample, 0, FRAME_H_PIXELS); soundfile.read(i * FRAME_H_PIXELS, frameSample, 0, FRAME_H_PIXELS);
for (int y = 0; y < FRAME_H_PIXELS; y++) { for (int y = 0; y < FRAME_H_PIXELS; y++) {
LINE_W = round(map(frameSample[y], min, max, 0, DEPTH * VOLUME)); LINE_W = Math.round(parent.map(frameSample[y], min, max, (float) 0, DEPTH * VOLUME));
//println();
if (TYPE == "unilateral") { if (TYPE == "unilateral") {
line(X + 0, Y + y, X + LINE_W, Y + y); parent.line(X + 0, Y + y, X + LINE_W, Y + y);
} else if (TYPE == "dual unilateral") { } else if (TYPE == "dual unilateral") {
/* TODO!!!! */ /* TODO!!!! */
} else if (TYPE == "single variable area") { } else if (TYPE == "variable area" || TYPE == "single variable area") {
LEFT = X + round((DEPTH - LINE_W) / 2); LEFT = X + Math.round((DEPTH - LINE_W) / 2);
line(LEFT, Y + y, LEFT + LINE_W, Y + y); parent.line(LEFT, Y + y, LEFT + LINE_W, Y + y);
} else if (TYPE == "dual variable area") { } else if (TYPE == "dual variable area") {
LEFT = X + round((DEPTH / 4) - (LINE_W / 4)); LEFT = X + Math.round((DEPTH / 4) - (LINE_W / 4));
line(LEFT, Y + y, LEFT + (LINE_W / 2), Y + y); parent.line(LEFT, Y + y, LEFT + (LINE_W / 2), Y + y);
line(LEFT + (DEPTH / 2), Y + y, LEFT + (DEPTH / 2) + (LINE_W / 2), Y + y); parent.line(LEFT + (DEPTH / 2), Y + y, LEFT + (DEPTH / 2) + (LINE_W / 2), Y + y);
} else if (TYPE == "multiple variable area" || TYPE == "maurer") { } else if (TYPE == "multiple variable area" || TYPE == "maurer") {
LEFT = X + round((DEPTH / 16) - (LINE_W / 16)); LEFT = X + Math.round((DEPTH / 16) - (LINE_W / 16));
for (int x = 1; x < 7; x++) { for (int x = 1; x < 7; x++) {
line(LEFT + ((x * DEPTH) / 8), Y + y, LEFT + ((x * DEPTH) / 8) + (LINE_W / 8), Y + y); parent.line(LEFT + ((x * DEPTH) / 8), Y + y, LEFT + ((x * DEPTH) / 8) + (LINE_W / 8), Y + y);
} }
} else if (TYPE == "variable density") { } else if (TYPE == "variable density") {
DENSITY = map(frameSample[y], min, max, 0, 255 * VOLUME); DENSITY = parent.map(frameSample[y], min, max, (float) 0, 255 * VOLUME);
if (POSITIVE) { if (POSITIVE) {
stroke(DENSITY); parent.stroke(DENSITY);
} else { } else {
stroke(255 - DENSITY); parent.stroke(255 - DENSITY);
} }
line(X + 0, Y + y, X + DEPTH, Y + y); parent.line(X + 0, Y + y, X + DEPTH, Y + y);
} }
} }
i++; i++;