Created
December 19, 2023 10:12
Revisions
-
kylemcdonald created this gist
Dec 19, 2023 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,43 @@ #pragma once #include <vector> #include "ofImage.h" class FixedVideoDelay { private: int delayAmount; int totalFrames; int readPosition; int writePosition; std::vector<ofPixels> buffer; public: FixedVideoDelay() {} void setup(int width, int height, int delayAmount) { this->delayAmount = delayAmount; int bufferSize = delayAmount * 2; for (int i = 0; i < bufferSize; i++) { ofPixels pix; pix.allocate(width, height, OF_IMAGE_COLOR); buffer.push_back(pix); } totalFrames = 0; readPosition = 0; writePosition = 0; } void writeFrame(ofPixels &pixels) { buffer[writePosition] = pixels; writePosition = (writePosition + 1) % buffer.size(); totalFrames++; } bool ready() { return totalFrames >= delayAmount; } ofPixels &readFrame() { readPosition = (readPosition + 1) % buffer.size(); return buffer[readPosition]; } };