Skip to content

Instantly share code, notes, and snippets.

@kylemcdonald
Last active February 1, 2023 15:38
Show Gist options
  • Save kylemcdonald/9a4c7496de122bf2c4be to your computer and use it in GitHub Desktop.
Save kylemcdonald/9a4c7496de122bf2c4be to your computer and use it in GitHub Desktop.
Reconstructing cyclo. id#00 by Carsten Nicolai & Ryoji Ikeda with openFrameworks.
// download cycolid.wav with:
// $ wget -O cycloid.mp4 "https://vimeo.com/73860675/download?t=1446320826&v=187839750&s=46dcfa8c1c9ed3539dcc260443df6da08032ee60796f781df237bb6957cb8138"
// $ ffmpeg -i cycloid.mp4 cycloid.wav
#include "ofMain.h"
#include "ofxAudioDecoder.h"
class ofApp : public ofBaseApp {
public:
ofxAudioDecoder audio;
ofSoundPlayer sound;
void setup() {
ofBackground(0);
audio.load("cycloid.wav");
sound.load("cycloid.wav");
sound.play();
}
void draw() {
int audioFrames = audio.getNumFrames();
int audioFramesPerVideoFrame = 880;
int audioFrameOffset = sound.getPosition() * audioFrames;
if(ofGetMousePressed()) {
audioFrameOffset = ofMap(mouseX, 0, ofGetWidth(), 0, audioFrames);
}
ofMesh mesh;
mesh.setMode(OF_PRIMITIVE_POINTS);
auto& samples = audio.getRawSamples();
for(int i = 0; i < audioFramesPerVideoFrame; i++) {
int j = 2 * (audioFrameOffset + i);
j = MIN(j, audio.getNumSamples() - 2);
mesh.addVertex(ofVec2f(samples[j], samples[j+1]));
}
ofTranslate(ofGetWidth() / 2, ofGetHeight() / 2);
float scale = MIN(ofGetWidth(), ofGetHeight()) / 2;
ofScale(scale, scale);
mesh.draw();
}
};
int main() {
ofSetupOpenGL(800, 800, OF_FULLSCREEN);
ofRunApp(new ofApp());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment