Add a new `buffer()` method that returns the PGraphics object of a specific frame. This is needed for a new project that remains a secret.
This commit is contained in:
parent
cf95be0ea9
commit
315f1bd296
12
README.md
12
README.md
|
@ -43,7 +43,7 @@ void draw () {
|
|||
}
|
||||
```
|
||||
|
||||
### Alternate usage
|
||||
### Alternate usages
|
||||
|
||||
Use the `frame(int x, int y, int frameNumber)` method to draw specific frames--used for laying out multiple frames of soundtrack on a single screen.
|
||||
|
||||
|
@ -53,3 +53,13 @@ void draw () {
|
|||
}
|
||||
|
||||
```
|
||||
|
||||
Use the `buffer(int frameNumber)` method to return the internal `PGraphics` object that contains the specific frame of soundtrack data specified by the frameNumber. You can then draw onto the canvas, address the pixels directly, or as in the provided BufferExample.pde assign the image data to a PImage to be manipulated using the built-in transformation methods.
|
||||
|
||||
```java
|
||||
void draw () {
|
||||
PGraphics soundtrackBuffer = soundtrack.buffer(frameCount);
|
||||
image(soundtrackBuffer, 0, 0);
|
||||
}
|
||||
|
||||
```
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
import processing.sound.*;
|
||||
import soundtrack.optical.*;
|
||||
|
||||
SoundtrackOptical soundtrack;
|
||||
String type = "variable density";
|
||||
PGraphics soundtrackBuffer;
|
||||
PImage transform;
|
||||
|
||||
String soundtrackFile = "../../data/barking.wav";
|
||||
int dpi = 2400;
|
||||
float volume = 1.0;
|
||||
String pitch = "long";
|
||||
boolean positive = true;
|
||||
|
||||
void setup() {
|
||||
size(620, 213, P2D);
|
||||
soundtrack = new SoundtrackOptical(this, soundtrackFile, dpi, volume, type, pitch, positive);
|
||||
imageMode(CENTER);
|
||||
}
|
||||
|
||||
void draw () {
|
||||
soundtrackBuffer = soundtrack.buffer(frameCount);
|
||||
transform = soundtrackBuffer.get();
|
||||
translate(width>>1, height>>1);
|
||||
rotate(HALF_PI);
|
||||
image(transform, 0, 0);
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
import processing.sound.*;
|
||||
import soundtrack.optical.*;
|
||||
|
||||
SoundtrackOptical soundtrack;
|
||||
String type = "dual variable area";
|
||||
|
||||
String soundtrackFile = "../../data/barking.wav";
|
||||
int dpi = 2400;
|
||||
float volume = 1.0;
|
||||
String pitch = "long";
|
||||
boolean positive = true;
|
||||
|
||||
void setup() {
|
||||
size(1065, 620, P2D);
|
||||
soundtrack = new SoundtrackOptical(this, soundtrackFile, dpi, volume, type, pitch, positive);
|
||||
}
|
||||
|
||||
void draw () {
|
||||
for (int i = 0; i < 5; i++) {
|
||||
soundtrack.frame(i * 213, 0, frameCount + i);
|
||||
}
|
||||
|
||||
stroke(255, 0, 0);
|
||||
for (int i = 1; i < 5; i++) {
|
||||
line(213 * i, 0, 213 * i, height);
|
||||
}
|
||||
}
|
Binary file not shown.
|
@ -161,6 +161,58 @@ public class SoundtrackOptical {
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("static-access")
|
||||
public PGraphics buffer (int frameNumber) {
|
||||
if (frameNumber != -1) {
|
||||
i = frameNumber;
|
||||
}
|
||||
if (i >= FRAMES) {
|
||||
return null;
|
||||
}
|
||||
raw.beginDraw();
|
||||
//draw bg
|
||||
raw.noStroke();
|
||||
if (POSITIVE) {
|
||||
raw.fill(0);
|
||||
} else {
|
||||
raw.fill(255);
|
||||
}
|
||||
|
||||
if (TYPE != "variable density") {
|
||||
raw.rect(0, 0, RAW_FRAME_W, RAW_FRAME_H);
|
||||
}
|
||||
|
||||
//draw top
|
||||
if (POSITIVE) {
|
||||
raw.stroke(255);
|
||||
} else {
|
||||
raw.stroke(0);
|
||||
}
|
||||
|
||||
soundfile.read(i * RAW_FRAME_H, frameSample, 0, RAW_FRAME_H);
|
||||
|
||||
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") {
|
||||
unilateral(y, LINE_W);
|
||||
} else if (TYPE == "dual unilateral") {
|
||||
/* TODO!!!! */
|
||||
} else if (TYPE == "single variable area" || TYPE == "variable area") {
|
||||
variableArea(y, LINE_W);
|
||||
} else if (TYPE == "dual variable area") {
|
||||
dualVariableArea(y, LINE_W);
|
||||
} else if (TYPE == "multiple variable area" || TYPE == "maurer") {
|
||||
multipleVariableArea(y, LINE_W);
|
||||
} else if (TYPE == "variable density") {
|
||||
variableDensity(y);
|
||||
}
|
||||
}
|
||||
raw.endDraw();
|
||||
return raw;
|
||||
}
|
||||
|
||||
private void unilateral (int y, int LINE_W) {
|
||||
raw.line(0, y, LINE_W, y);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue