New SDL sound code. Architecturally more similar to Mac code; main feature is that the same sound can be playing on more than one channel at once. Written without test builds, built almost without fixes and worked straight away, so there are almost certainly lurking bugs waiting to bite.
git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@1739 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
parent
02a8e76d59
commit
61e4d9f989
@ -26,7 +26,7 @@ endif
|
||||
OBJC_PROGRAM_NAME = oolite
|
||||
|
||||
oolite_C_FILES = legacy_random.c strlcpy.c OOTCPStreamDecoder.c
|
||||
oolite_OBJC_FILES = OOCocoa.m Comparison.m AI.m DustEntity.m Entity.m GameController.m GuiDisplayGen.m HeadUpDisplay.m main.m MyOpenGLView.m OpenGLSprite.m ParticleEntity.m PlanetEntity.m PlayerEntityLegacyScriptEngine.m PlayerEntityContracts.m PlayerEntityControls.m PlayerEntityLoadSave.m PlayerEntitySound.m PlayerEntity.m ResourceManager.m RingEntity.m ShipEntityAI.m ShipEntity.m SkyEntity.m StationEntity.m Universe.m OOSound.m SDLMusic.m NSFileManagerOOExtensions.m JoystickHandler.m PlayerEntityStickMapper.m OOBasicSoundReferencePoint.m OOBasicSoundSource.m OOCharacter.m OOTrumble.m WormholeEntity.m NSScannerOOExtensions.m OOXMLExtensions.m NSMutableDictionaryOOExtensions.m Geometry.m Octree.m CollisionRegion.m OOColor.m OOLogging.m OOCacheManager.m OOCache.m OOStringParsing.m OOCollectionExtractors.m OOVector.m OOMatrix.m OOQuaternion.m OOVoxel.m OOTriangle.m OOPListParsing.m OOFastArithmetic.m OOTextureScaling.m OOConstToString.m OOScript.m OOJSScript.m OOJavaScriptEngine.m OOPListScript.m NSStringOOExtensions.m PlayerEntityScriptMethods.m OOWeakReference.m OOJSEntity.m EntityOOJavaScriptExtensions.m OOJSQuaternion.m OOMaterial.m OOShaderMaterial.m OOShaderProgram.m OOShaderUniform.m OOTexture.m OOTextureLoader.m OOPNGTextureLoader.m OOOpenGLExtensionManager.m OOBasicMaterial.m OOSingleTextureMaterial.m OOCPUInfo.m OOSelfDrawingEntity.m OOEntityWithDrawable.m OODrawable.m OOJSVector.m OOMesh.m OOOpenGL.m OOGraphicsResetManager.m OOProbabilisticTextureManager.m OODebugGLDrawing.m OOShaderUniformMethodType.m OOAsyncQueue.m TextureStore.m OOOXPVerifier.m OOOXPVerifierStage.m OOFileScannerVerifierStage.m OOCheckRequiresPListVerifierStage.m OOCheckDemoShipsPListVerifierStage.m OOCheckEquipmentPListVerifierStage.m OOTextureVerifierStage.m OOModelVerifierStage.m OOCheckShipDataPListVerifierStage.m OOPListSchemaVerifier.m OOJSShip.m OOJSPlayer.m OOJSCall.m OOJSStation.m OOJSSystem.m OOLegacyEventHandlerScript.m OOJSOolite.m OORoleSet.m OOJSGlobal.m OOJSMissionVariables.m OOJSMission.m OOPriorityQueue.m OOScriptTimer.m OOJSTimer.m OOJSClock.m OODebugSupport.m OODebugMonitor.m OOJSConsole.m OODebugTCPConsoleClient.m OOTCPStreamDecoderAbstractionLayer.m OOEntityFilterPredicate.m OOJSPlanet.m OOJSWorldScripts.m OOJSSun.m NSThreadOOExtensions.m OOEncodingConverter.m OOJSSound.m OOJSSoundSource.m OOMusicController.m OOLogHeader.m OOJSSpecialFunctions.m OOSpatialReference.m OOSkyDrawable.m OOFilteringEnumerator.m OOSoundSourcePool.m ShipEntityScriptMethods.m OOShipRegistry.m OOProbabilitySet.m OOJSSystemInfo.m NSDictionaryOOExtensions.m OOEquipmentType.m OOCamera.m OOJSPlayerShip.m
|
||||
oolite_OBJC_FILES = OOCocoa.m Comparison.m AI.m DustEntity.m Entity.m GameController.m GuiDisplayGen.m HeadUpDisplay.m main.m MyOpenGLView.m OpenGLSprite.m ParticleEntity.m PlanetEntity.m PlayerEntityLegacyScriptEngine.m PlayerEntityContracts.m PlayerEntityControls.m PlayerEntityLoadSave.m PlayerEntitySound.m PlayerEntity.m ResourceManager.m RingEntity.m ShipEntityAI.m ShipEntity.m SkyEntity.m StationEntity.m Universe.m NSFileManagerOOExtensions.m JoystickHandler.m PlayerEntityStickMapper.m OOCharacter.m OOTrumble.m WormholeEntity.m NSScannerOOExtensions.m OOXMLExtensions.m NSMutableDictionaryOOExtensions.m Geometry.m Octree.m CollisionRegion.m OOColor.m OOLogging.m OOCacheManager.m OOCache.m OOStringParsing.m OOCollectionExtractors.m OOVector.m OOMatrix.m OOQuaternion.m OOVoxel.m OOTriangle.m OOPListParsing.m OOFastArithmetic.m OOTextureScaling.m OOConstToString.m OOScript.m OOJSScript.m OOJavaScriptEngine.m OOPListScript.m NSStringOOExtensions.m PlayerEntityScriptMethods.m OOWeakReference.m OOJSEntity.m EntityOOJavaScriptExtensions.m OOJSQuaternion.m OOMaterial.m OOShaderMaterial.m OOShaderProgram.m OOShaderUniform.m OOTexture.m OOTextureLoader.m OOPNGTextureLoader.m OOOpenGLExtensionManager.m OOBasicMaterial.m OOSingleTextureMaterial.m OOCPUInfo.m OOSelfDrawingEntity.m OOEntityWithDrawable.m OODrawable.m OOJSVector.m OOMesh.m OOOpenGL.m OOGraphicsResetManager.m OOProbabilisticTextureManager.m OODebugGLDrawing.m OOShaderUniformMethodType.m OOAsyncQueue.m TextureStore.m OOOXPVerifier.m OOOXPVerifierStage.m OOFileScannerVerifierStage.m OOCheckRequiresPListVerifierStage.m OOCheckDemoShipsPListVerifierStage.m OOCheckEquipmentPListVerifierStage.m OOTextureVerifierStage.m OOModelVerifierStage.m OOCheckShipDataPListVerifierStage.m OOPListSchemaVerifier.m OOJSShip.m OOJSPlayer.m OOJSCall.m OOJSStation.m OOJSSystem.m OOLegacyEventHandlerScript.m OOJSOolite.m OORoleSet.m OOJSGlobal.m OOJSMissionVariables.m OOJSMission.m OOPriorityQueue.m OOScriptTimer.m OOJSTimer.m OOJSClock.m OODebugSupport.m OODebugMonitor.m OOJSConsole.m OODebugTCPConsoleClient.m OOTCPStreamDecoderAbstractionLayer.m OOEntityFilterPredicate.m OOJSPlanet.m OOJSWorldScripts.m OOJSSun.m NSThreadOOExtensions.m OOEncodingConverter.m OOJSSound.m OOJSSoundSource.m OOMusicController.m OOLogHeader.m OOJSSpecialFunctions.m OOSpatialReference.m OOSkyDrawable.m OOFilteringEnumerator.m OOSoundSourcePool.m ShipEntityScriptMethods.m OOShipRegistry.m OOProbabilitySet.m OOJSSystemInfo.m NSDictionaryOOExtensions.m OOEquipmentType.m OOCamera.m OOJSPlayerShip.m OOSDLSound.m OOSDLConcreteSound.m OOSoundSource.m OOSDLSoundMixer.m OOSDLSoundChannel.m OOBasicSoundReferencePoint.m SDLMusic.m
|
||||
|
||||
include $(GNUSTEP_MAKEFILES)/objc.make
|
||||
include GNUmakefile.postamble
|
||||
|
@ -418,6 +418,8 @@
|
||||
1A6B25EF0C9C2746000717CF /* OOJSClock.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A6B25ED0C9C2746000717CF /* OOJSClock.m */; };
|
||||
1A6DD1230C57B5BC00A892F4 /* OOPListSchemaVerifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A6DD1210C57B5BC00A892F4 /* OOPListSchemaVerifier.h */; };
|
||||
1A6DD1240C57B5BC00A892F4 /* OOPListSchemaVerifier.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A6DD1220C57B5BC00A892F4 /* OOPListSchemaVerifier.m */; };
|
||||
1A71D8AA0E5F17410088C456 /* OOSoundSource.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A71D8A80E5F17410088C456 /* OOSoundSource.m */; };
|
||||
1A71D8AB0E5F17410088C456 /* OOSoundSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A71D8A90E5F17410088C456 /* OOSoundSource.h */; };
|
||||
1A71E6F80BCE345000CD5C13 /* libpng.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1A71E6F30BCE340C00CD5C13 /* libpng.a */; };
|
||||
1A71E7170BCE34CF00CD5C13 /* pngconf.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A71E7030BCE34CF00CD5C13 /* pngconf.h */; };
|
||||
1A71E7180BCE34CF00CD5C13 /* pngmem.c in Sources */ = {isa = PBXBuildFile; fileRef = 1A71E7040BCE34CF00CD5C13 /* pngmem.c */; };
|
||||
@ -452,6 +454,7 @@
|
||||
1A7376BF0C64AE330097AC37 /* OOJSSystem.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A7376BD0C64AE330097AC37 /* OOJSSystem.m */; };
|
||||
1A73795D0C65CF090097AC37 /* OOLegacyEventHandlerScript.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A73795B0C65CF090097AC37 /* OOLegacyEventHandlerScript.h */; };
|
||||
1A73795E0C65CF090097AC37 /* OOLegacyEventHandlerScript.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A73795C0C65CF090097AC37 /* OOLegacyEventHandlerScript.m */; };
|
||||
1A7B967F0E620C9E00322821 /* OOSoundInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A7B967E0E620C9E00322821 /* OOSoundInternal.h */; };
|
||||
1A7BA8830D843485003C6CA3 /* ShipEntityScriptMethods.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A7BA80B0D84231A003C6CA3 /* ShipEntityScriptMethods.h */; };
|
||||
1A7BA8840D843485003C6CA3 /* ShipEntityScriptMethods.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A7BA80C0D84231A003C6CA3 /* ShipEntityScriptMethods.m */; };
|
||||
1A7C75C30CC39EC3005D0AA2 /* OOJSSun.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A7C75980CC39D11005D0AA2 /* OOJSSun.m */; };
|
||||
@ -564,9 +567,7 @@
|
||||
25160E2F0995362F0037C2E1 /* OOCocoa.h in Headers */ = {isa = PBXBuildFile; fileRef = 25160E2E0995362F0037C2E1 /* OOCocoa.h */; };
|
||||
251610DD099544090037C2E1 /* OOCABufferedSound.h in Headers */ = {isa = PBXBuildFile; fileRef = 251610CA099544090037C2E1 /* OOCABufferedSound.h */; };
|
||||
251610DE099544090037C2E1 /* OOCASoundMixer.h in Headers */ = {isa = PBXBuildFile; fileRef = 251610CB099544090037C2E1 /* OOCASoundMixer.h */; };
|
||||
251610DF099544090037C2E1 /* OOCASoundSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 251610CC099544090037C2E1 /* OOCASoundSource.h */; };
|
||||
251610E0099544090037C2E1 /* OOCASoundChannel.h in Headers */ = {isa = PBXBuildFile; fileRef = 251610CD099544090037C2E1 /* OOCASoundChannel.h */; };
|
||||
251610E1099544090037C2E1 /* OOCASoundSource.m in Sources */ = {isa = PBXBuildFile; fileRef = 251610CE099544090037C2E1 /* OOCASoundSource.m */; };
|
||||
251610E2099544090037C2E1 /* OOCASoundReferencePoint.m in Sources */ = {isa = PBXBuildFile; fileRef = 251610CF099544090037C2E1 /* OOCASoundReferencePoint.m */; };
|
||||
251610E3099544090037C2E1 /* OOCASound.h in Headers */ = {isa = PBXBuildFile; fileRef = 251610D0099544090037C2E1 /* OOCASound.h */; };
|
||||
251610E4099544090037C2E1 /* OOCASoundMixer.m in Sources */ = {isa = PBXBuildFile; fileRef = 251610D1099544090037C2E1 /* OOCASoundMixer.m */; };
|
||||
@ -1433,6 +1434,8 @@
|
||||
1A6DD1210C57B5BC00A892F4 /* OOPListSchemaVerifier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OOPListSchemaVerifier.h; sourceTree = "<group>"; };
|
||||
1A6DD1220C57B5BC00A892F4 /* OOPListSchemaVerifier.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OOPListSchemaVerifier.m; sourceTree = "<group>"; };
|
||||
1A6DD19E0C5924A300A892F4 /* plist verifier design.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "plist verifier design.txt"; sourceTree = "<group>"; };
|
||||
1A71D8A80E5F17410088C456 /* OOSoundSource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OOSoundSource.m; sourceTree = "<group>"; };
|
||||
1A71D8A90E5F17410088C456 /* OOSoundSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OOSoundSource.h; sourceTree = "<group>"; };
|
||||
1A71E6F30BCE340C00CD5C13 /* libpng.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libpng.a; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
1A71E7030BCE34CF00CD5C13 /* pngconf.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = pngconf.h; sourceTree = "<group>"; };
|
||||
1A71E7040BCE34CF00CD5C13 /* pngmem.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = pngmem.c; sourceTree = "<group>"; };
|
||||
@ -1465,6 +1468,7 @@
|
||||
1A7376BD0C64AE330097AC37 /* OOJSSystem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OOJSSystem.m; sourceTree = "<group>"; };
|
||||
1A73795B0C65CF090097AC37 /* OOLegacyEventHandlerScript.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OOLegacyEventHandlerScript.h; sourceTree = "<group>"; };
|
||||
1A73795C0C65CF090097AC37 /* OOLegacyEventHandlerScript.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OOLegacyEventHandlerScript.m; sourceTree = "<group>"; };
|
||||
1A7B967E0E620C9E00322821 /* OOSoundInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OOSoundInternal.h; sourceTree = "<group>"; };
|
||||
1A7BA80B0D84231A003C6CA3 /* ShipEntityScriptMethods.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ShipEntityScriptMethods.h; sourceTree = "<group>"; };
|
||||
1A7BA80C0D84231A003C6CA3 /* ShipEntityScriptMethods.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ShipEntityScriptMethods.m; sourceTree = "<group>"; };
|
||||
1A7C75980CC39D11005D0AA2 /* OOJSSun.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OOJSSun.m; sourceTree = "<group>"; };
|
||||
@ -1586,9 +1590,7 @@
|
||||
25160E2E0995362F0037C2E1 /* OOCocoa.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OOCocoa.h; sourceTree = "<group>"; };
|
||||
251610CA099544090037C2E1 /* OOCABufferedSound.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OOCABufferedSound.h; sourceTree = "<group>"; };
|
||||
251610CB099544090037C2E1 /* OOCASoundMixer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OOCASoundMixer.h; sourceTree = "<group>"; };
|
||||
251610CC099544090037C2E1 /* OOCASoundSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OOCASoundSource.h; sourceTree = "<group>"; };
|
||||
251610CD099544090037C2E1 /* OOCASoundChannel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OOCASoundChannel.h; sourceTree = "<group>"; };
|
||||
251610CE099544090037C2E1 /* OOCASoundSource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OOCASoundSource.m; sourceTree = "<group>"; };
|
||||
251610CF099544090037C2E1 /* OOCASoundReferencePoint.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OOCASoundReferencePoint.m; sourceTree = "<group>"; };
|
||||
251610D0099544090037C2E1 /* OOCASound.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OOCASound.h; sourceTree = "<group>"; };
|
||||
251610D1099544090037C2E1 /* OOCASoundMixer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OOCASoundMixer.m; sourceTree = "<group>"; };
|
||||
@ -2314,6 +2316,17 @@
|
||||
name = Shaders;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
1A7B96800E620CA000322821 /* Audio */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
1A71D8A90E5F17410088C456 /* OOSoundSource.h */,
|
||||
1A71D8A80E5F17410088C456 /* OOSoundSource.m */,
|
||||
1A7B967E0E620C9E00322821 /* OOSoundInternal.h */,
|
||||
1A8A3D8F0B9B058500AB7625 /* Mac-specific */,
|
||||
);
|
||||
name = Audio;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
1A8071D70C0480AC00BA1935 /* Debug OXP */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
@ -2348,6 +2361,7 @@
|
||||
1A60AFB60D56093B0070510D /* OOMusicController.m */,
|
||||
1A5218D80D72EC21000865E9 /* OOSpatialReference.h */,
|
||||
1A5218DD0D72ECE5000865E9 /* OOSpatialReference.m */,
|
||||
1A7B96800E620CA000322821 /* Audio */,
|
||||
1A2A1B020BD2768300152975 /* Graphics */,
|
||||
1A5DBA980BC000DC00D57389 /* Scripting */,
|
||||
1A2DA2A00CB4CB3500DE6823 /* Debug */,
|
||||
@ -2365,7 +2379,6 @@
|
||||
25F46751099695D5009483BF /* OoliteApp.m */,
|
||||
2576E7B209B4F418007410F7 /* MyOpenGLView.h */,
|
||||
25F4676309969672009483BF /* MyOpenGLView.m */,
|
||||
1A8A3D8F0B9B058500AB7625 /* Audio */,
|
||||
1A8A3D9E0B9B05C400AB7625 /* Groolite */,
|
||||
1ADF5F110B9E374B00FDB2A3 /* JoystickHandler.h */,
|
||||
1AE546300C19A2E2005B89F3 /* JoystickHandler.m */,
|
||||
@ -2540,7 +2553,7 @@
|
||||
name = Mathematics;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
1A8A3D8F0B9B058500AB7625 /* Audio */ = {
|
||||
1A8A3D8F0B9B058500AB7625 /* Mac-specific */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
251610D0099544090037C2E1 /* OOCASound.h */,
|
||||
@ -2556,8 +2569,6 @@
|
||||
251610D1099544090037C2E1 /* OOCASoundMixer.m */,
|
||||
251610CD099544090037C2E1 /* OOCASoundChannel.h */,
|
||||
251610D6099544090037C2E1 /* OOCASoundChannel.m */,
|
||||
251610CC099544090037C2E1 /* OOCASoundSource.h */,
|
||||
251610CE099544090037C2E1 /* OOCASoundSource.m */,
|
||||
251610D9099544090037C2E1 /* OOCASoundReferencePoint.h */,
|
||||
251610CF099544090037C2E1 /* OOCASoundReferencePoint.m */,
|
||||
251610D4099544090037C2E1 /* OOCASoundDecoder.h */,
|
||||
@ -2567,7 +2578,8 @@
|
||||
251610F1099544190037C2E1 /* VirtualRingBuffer.h */,
|
||||
251610F0099544190037C2E1 /* VirtualRingBuffer.m */,
|
||||
);
|
||||
name = Audio;
|
||||
name = "Mac-specific";
|
||||
path = ../Cocoa;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
1A8A3D9E0B9B05C400AB7625 /* Groolite */ = {
|
||||
@ -2727,7 +2739,6 @@
|
||||
25160E2F0995362F0037C2E1 /* OOCocoa.h in Headers */,
|
||||
251610DD099544090037C2E1 /* OOCABufferedSound.h in Headers */,
|
||||
251610DE099544090037C2E1 /* OOCASoundMixer.h in Headers */,
|
||||
251610DF099544090037C2E1 /* OOCASoundSource.h in Headers */,
|
||||
251610E0099544090037C2E1 /* OOCASoundChannel.h in Headers */,
|
||||
251610E3099544090037C2E1 /* OOCASound.h in Headers */,
|
||||
251610E7099544090037C2E1 /* OOCASoundDecoder.h in Headers */,
|
||||
@ -2891,6 +2902,8 @@
|
||||
1A9322970DF53C33003FD306 /* OOJSSystemInfo.h in Headers */,
|
||||
1A62F0FE0E26A2A000897506 /* OOEquipmentType.h in Headers */,
|
||||
1A54AB530E3E17A1001EB817 /* OOJSPlayerShip.h in Headers */,
|
||||
1A71D8AB0E5F17410088C456 /* OOSoundSource.h in Headers */,
|
||||
1A7B967F0E620C9E00322821 /* OOSoundInternal.h in Headers */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@ -3091,7 +3104,6 @@
|
||||
25F3E6330994F04C002F25FD /* legacy_random.c in Sources */,
|
||||
25F3E6BD0994F30A002F25FD /* main.m in Sources */,
|
||||
25F3E6F30994F466002F25FD /* Groolite.m in Sources */,
|
||||
251610E1099544090037C2E1 /* OOCASoundSource.m in Sources */,
|
||||
251610E2099544090037C2E1 /* OOCASoundReferencePoint.m in Sources */,
|
||||
251610E4099544090037C2E1 /* OOCASoundMixer.m in Sources */,
|
||||
251610E5099544090037C2E1 /* OOCABufferedSound.m in Sources */,
|
||||
@ -3243,6 +3255,7 @@
|
||||
1A9322980DF53C33003FD306 /* OOJSSystemInfo.m in Sources */,
|
||||
1A62F0FD0E26A2A000897506 /* OOEquipmentType.m in Sources */,
|
||||
1A54AB540E3E17A1001EB817 /* OOJSPlayerShip.m in Sources */,
|
||||
1A71D8AA0E5F17410088C456 /* OOSoundSource.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -17,6 +17,8 @@
|
||||
<string>Oolite Saved Game</string>
|
||||
<key>CFBundleTypeRole</key>
|
||||
<string>Editor</string>
|
||||
<key>LSHandlerRank</key>
|
||||
<string>Owner</string>
|
||||
<key>LSItemContentTypes</key>
|
||||
<array>
|
||||
<string>org.aegidian.oolite.save</string>
|
||||
@ -32,7 +34,9 @@
|
||||
<key>CFBundleTypeName</key>
|
||||
<string>Oolite Expansion Pack</string>
|
||||
<key>CFBundleTypeRole</key>
|
||||
<string>None</string>
|
||||
<string>Viewer</string>
|
||||
<key>LSHandlerRank</key>
|
||||
<string>Alternate</string>
|
||||
<key>LSTypeIsPackage</key>
|
||||
<true/>
|
||||
<key>LSItemContentTypes</key>
|
||||
|
@ -17,6 +17,12 @@
|
||||
<string>Oolite Saved Game</string>
|
||||
<key>CFBundleTypeRole</key>
|
||||
<string>Editor</string>
|
||||
<key>LSHandlerRank</key>
|
||||
<string>Owner</string>
|
||||
<key>LSItemContentTypes</key>
|
||||
<array>
|
||||
<string>org.aegidian.oolite.save</string>
|
||||
</array>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>CFBundleTypeExtensions</key>
|
||||
@ -28,9 +34,15 @@
|
||||
<key>CFBundleTypeName</key>
|
||||
<string>Oolite Expansion Pack</string>
|
||||
<key>CFBundleTypeRole</key>
|
||||
<string>None</string>
|
||||
<string>Viewer</string>
|
||||
<key>LSHandlerRank</key>
|
||||
<string>Alternate</string>
|
||||
<key>LSTypeIsPackage</key>
|
||||
<true/>
|
||||
<key>LSItemContentTypes</key>
|
||||
<array>
|
||||
<string>org.aegidian.oolite.oxp</string>
|
||||
</array>
|
||||
</dict>
|
||||
</array>
|
||||
<key>CFBundleExecutable</key>
|
||||
@ -80,7 +92,6 @@
|
||||
<string>Oolite Expansion Pack</string>
|
||||
<key>UTTypeConformsTo</key>
|
||||
<array>
|
||||
<string>public.item</string>
|
||||
<string>com.apple.package</string>
|
||||
</array>
|
||||
<key>UTTypeTagSpecification</key>
|
||||
|
@ -7,7 +7,7 @@ Subclass of OOSound playing from an in-memory buffer.
|
||||
This class is an implementation detail. Do not use it directly; use OOSound.
|
||||
|
||||
OOCASound - Core Audio sound implementation for Oolite.
|
||||
Copyright (C) 2005-2006 Jens Ayton
|
||||
Copyright (C) 2005-2008 Jens Ayton
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
|
@ -3,7 +3,7 @@
|
||||
OOCABufferedSound.m
|
||||
|
||||
OOCASound - Core Audio sound implementation for Oolite.
|
||||
Copyright (C) 2005-2006 Jens Ayton
|
||||
Copyright (C) 2005-2008 Jens Ayton
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
@ -86,7 +86,7 @@ SOFTWARE.
|
||||
|
||||
- (void)play
|
||||
{
|
||||
[[OOCASoundMixer mixer] playSound:self];
|
||||
[[OOSoundMixer sharedMixer] playSound:self];
|
||||
}
|
||||
|
||||
|
||||
|
@ -6,7 +6,7 @@ Subclass of OOSound with additional controls specific to music playback. Only
|
||||
one instance of OOMusic may be playing at a time.
|
||||
|
||||
OOCASound - Core Audio sound implementation for Oolite.
|
||||
Copyright (C) 2005-2006 Jens Ayton
|
||||
Copyright (C) 2005-2008 Jens Ayton
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
|
@ -3,7 +3,7 @@
|
||||
OOCAMusic.m
|
||||
|
||||
OOCASound - Core Audio sound implementation for Oolite.
|
||||
Copyright (C) 2005-2006 Jens Ayton
|
||||
Copyright (C) 2005-2008 Jens Ayton
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
|
@ -5,7 +5,7 @@ OOCASound.h
|
||||
Abstract base class for sounds, and primary sound loading interface.
|
||||
|
||||
OOCASound - Core Audio sound implementation for Oolite.
|
||||
Copyright (C) 2005-2006 Jens Ayton
|
||||
Copyright (C) 2005-2008 Jens Ayton
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
@ -56,7 +56,6 @@ SOFTWARE.
|
||||
}
|
||||
|
||||
+ (void) setUp;
|
||||
+ (void) tearDown;
|
||||
+ (void) update;
|
||||
|
||||
+ (void) setMasterVolume:(float) fraction;
|
||||
|
@ -3,7 +3,7 @@
|
||||
OOCASound.m
|
||||
|
||||
OOCASound - Core Audio sound implementation for Oolite.
|
||||
Copyright (C) 2005-2006 Jens Ayton
|
||||
Copyright (C) 2005-2008 Jens Ayton
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
@ -146,17 +146,16 @@ static size_t sMaxBufferedSoundSize = 1 << 20; // 1 MB
|
||||
}
|
||||
if (!gOOSoundBroken)
|
||||
{
|
||||
if (![OOCASoundChannel setUp])
|
||||
gOOSoundBroken = YES;
|
||||
if (![OOSoundChannel setUp]) gOOSoundBroken = YES;
|
||||
}
|
||||
|
||||
gOOSoundSetUp = YES; // Must be before [OOCASoundMixer mixer] below.
|
||||
gOOSoundSetUp = YES; // Must be before [OOSoundMixer sharedMixer] below.
|
||||
|
||||
prefs = [NSUserDefaults standardUserDefaults];
|
||||
|
||||
if ([prefs objectForKey:KEY_VOLUME_CONTROL]) sNominalVolume = [prefs floatForKey:KEY_VOLUME_CONTROL];
|
||||
else sNominalVolume = 0.75; // default setting at 75% system volume
|
||||
[[OOCASoundMixer mixer] setMasterVolume:sNominalVolume];
|
||||
[[OOSoundMixer sharedMixer] setMasterVolume:sNominalVolume];
|
||||
|
||||
if ([prefs objectForKey:KEY_MAX_BUFFERED_SOUND])
|
||||
{
|
||||
@ -167,25 +166,9 @@ static size_t sMaxBufferedSoundSize = 1 << 20; // 1 MB
|
||||
}
|
||||
|
||||
|
||||
+ (void) tearDown
|
||||
{
|
||||
if (gOOSoundSetUp)
|
||||
{
|
||||
[gOOCASoundSyncLock release];
|
||||
gOOCASoundSyncLock = nil;
|
||||
[OOCASoundMixer destroy];
|
||||
}
|
||||
[OOCASoundChannel tearDown];
|
||||
gOOSoundSetUp = NO;
|
||||
gOOSoundBroken = NO;
|
||||
|
||||
[sSingletonOOSound release];
|
||||
}
|
||||
|
||||
|
||||
+ (void) update
|
||||
{
|
||||
[[OOCASoundMixer mixer] update];
|
||||
[[OOSoundMixer sharedMixer] update];
|
||||
}
|
||||
|
||||
|
||||
@ -193,7 +176,7 @@ static size_t sMaxBufferedSoundSize = 1 << 20; // 1 MB
|
||||
{
|
||||
if (fraction != sNominalVolume)
|
||||
{
|
||||
[[OOCASoundMixer mixer] setMasterVolume:fraction];
|
||||
[[OOSoundMixer sharedMixer] setMasterVolume:fraction];
|
||||
|
||||
sNominalVolume = fraction;
|
||||
[[NSUserDefaults standardUserDefaults] setFloat:fraction forKey:KEY_VOLUME_CONTROL];
|
||||
@ -231,7 +214,9 @@ static size_t sMaxBufferedSoundSize = 1 << 20; // 1 MB
|
||||
|
||||
if (nil != self)
|
||||
{
|
||||
OOLog(kOOLogSoundLoadingSuccess, @"Loaded sound %@", self);
|
||||
#ifndef NDEBUG
|
||||
OOLog(kOOLogSoundLoadingSuccess, @"Loaded sound %@", self);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -8,7 +8,7 @@ This class is an implementation detail. Do not use it directly; use an
|
||||
OOSoundSource to play an OOSound.
|
||||
|
||||
OOCASound - Core Audio sound implementation for Oolite.
|
||||
Copyright (C) 2005-2006 Jens Ayton
|
||||
Copyright (C) 2005-2008 Jens Ayton
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
@ -57,12 +57,12 @@ SOFTWARE.
|
||||
|
||||
|
||||
typedef uintptr_t OOCASoundRenderContext;
|
||||
typedef OSStatus (*OOCASoundChannel_RenderIMP)(id inSelf, SEL inSelector, AudioUnitRenderActionFlags *ioFlags, UInt32 inNumFrames, OOCASoundRenderContext *ioContext, AudioBufferList *ioData);
|
||||
typedef OSStatus (*OOSoundChannel_RenderIMP)(id inSelf, SEL inSelector, AudioUnitRenderActionFlags *ioFlags, UInt32 inNumFrames, OOCASoundRenderContext *ioContext, AudioBufferList *ioData);
|
||||
|
||||
|
||||
@interface OOCASoundChannel: NSObject
|
||||
@interface OOSoundChannel: NSObject
|
||||
{
|
||||
OOCASoundChannel *_next;
|
||||
OOSoundChannel *_next;
|
||||
id _delegate;
|
||||
AUNode _subGraphNode;
|
||||
AUGraph _subGraph;
|
||||
@ -70,7 +70,7 @@ typedef OSStatus (*OOCASoundChannel_RenderIMP)(id inSelf, SEL inSelector, Audio
|
||||
AudioUnit _au;
|
||||
OOSound *_sound;
|
||||
OOCASoundRenderContext _context;
|
||||
OOCASoundChannel_RenderIMP Render;
|
||||
OOSoundChannel_RenderIMP Render;
|
||||
uint8_t _state,
|
||||
_id,
|
||||
_stopReq;
|
||||
@ -89,8 +89,8 @@ typedef OSStatus (*OOCASoundChannel_RenderIMP)(id inSelf, SEL inSelector, Audio
|
||||
- (AUNode)auSubGraphNode;
|
||||
|
||||
// Unretained pointer used to maintain simple stack
|
||||
- (OOCASoundChannel *)next;
|
||||
- (void)setNext:(OOCASoundChannel *)inNext;
|
||||
- (OOSoundChannel *)next;
|
||||
- (void)setNext:(OOSoundChannel *)inNext;
|
||||
|
||||
- (BOOL)playSound:(OOSound *)inSound looped:(BOOL)inLoop;
|
||||
- (void)stop;
|
||||
@ -102,9 +102,9 @@ typedef OSStatus (*OOCASoundChannel_RenderIMP)(id inSelf, SEL inSelector, Audio
|
||||
@end
|
||||
|
||||
|
||||
@interface NSObject(OOCASoundChannelDelegate)
|
||||
@interface NSObject(OOSoundChannelDelegate)
|
||||
|
||||
// Note: this will be called in a separate thread.
|
||||
- (void)channel:(OOCASoundChannel *)inChannel didFinishPlayingSound:(OOSound *)inSound;
|
||||
- (void)channel:(OOSoundChannel *)inChannel didFinishPlayingSound:(OOSound *)inSound;
|
||||
|
||||
@end
|
||||
|
@ -3,7 +3,7 @@
|
||||
OOCASoundChannel.m
|
||||
|
||||
OOCASound - Core Audio sound implementation for Oolite.
|
||||
Copyright (C) 2005-2006 Jens Ayton
|
||||
Copyright (C) 2005-2008 Jens Ayton
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
@ -72,7 +72,7 @@ static NSString * const kOOLogSoundMachPortError = @"sound.channel.machPortErro
|
||||
static mach_port_t sReapPort = MACH_PORT_NULL;
|
||||
static mach_port_t sStatusPort = MACH_PORT_NULL;
|
||||
static BOOL sReaperRunning = NO;
|
||||
static OOCASoundChannel_RenderIMP SoundChannelRender = NULL;
|
||||
static OOSoundChannel_RenderIMP SoundChannelRender = NULL;
|
||||
|
||||
#if COUNT_NULLS
|
||||
static int32_t sDebugUnexpectedNullCount = 0;
|
||||
@ -85,8 +85,8 @@ static int32_t sDebugUnexpectedNullCount = 0;
|
||||
to use a mutex-protected list to communicate with the reap queue without having to wait on the
|
||||
mutex in the real-time thread.
|
||||
*/
|
||||
static OOCASoundChannel *sPlayThreadDeadList = NULL;
|
||||
static OOCASoundChannel *sReapQueue = NULL;
|
||||
static OOSoundChannel *sPlayThreadDeadList = NULL;
|
||||
static OOSoundChannel *sReapQueue = NULL;
|
||||
static pthread_mutex_t sReapQueueMutex = { 0 };
|
||||
|
||||
enum
|
||||
@ -103,7 +103,7 @@ enum
|
||||
#define kAURenderSelector @selector(renderWithFlags:frames:context:data:)
|
||||
|
||||
|
||||
@interface OOCASoundChannel(Private)
|
||||
@interface OOSoundChannel(Private)
|
||||
|
||||
+ (void)reaperThread:junk;
|
||||
|
||||
@ -158,7 +158,7 @@ static void PortSend(mach_port_t inPort, PortMessage inMessage);
|
||||
static BOOL PortWait(mach_port_t inPort, PortMessage *outMessage);
|
||||
|
||||
|
||||
@implementation OOCASoundChannel
|
||||
@implementation OOSoundChannel
|
||||
|
||||
+ (BOOL)setUp
|
||||
{
|
||||
@ -167,7 +167,7 @@ static BOOL PortWait(mach_port_t inPort, PortMessage *outMessage);
|
||||
|
||||
if (sReaperRunning) return YES;
|
||||
|
||||
SoundChannelRender = (OOCASoundChannel_RenderIMP)[OOCASoundChannel instanceMethodForSelector:kAURenderSelector];
|
||||
SoundChannelRender = (OOSoundChannel_RenderIMP)[OOSoundChannel instanceMethodForSelector:kAURenderSelector];
|
||||
if (NULL == SoundChannelRender) OK = NO;
|
||||
|
||||
if (OK)
|
||||
@ -225,10 +225,10 @@ static BOOL PortWait(mach_port_t inPort, PortMessage *outMessage);
|
||||
+ (void)reaperThread:junk
|
||||
{
|
||||
PortMessage message = { kMsgThreadUp, NULL };
|
||||
OOCASoundChannel *chan;
|
||||
OOSoundChannel *chan;
|
||||
NSAutoreleasePool *pool = nil;
|
||||
|
||||
[NSThread ooSetCurrentThreadName:@"OOCASoundChannel reaper thread"];
|
||||
[NSThread ooSetCurrentThreadName:@"OOSoundChannel reaper thread"];
|
||||
sReaperRunning = YES;
|
||||
PortSend(sStatusPort, message);
|
||||
|
||||
@ -353,13 +353,13 @@ static BOOL PortWait(mach_port_t inPort, PortMessage *outMessage);
|
||||
}
|
||||
|
||||
|
||||
- (OOCASoundChannel *)next
|
||||
- (OOSoundChannel *)next
|
||||
{
|
||||
return _next;
|
||||
}
|
||||
|
||||
|
||||
- (void)setNext:(OOCASoundChannel *)inNext
|
||||
- (void)setNext:(OOSoundChannel *)inNext
|
||||
{
|
||||
_next = inNext;
|
||||
}
|
||||
@ -403,7 +403,7 @@ static BOOL PortWait(mach_port_t inPort, PortMessage *outMessage);
|
||||
{
|
||||
OOLog(kOOLogSoundBadReuse, @"Channel %@ reused while playing.", self);
|
||||
|
||||
[[OOCASoundMixer mixer] disconnectChannel:self];
|
||||
[[OOSoundMixer sharedMixer] disconnectChannel:self];
|
||||
if (_sound)
|
||||
{
|
||||
Render = NULL;
|
||||
@ -417,7 +417,7 @@ static BOOL PortWait(mach_port_t inPort, PortMessage *outMessage);
|
||||
_state = kState_Stopped;
|
||||
}
|
||||
|
||||
Render = (OOCASoundChannel_RenderIMP)[inSound methodForSelector:kAURenderSelector];
|
||||
Render = (OOSoundChannel_RenderIMP)[inSound methodForSelector:kAURenderSelector];
|
||||
OK = (NULL != Render);
|
||||
|
||||
if (OK) OK = [inSound getAudioStreamBasicDescription:&format];
|
||||
@ -439,7 +439,7 @@ static BOOL PortWait(mach_port_t inPort, PortMessage *outMessage);
|
||||
OK = !err;
|
||||
}
|
||||
|
||||
if (OK) OK = [[OOCASoundMixer mixer] connectChannel:self];
|
||||
if (OK) OK = [[OOSoundMixer sharedMixer] connectChannel:self];
|
||||
|
||||
if (OK)
|
||||
{
|
||||
@ -474,7 +474,7 @@ static BOOL PortWait(mach_port_t inPort, PortMessage *outMessage);
|
||||
{
|
||||
OSStatus err;
|
||||
|
||||
err = [[OOCASoundMixer mixer] disconnectChannel:self];
|
||||
err = [[OOSoundMixer sharedMixer] disconnectChannel:self];
|
||||
|
||||
if (noErr == err)
|
||||
{
|
||||
@ -617,7 +617,7 @@ static BOOL PortWait(mach_port_t inPort, PortMessage *outMessage);
|
||||
if (__builtin_expect(nil != sPlayThreadDeadList && !pthread_mutex_trylock(&sReapQueueMutex), 0))
|
||||
{
|
||||
// Put sPlayThreadDeadList at front of sReapQueue
|
||||
OOCASoundChannel *curr;
|
||||
OOSoundChannel *curr;
|
||||
|
||||
curr = sPlayThreadDeadList;
|
||||
while (nil != curr->_next) curr = curr->_next;
|
||||
|
@ -7,7 +7,7 @@ class is an implementation detail. Do not use it directly; use OOSound to
|
||||
load sounds.
|
||||
|
||||
OOCASound - Core Audio sound implementation for Oolite.
|
||||
Copyright (C) 2005-2006 Jens Ayton
|
||||
Copyright (C) 2005-2008 Jens Ayton
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
|
@ -3,7 +3,7 @@
|
||||
OOCASoundDecoder.m
|
||||
|
||||
OOCASound - Core Audio sound implementation for Oolite.
|
||||
Copyright (C) 2005-2006 Jens Ayton
|
||||
Copyright (C) 2005-2008 Jens Ayton
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
|
@ -6,7 +6,7 @@ Declarations used within OOCASound. This file should not be used by client
|
||||
code.
|
||||
|
||||
OOCASound - Core Audio sound implementation for Oolite.
|
||||
Copyright (C) 2005-2006 Jens Ayton
|
||||
Copyright (C) 2005-2008 Jens Ayton
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
@ -48,15 +48,13 @@ SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#import "OOCASound.h"
|
||||
#import "OOCASoundMixer.h"
|
||||
#import "OOSoundInternal.h"
|
||||
#import "OOCASoundChannel.h"
|
||||
#import "OOCABufferedSound.h"
|
||||
#import "OOCAStreamingSound.h"
|
||||
#import <CoreAudio/CoreAudio.h>
|
||||
#import <AudioToolbox/AudioToolbox.h>
|
||||
#import "OOErrorDescription.h"
|
||||
#import "OOCASoundSource.h"
|
||||
#import "OOLogging.h"
|
||||
|
||||
|
||||
@ -78,16 +76,15 @@ SOFTWARE.
|
||||
@end
|
||||
|
||||
|
||||
@interface OOCASoundMixer (Internal)
|
||||
@interface OOSoundMixer (Internal)
|
||||
|
||||
- (BOOL)connectChannel:(OOCASoundChannel *)inChannel;
|
||||
- (OSStatus)disconnectChannel:(OOCASoundChannel *)inChannel;
|
||||
- (BOOL)connectChannel:(OOSoundChannel *)inChannel;
|
||||
- (OSStatus)disconnectChannel:(OOSoundChannel *)inChannel;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
extern BOOL gOOSoundSetUp, gOOSoundBroken;
|
||||
extern NSRecursiveLock *gOOCASoundSyncLock;
|
||||
|
||||
extern NSString * const kOOLogDeprecatedMethodOOCASound;
|
||||
extern NSString * const kOOLogSoundInitError;
|
||||
|
@ -7,7 +7,7 @@ implementation detail. Do not use it directly; use an OOSoundSource to play an
|
||||
OOSound.
|
||||
|
||||
OOCASound - Core Audio sound implementation for Oolite.
|
||||
Copyright (C) 2005-2006 Jens Ayton
|
||||
Copyright (C) 2005-2008 Jens Ayton
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
@ -53,17 +53,22 @@ SOFTWARE.
|
||||
#import <mach/port.h>
|
||||
#import <AudioToolbox/AudioToolbox.h>
|
||||
|
||||
@class OOMusic, OOCASoundChannel, OOSoundSource;
|
||||
@class OOMusic, OOSoundChannel, OOSoundSource;
|
||||
|
||||
|
||||
enum
|
||||
{
|
||||
kMixerGeneralChannels = 32
|
||||
};
|
||||
|
||||
|
||||
#define kMixerGeneralChannels 32
|
||||
#define SUPPORT_SOUND_INSPECTOR 0
|
||||
|
||||
|
||||
@interface OOCASoundMixer: NSObject
|
||||
@interface OOSoundMixer: NSObject
|
||||
{
|
||||
OOCASoundChannel *_channels[kMixerGeneralChannels];
|
||||
OOCASoundChannel *_freeList;
|
||||
OOSoundChannel *_channels[kMixerGeneralChannels];
|
||||
OOSoundChannel *_freeList;
|
||||
NSLock *_listLock;
|
||||
|
||||
AUGraph _graph;
|
||||
@ -85,16 +90,13 @@ SOFTWARE.
|
||||
}
|
||||
|
||||
// Singleton accessor
|
||||
+ (OOCASoundMixer *)mixer;
|
||||
+ (void)destroy; // releases singleton
|
||||
+ (id) sharedMixer;
|
||||
|
||||
- (void)playSound:(OOSound *)inSound;
|
||||
- (void) update;
|
||||
|
||||
- (void)update;
|
||||
- (void) setMasterVolume:(float)inVolume;
|
||||
|
||||
- (void)setMasterVolume:(float)inVolume;
|
||||
|
||||
- (OOCASoundChannel *)popChannel;
|
||||
- (void)pushChannel:(OOCASoundChannel *)inChannel;
|
||||
- (OOSoundChannel *) popChannel;
|
||||
- (void) pushChannel:(OOSoundChannel *)inChannel;
|
||||
|
||||
@end
|
||||
|
@ -7,7 +7,7 @@ implementation detail. Do not use it directly; use an OOSoundSource to play an
|
||||
OOSound.
|
||||
|
||||
OOCASound - Core Audio sound implementation for Oolite.
|
||||
Copyright (C) 2005-2006 Jens Ayton
|
||||
Copyright (C) 2005-2008 Jens Ayton
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
@ -60,26 +60,23 @@ static NSString * const kOOLogSoundMixerReplacingBrokenChannel = @"sound.mixer.r
|
||||
static NSString * const kOOLogSoundMixerFailedToConnectChannel = @"sound.mixer.failedToConnectChannel";
|
||||
|
||||
|
||||
@interface OOCASoundMixer(Private)
|
||||
@interface OOSoundMixer (Private)
|
||||
|
||||
- (void)reallyRelease;
|
||||
- (void)channelSoundEnded:(OOCASoundChannel *)inChannel;
|
||||
|
||||
- (void)pushChannel:(OOCASoundChannel *)inChannel;
|
||||
- (OOCASoundChannel *)popChannel;
|
||||
- (void)pushChannel:(OOSoundChannel *)inChannel;
|
||||
- (OOSoundChannel *)popChannel;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
static OOCASoundMixer *sSingleton = nil;
|
||||
static OOSoundMixer *sSingleton = nil;
|
||||
|
||||
@implementation OOCASoundMixer
|
||||
@implementation OOSoundMixer
|
||||
|
||||
+ (OOCASoundMixer *)mixer
|
||||
+ (id) sharedMixer
|
||||
{
|
||||
if (nil == sSingleton)
|
||||
{
|
||||
sSingleton = [[self alloc] init];
|
||||
[[self alloc] init];
|
||||
}
|
||||
return sSingleton;
|
||||
}
|
||||
@ -87,129 +84,88 @@ static OOCASoundMixer *sSingleton = nil;
|
||||
|
||||
- (id)init
|
||||
{
|
||||
OSStatus err = noErr;
|
||||
BOOL OK;
|
||||
uint32_t idx = 0, count = kMixerGeneralChannels;
|
||||
OOCASoundChannel *temp;
|
||||
ComponentDescription desc;
|
||||
OSStatus err = noErr;
|
||||
BOOL OK;
|
||||
uint32_t idx = 0, count = kMixerGeneralChannels;
|
||||
OOSoundChannel *temp;
|
||||
ComponentDescription desc;
|
||||
|
||||
if (!gOOSoundSetUp) [OOSound setUp];
|
||||
if (!gOOSoundSetUp) [OOSound setUp];
|
||||
|
||||
if (nil != sSingleton)
|
||||
self = [super init];
|
||||
if (nil != self)
|
||||
{
|
||||
[super release];
|
||||
}
|
||||
else
|
||||
{
|
||||
self = [super init];
|
||||
if (nil != self)
|
||||
_listLock = [[NSLock alloc] init];
|
||||
[_listLock ooSetName:@"OOSoundMixer list lock"];
|
||||
OK = nil != _listLock;
|
||||
|
||||
if (OK)
|
||||
{
|
||||
_listLock = [[NSLock alloc] init];
|
||||
[_listLock ooSetName:@"OOCASoundMixer list lock"];
|
||||
OK = nil != _listLock;
|
||||
// Create audio graph
|
||||
err = NewAUGraph(&_graph);
|
||||
|
||||
if (OK)
|
||||
{
|
||||
// Create audio graph
|
||||
err = NewAUGraph(&_graph);
|
||||
|
||||
// Add output node
|
||||
desc.componentType = kAudioUnitType_Output;
|
||||
desc.componentSubType = kAudioUnitSubType_DefaultOutput;
|
||||
desc.componentManufacturer = kAudioUnitManufacturer_Apple;
|
||||
desc.componentFlags = 0;
|
||||
desc.componentFlagsMask = 0;
|
||||
if (!err) err = OOAUGraphAddNode(_graph, &desc, &_outputNode);
|
||||
|
||||
// Add mixer node
|
||||
desc.componentType = kAudioUnitType_Mixer;
|
||||
desc.componentSubType = kAudioUnitSubType_StereoMixer;
|
||||
desc.componentManufacturer = kAudioUnitManufacturer_Apple;
|
||||
desc.componentFlags = 0;
|
||||
desc.componentFlagsMask = 0;
|
||||
if (!err) err = OOAUGraphAddNode(_graph, &desc, &_mixerNode);
|
||||
|
||||
// Connect mixer to output
|
||||
if (!err) err = AUGraphConnectNodeInput(_graph, _mixerNode, 0, _outputNode, 0);
|
||||
|
||||
// Open the graph (turn it into concrete AUs) and extract mixer AU
|
||||
if (!err) err = AUGraphOpen(_graph);
|
||||
if (!err) err = OOAUGraphNodeInfo(_graph, _mixerNode, NULL, &_mixerUnit);
|
||||
|
||||
if (err) OK = NO;
|
||||
}
|
||||
// Add output node
|
||||
desc.componentType = kAudioUnitType_Output;
|
||||
desc.componentSubType = kAudioUnitSubType_DefaultOutput;
|
||||
desc.componentManufacturer = kAudioUnitManufacturer_Apple;
|
||||
desc.componentFlags = 0;
|
||||
desc.componentFlagsMask = 0;
|
||||
if (!err) err = OOAUGraphAddNode(_graph, &desc, &_outputNode);
|
||||
|
||||
if (OK)
|
||||
{
|
||||
// Allocate channels
|
||||
do
|
||||
{
|
||||
temp = [[OOCASoundChannel alloc] initWithID:count auGraph:_graph];
|
||||
if (nil != temp)
|
||||
{
|
||||
_channels[idx++] = temp;
|
||||
[temp setNext:_freeList];
|
||||
_freeList = temp;
|
||||
}
|
||||
} while (--count);
|
||||
|
||||
if (noErr != AUGraphInitialize(_graph)) OK = NO;
|
||||
}
|
||||
// Add mixer node
|
||||
desc.componentType = kAudioUnitType_Mixer;
|
||||
desc.componentSubType = kAudioUnitSubType_StereoMixer;
|
||||
desc.componentManufacturer = kAudioUnitManufacturer_Apple;
|
||||
desc.componentFlags = 0;
|
||||
desc.componentFlagsMask = 0;
|
||||
if (!err) err = OOAUGraphAddNode(_graph, &desc, &_mixerNode);
|
||||
|
||||
if (!OK)
|
||||
{
|
||||
[self reallyRelease];
|
||||
self = nil;
|
||||
}
|
||||
// Connect mixer to output
|
||||
if (!err) err = AUGraphConnectNodeInput(_graph, _mixerNode, 0, _outputNode, 0);
|
||||
|
||||
#if SUPPORT_SOUND_INSPECTOR
|
||||
if (![NSBundle loadNibNamed:@"SoundInspector" owner:self])
|
||||
{
|
||||
OOLog(kOOLogSoundInspetorNotLoaded, @"Failed to load sound inspector panel.");
|
||||
}
|
||||
#endif
|
||||
// Open the graph (turn it into concrete AUs) and extract mixer AU
|
||||
if (!err) err = AUGraphOpen(_graph);
|
||||
if (!err) err = OOAUGraphNodeInfo(_graph, _mixerNode, NULL, &_mixerUnit);
|
||||
|
||||
if (err) OK = NO;
|
||||
}
|
||||
sSingleton = self;
|
||||
|
||||
if (OK)
|
||||
{
|
||||
// Allocate channels
|
||||
do
|
||||
{
|
||||
temp = [[OOSoundChannel alloc] initWithID:count auGraph:_graph];
|
||||
if (nil != temp)
|
||||
{
|
||||
_channels[idx++] = temp;
|
||||
[temp setNext:_freeList];
|
||||
_freeList = temp;
|
||||
}
|
||||
} while (--count);
|
||||
|
||||
if (noErr != AUGraphInitialize(_graph)) OK = NO;
|
||||
}
|
||||
|
||||
if (!OK)
|
||||
{
|
||||
[super release];
|
||||
self = nil;
|
||||
}
|
||||
|
||||
#if SUPPORT_SOUND_INSPECTOR
|
||||
if (![NSBundle loadNibNamed:@"SoundInspector" owner:self])
|
||||
{
|
||||
OOLog(kOOLogSoundInspetorNotLoaded, @"Failed to load sound inspector panel.");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
sSingleton = self;
|
||||
|
||||
return sSingleton;
|
||||
}
|
||||
|
||||
|
||||
- (id)retain
|
||||
{
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
- (void)release
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
- (void)reallyRelease
|
||||
{
|
||||
[super release];
|
||||
}
|
||||
|
||||
|
||||
- (id)autorelease
|
||||
{
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
+ (void)destroy
|
||||
{
|
||||
if (nil != sSingleton)
|
||||
{
|
||||
[sSingleton reallyRelease];
|
||||
sSingleton = nil;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
uint32_t idx;
|
||||
@ -230,38 +186,7 @@ static OOCASoundMixer *sSingleton = nil;
|
||||
}
|
||||
|
||||
|
||||
- (void)playSound:(OOSound *)inSound
|
||||
{
|
||||
BOOL OK = YES;
|
||||
OOCASoundChannel *chan;
|
||||
|
||||
if (nil == inSound) return;
|
||||
|
||||
chan = [self popChannel];
|
||||
|
||||
if (nil != chan)
|
||||
{
|
||||
[chan setDelegate:self];
|
||||
OK = [chan playSound:inSound looped:NO];
|
||||
|
||||
if (OK)
|
||||
{
|
||||
[inSound incrementPlayingCount];
|
||||
[self retain];
|
||||
}
|
||||
else
|
||||
{
|
||||
[self pushChannel:chan];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
OOLog(kOOLogSoundMixerOutOfChannels, @"Out of sound channels! Pretend you're hearing %@", [inSound name]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (void)channel:(OOCASoundChannel *)inChannel didFinishPlayingSound:(OOSound *)inSound
|
||||
- (void)channel:(OOSoundChannel *)inChannel didFinishPlayingSound:(OOSound *)inSound
|
||||
{
|
||||
uint32_t ID;
|
||||
|
||||
@ -272,7 +197,7 @@ static OOCASoundMixer *sSingleton = nil;
|
||||
OOLog(kOOLogSoundMixerReplacingBrokenChannel, @"Sound mixer: replacing broken channel %@.", inChannel);
|
||||
ID = [inChannel ID];
|
||||
[inChannel release];
|
||||
inChannel = [[OOCASoundChannel alloc] initWithID:ID auGraph:_graph];
|
||||
inChannel = [[OOSoundChannel alloc] initWithID:ID auGraph:_graph];
|
||||
}
|
||||
|
||||
[self pushChannel:inChannel];
|
||||
@ -328,30 +253,9 @@ static OOCASoundMixer *sSingleton = nil;
|
||||
}
|
||||
|
||||
|
||||
- (void)pushChannel:(OOCASoundChannel *)inChannel
|
||||
- (OOSoundChannel *)popChannel
|
||||
{
|
||||
uint32_t ID;
|
||||
|
||||
assert(nil != inChannel);
|
||||
|
||||
[_listLock lock];
|
||||
|
||||
[inChannel setNext:_freeList];
|
||||
_freeList = inChannel;
|
||||
|
||||
if (0 == --_activeChannels)
|
||||
{
|
||||
AUGraphStop(_graph);
|
||||
}
|
||||
ID = [inChannel ID] - 1;
|
||||
if (ID < 32) _playMask &= ~(1 << ID);
|
||||
[_listLock unlock];
|
||||
}
|
||||
|
||||
|
||||
- (OOCASoundChannel *)popChannel
|
||||
{
|
||||
OOCASoundChannel *result;
|
||||
OOSoundChannel *result;
|
||||
uint32_t ID;
|
||||
|
||||
[_listLock lock];
|
||||
@ -374,7 +278,28 @@ static OOCASoundMixer *sSingleton = nil;
|
||||
}
|
||||
|
||||
|
||||
- (BOOL)connectChannel:(OOCASoundChannel *)inChannel
|
||||
- (void)pushChannel:(OOSoundChannel *)inChannel
|
||||
{
|
||||
uint32_t ID;
|
||||
|
||||
assert(nil != inChannel);
|
||||
|
||||
[_listLock lock];
|
||||
|
||||
[inChannel setNext:_freeList];
|
||||
_freeList = inChannel;
|
||||
|
||||
if (0 == --_activeChannels)
|
||||
{
|
||||
AUGraphStop(_graph);
|
||||
}
|
||||
ID = [inChannel ID] - 1;
|
||||
if (ID < 32) _playMask &= ~(1 << ID);
|
||||
[_listLock unlock];
|
||||
}
|
||||
|
||||
|
||||
- (BOOL)connectChannel:(OOSoundChannel *)inChannel
|
||||
{
|
||||
AUNode node;
|
||||
OSStatus err;
|
||||
@ -391,7 +316,7 @@ static OOCASoundMixer *sSingleton = nil;
|
||||
}
|
||||
|
||||
|
||||
- (OSStatus)disconnectChannel:(OOCASoundChannel *)inChannel
|
||||
- (OSStatus)disconnectChannel:(OOSoundChannel *)inChannel
|
||||
{
|
||||
OSStatus err;
|
||||
|
||||
@ -404,3 +329,53 @@ static OOCASoundMixer *sSingleton = nil;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation OOSoundMixer (Singleton)
|
||||
|
||||
/* Canonical singleton boilerplate.
|
||||
See Cocoa Fundamentals Guide: Creating a Singleton Instance.
|
||||
See also +sharedMixer above.
|
||||
|
||||
NOTE: assumes single-threaded access.
|
||||
*/
|
||||
|
||||
+ (id)allocWithZone:(NSZone *)inZone
|
||||
{
|
||||
if (sSingleton == nil)
|
||||
{
|
||||
sSingleton = [super allocWithZone:inZone];
|
||||
return sSingleton;
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
||||
- (id)copyWithZone:(NSZone *)inZone
|
||||
{
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
- (id)retain
|
||||
{
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
- (OOUInteger)retainCount
|
||||
{
|
||||
return UINT_MAX;
|
||||
}
|
||||
|
||||
|
||||
- (void)release
|
||||
{}
|
||||
|
||||
|
||||
- (id)autorelease
|
||||
{
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -7,7 +7,7 @@ specified relative to an OOSoundReferencePoint. Since positional audio is
|
||||
currently unimplemented, this class does nothing.
|
||||
|
||||
OOCASound - Core Audio sound implementation for Oolite.
|
||||
Copyright (C) 2005-2006 Jens Ayton
|
||||
Copyright (C) 2005-2008 Jens Ayton
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
|
@ -3,7 +3,7 @@
|
||||
OOCASoundReferencePoint.m
|
||||
|
||||
OOCASound - Core Audio sound implementation for Oolite.
|
||||
Copyright (C) 2005-2006 Jens Ayton
|
||||
Copyright (C) 2005-2008 Jens Ayton
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
@ -23,7 +23,7 @@ MA 02110-1301, USA.
|
||||
|
||||
This file may also be distributed under the MIT/X11 license:
|
||||
|
||||
Copyright (C) 2005-2006 Jens Ayton
|
||||
Copyright (C) 2005-2008 Jens Ayton
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -1,277 +0,0 @@
|
||||
/*
|
||||
|
||||
OOCASoundSource.m
|
||||
|
||||
OOCASound - Core Audio sound implementation for Oolite.
|
||||
Copyright (C) 2005-2006 Jens Ayton
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA.
|
||||
|
||||
|
||||
This file may also be distributed under the MIT/X11 license:
|
||||
|
||||
Copyright (C) 2005-2008 Jens Ayton
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
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 Software.
|
||||
|
||||
THE SOFTWARE IS 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 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#import "OOCASoundInternal.h"
|
||||
|
||||
|
||||
@implementation OOSoundSource
|
||||
|
||||
#pragma mark NSObject
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[self stop];
|
||||
[sound autorelease];
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
||||
- (NSString *)description
|
||||
{
|
||||
if ([self isPlaying])
|
||||
{
|
||||
return [NSString stringWithFormat:@"<%@ %p>{sound=%@, loop=%s, repeatCount=%u, playing on channel %@}", [self className], self, sound, [self loop] ? "YES" : "NO", [self repeatCount], channel];
|
||||
}
|
||||
else
|
||||
{
|
||||
return [NSString stringWithFormat:@"<%@ %p>{sound=%@, loop=%s, repeatCount=%u, not playing}", [self className], self, sound, [self loop] ? "YES" : "NO", [self repeatCount]];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#pragma mark OOSoundSource
|
||||
|
||||
+ (id)sourceWithSound:(OOSound *)inSound
|
||||
{
|
||||
return [[[self alloc] initWithSound:inSound] autorelease];
|
||||
}
|
||||
|
||||
|
||||
- (id)initWithSound:(OOSound *)inSound
|
||||
{
|
||||
self = [self init];
|
||||
if (!self) return nil;
|
||||
|
||||
[self setSound:inSound];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
- (OOSound *)sound
|
||||
{
|
||||
return sound;
|
||||
}
|
||||
|
||||
|
||||
- (void)setSound:(OOSound *)inSound
|
||||
{
|
||||
if (sound != inSound)
|
||||
{
|
||||
[sound autorelease];
|
||||
sound = [inSound retain];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (BOOL)loop
|
||||
{
|
||||
return loop;
|
||||
}
|
||||
|
||||
|
||||
- (void)setLoop:(BOOL)inLoop
|
||||
{
|
||||
loop = !!inLoop;
|
||||
}
|
||||
|
||||
|
||||
- (uint8_t)repeatCount
|
||||
{
|
||||
return repeatCount ? repeatCount : 1;
|
||||
}
|
||||
|
||||
|
||||
- (void)setRepeatCount:(uint8_t)inCount
|
||||
{
|
||||
repeatCount = inCount;
|
||||
}
|
||||
|
||||
|
||||
- (BOOL)isPlaying
|
||||
{
|
||||
return (nil != channel);
|
||||
}
|
||||
|
||||
|
||||
- (void)play
|
||||
{
|
||||
if (nil == sound) return;
|
||||
|
||||
[gOOCASoundSyncLock lock];
|
||||
|
||||
if (channel) [self stop];
|
||||
|
||||
channel = [[OOCASoundMixer mixer] popChannel];
|
||||
if (nil != channel)
|
||||
{
|
||||
remainingCount = [self repeatCount];
|
||||
[channel setDelegate:self];
|
||||
[channel playSound:sound looped:loop];
|
||||
[self retain];
|
||||
}
|
||||
[gOOCASoundSyncLock unlock];
|
||||
}
|
||||
|
||||
|
||||
- (void)playOrRepeat
|
||||
{
|
||||
if (![self isPlaying]) [self play];
|
||||
else ++remainingCount;
|
||||
}
|
||||
|
||||
|
||||
- (void)stop
|
||||
{
|
||||
[gOOCASoundSyncLock lock];
|
||||
if (nil != channel)
|
||||
{
|
||||
[channel setDelegate:[self class]];
|
||||
[channel stop];
|
||||
channel = nil;
|
||||
[self release];
|
||||
}
|
||||
|
||||
[gOOCASoundSyncLock unlock];
|
||||
}
|
||||
|
||||
|
||||
- (void)playSound:(OOSound *)inSound
|
||||
{
|
||||
[self playSound:inSound repeatCount:repeatCount];
|
||||
}
|
||||
|
||||
|
||||
- (void)playSound:(OOSound *)inSound repeatCount:(uint8_t)inCount
|
||||
{
|
||||
[self stop];
|
||||
[self setSound:inSound];
|
||||
[self setRepeatCount:inCount];
|
||||
[self play];
|
||||
}
|
||||
|
||||
|
||||
- (void)playOrRepeatSound:(OOSound *)inSound
|
||||
{
|
||||
if (sound != inSound) [self playSound:inSound];
|
||||
else [self playOrRepeat];
|
||||
}
|
||||
|
||||
|
||||
- (void)positionRelativeTo:(OOSoundReferencePoint *)inPoint
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
- (void)setPositional:(BOOL)inPositional
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
- (void)setPosition:(Vector)inPosition
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
- (void)setVelocity:(Vector)inVelocity
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
- (void)setOrientation:(Vector)inOrientation
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
- (void)setConeAngle:(float)inAngle
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
- (void)setGainInsideCone:(float)inInside outsideCone:(float)inOutside
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
#pragma mark (OOCASoundChannelDelegate)
|
||||
|
||||
- (void)channel:(OOCASoundChannel *)inChannel didFinishPlayingSound:(OOSound *)inSound
|
||||
{
|
||||
assert(channel == inChannel);
|
||||
|
||||
[gOOCASoundSyncLock lock];
|
||||
|
||||
if (--remainingCount)
|
||||
{
|
||||
[channel playSound:sound looped:NO];
|
||||
}
|
||||
else
|
||||
{
|
||||
[channel setDelegate:nil];
|
||||
[[OOCASoundMixer mixer] pushChannel:channel];
|
||||
channel = nil;
|
||||
[self release];
|
||||
}
|
||||
[gOOCASoundSyncLock unlock];
|
||||
}
|
||||
|
||||
|
||||
+ (void)channel:(OOCASoundChannel *)inChannel didFinishPlayingSound:(OOSound *)inSound
|
||||
{
|
||||
// This delegate is used for a stopped source
|
||||
[[OOCASoundMixer mixer] pushChannel:inChannel];
|
||||
}
|
||||
|
||||
@end
|
@ -7,7 +7,7 @@ Subclass of OOSound which streams audio from disk.
|
||||
This class is an implementation detail. Do not use it directly; use OOSound.
|
||||
|
||||
OOCASound - Core Audio sound implementation for Oolite.
|
||||
Copyright (C) 2005-2006 Jens Ayton
|
||||
Copyright (C) 2005-2008 Jens Ayton
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
@ -27,7 +27,7 @@ MA 02110-1301, USA.
|
||||
|
||||
This file may also be distributed under the MIT/X11 license:
|
||||
|
||||
Copyright (C) 2005-2006 Jens Ayton
|
||||
Copyright (C) 2005-2008 Jens Ayton
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -5,7 +5,7 @@ OOCAStreamingSound.m
|
||||
This class is an implementation detail. Do not use it directly; use OOSound.
|
||||
|
||||
OOCASound - Core Audio sound implementation for Oolite.
|
||||
Copyright (C) 2005-2006 Jens Ayton
|
||||
Copyright (C) 2005-2008 Jens Ayton
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
@ -25,7 +25,7 @@ MA 02110-1301, USA.
|
||||
|
||||
This file may also be distributed under the MIT/X11 license:
|
||||
|
||||
Copyright (C) 2005-2006 Jens Ayton
|
||||
Copyright (C) 2005-2008 Jens Ayton
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
@ -160,7 +160,7 @@ enum
|
||||
|
||||
- (void)play
|
||||
{
|
||||
[[OOCASoundMixer mixer] playSound:self];
|
||||
[[OOSoundMixer sharedMixer] playSound:self];
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,39 +0,0 @@
|
||||
/*
|
||||
|
||||
OOBasicSoundReferencePoint.h
|
||||
|
||||
No-op implementation of OOSoundReferencePoint; see OOSound.h for information
|
||||
about sound architecture.
|
||||
|
||||
Oolite
|
||||
Copyright (C) 2004-2007 Giles C Williams and contributors
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA.
|
||||
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "OOMaths.h"
|
||||
|
||||
|
||||
@interface OOSoundReferencePoint: NSObject
|
||||
|
||||
// Positional audio attributes are ignored in this implementation
|
||||
- (void)setPosition:(Vector)inPosition;
|
||||
- (void)setVelocity:(Vector)inVelocity;
|
||||
- (void)setOrientation:(Vector)inOrientation;
|
||||
|
||||
@end
|
@ -1,47 +0,0 @@
|
||||
/*
|
||||
|
||||
OOBasicSoundReferencePoint.m
|
||||
|
||||
Oolite
|
||||
Copyright (C) 2004-2007 Giles C Williams and contributors
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA.
|
||||
|
||||
*/
|
||||
|
||||
#import "OOBasicSoundReferencePoint.h"
|
||||
|
||||
|
||||
@implementation OOSoundReferencePoint
|
||||
|
||||
- (void)setPosition:(Vector)inPosition
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
- (void)setVelocity:(Vector)inVelocity
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
- (void)setOrientation:(Vector)inOrientation
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@end
|
@ -45,13 +45,13 @@ MA 02110-1301, USA.
|
||||
|
||||
|
||||
#if OOLITE_SDL
|
||||
#import "SDLSound.h"
|
||||
#import "OOSDLSound.h"
|
||||
#import "SDLMusic.h"
|
||||
#import "OOBasicSoundSource.h"
|
||||
#import "OOBasicSoundReferencePoint.h"
|
||||
#else
|
||||
#import "OOCASound.h"
|
||||
#import "OOCAMusic.h"
|
||||
#import "OOCASoundSource.h"
|
||||
#import "OOCASoundReferencePoint.h"
|
||||
#endif
|
||||
|
||||
#import "OOSoundSource.h"
|
||||
|
@ -1,12 +0,0 @@
|
||||
// OOSound.m: Selects the appropriate sound class source file
|
||||
// depending on the operating system defined.
|
||||
//
|
||||
// Add new OS imports here. The -DOS_NAME flag in the GNUmakefile
|
||||
// will select which one gets compiled.
|
||||
//
|
||||
// Dylan Smith, 2005-04-22
|
||||
|
||||
#ifdef LINUX
|
||||
#import "SDLSound.m"
|
||||
#endif
|
||||
|
21
src/Core/OOSoundInternal.h
Normal file
21
src/Core/OOSoundInternal.h
Normal file
@ -0,0 +1,21 @@
|
||||
#import "OOSound.h"
|
||||
|
||||
#if OOLITE_SDL
|
||||
|
||||
#import "OOSDLSoundMixer.h"
|
||||
#import "OOSDLSoundChannel.h"
|
||||
|
||||
#define OOSoundAcquireLock() do {} while(0)
|
||||
#define OOSoundReleaseLock() do {} while(0)
|
||||
|
||||
#elif OOLITE_MAC_OS_X
|
||||
|
||||
#import "OOCASoundMixer.h"
|
||||
#import "OOCASoundChannel.h"
|
||||
|
||||
extern NSRecursiveLock *gOOCASoundSyncLock;
|
||||
|
||||
#define OOSoundAcquireLock() [gOOCASoundSyncLock lock]
|
||||
#define OOSoundReleaseLock() [gOOCASoundSyncLock unlock]
|
||||
|
||||
#endif
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
|
||||
OOCASoundSource.h
|
||||
OOSoundSource.h
|
||||
|
||||
A sound source.
|
||||
Each playing sound is associated with a sound source, either explicitly or by
|
||||
@ -8,8 +8,8 @@ creating one on the fly. Each sound source can play one sound at a time, and
|
||||
has a number of attributes related to positional audio (which is currently
|
||||
unimplemented).
|
||||
|
||||
OOCASound - Core Audio sound implementation for Oolite.
|
||||
Copyright (C) 2005-2006 Jens Ayton
|
||||
Copyright (C) 2006-2008 Jens Ayton
|
||||
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
@ -29,7 +29,7 @@ MA 02110-1301, USA.
|
||||
|
||||
This file may also be distributed under the MIT/X11 license:
|
||||
|
||||
Copyright (C) 2005-2008 Jens Ayton
|
||||
Copyright (C) 2006-2008 Jens Ayton
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
@ -46,55 +46,53 @@ 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 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
OUT OF OR
|
||||
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "OOSoundSource.h"
|
||||
#import "OOMaths.h"
|
||||
#import "OOCASoundReferencePoint.h"
|
||||
|
||||
@class OOSound, OOCASoundChannel;
|
||||
@class OOSound, OOSoundChannel, OOSoundReferencePoint;
|
||||
|
||||
|
||||
@interface OOSoundSource: NSObject
|
||||
{
|
||||
OOSound *sound;
|
||||
OOCASoundChannel *channel;
|
||||
BOOL loop;
|
||||
uint8_t repeatCount,
|
||||
remainingCount;
|
||||
OOSound *_sound;
|
||||
OOSoundChannel *_channel;
|
||||
BOOL _loop;
|
||||
uint8_t _repeatCount,
|
||||
_remainingCount;
|
||||
}
|
||||
|
||||
+ (id)sourceWithSound:(OOSound *)inSound;
|
||||
- (id)initWithSound:(OOSound *)inSound;
|
||||
+ (id) sourceWithSound:(OOSound *)inSound;
|
||||
- (id) initWithSound:(OOSound *)inSound;
|
||||
|
||||
// These options should be set before playing. Effect of setting them while playing is undefined.
|
||||
- (OOSound *)sound;
|
||||
- (void)setSound:(OOSound *)inSound;
|
||||
- (BOOL)loop;
|
||||
- (void)setLoop:(BOOL)inLoop;
|
||||
- (uint8_t)repeatCount;
|
||||
- (void)setRepeatCount:(uint8_t)inCount;
|
||||
- (OOSound *) sound;
|
||||
- (void )setSound:(OOSound *)inSound;
|
||||
- (BOOL) loop;
|
||||
- (void) setLoop:(BOOL)inLoop;
|
||||
- (uint8_t) repeatCount;
|
||||
- (void) setRepeatCount:(uint8_t)inCount;
|
||||
|
||||
- (BOOL)isPlaying;
|
||||
- (void)play;
|
||||
- (void)playOrRepeat;
|
||||
- (void)stop;
|
||||
- (BOOL) isPlaying;
|
||||
- (void) play;
|
||||
- (void) playOrRepeat;
|
||||
- (void) stop;
|
||||
|
||||
// Conveniences:
|
||||
- (void)playSound:(OOSound *)inSound;
|
||||
- (void)playSound:(OOSound *)inSound repeatCount:(uint8_t)inCount;
|
||||
- (void)playOrRepeatSound:(OOSound *)inSound;
|
||||
- (void) playSound:(OOSound *)inSound;
|
||||
- (void) playSound:(OOSound *)inSound repeatCount:(uint8_t)inCount;
|
||||
- (void) playOrRepeatSound:(OOSound *)inSound;
|
||||
|
||||
// Positional audio attributes are ignored in this implementation
|
||||
- (void)setPositional:(BOOL)inPositional;
|
||||
- (void)setPosition:(Vector)inPosition;
|
||||
- (void)setVelocity:(Vector)inVelocity;
|
||||
- (void)setOrientation:(Vector)inOrientation;
|
||||
- (void)setConeAngle:(float)inAngle;
|
||||
- (void)setGainInsideCone:(float)inInside outsideCone:(float)inOutside;
|
||||
- (void)positionRelativeTo:(OOSoundReferencePoint *)inPoint;
|
||||
- (void) setPositional:(BOOL)inPositional;
|
||||
- (void) setPosition:(Vector)inPosition;
|
||||
- (void) setVelocity:(Vector)inVelocity;
|
||||
- (void) setOrientation:(Vector)inOrientation;
|
||||
- (void) setConeAngle:(float)inAngle;
|
||||
- (void) setGainInsideCone:(float)inInside outsideCone:(float)inOutside;
|
||||
- (void) positionRelativeTo:(OOSoundReferencePoint *)inPoint;
|
||||
|
||||
@end
|
276
src/Core/OOSoundSource.m
Normal file
276
src/Core/OOSoundSource.m
Normal file
@ -0,0 +1,276 @@
|
||||
/*
|
||||
|
||||
OOSoundSource.m
|
||||
|
||||
Copyright (C) 2006-2008 Jens Ayton
|
||||
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA.
|
||||
|
||||
|
||||
This file may also be distributed under the MIT/X11 license:
|
||||
|
||||
Copyright (C) 2006-2008 Jens Ayton
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
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 Software.
|
||||
|
||||
THE SOFTWARE IS 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 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#import "OOSoundInternal.h"
|
||||
#import "OOLogging.h"
|
||||
|
||||
|
||||
@implementation OOSoundSource
|
||||
|
||||
+ (id) sourceWithSound:(OOSound *)inSound
|
||||
{
|
||||
return [[[self alloc] initWithSound:inSound] autorelease];
|
||||
}
|
||||
|
||||
|
||||
- (id) initWithSound:(OOSound *)inSound
|
||||
{
|
||||
self = [self init];
|
||||
if (!self) return nil;
|
||||
|
||||
[self setSound:inSound];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[self stop];
|
||||
[_sound autorelease];
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
||||
- (NSString *) descriptionComponents
|
||||
{
|
||||
if ([self isPlaying])
|
||||
{
|
||||
return [NSString stringWithFormat:@"sound=%@, loop=%s, repeatCount=%u, playing on channel %@", _sound, [self loop] ? "YES" : "NO", [self repeatCount], _channel];
|
||||
}
|
||||
else
|
||||
{
|
||||
return [NSString stringWithFormat:@"sound=%@, loop=%s, repeatCount=%u, not playing", _sound, [self loop] ? "YES" : "NO", [self repeatCount]];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (OOSound *) sound
|
||||
{
|
||||
return _sound;
|
||||
}
|
||||
|
||||
|
||||
- (void) setSound:(OOSound *)sound
|
||||
{
|
||||
if (_sound != sound)
|
||||
{
|
||||
[_sound autorelease];
|
||||
_sound = [sound retain];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (BOOL) loop
|
||||
{
|
||||
return _loop;
|
||||
}
|
||||
|
||||
|
||||
- (void) setLoop:(BOOL)loop
|
||||
{
|
||||
_loop = !!loop;
|
||||
}
|
||||
|
||||
|
||||
- (uint8_t) repeatCount
|
||||
{
|
||||
return _repeatCount ? _repeatCount : 1;
|
||||
}
|
||||
|
||||
|
||||
- (void) setRepeatCount:(uint8_t)count
|
||||
{
|
||||
_repeatCount = count;
|
||||
}
|
||||
|
||||
|
||||
- (BOOL) isPlaying
|
||||
{
|
||||
return _channel != nil;
|
||||
}
|
||||
|
||||
|
||||
- (void)play
|
||||
{
|
||||
if ([self sound] == nil) return;
|
||||
|
||||
OOSoundAcquireLock();
|
||||
|
||||
if (_channel) [self stop];
|
||||
|
||||
_channel = [[OOSoundMixer sharedMixer] popChannel];
|
||||
if (nil != _channel)
|
||||
{
|
||||
_remainingCount = [self repeatCount];
|
||||
[_channel setDelegate:self];
|
||||
[_channel playSound:[self sound] looped:[self loop]];
|
||||
[self retain];
|
||||
}
|
||||
|
||||
OOSoundReleaseLock();
|
||||
}
|
||||
|
||||
|
||||
- (void) playOrRepeat
|
||||
{
|
||||
if (![self isPlaying]) [self play];
|
||||
else ++_remainingCount;
|
||||
}
|
||||
|
||||
|
||||
- (void)stop
|
||||
{
|
||||
OOSoundAcquireLock();
|
||||
|
||||
if (nil != _channel)
|
||||
{
|
||||
[_channel setDelegate:[self class]];
|
||||
[_channel stop];
|
||||
_channel = nil;
|
||||
[self release];
|
||||
}
|
||||
|
||||
OOSoundReleaseLock();
|
||||
}
|
||||
|
||||
|
||||
- (void) playSound:(OOSound *)sound
|
||||
{
|
||||
[self playSound:sound repeatCount:_repeatCount];
|
||||
}
|
||||
|
||||
|
||||
- (void) playSound:(OOSound *)sound repeatCount:(uint8_t)count
|
||||
{
|
||||
[self stop];
|
||||
[self setSound:sound];
|
||||
[self setRepeatCount:count];
|
||||
[self play];
|
||||
}
|
||||
|
||||
|
||||
- (void) playOrRepeatSound:(OOSound *)sound
|
||||
{
|
||||
if (_sound != sound) [self playSound:sound];
|
||||
else [self playOrRepeat];
|
||||
}
|
||||
|
||||
|
||||
- (void) setPositional:(BOOL)inPositional
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
- (void) setPosition:(Vector)inPosition
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
- (void) setVelocity:(Vector)inVelocity
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
- (void) setOrientation:(Vector)inOrientation
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
- (void) setConeAngle:(float)inAngle
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
- (void) setGainInsideCone:(float)inInside outsideCone:(float)inOutside
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
- (void) positionRelativeTo:(OOSoundReferencePoint *)inPoint
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
#pragma mark (OOSoundChannelDelegate)
|
||||
|
||||
- (void)channel:(OOSoundChannel *)channel didFinishPlayingSound:(OOSound *)sound
|
||||
{
|
||||
assert(_channel == channel);
|
||||
|
||||
OOSoundAcquireLock();
|
||||
|
||||
if (--_remainingCount)
|
||||
{
|
||||
[_channel playSound:[self sound] looped:NO];
|
||||
}
|
||||
else
|
||||
{
|
||||
[_channel setDelegate:nil];
|
||||
[[OOSoundMixer sharedMixer] pushChannel:_channel];
|
||||
_channel = nil;
|
||||
[self release];
|
||||
}
|
||||
OOSoundReleaseLock();
|
||||
}
|
||||
|
||||
|
||||
+ (void)channel:(OOSoundChannel *)inChannel didFinishPlayingSound:(OOSound *)inSound
|
||||
{
|
||||
// This delegate is used for a stopped source
|
||||
[[OOSoundMixer sharedMixer] pushChannel:inChannel];
|
||||
}
|
||||
|
||||
@end
|
@ -92,17 +92,11 @@ MA 02110-1301, USA.
|
||||
[self dealloc];
|
||||
return nil;
|
||||
}
|
||||
else if (Mix_OpenAudio(44100, AUDIO_S16LSB, 2, 2048) < 0)
|
||||
{
|
||||
OOLog(@"sdl.init.audio.failed", @"Mix_OpenAudio: %s\n", Mix_GetError());
|
||||
[self dealloc];
|
||||
return nil;
|
||||
}
|
||||
|
||||
Mix_AllocateChannels(MAX_CHANNELS);
|
||||
|
||||
stickHandler=[[JoystickHandler alloc] init];
|
||||
// end TODO
|
||||
|
||||
|
||||
[OOSound setUp];
|
||||
|
||||
// Generate the window caption, containing the version number and the date the executable was compiled.
|
||||
static char windowCaption[128];
|
||||
|
66
src/SDL/OOSDLConcreteSound.h
Normal file
66
src/SDL/OOSDLConcreteSound.h
Normal file
@ -0,0 +1,66 @@
|
||||
/*
|
||||
|
||||
OOSDLConcreteSound.h
|
||||
|
||||
OOSDLSound - SDL_mixer sound implementation for Oolite.
|
||||
Copyright (C) 2006-2008 Jens Ayton
|
||||
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA.
|
||||
|
||||
|
||||
This file may also be distributed under the MIT/X11 license:
|
||||
|
||||
Copyright (C) 2006-2008 Jens Ayton
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
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 Software.
|
||||
|
||||
THE SOFTWARE IS 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 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#import "OOSDLSound.h"
|
||||
#import "SDL.h"
|
||||
#import "SDL_mixer.h"
|
||||
|
||||
|
||||
@interface OOSDLConcreteSound: OOSound
|
||||
{
|
||||
Mix_Chunk *_chunk;
|
||||
NSString *_name;
|
||||
}
|
||||
@end
|
||||
|
||||
|
||||
@interface OOSound (SDL)
|
||||
|
||||
- (Mix_Chunk *) chunk;
|
||||
|
||||
@end
|
116
src/SDL/OOSDLConcreteSound.m
Normal file
116
src/SDL/OOSDLConcreteSound.m
Normal file
@ -0,0 +1,116 @@
|
||||
/*
|
||||
|
||||
OOSDLConcreteSound.m
|
||||
|
||||
OOSDLSound - SDL_mixer sound implementation for Oolite.
|
||||
Copyright (C) 2006-2008 Jens Ayton
|
||||
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA.
|
||||
|
||||
|
||||
This file may also be distributed under the MIT/X11 license:
|
||||
|
||||
Copyright (C) 2006-2008 Jens Ayton
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
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 Software.
|
||||
|
||||
THE SOFTWARE IS 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 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#import "OOSDLConcreteSound.h"
|
||||
#import "OOLogging.h"
|
||||
|
||||
|
||||
@implementation OOSDLConcreteSound
|
||||
|
||||
- (id) initWithContentsOfFile:(NSString *)path
|
||||
{
|
||||
if ((self = [super init]))
|
||||
{
|
||||
_chunk = Mix_LoadWAV([path cString]);
|
||||
|
||||
if (_chunk != NULL)
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
OOLog(@"sound.load.success", @"Loaded a sound from \"%@\".", path);
|
||||
#endif
|
||||
_name = [[path lastPathComponent] copy];
|
||||
}
|
||||
else
|
||||
{
|
||||
OOLog(@"sound.load.failed", @"Could not load a sound from \"%@\".", path);
|
||||
[self release];
|
||||
self = nil;
|
||||
}
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
if (_chunk != NULL) Mix_FreeChunk(_chunk);
|
||||
[_name autorelease];
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
||||
- (NSString *) descriptionComponents
|
||||
{
|
||||
return [NSString stringWithFormat:@"\"%@\"", _name];
|
||||
}
|
||||
|
||||
|
||||
- (NSString *)name
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
|
||||
|
||||
- (Mix_Chunk *) chunk
|
||||
{
|
||||
return _chunk;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation OOSound (SDL)
|
||||
|
||||
- (Mix_Chunk *) chunk
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@end
|
64
src/SDL/OOSDLSound.h
Normal file
64
src/SDL/OOSDLSound.h
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
|
||||
OOSDLSound.h
|
||||
|
||||
OOSDLSound - SDL_mixer sound implementation for Oolite.
|
||||
Copyright (C) 2006-2008 Jens Ayton
|
||||
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA.
|
||||
|
||||
|
||||
This file may also be distributed under the MIT/X11 license:
|
||||
|
||||
Copyright (C) 2006-2008 Jens Ayton
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
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 Software.
|
||||
|
||||
THE SOFTWARE IS 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 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
|
||||
@interface OOSound: NSObject
|
||||
|
||||
+ (BOOL) setUp;
|
||||
+ (void) update;
|
||||
|
||||
+ (void) setMasterVolume:(float) fraction;
|
||||
+ (float) masterVolume;
|
||||
|
||||
- (id) initWithContentsOfFile:(NSString *)path;
|
||||
|
||||
- (NSString *)name;
|
||||
|
||||
@end
|
145
src/SDL/OOSDLSound.m
Normal file
145
src/SDL/OOSDLSound.m
Normal file
@ -0,0 +1,145 @@
|
||||
/*
|
||||
|
||||
OOSDLSound.m
|
||||
|
||||
OOSDLSound - SDL_mixer sound implementation for Oolite.
|
||||
Copyright (C) 2006-2008 Jens Ayton
|
||||
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA.
|
||||
|
||||
|
||||
This file may also be distributed under the MIT/X11 license:
|
||||
|
||||
Copyright (C) 2006-2008 Jens Ayton
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
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 Software.
|
||||
|
||||
THE SOFTWARE IS 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 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#import "OOSDLSoundInternal.h"
|
||||
#import "OOLogging.h"
|
||||
#import "OOCollectionExtractors.h"
|
||||
#import "OOMaths.h"
|
||||
|
||||
|
||||
#define KEY_VOLUME_CONTROL @"volume_control"
|
||||
|
||||
|
||||
static BOOL sIsSetUp = NO;
|
||||
static BOOL sIsSoundOK = NO;
|
||||
static int sEffectiveMasterVolume = MIX_MAX_VOLUME;
|
||||
|
||||
|
||||
@implementation OOSound
|
||||
|
||||
+ (BOOL) setUp
|
||||
{
|
||||
if (!sIsSetUp)
|
||||
{
|
||||
sIsSetUp = YES;
|
||||
|
||||
if (Mix_OpenAudio(44100, AUDIO_S16LSB, 2, 2048) < 0)
|
||||
{
|
||||
OOLog(@"sdl.init.audio.failed", @"Mix_OpenAudio: %s\n", Mix_GetError());
|
||||
return NO;
|
||||
}
|
||||
|
||||
Mix_AllocateChannels(kMixerGeneralChannels);
|
||||
sIsSoundOK = YES;
|
||||
|
||||
float volume = [[NSUserDefaults standardUserDefaults] floatForKey:KEY_VOLUME_CONTROL defaultValue:1.0];
|
||||
[self setMasterVolume:volume];
|
||||
|
||||
[OOSoundMixer sharedMixer];
|
||||
}
|
||||
|
||||
return sIsSoundOK;
|
||||
}
|
||||
|
||||
|
||||
+ (void) setMasterVolume:(float) fraction
|
||||
{
|
||||
if (!sIsSetUp) [self setUp];
|
||||
|
||||
fraction = OOClamp_0_1_f(fraction);
|
||||
int volume = (float)MIX_MAX_VOLUME * fraction;
|
||||
|
||||
if (volume != sEffectiveMasterVolume)
|
||||
{
|
||||
// -1 = all channels
|
||||
Mix_Volume(-1, volume);
|
||||
Mix_VolumeMusic(volume);
|
||||
|
||||
sEffectiveMasterVolume = volume;
|
||||
[[NSUserDefaults standardUserDefaults] setFloat:[self masterVolume] forKey:KEY_VOLUME_CONTROL];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+ (float) masterVolume
|
||||
{
|
||||
if (!sIsSetUp) [self setUp];
|
||||
|
||||
return (float)sEffectiveMasterVolume / (float)MIX_MAX_VOLUME;
|
||||
}
|
||||
|
||||
|
||||
- (id) init
|
||||
{
|
||||
if (!sIsSetUp) [OOSound setUp];
|
||||
return [super init];
|
||||
}
|
||||
|
||||
|
||||
- (id) initWithContentsOfFile:(NSString *)path
|
||||
{
|
||||
[self release];
|
||||
if (!sIsSetUp && ![OOSound setUp]) return nil;
|
||||
|
||||
return [[OOSDLConcreteSound alloc] initWithContentsOfFile:path];
|
||||
}
|
||||
|
||||
|
||||
- (NSString *)name
|
||||
{
|
||||
OOLogGenericSubclassResponsibility();
|
||||
return @"";
|
||||
}
|
||||
|
||||
|
||||
+ (void) update
|
||||
{
|
||||
[[OOSoundMixer sharedMixer] update];
|
||||
}
|
||||
|
||||
@end
|
91
src/SDL/OOSDLSoundChannel.h
Normal file
91
src/SDL/OOSDLSoundChannel.h
Normal file
@ -0,0 +1,91 @@
|
||||
/*
|
||||
|
||||
OOSDLSoundChannel.h
|
||||
|
||||
A channel for audio playback.
|
||||
|
||||
This class is an implementation detail. Do not use it directly; use an
|
||||
OOSoundSource to play an OOSound.
|
||||
|
||||
OOSDLSound - SDL_mixer sound implementation for Oolite.
|
||||
Copyright (C) 2006-2008 Jens Ayton
|
||||
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA.
|
||||
|
||||
|
||||
This file may also be distributed under the MIT/X11 license:
|
||||
|
||||
Copyright (C) 2006-2008 Jens Ayton
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
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 Software.
|
||||
|
||||
THE SOFTWARE IS 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 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@class OOSound;
|
||||
|
||||
|
||||
@interface OOSoundChannel: NSObject
|
||||
{
|
||||
OOSoundChannel *_next;
|
||||
id _delegate;
|
||||
OOSound *_sound;
|
||||
uint16_t _ID;
|
||||
BOOL _playing;
|
||||
}
|
||||
|
||||
- (id) initWithID:(uint16_t)ID;
|
||||
|
||||
- (void) update;
|
||||
|
||||
- (void) setDelegate:(id)delegate;
|
||||
- (uint32_t) ID;
|
||||
|
||||
// Unretained pointer used to maintain simple stack
|
||||
- (OOSoundChannel *) next;
|
||||
- (void) setNext:(OOSoundChannel *)next;
|
||||
|
||||
- (BOOL) playSound:(OOSound *)sound looped:(BOOL)loop;
|
||||
- (void)stop;
|
||||
|
||||
- (OOSound *)sound;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@interface NSObject(OOSoundChannelDelegate)
|
||||
|
||||
- (void)channel:(OOSoundChannel *)inChannel didFinishPlayingSound:(OOSound *)inSound;
|
||||
|
||||
@end
|
147
src/SDL/OOSDLSoundChannel.m
Normal file
147
src/SDL/OOSDLSoundChannel.m
Normal file
@ -0,0 +1,147 @@
|
||||
/*
|
||||
|
||||
OOSDLSoundChannel.m
|
||||
|
||||
OOSDLSound - SDL_mixer sound implementation for Oolite.
|
||||
Copyright (C) 2006-2008 Jens Ayton
|
||||
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA.
|
||||
|
||||
|
||||
This file may also be distributed under the MIT/X11 license:
|
||||
|
||||
Copyright (C) 2006-2008 Jens Ayton
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
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 Software.
|
||||
|
||||
THE SOFTWARE IS 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 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#import "OOSDLSoundInternal.h"
|
||||
|
||||
|
||||
@interface OOSoundChannel (Private)
|
||||
|
||||
- (void) hasStopped;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation OOSoundChannel
|
||||
|
||||
- (id) initWithID:(uint16_t)ID
|
||||
{
|
||||
if ((self = [super init]))
|
||||
{
|
||||
_ID = ID;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
- (void) update
|
||||
{
|
||||
// Check if we've reached the end of a sound.
|
||||
if (_sound != nil && !Mix_Playing(_ID)) [self hasStopped];
|
||||
}
|
||||
|
||||
|
||||
- (void) setDelegate:(id)delegate
|
||||
{
|
||||
_delegate = delegate;
|
||||
}
|
||||
|
||||
|
||||
- (uint32_t)ID
|
||||
{
|
||||
return _ID;
|
||||
}
|
||||
|
||||
|
||||
- (OOSoundChannel *) next
|
||||
{
|
||||
return _next;
|
||||
}
|
||||
|
||||
|
||||
- (void) setNext:(OOSoundChannel *)next
|
||||
{
|
||||
_next = next;
|
||||
}
|
||||
|
||||
|
||||
- (BOOL) playSound:(OOSound *)sound looped:(BOOL)loop
|
||||
{
|
||||
if (sound == nil) return NO;
|
||||
|
||||
if (_sound != nil) [self stop];
|
||||
|
||||
Mix_Chunk *chunk = [sound chunk];
|
||||
if (chunk != NULL)
|
||||
{
|
||||
Mix_PlayChannel(_ID, chunk, loop ? -1 : 0);
|
||||
_sound = [sound retain];
|
||||
return YES;
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
|
||||
- (void) stop
|
||||
{
|
||||
if (_sound != nil)
|
||||
{
|
||||
Mix_HaltChannel(_ID);
|
||||
[self hasStopped];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (void) hasStopped
|
||||
{
|
||||
OOSound *sound = _sound;
|
||||
_sound = nil;
|
||||
|
||||
if (nil != _delegate && [_delegate respondsToSelector:@selector(channel:didFinishPlayingSound:)])
|
||||
{
|
||||
[_delegate channel:self didFinishPlayingSound:sound];
|
||||
}
|
||||
[sound release];
|
||||
}
|
||||
|
||||
|
||||
- (OOSound *)sound
|
||||
{
|
||||
return _sound;
|
||||
}
|
||||
|
||||
@end
|
53
src/SDL/OOSDLSoundInternal.h
Normal file
53
src/SDL/OOSDLSoundInternal.h
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
|
||||
OOSDLSoundInternal.h
|
||||
|
||||
OOSDLSound - SDL_mixer sound implementation for Oolite.
|
||||
Copyright (C) 2006-2008 Jens Ayton
|
||||
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA.
|
||||
|
||||
|
||||
This file may also be distributed under the MIT/X11 license:
|
||||
|
||||
Copyright (C) 2006-2008 Jens Ayton
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
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 Software.
|
||||
|
||||
THE SOFTWARE IS 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 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#import "OOSDLSound.h"
|
||||
#import "OOSDLConcreteSound.h"
|
||||
#import "OOSDLSoundMixer.h"
|
||||
#import "OOSDLSoundChannel.h"
|
82
src/SDL/OOSDLSoundMixer.h
Normal file
82
src/SDL/OOSDLSoundMixer.h
Normal file
@ -0,0 +1,82 @@
|
||||
/*
|
||||
|
||||
OOSDLSoundMixer.h
|
||||
|
||||
Class responsible for managing and mixing sound channels. This class is an
|
||||
implementation detail. Do not use it directly; use an OOSoundSource to play an
|
||||
OOSound.
|
||||
|
||||
OOSDLSound - SDL_mixer sound implementation for Oolite.
|
||||
Copyright (C) 2006-2008 Jens Ayton
|
||||
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA.
|
||||
|
||||
|
||||
This file may also be distributed under the MIT/X11 license:
|
||||
|
||||
Copyright (C) 2006-2008 Jens Ayton
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
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 Software.
|
||||
|
||||
THE SOFTWARE IS 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 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@class OOSoundChannel;
|
||||
|
||||
|
||||
enum
|
||||
{
|
||||
kMixerGeneralChannels = 32
|
||||
};
|
||||
|
||||
|
||||
@interface OOSoundMixer: NSObject
|
||||
{
|
||||
OOSoundChannel *_channels[kMixerGeneralChannels];
|
||||
OOSoundChannel *_freeList;
|
||||
|
||||
uint32_t _maxChannels;
|
||||
uint32_t _playMask;
|
||||
|
||||
}
|
||||
|
||||
// Singleton accessor
|
||||
+ (id) sharedMixer;
|
||||
|
||||
- (void) update;
|
||||
|
||||
- (OOSoundChannel *) popChannel;
|
||||
- (void) pushChannel:(OOSoundChannel *)channel;
|
||||
|
||||
@end
|
181
src/SDL/OOSDLSoundMixer.m
Normal file
181
src/SDL/OOSDLSoundMixer.m
Normal file
@ -0,0 +1,181 @@
|
||||
/*
|
||||
|
||||
OOSDLSoundMixer.m
|
||||
|
||||
OOSDLSound - SDL_mixer sound implementation for Oolite.
|
||||
Copyright (C) 2006-2008 Jens Ayton
|
||||
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA.
|
||||
|
||||
|
||||
This file may also be distributed under the MIT/X11 license:
|
||||
|
||||
Copyright (C) 2006-2008 Jens Ayton
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
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 Software.
|
||||
|
||||
THE SOFTWARE IS 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 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#import "OOSDLSoundInternal.h"
|
||||
|
||||
|
||||
static OOSoundMixer *sSingleton = nil;
|
||||
|
||||
|
||||
@implementation OOSoundMixer
|
||||
|
||||
+ (id) sharedMixer
|
||||
{
|
||||
if (nil == sSingleton)
|
||||
{
|
||||
[[self alloc] init];
|
||||
}
|
||||
return sSingleton;
|
||||
}
|
||||
|
||||
|
||||
- (id) init
|
||||
{
|
||||
BOOL OK = YES;
|
||||
uint32_t idx = 0, count = kMixerGeneralChannels;
|
||||
OOSoundChannel *channel;
|
||||
|
||||
if (!(self = [super init])) return nil;
|
||||
if (![OOSound setUp]) OK = NO;
|
||||
|
||||
if (OK)
|
||||
{
|
||||
// Allocate channels
|
||||
do
|
||||
{
|
||||
channel = [[OOSoundChannel alloc] initWithID:count];
|
||||
if (nil != channel)
|
||||
{
|
||||
_channels[idx++] = channel;
|
||||
[self pushChannel:channel];
|
||||
}
|
||||
} while (--count);
|
||||
}
|
||||
|
||||
if (!OK)
|
||||
{
|
||||
[super release];
|
||||
self = nil;
|
||||
}
|
||||
else
|
||||
{
|
||||
sSingleton = self;
|
||||
}
|
||||
|
||||
return sSingleton;
|
||||
}
|
||||
|
||||
|
||||
- (void) update
|
||||
{
|
||||
for (uint32_t i = 0; i < kMixerGeneralChannels; ++i)
|
||||
{
|
||||
[_channels[i] update];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (OOSoundChannel *) popChannel
|
||||
{
|
||||
OOSoundChannel *channel = _freeList;
|
||||
_freeList = [channel next];
|
||||
[channel setNext:nil];
|
||||
|
||||
return channel;
|
||||
}
|
||||
|
||||
|
||||
- (void) pushChannel:(OOSoundChannel *)channel
|
||||
{
|
||||
assert(channel != nil);
|
||||
|
||||
[channel setNext:_freeList];
|
||||
_freeList = channel;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation OOSoundMixer (Singleton)
|
||||
|
||||
/* Canonical singleton boilerplate.
|
||||
See Cocoa Fundamentals Guide: Creating a Singleton Instance.
|
||||
See also +sharedMixer above.
|
||||
|
||||
NOTE: assumes single-threaded access.
|
||||
*/
|
||||
|
||||
+ (id)allocWithZone:(NSZone *)inZone
|
||||
{
|
||||
if (sSingleton == nil)
|
||||
{
|
||||
sSingleton = [super allocWithZone:inZone];
|
||||
return sSingleton;
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
||||
- (id)copyWithZone:(NSZone *)inZone
|
||||
{
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
- (id)retain
|
||||
{
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
- (OOUInteger)retainCount
|
||||
{
|
||||
return UINT_MAX;
|
||||
}
|
||||
|
||||
|
||||
- (void)release
|
||||
{}
|
||||
|
||||
|
||||
- (id)autorelease
|
||||
{
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
Loading…
x
Reference in New Issue
Block a user