Skip to content

Commit 1c295aa

Browse files
tctrdanoli3
authored andcommitted
Android example : adding ofSoundPlayer features
(cherry picked from commit 25e9001)
1 parent c131dfd commit 1c295aa

3 files changed

Lines changed: 47 additions & 9 deletions

File tree

examples/android/androidEmptyExample/ofApp/src/main/AndroidManifest.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424

2525
<uses-feature android:glEsVersion="0x00020000"/>
2626

27+
<!-- Audio Systems -->
28+
<uses-feature android:name="android.hardware.audio.output" android:required="true" />
29+
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
30+
2731
<supports-screens android:resizeable="false"
2832
android:smallScreens="true"
2933
android:normalScreens="true"

examples/android/androidEmptyExample/ofApp/src/main/cpp/ofApp.cpp

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,21 @@ void ofApp::setup(){
2727
text.setFillColor(ofColor(245, 58, 135));
2828

2929
doShader = false;
30+
31+
32+
// SOUND
33+
// ofSetOrientation(OF_ORIENTATION_90_LEFT);
34+
loadok = synth.loadSound("sounds/synth.wav");
35+
loadok = beats.loadSound("sounds/1085.mp3");
36+
loadok = vocals.loadSound("sounds/Violet.mp3");
37+
synth.setVolume(1.0f);
38+
beats.setVolume(0.75f);
39+
vocals.setVolume(1.0f);
40+
synth.setMultiPlay(true);
41+
beats.setMultiPlay(false);
42+
vocals.setMultiPlay(true);
43+
44+
3045
}
3146

3247
void ofApp::exit(){
@@ -35,7 +50,8 @@ void ofApp::exit(){
3550

3651
//--------------------------------------------------------------
3752
void ofApp::update(){
38-
53+
// update the sound playing system:
54+
ofSoundUpdate();
3955
}
4056

4157
//--------------------------------------------------------------
@@ -46,10 +62,6 @@ void ofApp::draw(){
4662
int b = 128 + 50 * sinf(ofGetElapsedTimef());
4763

4864
ofBackground(r,g,b);
49-
50-
//ofSetColor(245, 58, 135);
51-
//ofFill();
52-
//font.drawStringAsShapes("meditate", 300, 400);
5365

5466
if( doShader ){
5567
shader.begin();
@@ -69,9 +81,6 @@ void ofApp::draw(){
6981
if( doShader ){
7082
shader.end();
7183
}
72-
73-
74-
7584
}
7685

7786
//--------------------------------------------------------------
@@ -92,11 +101,32 @@ void ofApp::windowResized(int w, int h){
92101
//--------------------------------------------------------------
93102
void ofApp::touchDown(int x, int y, int id){
94103
doShader = true;
104+
105+
float widthStep = ofGetWidth() / 3.0f;
106+
if (x < widthStep){
107+
float pct = x / widthStep;
108+
synth.play();
109+
synth.setSpeed( 0.1f + ((float)(ofGetHeight() - y) / (float)ofGetHeight())*2.0f);
110+
synth.setPan(2.0*pct-1.0);
111+
}
112+
else if (x >= widthStep && x < widthStep*2){
113+
beats.play();
114+
}
115+
else {
116+
vocals.play();
117+
vocals.setSpeed( 0.1f + ((float)(ofGetHeight() - y) / (float)ofGetHeight())*2.0f);
118+
vocals.setPan(2.0*(float)(x - widthStep*2) / (float)widthStep-1.0);
119+
}
95120
}
96121

97122
//--------------------------------------------------------------
98123
void ofApp::touchMoved(int x, int y, int id){
99-
124+
// continuously control the speed of the beat sample via drag,
125+
// when in the "beat" region:
126+
float widthStep = ofGetWidth() / 3.0f;
127+
if (x >= widthStep && x < widthStep*2){
128+
beats.setSpeed( 0.5f + ((float)(ofGetHeight() - y) / (float)ofGetHeight())*1.0f);
129+
}
100130
}
101131

102132
//--------------------------------------------------------------

examples/android/androidEmptyExample/ofApp/src/main/cpp/ofApp.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,8 @@ class ofApp : public ofxAndroidApp{
4141
ofTrueTypeFont font;
4242
ofShader shader;
4343
bool doShader;
44+
45+
ofSoundPlayer beats;
46+
ofSoundPlayer synth;
47+
ofSoundPlayer vocals;
4448
};

0 commit comments

Comments
 (0)