소스 검색

New try with OpenSL.

Joachim Meyer 9 년 전
부모
커밋
71b070cc07

+ 3 - 1
build/android/TemplateApp/jni/PolycodeTemplateApp.cpp

@@ -10,9 +10,11 @@ PolycodeTemplateApp::PolycodeTemplateApp(PolycodeView *view) {
     core = new POLYCODE_CORE(view, 800,480,false,false, 0,0,60, -1, true);
 
     core->addFileSource("archive", "default.pak");
+    core->addFileSource("folder", core->getDefaultWorkingDirectory());
     ResourcePool *globalPool = Services()->getResourceManager()->getGlobalPool();
     globalPool->loadResourcesFromFolder("default", true);
 
+
 	// Write your code here!
     srand(time(NULL));
     scene = new Scene(Scene::SCENE_2D);
@@ -37,7 +39,7 @@ PolycodeTemplateApp::PolycodeTemplateApp(PolycodeView *view) {
         scene->addChild(box);
     }*/
 
-//    bgSound = new Sound("FightBG.WAV");
+    bgSound = new Sound("FightBG.OGG");
 //    bgSound->Play();
 //    bgSound->setPitch(10.0);
 

+ 15 - 41
include/polycode/core/PolyOpenSLAudioInterface.h

@@ -26,59 +26,33 @@
 #include "polycode/core/PolySoundManager.h"
 #include "polycode/core/PolyThreaded.h"
 
-// #if PLATFORM == PLATFORM_ANDROID
 #include <SLES/OpenSLES_Android.h>
-// #else
-// #include <SLES/OpenSLES.h>
-// #endif
 
 namespace Polycode {
-	
-	class OpenSLStream : public Threaded {
+
+    class OpenSLAudioInterface : public AudioInterface {
 	public:
-		OpenSLStream();
-		virtual ~OpenSLStream();
+		OpenSLAudioInterface();
+		~OpenSLAudioInterface();
 		
-		void runThread();
 		void setMixer(AudioMixer* newMixer);
 		
-		static void bqPlayerCallback(SLAndroidSimpleBufferQueueItf bq, void* context);
+		void initOpenSL();
+		void terminateOpenSL();
 		
+		static void queueCallback(SLAndroidSimpleBufferQueueItf caller, void *pContext);
 	private:
-		AudioMixer* mixer;
-		int16_t *playBuffer;
-		int16_t *backBuffer;
-		
-		// engine interfaces
-		SLObjectItf engineObject;
-		SLEngineItf engineEngine;
-
-		// output mix interfaces
-		SLObjectItf outputMixObject;
 
-		// buffer queue player interfaces
-		SLObjectItf bqPlayerObject;
-		SLPlayItf bqPlayerPlay;
-		SLAndroidSimpleBufferQueueItf bqPlayerBufferQueue;
-		SLEffectSendItf bqPlayerEffectSend;
+		SLObjectItf mEngineObj;
+		SLEngineItf mEngine;
+		SLObjectItf mOutputMixObj;
 		
- 		void swapBuffers();
-		bool swappedBuffers;
+		SLObjectItf mPlayerObj; 
+		SLPlayItf mPlayer;
+		SLAndroidSimpleBufferQueueItf mPlayerQueue;
+		SLVolumeItf mVolume;
 		
-		void initOpenSL();
-		void terminateOpenSL();
-		CoreMutex* streamMutex;
-	};
-	
-    class OpenSLAudioInterface : public AudioInterface {
-	public:
-		OpenSLAudioInterface();
-		~OpenSLAudioInterface();
-			
-		void setMixer(AudioMixer* newMixer);
-			
-	private:
-		OpenSLStream* stream;
+		int16_t buffer[44100];
     };
 }
 

+ 0 - 182
src/core/OpenSLES_IID.c

@@ -1,182 +0,0 @@
-/*
- * Copyright (c) 2007-2009 The Khronos Group Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of
- * this software and /or associated documentation files (the "Materials "), to
- * deal in the Materials without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Materials, and to permit persons to whom the Materials are
- * furnished to do so, subject to 
- * the following conditions: 
- *
- * The above copyright notice and this permission notice shall be included 
- * in all copies or substantial portions of the Materials. 
- *
- * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE USE OR OTHER DEALINGS IN THE
- * MATERIALS.
- *
- * OpenSLES_IID.c - OpenSL ES version 1.0
- *
- */
-
-/****************************************************************************/
-/* NOTE: This file is a standard OpenSL ES file and should not be           */
-/* modified in any way.                                                     */
-/****************************************************************************/
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-
-
-#include "OpenSLES.h" /* SL Header */
-
-/*****************************************************************************/
-/* Interface IDs                                                             */
-/*****************************************************************************/
-
-static const struct SLInterfaceID_ SL_IID_NULL_ = { 0xec7178ec, 0xe5e1, 0x4432, 0xa3f4, { 0x46, 0x57, 0xe6, 0x79, 0x52, 0x10 } };
-const SLInterfaceID SL_IID_NULL = &SL_IID_NULL_;
-
-static const struct SLInterfaceID_ SL_IID_AUDIOIODEVICECAPABILITIES_ = { 0xb2564dc0, 0xddd3, 0x11db, 0xbd62, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } };
-const SLInterfaceID SL_IID_AUDIOIODEVICECAPABILITIES = &SL_IID_AUDIOIODEVICECAPABILITIES_;
-
-static const struct SLInterfaceID_ SL_IID_LED_ = { 0x2cc1cd80, 0xddd6, 0x11db, 0x807e, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } };
-const SLInterfaceID SL_IID_LED = &SL_IID_LED_;
-
-static const struct SLInterfaceID_ SL_IID_VIBRA_ = { 0x169a8d60, 0xdddd, 0x11db, 0x923d, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } };
-const SLInterfaceID SL_IID_VIBRA = &SL_IID_VIBRA_;
-
-static const struct SLInterfaceID_ SL_IID_METADATAEXTRACTION_ = { 0xaa5b1f80, 0xddd6, 0x11db, 0xac8e, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } };
-const SLInterfaceID SL_IID_METADATAEXTRACTION = &SL_IID_METADATAEXTRACTION_;
-
-static const struct SLInterfaceID_ SL_IID_METADATATRAVERSAL_ = { 0xc43662c0, 0xddd6, 0x11db, 0xa7ab, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } };
-const SLInterfaceID SL_IID_METADATATRAVERSAL = &SL_IID_METADATATRAVERSAL_;
-
-static const struct SLInterfaceID_ SL_IID_DYNAMICSOURCE_ = { 0xc55cc100, 0x038b, 0x11dc, 0xbb45, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } };
-const SLInterfaceID SL_IID_DYNAMICSOURCE = &SL_IID_DYNAMICSOURCE_;
-
-static const struct SLInterfaceID_ SL_IID_OUTPUTMIX_ = { 0x97750f60, 0xddd7, 0x11db, 0x92b1, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } };
-const SLInterfaceID SL_IID_OUTPUTMIX = &SL_IID_OUTPUTMIX_;
-
-static const struct SLInterfaceID_ SL_IID_PLAY_ = { 0xef0bd9c0, 0xddd7, 0x11db, 0xbf49, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } };
-const SLInterfaceID SL_IID_PLAY = &SL_IID_PLAY_;
-
-static const struct SLInterfaceID_ SL_IID_PREFETCHSTATUS_ = { 0x2a41ee80, 0xddd8, 0x11db, 0xa41f, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } };
-const SLInterfaceID SL_IID_PREFETCHSTATUS = &SL_IID_PREFETCHSTATUS_;
-
-static const struct SLInterfaceID_ SL_IID_PLAYBACKRATE_ = { 0x2e3b2a40, 0xddda, 0x11db, 0xa349, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } };
-const SLInterfaceID SL_IID_PLAYBACKRATE = &SL_IID_PLAYBACKRATE_;
-
-static const struct SLInterfaceID_ SL_IID_SEEK_ = { 0xd43135a0, 0xdddc, 0x11db, 0xb458, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } };
-const SLInterfaceID SL_IID_SEEK = &SL_IID_SEEK_;
-
-static const struct SLInterfaceID_ SL_IID_RECORD_ = { 0xc5657aa0, 0xdddb, 0x11db, 0x82f7, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } };
-const SLInterfaceID SL_IID_RECORD = &SL_IID_RECORD_;
-
-static const struct SLInterfaceID_ SL_IID_EQUALIZER_ = { 0x0bed4300, 0xddd6, 0x11db, 0x8f34, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } };
-const SLInterfaceID SL_IID_EQUALIZER = &SL_IID_EQUALIZER_;
-
-static const struct SLInterfaceID_ SL_IID_VOLUME_ = { 0x09e8ede0, 0xddde, 0x11db, 0xb4f6, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } };
-const SLInterfaceID SL_IID_VOLUME = &SL_IID_VOLUME_;
-
-static const struct SLInterfaceID_ SL_IID_DEVICEVOLUME_ = { 0xe1634760, 0xf3e2, 0x11db, 0x9ca9, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } };
-const SLInterfaceID SL_IID_DEVICEVOLUME = &SL_IID_DEVICEVOLUME_;
-
-static const struct SLInterfaceID_ SL_IID_OBJECT_ = { 0x79216360, 0xddd7, 0x11db, 0xac16, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } };
-const SLInterfaceID SL_IID_OBJECT = &SL_IID_OBJECT_;
-
-static const struct SLInterfaceID_ SL_IID_BUFFERQUEUE_ = { 0x2bc99cc0, 0xddd4, 0x11db, 0x8d99, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } };
-const SLInterfaceID SL_IID_BUFFERQUEUE = &SL_IID_BUFFERQUEUE_;
-
-static const struct SLInterfaceID_ SL_IID_PRESETREVERB_ = { 0x47382d60, 0xddd8, 0x11db, 0xbf3a, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } };
-const SLInterfaceID SL_IID_PRESETREVERB = &SL_IID_PRESETREVERB_;
-
-static const struct SLInterfaceID_ SL_IID_ENVIRONMENTALREVERB_ = { 0xc2e5d5f0, 0x94bd, 0x4763, 0x9cac, { 0x4e, 0x23, 0x4d, 0x6, 0x83, 0x9e } };
-const SLInterfaceID SL_IID_ENVIRONMENTALREVERB = &SL_IID_ENVIRONMENTALREVERB_;
-
-static const struct SLInterfaceID_ SL_IID_EFFECTSEND_ = { 0x56e7d200, 0xddd4, 0x11db, 0xaefb, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } };
-const SLInterfaceID SL_IID_EFFECTSEND = &SL_IID_EFFECTSEND_;
-
-static const struct SLInterfaceID_ SL_IID_3DGROUPING_ = { 0xebe844e0, 0xddd2, 0x11db, 0xb510, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } };
-const SLInterfaceID SL_IID_3DGROUPING = &SL_IID_3DGROUPING_;
-
-static const struct SLInterfaceID_ SL_IID_3DCOMMIT_ = { 0x3564ad80, 0xdd0f, 0x11db, 0x9e19, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } };
-const SLInterfaceID SL_IID_3DCOMMIT = &SL_IID_3DCOMMIT_;
-
-static const struct SLInterfaceID_ SL_IID_3DLOCATION_ = { 0x2b878020, 0xddd3, 0x11db, 0x8a01, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } };
-const SLInterfaceID SL_IID_3DLOCATION = &SL_IID_3DLOCATION_;
-
-static const struct SLInterfaceID_ SL_IID_3DDOPPLER_ = { 0xb45c9a80, 0xddd2, 0x11db, 0xb028, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } };
-const SLInterfaceID SL_IID_3DDOPPLER = &SL_IID_3DDOPPLER_;
-
-static const struct SLInterfaceID_ SL_IID_3DSOURCE_ = { 0x70bc7b00, 0xddd3, 0x11db, 0xa873, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } };
-const SLInterfaceID SL_IID_3DSOURCE = &SL_IID_3DSOURCE_;
-
-static const struct SLInterfaceID_ SL_IID_3DMACROSCOPIC_ = { 0x5089aec0, 0xddd3, 0x11db, 0x9ad3, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } };
-const SLInterfaceID SL_IID_3DMACROSCOPIC = &SL_IID_3DMACROSCOPIC_;
-
-static const struct SLInterfaceID_ SL_IID_MUTESOLO_ = { 0x5a28ebe0, 0xddd7, 0x11db, 0x8220, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } };
-const SLInterfaceID SL_IID_MUTESOLO = &SL_IID_MUTESOLO_;
-
-static const struct SLInterfaceID_ SL_IID_DYNAMICINTERFACEMANAGEMENT_ = { 0x63936540, 0xf775, 0x11db, 0x9cc4, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } };
-const SLInterfaceID SL_IID_DYNAMICINTERFACEMANAGEMENT = &SL_IID_DYNAMICINTERFACEMANAGEMENT_;
-
-static const struct SLInterfaceID_ SL_IID_MIDIMESSAGE_ = { 0xddf4a820, 0xddd6, 0x11db, 0xb174, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } };
-const SLInterfaceID SL_IID_MIDIMESSAGE = &SL_IID_MIDIMESSAGE_;
-
-static const struct SLInterfaceID_ SL_IID_MIDITEMPO_ = { 0x1f347400, 0xddd7, 0x11db, 0xa7ce, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } };
-const SLInterfaceID SL_IID_MIDITEMPO = &SL_IID_MIDITEMPO_;
-
-static const struct SLInterfaceID_ SL_IID_MIDIMUTESOLO_ = { 0x039eaf80, 0xddd7, 0x11db, 0x9a02, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } };
-const SLInterfaceID SL_IID_MIDIMUTESOLO = &SL_IID_MIDIMUTESOLO_;
-
-static const struct SLInterfaceID_ SL_IID_MIDITIME_ = { 0x3da51de0, 0xddd7, 0x11db, 0xaf70, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } };
-const SLInterfaceID SL_IID_MIDITIME = &SL_IID_MIDITIME_;
-
-static const struct SLInterfaceID_ SL_IID_AUDIODECODERCAPABILITIES_ = { 0x3fe5a3a0, 0xfcc6, 0x11db, 0x94ac, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } };
-const SLInterfaceID SL_IID_AUDIODECODERCAPABILITIES = &SL_IID_AUDIODECODERCAPABILITIES_;
-
-static const struct SLInterfaceID_ SL_IID_AUDIOENCODER_ = { 0xd7d5af7a, 0x351c, 0x41a6, 0x94ec, { 0x1a, 0xc9, 0x5c, 0x71, 0x82, 0x2c } };
-const SLInterfaceID SL_IID_AUDIOENCODER = &SL_IID_AUDIOENCODER_;
-
-static const struct SLInterfaceID_ SL_IID_AUDIOENCODERCAPABILITIES_ = { 0x0f52a340, 0xfcd1, 0x11db, 0xa993, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } };
-const SLInterfaceID SL_IID_AUDIOENCODERCAPABILITIES = &SL_IID_AUDIOENCODERCAPABILITIES_;
-
-static const struct SLInterfaceID_ SL_IID_BASSBOOST_ = { 0x0634f220, 0xddd4, 0x11db, 0xa0fc, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } };
-const SLInterfaceID SL_IID_BASSBOOST = &SL_IID_BASSBOOST_;
-
-static const struct SLInterfaceID_ SL_IID_PITCH_ = { 0xc7e8ee00, 0xddd7, 0x11db, 0xa42c, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } };
-const SLInterfaceID SL_IID_PITCH = &SL_IID_PITCH_;
-
-static const struct SLInterfaceID_ SL_IID_RATEPITCH_ = { 0x61b62e60, 0xddda, 0x11db, 0x9eb8, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } };
-const SLInterfaceID SL_IID_RATEPITCH = &SL_IID_RATEPITCH_;
-
-static const struct SLInterfaceID_ SL_IID_VIRTUALIZER_ = { 0x37cc2c00, 0xdddd, 0x11db, 0x8577, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } };
-const SLInterfaceID SL_IID_VIRTUALIZER = &SL_IID_VIRTUALIZER_;
-
-static const struct SLInterfaceID_ SL_IID_VISUALIZATION_ = { 0xe46b26a0, 0xdddd, 0x11db, 0x8afd, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } };
-const SLInterfaceID SL_IID_VISUALIZATION = &SL_IID_VISUALIZATION_;
-
-static const struct SLInterfaceID_ SL_IID_ENGINE_ = { 0x8d97c260, 0xddd4, 0x11db, 0x958f, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } };
-const SLInterfaceID SL_IID_ENGINE = &SL_IID_ENGINE_;
-
-static const struct SLInterfaceID_ SL_IID_ENGINECAPABILITIES_ = { 0x8320d0a0, 0xddd5, 0x11db, 0xa1b1, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } };
-const SLInterfaceID SL_IID_ENGINECAPABILITIES = &SL_IID_ENGINECAPABILITIES_;
-
-static const struct SLInterfaceID_ SL_IID_THREADSYNC_ = { 0xf6ac6b40, 0xdddc, 0x11db, 0xa62e, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } };
-const SLInterfaceID SL_IID_THREADSYNC = &SL_IID_THREADSYNC_;
-
-
-#ifdef __cplusplus
-} /* extern "C" */
-#endif
-

