Files
processing4/java/libraries/video/examples/Pipelines/Raw/Raw.pde
T
2011-06-18 16:27:28 +00:00

49 lines
1.2 KiB
Plaintext

/**
* Raw pipeline.
* By Andres Colubri
*
*/
import codeanticode.gsvideo.*;
GSPipeline pipeline;
void setup() {
size(200, 200);
// A raw pipeline can be used to retrieve the data frames from the stream right after it has
// been decoded from the file.
// Reading audio frames from mp3 file. Note we need to add the decoding element (mad):
pipeline = new GSPipeline(this, "filesrc location=" + dataPath("groove.mp3") + " ! mad", GSVideo.RAW);
// Test audio signal generated by the audiotestsrc element. Here we don't need any decoding, as the
// frames coming out of audiotestsrc already contain valid audio data:
//pipeline = new GSPipeline(this, "audiotestsrc", GSVideo.RAW);
pipeline.loop();
}
void pipelineEvent(GSPipeline p) {
p.read();
}
void draw() {
background(0);
if (pipeline.data != null) {
//println("Data size: " + pipeline.data.length);
//println("Data caps: " + pipeline.dataCaps);
// Mapping audio bytes to pixel color.
loadPixels();
byte[] data = pipeline.data;
for (int i = 0; i < data.length; i++) {
int k = int(map(i, 0, data.length - 1, 0, width * height - 1));
pixels[k] = color(data[i] + 128, 0, 0, 255);
}
updatePixels();
}
}