Explorar el Código

Implmented audio in iOS core

Ivan Safrin hace 9 años
padre
commit
a2e47ba413

BIN
assets/default/default.pak


+ 8 - 6
build/ios/PolycodeCore/PolycodeCore.xcodeproj/project.pbxproj

@@ -9,7 +9,7 @@
 /* Begin PBXBuildFile section */
 		6D904FDD1CCBF95700D0E80A /* PolyScript.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6D904FDC1CCBF95700D0E80A /* PolyScript.cpp */; };
 		6D904FE01CCBF9F900D0E80A /* duktape.c in Sources */ = {isa = PBXBuildFile; fileRef = 6D904FDF1CCBF9F900D0E80A /* duktape.c */; };
-		6D9050591CCBFCE800D0E80A /* PolyLuaAPI.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6D9050581CCBFCE800D0E80A /* PolyLuaAPI.cpp */; };
+		6D9D8C221CD975B1001E636B /* PolycodeLua.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6D9D8C211CD975B1001E636B /* PolycodeLua.cpp */; };
 		8A0F81471BF541F900E24F9B /* lodepng.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8A0F80F91BF541F800E24F9B /* lodepng.cpp */; };
 		8A0F81481BF541F900E24F9B /* PolyBasicFileProvider.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8A0F80FA1BF541F800E24F9B /* PolyBasicFileProvider.cpp */; };
 		8A0F81491BF541F900E24F9B /* PolyBezierCurve.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8A0F80FB1BF541F800E24F9B /* PolyBezierCurve.cpp */; };
@@ -105,8 +105,9 @@
 		6D904FDC1CCBF95700D0E80A /* PolyScript.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = PolyScript.cpp; path = ../../../src/core/PolyScript.cpp; sourceTree = "<group>"; };
 		6D904FDE1CCBF96D00D0E80A /* PolyScript.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PolyScript.h; path = ../../../include/polycode/core/PolyScript.h; sourceTree = "<group>"; };
 		6D904FDF1CCBF9F900D0E80A /* duktape.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = duktape.c; path = ../../../src/duktape/duktape.c; sourceTree = "<group>"; };
-		6D9050581CCBFCE800D0E80A /* PolyLuaAPI.cpp */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp; fileEncoding = 4; name = PolyLuaAPI.cpp; path = ../../../src/core/PolyLuaAPI.cpp; sourceTree = "<group>"; };
-		6D90505B1CCBFD0E00D0E80A /* PolyLuaAPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PolyLuaAPI.h; path = ../../../include/polycode/core/PolyLuaAPI.h; sourceTree = "<group>"; };
+		6D9D8C1F1CD9759E001E636B /* PolycodeLua.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PolycodeLua.h; path = ../../../include/polycode/bindings/lua/PolycodeLua.h; sourceTree = "<group>"; };
+		6D9D8C201CD9759E001E636B /* PolycodeLuaWrappers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PolycodeLuaWrappers.h; path = ../../../include/polycode/bindings/lua/PolycodeLuaWrappers.h; sourceTree = "<group>"; };
+		6D9D8C211CD975B1001E636B /* PolycodeLua.cpp */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp.preprocessed; fileEncoding = 4; name = PolycodeLua.cpp; path = ../../../src/bindings/lua/PolycodeLua.cpp; sourceTree = "<group>"; };
 		8A0F80A01BF5411500E24F9B /* libPolycodeCore.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPolycodeCore.a; sourceTree = BUILT_PRODUCTS_DIR; };
 		8A0F80AE1BF5417E00E24F9B /* PolyBasicFileProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PolyBasicFileProvider.h; path = ../../../include/polycode/core/PolyBasicFileProvider.h; sourceTree = "<group>"; };
 		8A0F80AF1BF5417E00E24F9B /* PolyBezierCurve.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PolyBezierCurve.h; path = ../../../include/polycode/core/PolyBezierCurve.h; sourceTree = "<group>"; };
@@ -292,7 +293,8 @@
 		8A0F80AC1BF5413300E24F9B /* include */ = {
 			isa = PBXGroup;
 			children = (
-				6D90505B1CCBFD0E00D0E80A /* PolyLuaAPI.h */,
+				6D9D8C1F1CD9759E001E636B /* PolycodeLua.h */,
+				6D9D8C201CD9759E001E636B /* PolycodeLuaWrappers.h */,
 				8A0F80AE1BF5417E00E24F9B /* PolyBasicFileProvider.h */,
 				8A0F80AF1BF5417E00E24F9B /* PolyBezierCurve.h */,
 				8A0F80B01BF5417E00E24F9B /* PolyBone.h */,
@@ -375,8 +377,8 @@
 		8A0F80AD1BF5413800E24F9B /* src */ = {
 			isa = PBXGroup;
 			children = (
+				6D9D8C211CD975B1001E636B /* PolycodeLua.cpp */,
 				6D904FDF1CCBF9F900D0E80A /* duktape.c */,
-				6D9050581CCBFCE800D0E80A /* PolyLuaAPI.cpp */,
 				8A0F80F91BF541F800E24F9B /* lodepng.cpp */,
 				8A0F80FA1BF541F800E24F9B /* PolyBasicFileProvider.cpp */,
 				8A0F80FB1BF541F800E24F9B /* PolyBezierCurve.cpp */,
@@ -533,6 +535,7 @@
 			buildActionMask = 2147483647;
 			files = (
 				8A0F815F1BF541F900E24F9B /* PolyIOSCore.mm in Sources */,
+				6D9D8C221CD975B1001E636B /* PolycodeLua.cpp in Sources */,
 				8A0F81911BF541F900E24F9B /* tinystr.cpp in Sources */,
 				8A0F81701BF541F900E24F9B /* PolyRenderDataArray.cpp in Sources */,
 				8A35E1A11C87B25900BF9EEA /* PolyPhysFSFileProvider.cpp in Sources */,
@@ -611,7 +614,6 @@
 				8A0F81541BF541F900E24F9B /* PolyData.cpp in Sources */,
 				8A0F815D1BF541F900E24F9B /* PolyImage.cpp in Sources */,
 				8A0F81581BF541F900E24F9B /* PolyEventHandler.cpp in Sources */,
-				6D9050591CCBFCE800D0E80A /* PolyLuaAPI.cpp in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

+ 27 - 3
build/ios/TemplateApp/TemplateApp.xcodeproj/project.pbxproj

@@ -7,11 +7,17 @@
 	objects = {
 
 /* Begin PBXBuildFile section */
+		6D086CF21CD9B3770057F210 /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6D086CF11CD9B3770057F210 /* AudioToolbox.framework */; };
+		6D086D661CD9BC330057F210 /* libogg.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 6D086D631CD9BC330057F210 /* libogg.a */; };
+		6D086D671CD9BC330057F210 /* libvorbis.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 6D086D641CD9BC330057F210 /* libvorbis.a */; };
+		6D086D681CD9BC330057F210 /* libvorbisfile.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 6D086D651CD9BC330057F210 /* libvorbisfile.a */; };
+		6D086D6A1CD9BC820057F210 /* test.ogg in Resources */ = {isa = PBXBuildFile; fileRef = 6D086D691CD9BC820057F210 /* test.ogg */; };
 		6D1992381CD692ED00DE01FA /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6D1992341CD692ED00DE01FA /* QuartzCore.framework */; };
 		6D1992391CD692ED00DE01FA /* CoreMotion.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6D1992351CD692ED00DE01FA /* CoreMotion.framework */; };
 		6D19923A1CD692ED00DE01FA /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6D1992361CD692ED00DE01FA /* UIKit.framework */; };
 		6D19923B1CD692ED00DE01FA /* OpenGLES.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6D1992371CD692ED00DE01FA /* OpenGLES.framework */; };
 		6D90505D1CCBFFD400D0E80A /* liblua.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 6D90505C1CCBFFD400D0E80A /* liblua.a */; };
