Research Journal(11.16)

Today, in my project, I want to add some buttons to interact with the audience. For example,In my project in a specified by the audience pressed the button to play the sound of the river.  Last weekend I went to the Avon River and recorded the sound of the river with a recorder, and selected two sounds stored in the computer, and named "meng11.wav" and "meng22.wav" respectively, they are stored in the "Data" file of this project.

Then, open this project, which is roughly the same as the steps in the previous diary. Firstly,  open the "ofApp.h" file and name the two audios: "ofSoundPlayer synth" and "ofSoundPlayer beats". As shown below:

Next, in the file "ofApp.cpp", upload the audio saved in the "Data" file as shown:

After uploading this data, set it in this project:
                                        void ofApp::keyPressed(int key){
                                                                        switch (key) {
                                                                        case '1':
                                                                        synth.play();
                                                                       break;”
                                                        }
                                         }
This code means that when you press the number "1", you can hear the "synth" audio (that is "meng11"), now you can play sounds of this river that I have recorded in this system.

The final step today is to add a little bit of special effects. When you run this project, every time you click the mouse, the sound of water will appear. Similarly, in "ofApp.cpp", the code is set as follows:
                                      void ofApp::mousePressed(int x, int y, int button){
                                                        float widthStep = ofGetWidth() / 2.0f;
                                                        if (x < widthStep){
                                                              beats.play();
                                                              synth.setSpeed( 0.1f + ((float)(ofGetHeight() - y) / (float)ofGetHeight())*10);
                                                              // synth.setPan(ofMap(x, 0, widthStep, -1, 1, true));
                                                              synth.setVolume(ofMap(y, 0, ofGetHeight(), 0, 1));
                                                              // here we use a MAP funtion to map a range of input values to a range of desired              output values
                                                              // in our case we take in the mouseY position (range from 0 to the screen height)        and MAP this to values from 0 to 1 that we can use to send to the synth.setVolume() function
                                                             // the syntax for the oF map function is as follows:
                                                             // ofMap(<#float value#>, <#float inputMin#>, <#float inputMax#>, <#float outputMin#>, <#float outputMax#>)
                                                         } else if (x >= widthStep && x < widthStep*2){
                                                             beats.play();
                                                             beats.setSpeed( 0.1f + ((float)(ofGetHeight() - y) / (float)ofGetHeight())*10);
                                                             beats.setPan(ofMap(x, 0, widthStep, -1, 1, true));
                                                          }
                                                   }
After setting, when you click the mouse, there will be a sound of water. Continuous update progress...
reference:


评论