diff options
| author | Tim Redfern <tim@getdrop.com> | 2022-11-15 01:48:26 +0000 |
|---|---|---|
| committer | Tim Redfern <tim@getdrop.com> | 2022-11-15 01:48:26 +0000 |
| commit | 25467cc7d96c56eb2b739a3ffb093ab5a9c57b13 (patch) | |
| tree | 94a350bc12ad4735858b58156590ae257f48f358 /audioin/src/ofApp.h | |
| parent | af28dee8c32670db6a9eaf19793678a119cf1dd4 (diff) | |
testing oscilloscope latency
Diffstat (limited to 'audioin/src/ofApp.h')
| -rw-r--r-- | audioin/src/ofApp.h | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/audioin/src/ofApp.h b/audioin/src/ofApp.h new file mode 100644 index 0000000..cecc23e --- /dev/null +++ b/audioin/src/ofApp.h @@ -0,0 +1,68 @@ +#pragma once + +#include "ofMain.h" + +#include <baudvine/ringbuf.h> + +#define SAMPLERATE 48000 +#define min(a,b) (a<b?a:b) + +class Buffer{ +public: + Buffer(size_t sz=0){ + if (sz){ + data =new float[sz]; + size=sz; + } + } + ~Buffer(){ + delete data; + } + void add(float * input, int num){ + memcpy(&data[writePoint],input,min(num,size-writePoint)*4); + if (size-writePoint<num){ + memcpy(data,&input[size-writePoint],(num-(size-writePoint))*4); + writePoint=num-(size-writePoint); + } + else writePoint+=num; + } + float operator [] (int i) const {return data[writePoint>i?writePoint-i:size-(i-writePoint)];} + float& operator [] (int i) {return data[writePoint>i?writePoint-i:size-(i-writePoint)];} +private: + size_t size; + float *data; + int writePoint; +}; + +class ofApp : public ofBaseApp{ + + public: + void setup(); + void update(); + void draw(); + + void keyPressed(int key); + void keyReleased(int key); + void mouseMoved(int x, int y ); + void mouseDragged(int x, int y, int button); + void mousePressed(int x, int y, int button); + void mouseReleased(int x, int y, int button); + void windowResized(int w, int h); + void dragEvent(ofDragInfo dragInfo); + void gotMessage(ofMessage msg); + + void audioIn(float * input, int bufferSize, int nChannels); + + ofSoundStream soundStream; + int blockSize; + int sampleRate; + + int frameHead; //last sample drawn + + //baudvine::RingBuf<float, SAMPLERATE> buffer; + + Buffer buffer; + + float hScale; + float vScale; +}; |