+		6DB2E6B51CD9ABD000FB0E28 /* test.wav in Resources */ = {isa = PBXBuildFile; fileRef = 6DB2E6B41CD9ABD000FB0E28 /* test.wav */; };
 		8A0F80641BF536C800E24F9B /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 8A0F80631BF536C800E24F9B /* AppDelegate.m */; };
 		8A0F80671BF536C800E24F9B /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8A0F80661BF536C800E24F9B /* ViewController.m */; };
 		8A0F806A1BF536C800E24F9B /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8A0F80681BF536C800E24F9B /* Main.storyboard */; };
@@ -27,11 +33,17 @@
 /* End PBXBuildFile section */
 
 /* Begin PBXFileReference section */
+		6D086CF11CD9B3770057F210 /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = System/Library/Frameworks/AudioToolbox.framework; sourceTree = SDKROOT; };
+		6D086D631CD9BC330057F210 /* libogg.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libogg.a; path = ../../../../lib/ios/iphonesimulator/libogg.a; sourceTree = "<group>"; };
+		6D086D641CD9BC330057F210 /* libvorbis.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libvorbis.a; path = ../../../../lib/ios/iphonesimulator/libvorbis.a; sourceTree = "<group>"; };
+		6D086D651CD9BC330057F210 /* libvorbisfile.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libvorbisfile.a; path = ../../../../lib/ios/iphonesimulator/libvorbisfile.a; sourceTree = "<group>"; };
+		6D086D691CD9BC820057F210 /* test.ogg */ = {isa = PBXFileReference; lastKnownFileType = file; name = test.ogg; path = ../../../../../../../Downloads/test.ogg; sourceTree = "<group>"; };
 		6D1992341CD692ED00DE01FA /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
 		6D1992351CD692ED00DE01FA /* CoreMotion.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreMotion.framework; path = System/Library/Frameworks/CoreMotion.framework; sourceTree = SDKROOT; };
 		6D1992361CD692ED00DE01FA /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
 		6D1992371CD692ED00DE01FA /* OpenGLES.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGLES.framework; path = System/Library/Frameworks/OpenGLES.framework; sourceTree = SDKROOT; };
 		6D90505C1CCBFFD400D0E80A /* liblua.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = liblua.a; path = ../../../../lib/ios/iphonesimulator/liblua.a; sourceTree = "<group>"; };
+		6DB2E6B41CD9ABD000FB0E28 /* test.wav */ = {isa = PBXFileReference; lastKnownFileType = audio.wav; name = test.wav; path = ../../../../../../../Downloads/test.wav; sourceTree = "<group>"; };
 		8A0F805C1BF536C800E24F9B /* TemplateApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TemplateApp.app; sourceTree = BUILT_PRODUCTS_DIR; };
 		8A0F80621BF536C800E24F9B /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
 		8A0F80631BF536C800E24F9B /* AppDelegate.m */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp.preprocessed; path = AppDelegate.m; sourceTree = "<group>"; };
@@ -57,13 +69,17 @@
 			isa = PBXFrameworksBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
+				6D086CF21CD9B3770057F210 /* AudioToolbox.framework in Frameworks */,
 				6D1992381CD692ED00DE01FA /* QuartzCore.framework in Frameworks */,
 				6D1992391CD692ED00DE01FA /* CoreMotion.framework in Frameworks */,
+				6D086D661CD9BC330057F210 /* libogg.a in Frameworks */,
 				6D90505D1CCBFFD400D0E80A /* liblua.a in Frameworks */,
 				6D19923B1CD692ED00DE01FA /* OpenGLES.framework in Frameworks */,
+				6D086D681CD9BC330057F210 /* libvorbisfile.a in Frameworks */,
 				8A35E14F1C877DDB00BF9EEA /* libFreetype2.a in Frameworks */,
 				8A35E1C61C87B3BC00BF9EEA /* libphysfs.a in Frameworks */,
 				6D19923A1CD692ED00DE01FA /* UIKit.framework in Frameworks */,
+				6D086D671CD9BC330057F210 /* libvorbis.a in Frameworks */,
 				8AD300AB1BF68290004D243B /* libPolycodeCore.a in Frameworks */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
