diff options
| author | Tim Redfern <tim@getdrop.com> | 2022-11-15 18:07:58 +0000 |
|---|---|---|
| committer | Tim Redfern <tim@getdrop.com> | 2022-11-15 18:07:58 +0000 |
| commit | 8c69df689a9327b634f765f11984a76133d3777e (patch) | |
| tree | 8a0ce5fcbc918dea8454ceaef429dbeffae40d09 | |
| parent | 25467cc7d96c56eb2b739a3ffb093ab5a9c57b13 (diff) | |
minor audioin improvements
| -rw-r--r-- | audioin/src/ofApp.cpp | 23 | ||||
| -rw-r--r-- | audioin/src/ofApp.h | 15 |
2 files changed, 32 insertions, 6 deletions
diff --git a/audioin/src/ofApp.cpp b/audioin/src/ofApp.cpp index 4535c3c..cf454ce 100644 --- a/audioin/src/ofApp.cpp +++ b/audioin/src/ofApp.cpp @@ -9,7 +9,9 @@ void ofApp::setup(){ ofEnableAlphaBlending(); ofSetVerticalSync(true); - blockSize = SAMPLERATE / (frameRate*20); //200 + blockSize = SAMPLERATE / (frameRate*10); //80 + + ofSoundStreamListDevices(); soundStream.setup(this,0, 1, SAMPLERATE, blockSize, 1); @@ -17,6 +19,8 @@ void ofApp::setup(){ vScale=3.0f; hScale=8.0f; + + lineWidth=2.0f; } void ofApp::update(){ @@ -30,6 +34,8 @@ int frameNum=0; void ofApp::draw(){ ofBackground(0); + ofSetLineWidth(lineWidth); + ofPushMatrix(); ofTranslate(0,ofGetHeight()/2); @@ -37,16 +43,19 @@ void ofApp::draw(){ ofScale(1.0f,ofGetHeight()*vScale); ofPolyline line; + + line.addVertex(0,buffer[0]); float i=0.0f; while (i<ofGetWidth()){ + i+=max(1.0f,hScale); line.curveTo(i,buffer[(int)i]); - i+=hScale; } line.draw(); + ofPopMatrix(); frameNum++; @@ -98,6 +107,16 @@ void ofApp::keyPressed(int key){ ofLog()<< "hScale: "<<hScale; break; } + case ']':{ + lineWidth*=1.1f; + ofLog()<< "lineWidth: "<<lineWidth; + break; + } + case '[':{ + lineWidth/=1.1f; + ofLog()<< "lineWidth: "<<lineWidth; + break; + } default: break; } diff --git a/audioin/src/ofApp.h b/audioin/src/ofApp.h index cecc23e..d62dfa0 100644 --- a/audioin/src/ofApp.h +++ b/audioin/src/ofApp.h @@ -2,26 +2,31 @@ #include "ofMain.h" -#include <baudvine/ringbuf.h> +//#include <baudvine/ringbuf.h> #define SAMPLERATE 48000 #define min(a,b) (a<b?a:b) +#define max(a,b) (a>b?a:b) class Buffer{ public: Buffer(size_t sz=0){ if (sz){ data =new float[sz]; + memset(data,0,sz*sizeof(float)); size=sz; } + else data=NULL; } ~Buffer(){ - delete data; + if (data){ + //delete[] data; //why is this throwing an error + } } void add(float * input, int num){ - memcpy(&data[writePoint],input,min(num,size-writePoint)*4); + memcpy(&data[writePoint],input,min(num,size-writePoint)*sizeof(float)); if (size-writePoint<num){ - memcpy(data,&input[size-writePoint],(num-(size-writePoint))*4); + memcpy(data,&input[(size-writePoint)],(num-(size-writePoint))*sizeof(float)); writePoint=num-(size-writePoint); } else writePoint+=num; @@ -65,4 +70,6 @@ class ofApp : public ofBaseApp{ float hScale; float vScale; + + float lineWidth; }; |
