diff --git a/library/SoundtrackOptical.jar b/library/SoundtrackOptical.jar new file mode 100644 index 0000000..7351f99 Binary files /dev/null and b/library/SoundtrackOptical.jar differ diff --git a/src/soundtrack/optical/SoundtrackOptical.java b/src/soundtrack/optical/SoundtrackOptical.java old mode 100644 new mode 100755 index 1bd444c..92721a4 --- a/src/soundtrack/optical/SoundtrackOptical.java +++ b/src/soundtrack/optical/SoundtrackOptical.java @@ -1,25 +1,25 @@ package soundtrack.optical; -import processing.sound.*; import processing.core.*; +import processing.sound.*; public class SoundtrackOptical { String TYPE = "dual variable area"; //type of soundtrack int DPI = 2880; //dots/in boolean POSITIVE = true; - float VOLUME = 1.0; + float VOLUME = (float) 1.0; String pitch = "long"; //String filePath = "wavTones.com.unregistred.sweep_100Hz_6000Hz_-3dBFS_5s.wav"; - String FILEPATH = "barking.wav"; + String FILEPATH; - float IN = 25.4; //mm/in - float FRAME_H = 7.62; //mm - float FRAME_W = 12.52 - 10.26;; //mm + float IN = (float) 25.4; //mm/in + float FRAME_H = (float) 7.62; //mm + float FRAME_W = (float) (12.52 - 10.26);; //mm - float DPMM = DPI / IN; - int FRAME_H_PIXELS = round(DPMM * FRAME_H); + float DPMM = (float) (DPI / IN); + int FRAME_H_PIXELS = (int) Math.round(DPMM * FRAME_H); 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; float DENSITY = 0; @@ -35,78 +35,97 @@ public class SoundtrackOptical { AudioSample sample; float[] frameSample = new float[FRAME_H_PIXELS]; SoundFile soundfile; + PApplet parent; - Soundtrack (PApplet parent, String soundtrackFile, int dpi, float volume, String type, String pitch, boolean positive ) { - FILEPATH = soundtrackFile; + @SuppressWarnings("static-access") + public SoundtrackOptical (PApplet parent, String soundtrackFile, int dpi, float volume, String type, String pitch, boolean positive ) { + this.parent = parent; + + FILEPATH = soundtrackFile; TYPE = type; DPI = dpi; VOLUME = volume; POSITIVE = positive; - FRAME_H = pitch == "long" ? 7.62 : 7.605; - + FRAME_H = (float) ((pitch == "long") ? 7.62 : 7.605); 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; - DEPTH = floor(DPMM * FRAME_W); + DEPTH = (int) Math.floor(DPMM * FRAME_W); soundfile = new SoundFile(parent, FILEPATH); soundfile.rate(SAMPLE_RATE); - FRAMES = ceil(soundfile.frames() / FRAME_H_PIXELS); + FRAMES = (int) Math.ceil(soundfile.frames() / FRAME_H_PIXELS); - /* - println("SAMPLE RATE "); - println(SAMPLE_RATE); - println("FRAME_H"); - println(FRAME_H_PIXELS); - println("DEPTH "); - println(DEPTH); - println("FRAMES"); - println(FRAMES); - */ + parent.println(FRAMES); + parent.println(DEPTH); + parent.println(FRAME_H_PIXELS); + + for (int x = 0; x < soundfile.frames(); x++) { + compare = soundfile.read(x); + if (compare > max) { + max = compare; + } + if (compare < min) { + min = compare; + } + } + parent.println(min); + parent.println(max); } + @SuppressWarnings("static-access") public void frame(int X, int Y) { if (i >= FRAMES) { return; } - - if (POSITIVE) { - background(0); - stroke(255); + + //draw bg + parent.noStroke(); + if (POSITIVE) { + parent.fill(0); } else { - background(255); - stroke(0); + parent.fill(255); + } + + 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); for (int y = 0; y < FRAME_H_PIXELS; y++) { - LINE_W = round(map(frameSample[y], min, max, 0, DEPTH * VOLUME)); - //println(); + LINE_W = Math.round(parent.map(frameSample[y], min, max, (float) 0, DEPTH * VOLUME)); 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") { /* TODO!!!! */ - } else if (TYPE == "single variable area") { - LEFT = X + round((DEPTH - LINE_W) / 2); - line(LEFT, Y + y, LEFT + LINE_W, Y + y); + } else if (TYPE == "variable area" || TYPE == "single variable area") { + LEFT = X + Math.round((DEPTH - LINE_W) / 2); + parent.line(LEFT, Y + y, LEFT + LINE_W, Y + y); } else if (TYPE == "dual variable area") { - LEFT = X + round((DEPTH / 4) - (LINE_W / 4)); - line(LEFT, Y + y, LEFT + (LINE_W / 2), Y + y); - line(LEFT + (DEPTH / 2), Y + y, LEFT + (DEPTH / 2) + (LINE_W / 2), Y + y); + LEFT = X + Math.round((DEPTH / 4) - (LINE_W / 4)); + parent.line(LEFT, Y + y, LEFT + (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") { - LEFT = X + round((DEPTH / 16) - (LINE_W / 16)); + LEFT = X + Math.round((DEPTH / 16) - (LINE_W / 16)); 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") { - DENSITY = map(frameSample[y], min, max, 0, 255 * VOLUME); + DENSITY = parent.map(frameSample[y], min, max, (float) 0, 255 * VOLUME); if (POSITIVE) { - stroke(DENSITY); + parent.stroke(DENSITY); } 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++;