@@ -90,6 +106,10 @@
 		8A0F805E1BF536C800E24F9B /* TemplateApp */ = {
 			isa = PBXGroup;
 			children = (
+				6D086D631CD9BC330057F210 /* libogg.a */,
+				6D086D641CD9BC330057F210 /* libvorbis.a */,
+				6D086D651CD9BC330057F210 /* libvorbisfile.a */,
+				6D086CF11CD9B3770057F210 /* AudioToolbox.framework */,
 				6D1992341CD692ED00DE01FA /* QuartzCore.framework */,
 				6D1992351CD692ED00DE01FA /* CoreMotion.framework */,
 				6D1992361CD692ED00DE01FA /* UIKit.framework */,
@@ -105,10 +125,12 @@
 				8A0F80791BF53DD200E24F9B /* PolycodeTemplateApp.h */,
 				8A0F807A1BF53DD200E24F9B /* PolycodeTemplateApp.mm */,
 				8A35E1DB1C87B50600BF9EEA /* default.pak */,
+				6D086D691CD9BC820057F210 /* test.ogg */,
 				8A0F80681BF536C800E24F9B /* Main.storyboard */,
 				8A35E19E1C87A54A00BF9EEA /* PolycodeView.h */,
 				8A0F81981BF56A2D00E24F9B /* PolycodeView.m */,
 				8A0F806B1BF536C800E24F9B /* Assets.xcassets */,
+				6DB2E6B41CD9ABD000FB0E28 /* test.wav */,
 				8A0F806D1BF536C800E24F9B /* LaunchScreen.storyboard */,
 				8A35E14A1C877A8B00BF9EEA /* main.m */,
 				8A0F80701BF536C800E24F9B /* Info.plist */,
@@ -147,7 +169,7 @@
 				TargetAttributes = {
 					8A0F805B1BF536C800E24F9B = {
 						CreatedOnToolsVersion = 7.1;
-						DevelopmentTeam = L5CB3G5LX2;
+						DevelopmentTeam = 8R477NNJLJ;
 					};
 				};
 			};
@@ -174,10 +196,12 @@
 			isa = PBXResourcesBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
+				6DB2E6B51CD9ABD000FB0E28 /* test.wav in Resources */,
 				8A0F806F1BF536C800E24F9B /* LaunchScreen.storyboard in Resources */,
 				8A0F806C1BF536C800E24F9B /* Assets.xcassets in Resources */,
 				8A35E1DC1C87B50600BF9EEA /* default.pak in Resources */,
 				8A0F806A1BF536C800E24F9B /* Main.storyboard in Resources */,
+				6D086D6A1CD9BC820057F210 /* test.ogg in Resources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -310,7 +334,7 @@
 				HEADER_SEARCH_PATHS = "\"$(SRCROOT)/../../../include\"";
 				INFOPLIST_FILE = TemplateApp/Info.plist;
 				LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
-				LIBRARY_SEARCH_PATHS = "\"$(SRCROOT)/../../../lib/ios/iphonesimulator\"";
+				LIBRARY_SEARCH_PATHS = "\"$(SRCROOT)/../../../lib/ios/iphoneos\"";
 				OTHER_LDFLAGS = "";
 				PRODUCT_BUNDLE_IDENTIFIER = org.polycode.TemplateApp;
 				PRODUCT_NAME = "$(TARGET_NAME)";
@@ -328,7 +352,7 @@
 				HEADER_SEARCH_PATHS = "\"$(SRCROOT)/../../../include\"";
 				INFOPLIST_FILE = TemplateApp/Info.plist;
 				LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
-				LIBRARY_SEARCH_PATHS = "\"$(SRCROOT)/../../../lib/ios/iphonesimulator\"";
+				LIBRARY_SEARCH_PATHS = "\"$(SRCROOT)/../../../lib/ios/iphoneos\"";
 				OTHER_LDFLAGS = "";
 				PRODUCT_BUNDLE_IDENTIFIER = org.polycode.TemplateApp;
 				PRODUCT_NAME = "$(TARGET_NAME)";

+ 2 - 2
build/ios/TemplateApp/TemplateApp/PolycodeTemplateApp.mm

@@ -25,8 +25,8 @@ PolycodeTemplateApp::PolycodeTemplateApp(PolycodeView *view) {
 //    test->scissorBox.setRect(100, 50, 100, 30);
     scene->addChild(test);
     
-//    Sound *music = new Sound("BUGSHUFFLE.ogg");
-//    music->Play();
+    Sound *test = new Sound(core->getResourcePathForFile("test.ogg"));
+    test->Play(true);
     
     Services()->getInput()->addEventListener(this, InputEvent::EVENT_KEYDOWN);
 }

+ 18 - 0
build/osx/Polycode3DPhysics/Polycode3DPhysics.xcodeproj/project.pbxproj

@@ -114,6 +114,7 @@
 				6D8883B71CBC8B6900626AD7 /* Sources */,
 				6D8883B81CBC8B6900626AD7 /* Frameworks */,
 				6D8883B91CBC8B6900626AD7 /* Headers */,
+				6DB2E6B11CD97C9400FB0E28 /* ShellScript */,
 			);
 			buildRules = (
 			);
