summaryrefslogtreecommitdiff
path: root/audioin/src/ofApp.cpp
blob: 9160f656b7245a17a4938dcd3589f36580210bec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#include "ofApp.h"
void ofApp::setup(){

    int frameRate=60;
    
    ofSetFrameRate(frameRate);
    ofBackground(0);
    ofEnableSmoothing();
    ofEnableAlphaBlending();
    ofSetVerticalSync(true);

    blockSize = SAMPLERATE / (frameRate*10); //80

    ofSoundStreamListDevices();

    soundStream.setup(this,0, 1, SAMPLERATE, blockSize, 1);

    buffer=Buffer(SAMPLERATE);

    vScale=3.0f;
    hScale=8.0f;

    lineWidth=2.0f;
  
}
void ofApp::update(){
    
 
}

int sampleNum=0;
int frameNum=0;

void ofApp::draw(){
    ofBackground(0);

    ofSetLineWidth(lineWidth);

    ofPushMatrix();

    ofTranslate(0,ofGetHeight()/2);

    ofScale(1.0f,ofGetHeight()*vScale);

    ofPolyline line;


    line.addVertex(0,buffer[0]);

    float i=0.0f;
    while (i<(ofGetWidth()+hScale)){
        i+=max(1.0f,hScale);
        line.curveTo(i,buffer[(int)i]);
    }

    line.draw();


    ofPopMatrix();
    
    frameNum++;

    ofSetWindowTitle(ofToString(ofGetFrameRate()));

}



void ofApp::audioIn(float * input, int blockSize, int nChannels){
   //ofLog()<< "frame "<<frameNum<<" ,got blockr "<<sampleNum++<<" , "<<nChannels<<" channels "<<blockSize<<" samples";    
   
//    for (int i=0;i<blockSize;i++){
//        buffer.push_front()
//    }

    //ofLog()<< "samples: "<<input[0]<<" "<<input[1]<<" "<<input[2]<<" ";

    buffer.add(input,blockSize);

}


void ofApp::printOscParams(){
    ofLog()<<(1000.0f/(SAMPLERATE/(ofGetWidth()/hScale)))<<"ms, scale: "<<vScale<<", width "<<lineWidth;
}

//--------------------------------------------------------------
void ofApp::keyPressed(int key){
    switch(key){
        case 'f':{  
            ofToggleFullscreen();
            break;
        }
        case 'i':{
            vScale*=1.1f;
            printOscParams();
            break;
        }
        case 'm':{
            vScale/=1.1f;
            printOscParams();
            break;
        }
        case 'j':{
            hScale*=1.1f;
            printOscParams();
            break;
        }
        case 'k':{
            hScale/=1.1f;
            printOscParams();
            break;
        }
         case ']':{
            lineWidth*=1.1f;
            printOscParams();
            break;
        }
        case '[':{
            lineWidth/=1.1f;
            printOscParams();
            break;
        }
        default:
            break;
    }

}

//--------------------------------------------------------------
void ofApp::keyReleased(int key){

}

//--------------------------------------------------------------
void ofApp::mouseMoved(int x, int y ){

}

void ofApp::mouseDragged(int x, int y, int button){
 
}

//--------------------------------------------------------------
void ofApp::mousePressed(int x, int y, int button){

}

//--------------------------------------------------------------
void ofApp::mouseReleased(int x, int y, int button){

}

//--------------------------------------------------------------
void ofApp::windowResized(int w, int h){

}

//--------------------------------------------------------------
void ofApp::gotMessage(ofMessage msg){

}

//--------------------------------------------------------------
void ofApp::dragEvent(ofDragInfo dragInfo){

}