+ 2 - 2
src/core/PolyAndroidCore.cpp

@@ -51,9 +51,9 @@ void AndroidCoreMutex::unlock() {
 AndroidCore::AndroidCore(PolycodeView *view, int xRes, int yRes, bool fullScreen, bool vSync, int aaLevel, int anisotropyLevel, int frameRate, int monitorIndex, bool retinaSupport) 
 	: Core(xRes, yRes, fullScreen, vSync, aaLevel, anisotropyLevel, frameRate, monitorIndex) {
 	
-	fileProviders.push_back(new AAssetFileProvider(view->native_activity->assetManager));
 	fileProviders.push_back(new BasicFileProvider());
 	fileProviders.push_back(new PhysFSFileProvider());
+	fileProviders.push_back(new AAssetFileProvider(view->native_activity->assetManager));
 	
 	eventMutex = createMutex();
 	eglMutex = createMutex();
@@ -84,7 +84,7 @@ AndroidCore::AndroidCore(PolycodeView *view, int xRes, int yRes, bool fullScreen
 	defaultWorkingDirectory = view->native_activity->internalDataPath;
 	userHomeDirectory = view->native_activity->externalDataPath;
 	
-// 	services->getSoundManager()->setAudioInterface(new OpenSLAudioInterface());
+	services->getSoundManager()->setAudioInterface(new OpenSLAudioInterface());
 	paused = true;
 	
 	initKeyMap();

+ 87 - 131
src/core/PolyOpenSLAudioInterface.cpp

@@ -29,160 +29,116 @@ using namespace Polycode;
 
 OpenSLAudioInterface::OpenSLAudioInterface(){
 	Logger::log("OpenSL Interface");
-	stream = new OpenSLStream();
+// 	stream = new OpenSLStream();
 }
 
-OpenSLAudioInterface::~OpenSLAudioInterface(){ }
+OpenSLAudioInterface::~OpenSLAudioInterface(){
+	terminateOpenSL();
+}
 
 void OpenSLAudioInterface::setMixer(AudioMixer* newMixer){
 	Logger::log("OpenSL setMixer");
 	mixer = newMixer;
-	stream->setMixer(mixer);
 	Logger::log("OpenSL setMixer2");
-	Services()->getCore()->createThread(stream);
+// 	Services()->getCore()->createThread(stream);
+	
+	initOpenSL();
 	Logger::log("OpenSL setMixer3");
 }
 
-OpenSLStream::OpenSLStream(){
-	streamMutex = NULL;
-}
-
-OpenSLStream::~OpenSLStream(){
-
-}
-
-void OpenSLStream::initOpenSL(){
-	SLresult result;
-	//create Engine
-	Logger::log("OpenSL init");
-	slCreateEngine(&engineObject, 0, NULL, 0, NULL, NULL);
-	(*engineObject)->Realize(engineObject, SL_BOOLEAN_FALSE);
-	(*engineObject)->GetInterface(engineObject, SL_IID_ENGINE, &engineEngine);
+void OpenSLAudioInterface::initOpenSL(){
+	SLresult lRes;
 	
-	//init output
-	const SLInterfaceID ids[] = {SL_IID_VOLUME};
-	const SLboolean req[] = {SL_BOOLEAN_FALSE};
-	Logger::log("OpenSL before outputMixObject %d", result);
-	result = (*engineEngine)->CreateOutputMix(engineEngine, &outputMixObject, 0, NULL, NULL);
-	Logger::log("OpenSL create outputMixObject %d", result);
-	result = (*outputMixObject)->Realize(outputMixObject, SL_BOOLEAN_FALSE);
-	Logger::log("OpenSL realize outputMixObject %d", result);
-	//some options
-	SLDataLocator_AndroidSimpleBufferQueue loc_bufq = {SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE, 2};
+	const SLInterfaceID lEngineMixIIDs[]={SL_IID_ENGINE};
+	const SLboolean lEngineMixReqs[]={SL_BOOLEAN_TRUE};
+	const SLuint32 lOutputMixIIDCount=0;
+	const SLInterfaceID lOutputMixIIDs[]={};
+	const SLboolean lOutputMixReqs[]={};
+ 
+	lRes = slCreateEngine(&mEngineObj, 0, NULL, 1, lEngineMixIIDs, lEngineMixReqs);
+	Logger::log("engine: %d", lRes);
+	lRes = (*mEngineObj)->Realize(mEngineObj,SL_BOOLEAN_FALSE);
+	Logger::log("engine real: %d", lRes);
+	lRes = (*mEngineObj)->GetInterface(mEngineObj, SL_IID_ENGINE, &mEngine);
+	Logger::log("engine int: %d", lRes);
 	
-	int speakers;
-    if(POLY_NUM_CHANNELS > 1) 
-		speakers = SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT;
-    else
-		speakers = SL_SPEAKER_FRONT_CENTER;
+	lRes=(*mEngine)->CreateOutputMix(mEngine, &mOutputMixObj,lOutputMixIIDCount,lOutputMixIIDs, lOutputMixReqs);
+	lRes=(*mOutputMixObj)->Realize(mOutputMixObj, SL_BOOLEAN_FALSE);
 	
-	SLDataFormat_PCM format_pcm = {SL_DATAFORMAT_PCM,POLY_NUM_CHANNELS,POLY_AUDIO_FREQ*1000,
-               SL_PCMSAMPLEFORMAT_FIXED_16, SL_PCMSAMPLEFORMAT_FIXED_16,
-               speakers, SL_BYTEORDER_LITTLEENDIAN};
-
-	SLDataSource audioSrc = {&loc_bufq, &format_pcm};
-		
-	SLDataLocator_OutputMix loc_outmix = {SL_DATALOCATOR_OUTPUTMIX,outputMixObject};
-	SLDataSink audioSnk = {&loc_outmix, NULL};
+	SLDataLocator_AndroidSimpleBufferQueue lDataLocatorIn;
+	lDataLocatorIn.locatorType = SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE;
+	lDataLocatorIn.numBuffers = 1;
 	
-	const SLInterfaceID ids1[] = {SL_IID_ANDROIDSIMPLEBUFFERQUEUE};
-	const SLboolean req1[] = {SL_BOOLEAN_TRUE};
+	SLDataFormat_PCM lDataFormat;
+	lDataFormat.formatType = SL_DATAFORMAT_PCM;
+	lDataFormat.numChannels = 1; // Mono sound.
+	lDataFormat.samplesPerSec = SL_SAMPLINGRATE_8;
+	lDataFormat.bitsPerSample = SL_PCMSAMPLEFORMAT_FIXED_16;
+	lDataFormat.containerSize = SL_PCMSAMPLEFORMAT_FIXED_16;
+	lDataFormat.channelMask = SL_SPEAKER_FRONT_CENTER;
+	lDataFormat.endianness = SL_BYTEORDER_LITTLEENDIAN;
 	
-	//init audio player
-	Logger::log("OpenSL before AudioPlayer");
-	result = (*engineEngine)->CreateAudioPlayer(engineEngine, &bqPlayerObject, &audioSrc, &audioSnk, 1, ids1, req1);
-	if(result != SL_RESULT_SUCCESS){
-		Logger::log("OpenSL create failed %d", result);
-			return;
-	}
-	Logger::log("OpenSL create AudioPlayer");
-	(*bqPlayerObject)->Realize(bqPlayerObject, SL_BOOLEAN_FALSE);
-	if (result != SL_RESULT_SUCCESS){
-		Logger::log("OpenSL realize failed %d", result);
-		return;
-	}
-	Logger::log("OpenSL realize AudioPlayer");
+	SLDataSource lDataSource;
+	lDataSource.pLocator = &lDataLocatorIn;
+	lDataSource.pFormat = &lDataFormat;
+	
+	SLDataLocator_OutputMix lDataLocatorOut;
+	lDataLocatorOut.locatorType = SL_DATALOCATOR_OUTPUTMIX;
+	lDataLocatorOut.outputMix = mOutputMixObj;
+	
+	SLDataSink lDataSink;
+	lDataSink.pLocator = &lDataLocatorOut;
+	lDataSink.pFormat = NULL;
+	
+	const SLuint32 lSoundPlayerIIDCount = 2;
+	const SLInterfaceID lSoundPlayerIIDs[3] = { SL_IID_PLAY, SL_IID_ANDROIDSIMPLEBUFFERQUEUE, SL_IID_VOLUME };
+	const SLboolean lSoundPlayerReqs[3] = { SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE };
+	
+	Logger::log("before player");
+	lRes = (*mEngine)->CreateAudioPlayer(mEngine, &mPlayerObj, &lDataSource, &lDataSink, lSoundPlayerIIDCount, lSoundPlayerIIDs, lSoundPlayerReqs);
+	Logger::log("player: %d", lRes);
+	lRes = (*mPlayerObj)->Realize(mPlayerObj, SL_BOOLEAN_FALSE);
+	Logger::log("player real: %d", lRes);
+	
+	lRes = (*mPlayerObj)->GetInterface(mPlayerObj, SL_IID_PLAY, &mPlayer);
+	Logger::log("player getI: %d", lRes);
+	lRes = (*mPlayerObj)->GetInterface(mPlayerObj, SL_IID_ANDROIDSIMPLEBUFFERQUEUE, &mPlayerQueue);
+	Logger::log("player getBuffer: %d", lRes);
+	
+	lRes = (*mPlayerQueue)->RegisterCallback(mPlayerQueue, OpenSLAudioInterface::queueCallback, this);
+	Logger::log("queue call: %d", lRes);
 	
-	Logger::log("OpenSL before PLAY");
-	(*bqPlayerObject)->GetInterface(bqPlayerObject, SL_IID_PLAY, &bqPlayerPlay);
-	Logger::log("OpenSL before buffer");
-	(*bqPlayerObject)->GetInterface(bqPlayerObject, SL_IID_ANDROIDSIMPLEBUFFERQUEUE, &bqPlayerBufferQueue);
-	Logger::log("OpenSL before callback");
-	(*bqPlayerBufferQueue)->RegisterCallback(bqPlayerBufferQueue,bqPlayerCallback, this);
-	Logger::log("OpenSL after callback");
+// 	lRes = (*mPlayerObj)->GetInterface(mPlayerObj, SL_IID_VOLUME, &mVolume);
+// 	Logger::log("player itf: %d", lRes);
 	
-	Logger::log("OpenSL Play");
-	result = (*bqPlayerPlay)->SetPlayState(bqPlayerPlay, SL_PLAYSTATE_PLAYING);
-	Logger::log("OpenSL init finished %d", result);
+	lRes = (*mPlayer)->SetPlayState(mPlayer, SL_PLAYSTATE_PLAYING);
+	Logger::log("play: %d", lRes);
+	
+// 	int16_t *out = (int16_t*)buffer;
+// 	mixer->mixIntoBuffer(out, 44100);
+// 	(*(mPlayerQueue))->Enqueue(mPlayerQueue, out, 44100);
 }
 
-void OpenSLStream::terminateOpenSL(){
-	if (bqPlayerObject != NULL) {
-		(*bqPlayerObject)->Destroy(bqPlayerObject);
-	}
-
-	if (outputMixObject != NULL) {
-		(*outputMixObject)->Destroy(outputMixObject);
-	}
+void OpenSLAudioInterface::terminateOpenSL(){
+// 	if (mPlayerQueue != NULL) {
+// 		(*mPlayerQueue)->Destroy(mPlayerQueue);
+// 	}
 
-	if (engineObject != NULL) {
-		(*engineObject)->Destroy(engineObject);
+	if (mOutputMixObj != NULL) {
+		(*mOutputMixObj)->Destroy(mOutputMixObj);
 	}
-}
-
-
-void OpenSLStream::setMixer(AudioMixer* newMixer){
-	Logger::log("OpenSL StreamMixer");
-	if(!streamMutex){
-		streamMutex = Services()->getCore()->createMutex();
-		Logger::log("OpenSL mutexcreated");
+ 
+	if (mEngineObj != NULL) {
+		(*mEngineObj)->Destroy(mEngineObj);
 	}
-		
-	streamMutex->lock();
-	mixer = newMixer;
-	streamMutex->unlock();
-	Logger::log("OpenSL StreamMixer2");
 }
 
-void OpenSLStream::runThread(){
-	Logger::log("OpenSL runThread");
-	
-// 	while(!core->isWindowInitialized()){
-// 		usleep(1000000);
+void OpenSLAudioInterface::queueCallback(SLAndroidSimpleBufferQueueItf caller, void* pContext){
+// 	OpenSLAudioInterface *audioInterface = (OpenSLAudioInterface*) pContext;
+// 	if(audioInterface->buffer && audioInterface->getMixer()) {
+// 		int16_t *out = (int16_t*)audioInterface->buffer;
+// 		audioInterface->getMixer()->mixIntoBuffer(out, 44100);
+// 		(*(audioInterface->mPlayerQueue))->Enqueue(audioInterface->mPlayerQueue, out, 44100);
+// 		Logger::log("callback");
 // 	}
-	
-	initOpenSL();
-	playBuffer = (int16_t*)calloc(POLY_FRAMES_PER_BUFFER * POLY_NUM_CHANNELS, sizeof(int16_t));
-	backBuffer = (int16_t*)calloc(POLY_FRAMES_PER_BUFFER * POLY_NUM_CHANNELS, sizeof(int16_t));
-	Logger::log("OpenSL before While");
-	while(threadRunning){
-		Logger::log("OpenSL while");
-		streamMutex->lock();
-		if(swappedBuffers){
-			mixer->mixIntoBuffer(backBuffer, POLY_FRAMES_PER_BUFFER);
-			swappedBuffers = false;
-		}
-		streamMutex->unlock();
-	}
-	Logger::log("OpenSL after While");
-	terminateOpenSL();
-	free(playBuffer);
-	free(backBuffer);
-}
-
-void OpenSLStream::bqPlayerCallback(SLAndroidSimpleBufferQueueItf bq, void* context){
-	OpenSLStream *ctx = (OpenSLStream *) context;
-	int bytes = POLY_FRAMES_PER_BUFFER*POLY_NUM_CHANNELS*sizeof(int16_t);
- 	ctx->swapBuffers();
-	(*ctx->bqPlayerBufferQueue)->Enqueue(ctx->bqPlayerBufferQueue,ctx->playBuffer,bytes);
-}
-
-void OpenSLStream::swapBuffers(){
-	streamMutex->lock();
-	int16_t *tmpBuf;
-	tmpBuf = playBuffer;
-	playBuffer = backBuffer;
-	backBuffer = tmpBuf;
-	swappedBuffers = true;
-	streamMutex->unlock();
 }