@@ -155,6 +156,22 @@
 		};
 /* End PBXProject section */
 
+/* Begin PBXShellScriptBuildPhase section */
+		6DB2E6B11CD97C9400FB0E28 /* ShellScript */ = {
+			isa = PBXShellScriptBuildPhase;
+			buildActionMask = 2147483647;
+			files = (
+			);
+			inputPaths = (
+			);
+			outputPaths = (
+			);
+			runOnlyForDeploymentPostprocessing = 0;
+			shellPath = /bin/sh;
+			shellScript = "cp $TARGET_BUILD_DIR//$EXECUTABLE_NAME ../../../lib/osx";
+		};
+/* End PBXShellScriptBuildPhase section */
+
 /* Begin PBXSourcesBuildPhase section */
 		6D8883B71CBC8B6900626AD7 /* Sources */ = {
 			isa = PBXSourcesBuildPhase;
@@ -287,6 +304,7 @@
 				6D8883C11CBC8B6900626AD7 /* Release */,
 			);
 			defaultConfigurationIsVisible = 0;
+			defaultConfigurationName = Release;
 		};
 /* End XCConfigurationList section */
 	};

+ 0 - 1
include/polycode/core/PolyGlobals.h

@@ -79,7 +79,6 @@ typedef unsigned int PolyRendererIndexType;
     #if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
         #define PLATFORM PLATFORM_IOS
         #define STRICT_OPENGLES2 1
-        #define NO_OGG 1
     #else
         #define PLATFORM PLATFORM_MAC
     #endif

+ 24 - 0
include/polycode/core/PolyIOSCore.h

@@ -26,7 +26,18 @@ THE SOFTWARE.
 #import "polycode/view/ios/PolycodeView.h"
 #include "polycode/core/PolyInputEvent.h"
 #include "polycode/core/PolyOpenGLGraphicsInterface.h"
+#include "polycode/core/PolySoundManager.h"
 #include <pthread.h>
+#include <AudioToolbox/AudioQueue.h>
+#include <CoreAudio/CoreAudioTypes.h>
+
+/* CONFIG */
+
+// number of CoreAudio AudioQueue buffers
+
+#define NUM_AQ_BUFFERS 3
+
+/* ------ */
 
 @class PolycodeView;
 
