@@ -9,10 +9,9 @@ void ofApp::setup(){
99
1010 soundStream.printDeviceList ();
1111
12- int bufferSize = 256 ;
12+ int bufferSize = 512 ;
1313
14- left.assign (bufferSize, 0.0 );
15- right.assign (bufferSize, 0.0 );
14+
1615 volHistory.assign (400 , 0.0 );
1716
1817 bufferCounter = 0 ;
@@ -28,14 +27,16 @@ void ofApp::setup(){
2827 // settings.device = devices[4];
2928
3029 // you can also get devices for an specific api
31- // auto devices = soundStream.getDevicesByApi (ofSoundDevice::Api::PULSE);
30+ // auto devices = soundStream.getDeviceList (ofSoundDevice::Api::PULSE);
3231 // settings.device = devices[0];
3332
3433 // or get the default device for an specific api:
3534 // settings.api = ofSoundDevice::Api::PULSE;
3635
3736 // or by name
37+
3838 auto devices = soundStream.getMatchingDevices (" default" );
39+
3940 if (!devices.empty ()){
4041 settings.setInDevice (devices[0 ]);
4142 }
@@ -51,6 +52,11 @@ void ofApp::setup(){
5152 settings.bufferSize = bufferSize;
5253 soundStream.setup (settings);
5354
55+ bufferSize = soundStream.getBufferSize ();
56+
57+ left.assign (bufferSize, 0.0 );
58+ right.assign (bufferSize, 0.0 );
59+
5460}
5561
5662// --------------------------------------------------------------
@@ -167,8 +173,8 @@ void ofApp::audioIn(ofSoundBuffer & input){
167173
168174 // lets go through each sample and calculate the root mean square which is a rough way to calculate volume
169175 for (size_t i = 0 ; i < input.getNumFrames (); i++){
170- left[i] = input[i* 2 ]*0.5 ;
171- right[i] = input[i* 2 + 1 ]*0.5 ;
176+ left[i] = input[i]*0.5 ;
177+ right[i] = input[i]*0.5 ;
172178
173179 curVol += left[i] * left[i];
174180 curVol += right[i] * right[i];
0 commit comments