Răsfoiți Sursa

Fix OpenSLInterface.

Finally make the OpenSLInterface play convenient sound.
Joachim Meyer 9 ani în urmă
părinte
comite
4810fcb78d

+ 1 - 1
build/android/build.gradle

@@ -5,7 +5,7 @@ buildscript {
         jcenter()
     }
     dependencies {
-        classpath 'com.android.tools.build:gradle:2.1.0'
+        classpath 'com.android.tools.build:gradle:2.1.2'
 
         // NOTE: Do not place your application dependencies here; they belong
         // in the individual module build.gradle files

+ 6 - 2
include/polycode/core/PolyAndroidCore.h

@@ -41,6 +41,7 @@
 
 namespace Polycode {
 
+	class OpenSLAudioInterface;
 	class PolycodeView;
 // 	class ANativeActivity;
 	
@@ -133,6 +134,8 @@ namespace Polycode {
 		
 		PolyKEY mapKey(int keyCode);
 		void extractResources();
+		
+		OpenSLAudioInterface* getAudioInterface();
 	private:
 		PolycodeView* view;
 		
@@ -150,10 +153,11 @@ namespace Polycode {
 		
 		std::vector<AndroidEvent> systemInputEvents;
 
-		double pcFreq;
+// 		double pcFreq;
 
 		OpenGLGraphicsInterface *graphicsInterface;
-
+		OpenSLAudioInterface* audioInterface;
+		
 		void initKeyMap();
 		PolyKEY keyMap[1024];
 	};

+ 5 - 3
src/core/PolyAndroidCore.cpp

@@ -84,8 +84,6 @@ AndroidCore::AndroidCore(PolycodeView *view, int xRes, int yRes, bool fullScreen
 	defaultWorkingDirectory = view->native_activity->internalDataPath;
 	userHomeDirectory = view->native_activity->externalDataPath;
 	
-	services->getSoundManager()->setAudioInterface(new AudioInterface());
-	
 	paused = true;
 	
 	initKeyMap();
@@ -93,7 +91,8 @@ AndroidCore::AndroidCore(PolycodeView *view, int xRes, int yRes, bool fullScreen
 	this->view = view;
 	core = this;
 	
-	services->getSoundManager()->setAudioInterface(new OpenSLAudioInterface());
+	audioInterface = new OpenSLAudioInterface();
+	services->getSoundManager()->setAudioInterface(audioInterface);
 	extractResources();
 }
 
@@ -675,3 +674,6 @@ PolyKEY AndroidCore::mapKey(int keyCode){
 	return keyMap[(unsigned int) keyCode];
 }
 
+OpenSLAudioInterface* AndroidCore::getAudioInterface(){
+	return audioInterface;
+}

+ 1 - 1
src/core/PolyOpenSLAudioInterface.cpp

@@ -121,7 +121,7 @@ void OpenSLAudioInterface::terminateOpenSL(){
 
 void OpenSLAudioInterface::queueCallback(SLAndroidSimpleBufferQueueItf caller, void* pContext){
 	OpenSLAudioInterface *audioInterface = (OpenSLAudioInterface*) pContext;
-	if(audioInterface->buffer && audioInterface->getMixer()) {
+	if(audioInterface->buffer && audioInterface->getMixer() && !Services()->getCore()->paused) {
 		int16_t *out = (int16_t*)audioInterface->buffer;
 		audioInterface->getMixer()->mixIntoBuffer(out, POLY_FRAMES_PER_BUFFER);
 		(*(audioInterface->mPlayerQueue))->Enqueue(audioInterface->mPlayerQueue, out, sizeof(int16_t)*POLY_FRAMES_PER_BUFFER*POLY_NUM_CHANNELS);

+ 6 - 2
src/view/android/PolycodeView.cpp

@@ -104,14 +104,18 @@ void onStart(ANativeActivity* activity){
 void onResume(ANativeActivity* activity){
 	Logger::log("onResume");
 	JNIWakeLock(activity, true);
-	if(core)
+	if(core){
 		core->paused = false;
+		OpenSLAudioInterface::queueCallback(NULL, core->getAudioInterface());
+	}
 	((PolycodeView*)activity->instance)->lifecycleFlags |= APP_STATUS_ACTIVE;
 }
 
 void onPause(ANativeActivity* activity){
 	Logger::log("onPause");
 	JNIWakeLock(activity, false);
+	if(core)
+		core->paused = true;
 	((PolycodeView*)activity->instance)->lifecycleFlags &= ~APP_STATUS_ACTIVE;
 }
 
@@ -181,7 +185,7 @@ void onNativeWindowCreated(ANativeActivity* activity, ANativeWindow *window){
 		((PolycodeView*)activity->instance)->lifecycleFlags|=APP_STATUS_HAS_REAL_SURFACE;
 		if(core){
 			if(((PolycodeView*)activity->instance)->firstWindowCreate){
-				Services()->getSoundManager()->setAudioInterface(new OpenSLAudioInterface());
+				
 				((PolycodeView*)activity->instance)->firstWindowCreate = false;
 			}
 			core->recreateContext = true;