@@ -63,6 +74,19 @@ class IOSEvent {
 };
 
 namespace Polycode {
+    
+    class IOSCoreAudioInterface : public Polycode::AudioInterface {
+    public:
+        IOSCoreAudioInterface();
+        ~IOSCoreAudioInterface();
+        
+        static void CoreAudioCallback(void *custom_data, AudioQueueRef queue, AudioQueueBufferRef buffer);
+    private:
+        AudioQueueBufferRef buffers[NUM_AQ_BUFFERS];
+        AudioStreamBasicDescription format;
+        AudioQueueRef queue;
+        
+    };
 
 	class _PolyExport IOSCore : public Core {
 	public:

+ 38 - 0
src/core/PolyIOSCore.mm

@@ -25,6 +25,7 @@ THE SOFTWARE.
 
 #include "polycode/core/PolyBasicFileProvider.h"
 #include "polycode/core/PolyPhysFSFileProvider.h"
+#include "polycode/core/PolySoundManager.h"
 #include <mach/mach.h>
 #include <mach/mach_time.h>
 
@@ -38,6 +39,41 @@ void PosixMutex::unlock() {
     pthread_mutex_unlock(&pMutex);
 }
 
+IOSCoreAudioInterface::IOSCoreAudioInterface() {
+    
+    format.mSampleRate       = POLY_AUDIO_FREQ;
+    format.mFormatID         = kAudioFormatLinearPCM;
+    format.mFormatFlags      = kLinearPCMFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked;
+    format.mBitsPerChannel   = 8 * sizeof(short);
+    format.mChannelsPerFrame = POLY_NUM_CHANNELS;
+    format.mBytesPerFrame    = sizeof(short) * POLY_NUM_CHANNELS;
+    format.mFramesPerPacket  = 1;
+    format.mBytesPerPacket   = format.mBytesPerFrame * format.mFramesPerPacket;
+    format.mReserved         = 0;
+    
+    AudioQueueNewOutput(&format, CoreAudioCallback, this, CFRunLoopGetCurrent(), kCFRunLoopCommonModes, 0, &queue);
+    
+    for (int i = 0; i < NUM_AQ_BUFFERS; i++) {
+        AudioQueueAllocateBuffer(queue, POLY_FRAMES_PER_BUFFER * sizeof(short) * POLY_NUM_CHANNELS, &buffers[i]);
+        buffers[i]->mAudioDataByteSize = POLY_FRAMES_PER_BUFFER * sizeof(short) * POLY_NUM_CHANNELS;
+        memset(buffers[i]->mAudioData, 0, POLY_FRAMES_PER_BUFFER * sizeof(short) * POLY_NUM_CHANNELS);
+        AudioQueueEnqueueBuffer(queue, buffers[i], 0, NULL);
+    }
+    AudioQueueStart(queue, NULL);
+}
+
+void IOSCoreAudioInterface::CoreAudioCallback(void *custom_data, AudioQueueRef queue, AudioQueueBufferRef buffer) {
+    IOSCoreAudioInterface *audioInterface = (IOSCoreAudioInterface*) custom_data;
+    audioInterface->getMixer()->mixIntoBuffer((int16_t*)buffer->mAudioData, POLY_FRAMES_PER_BUFFER);
+    AudioQueueEnqueueBuffer(queue, buffer, 0, NULL);
+}
+
+IOSCoreAudioInterface::~IOSCoreAudioInterface() {
+    AudioQueueReset(queue);
+    AudioQueueStop(queue, YES);
+    AudioQueueDispose(queue, YES);
+}
+
 IOSCore::IOSCore(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) {
         
@@ -57,6 +93,8 @@ IOSCore::IOSCore(PolycodeView *view, int xRes, int yRes, bool fullScreen, bool v
         renderer->setGraphicsInterface(this, interface);
         services->setRenderer(renderer);
         
+        Services()->getSoundManager()->setAudioInterface(new IOSCoreAudioInterface());
+        
         CGRect screenBounds = [[UIScreen mainScreen] bounds];
         
         setVideoMode(screenBounds.size.width, screenBounds.size.height, fullScreen, vSync, aaLevel, anisotropyLevel, retinaSupport);

+ 3 - 1
src/core/PolySoundManager.cpp

@@ -131,7 +131,9 @@ void SoundManager::setAudioInterface(AudioInterface *audioInterface) {
 	if (!mixer->mixerMutex) {
 		mixer->mixerMutex = Services()->getCore()->createMutex();
 	}
-    audioInterface->setMixer(mixer);
+    if(audioInterface) {
+        audioInterface->setMixer(mixer);
+    }
 }