From b1d409ce6d204b6012234206c7287ebc4d5a0bfb Mon Sep 17 00:00:00 2001 From: litter Date: Tue, 29 Oct 2019 02:38:19 -0400 Subject: [PATCH] Caught a MAJOR issue with the original lib. Crazy bug. Ok, so it was not resampling the audio the way I thought, so what I'm doing now is drawing at the audio full resolution and then scaling to the desired image size. Ready for one more example before I pass out. --- library/SoundtrackOptical.jar | Bin 4354 -> 5564 bytes src/soundtrack/optical/SoundtrackOptical.java | 108 +++++++++++------- 2 files changed, 65 insertions(+), 43 deletions(-) diff --git a/library/SoundtrackOptical.jar b/library/SoundtrackOptical.jar index 7351f99870104fd36027982f016dfe5a7d45789b..94d9b24d7530ff9b9e428d5a797760e2bbf4f562 100644 GIT binary patch literal 5564 zcma)=1yodP*T(^YAq0^YQ3;WuQ@Vyy(xDq^7#L#c6lv)eX(>rb2|;4$25E*G8l*!S zeBs{ryW(Bnx7N4k%vxuibM`)K?|J6`?EM4F-9aZt!NS5qu_e}fg>uV?QP5Eoq*OsH zGK$h{3Lr%pX(<&|Rt4#+ZWNRQh29={ITqIMcycU^{k;Pf%IqUt$mNA)G!(EL0IS>^ zZTsPMs0Y_y@INp3g!<oApAc?E^P-kaO_i(_1*wr7%#Erp&F7Boh1H>q3z zGk7JBm4IT{jd@#u82K)MVr1e)()_oNdE2z3uhc!=7~Wtpyd*QwUc=7)k^QS8*G)3A z-gWGoNaNndj{Z#%eFsx4ny<5RMZI0b1&lxQ#=d?+SqdbnAjN8JVydEGJH>vt{#?VZ zuMPVyeP769_01|g@=`;I(9}RwQ)YoN8aZFdHo2h7W2Jujq)mFc8O5Y#k0GRW$0!mYlN$pKaOB**)#;FT} zZA#lSx@BLG(~htqG@_u3?oWUoYPAnbgs-)Tmbt9VlbL^CMvvVCk2I@_W?zWPX z#{?+{63k!l*Y_F%7?jl|-aTCS6x)yFM5!q_{KY zDh_*#0b$Z36+y;pXE+X}HTqYHA6gb_q5EN8L&_Jz(<2T6VFx6E3dKCgBWYPJ%;n0~ z1eee@iSO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$DFA>j%F`F%zX!;ATw_m^qo0FckQCa_2kq>KMLA=<9zvmK%ow6~cdes1b@H+U z6m@}If>>)HzrO&yLM}ahxRJ>ZbFjDTGX6Yw7UO5!=EPu<*uM%YS;?ge3i~+mEs-itmD8YhW-yh`z@j})W=1J8EWeqo9o_$LlbANFt;68 zKTukSjC}L;@DY)Te?2Vum-x>(1yg-M#6j;s|=?wn5 zGD+k+pkZ1U3i)xk#KUg%;DKd;N+WX?fBV@_>rT6s=&THx87W++ljPo++PiXmUX&x+ za%~;c#uOBx{5)5iHfhe)ioHh5eluV@6u6a1B%`T~XxjYGZE3E|_7m~dafN~C$a8-& z-=UA+$J?k531)jyE$ijZBj_unz8$eTybv(10O5giQ;cbN)s{NyK)=AV5pSQJ(H@1q z1}@6s2w&!KZ2@@yw$IdD`#=@_@dM}^$6RttTa;hO78~#y1H%R0{hXT6hD_Jq{d7+5 zFPG^o8owRw_^@(Kkz^CZP_D2QU*{UK^sL_V;k|aI$XD>%iNx#z9nv)<6=HDyXFVo$ z)=Zy&^21F z3?Err^-fmbqK>c%aG@r=ARPF`0zR%|MU!2zNlcSXb4ja8kq7x!BvUbROzIV9W_dhS zY=YNmd}lyGZ7bxT-_uH7rnRi5BA?|qtqjT`uz%#iRucIOpUNkH9X;TAYJ!pO+cyJv2e1ANQaM7N9NzOO(7i8|>NOHSA@NB*5g0 z;^?wk30A!|ou~{$X6ySr^yS<~jWqb-JLd6$TD`!xNu?rJbVGPT9mD<>w4VEmLg-@@ z00B=fDFr1v;Fo4TEp|^d^Y8Y5Dd^KtPK5DkvN;jPzs%wI_5UxEPscr>s?#KNg7?2n z^q6^m5!Y$Ilb`Q2gPc&*FLOPf{!3V=-A?G`G-Upsj(n2tU$QyvcarWj3Y-AyFB7Bx m-{AGX{-+P<1S@`70>i(^VG2Ea!o>jU max) { @@ -75,64 +75,86 @@ public class SoundtrackOptical { min = compare; } } - parent.println(min); - parent.println(max); } @SuppressWarnings("static-access") public void frame(int X, int Y) { if (i >= FRAMES) { return; } - + raw.beginDraw(); //draw bg - parent.noStroke(); + raw.noStroke(); if (POSITIVE) { - parent.fill(0); + raw.fill(0); } else { - parent.fill(255); + raw.fill(255); } if (TYPE != "variable density") { - parent.rect(X, Y, DEPTH, FRAME_H_PIXELS); + raw.rect(0, 0, RAW_FRAME_W, RAW_FRAME_H); } //draw top if (POSITIVE) { - parent.stroke(255); + raw.stroke(255); } else { - parent.stroke(0); + raw.stroke(0); } - soundfile.read(i * FRAME_H_PIXELS, frameSample, 0, FRAME_H_PIXELS); + soundfile.read(i * RAW_FRAME_H, frameSample, 0, RAW_FRAME_H); - for (int y = 0; y < FRAME_H_PIXELS; y++) { - LINE_W = Math.round(parent.map(frameSample[y], min, max, (float) 0, DEPTH * VOLUME)); + for (int y = 0; y < RAW_FRAME_H; y++) { + if (TYPE != "variable density") { + LINE_W = Math.round(parent.map(frameSample[y], min, max, (float) 0, RAW_FRAME_W * VOLUME)); + } if (TYPE == "unilateral") { - parent.line(X + 0, Y + y, X + LINE_W, Y + y); + unilateral(y, LINE_W); } else if (TYPE == "dual unilateral") { /* TODO!!!! */ - } 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 == "single variable area" || TYPE == "variable area") { + variableArea(y, LINE_W); } else if (TYPE == "dual variable area") { - 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); + dualVariableArea(y, LINE_W); } else if (TYPE == "multiple variable area" || TYPE == "maurer") { - LEFT = X + Math.round((DEPTH / 16) - (LINE_W / 16)); - for (int x = 1; x < 7; x++) { - parent.line(LEFT + ((x * DEPTH) / 8), Y + y, LEFT + ((x * DEPTH) / 8) + (LINE_W / 8), Y + y); - } + multipleVariableArea(y, LINE_W); } else if (TYPE == "variable density") { - DENSITY = parent.map(frameSample[y], min, max, (float) 0, 255 * VOLUME); - if (POSITIVE) { - parent.stroke(DENSITY); - } else { - parent.stroke(255 - DENSITY); - } - parent.line(X + 0, Y + y, X + DEPTH, Y + y); + variableDensity(y); } } + raw.endDraw(); + parent.image(raw, X, Y, DEPTH, FRAME_H_PIXELS); i++; } + + private void unilateral (int y, int LINE_W) { + raw.line(0, y, LINE_W, y); + } + + private void variableArea (int y, int LINE_W) { + LEFT = Math.round((RAW_FRAME_W - LINE_W) / 2); + raw.line(LEFT, y, LEFT + LINE_W, y); + } + + private void dualVariableArea (int y, int LINE_W) { + LEFT = Math.round((RAW_FRAME_W / 4) - (LINE_W / 4)); + raw.line(LEFT, y, LEFT + (LINE_W / 2), y); + raw.line(LEFT + (RAW_FRAME_W / 2), y, LEFT + (RAW_FRAME_W / 2) + (LINE_W / 2), y); + } + + private void multipleVariableArea (int y, int LINE_W) { + LEFT = Math.round((RAW_FRAME_W / 16) - (LINE_W / 16)); + for (int x = 1; x < 7; x++) { + raw.line(LEFT + ((x * RAW_FRAME_W) / 8), y, LEFT + ((x * RAW_FRAME_W) / 8) + (LINE_W / 8), y); + } + } + + private void variableDensity(int y) { + DENSITY = parent.map(frameSample[y], min, max, (float) 0, 255 * VOLUME); + if (POSITIVE) { + raw.stroke(DENSITY); + } else { + raw.stroke(255 - DENSITY); + } + raw.line(0, y, RAW_FRAME_W, y); + } }