joybox 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +15 -0
- data/.gitignore +18 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +27 -0
- data/LICENSE +22 -0
- data/README.md +86 -0
- data/Rakefile +14 -0
- data/app/app_delegate.rb +49 -0
- data/app/layers/box2d_layer.rb +109 -0
- data/app/layers/cocos2d_layer.rb +14 -0
- data/app/layers/cocos_motion_layer.rb +145 -0
- data/app/layers/menu_layer.rb +59 -0
- data/joybox.gemspec +25 -0
- data/lib/joybox.rb +47 -0
- data/lib/joybox/box2d/body.rb +106 -0
- data/lib/joybox/box2d/world.rb +79 -0
- data/lib/joybox/cocos2d/actions/actions.rb +7 -0
- data/lib/joybox/cocos2d/actions/move.rb +31 -0
- data/lib/joybox/cocos2d/actions/repeat.rb +24 -0
- data/lib/joybox/cocos2d/actions/rotate.rb +31 -0
- data/lib/joybox/cocos2d/actions/scale.rb +31 -0
- data/lib/joybox/cocos2d/actions/sequence.rb +22 -0
- data/lib/joybox/cocos2d/actions/skew.rb +36 -0
- data/lib/joybox/cocos2d/cocos2d.rb +15 -0
- data/lib/joybox/cocos2d/common/cg_point.rb +37 -0
- data/lib/joybox/cocos2d/common/color.rb +49 -0
- data/lib/joybox/cocos2d/common/gc_size.rb +39 -0
- data/lib/joybox/cocos2d/common/ns_set.rb +5 -0
- data/lib/joybox/cocos2d/common/numeric.rb +14 -0
- data/lib/joybox/cocos2d/common/screen.rb +39 -0
- data/lib/joybox/cocos2d/common/ui_touch.rb +15 -0
- data/lib/joybox/cocos2d/configuration/configuration.rb +68 -0
- data/lib/joybox/cocos2d/configuration/file_utils.rb +33 -0
- data/lib/joybox/cocos2d/configuration/gl_view.rb +44 -0
- data/lib/joybox/cocos2d/configuration/texture_2d.rb +27 -0
- data/lib/joybox/cocos2d/core/layer.rb +87 -0
- data/lib/joybox/cocos2d/core/node.rb +26 -0
- data/lib/joybox/cocos2d/core/physics_sprite.rb +52 -0
- data/lib/joybox/cocos2d/core/scene.rb +24 -0
- data/lib/joybox/cocos2d/core/sprite.rb +43 -0
- data/lib/joybox/cocos2d/core/sprite_batch.rb +24 -0
- data/lib/joybox/cocos2d/director.rb +43 -0
- data/lib/joybox/cocos2d/macros.rb +234 -0
- data/lib/joybox/cocos2d/ui/label.rb +34 -0
- data/lib/joybox/cocos2d/ui/menu.rb +25 -0
- data/lib/joybox/cocos2d/ui/menu_image.rb +22 -0
- data/lib/joybox/cocos2d/ui/menu_label.rb +45 -0
- data/lib/joybox/cocos2d/ui/ui.rb +7 -0
- data/lib/joybox/version.rb +3 -0
- data/resources/box2d/blocks_sprite_sheet.png +0 -0
- data/resources/cocos_motion/dot.png +0 -0
- data/resources/cocos_motion/dot_selected.png +0 -0
- data/resources/cocos_motion/grossini.png +0 -0
- data/resources/cocos_motion/grossinis_sister.png +0 -0
- data/resources/cocos_motion/grossinis_sister_two.png +0 -0
- data/resources/cocos_motion/left_arrow.png +0 -0
- data/resources/cocos_motion/left_arrow_selected.png +0 -0
- data/resources/cocos_motion/right_arrow.png +0 -0
- data/resources/cocos_motion/right_arrow_selected.png +0 -0
- data/resources/fps_images-hd.png +0 -0
- data/resources/fps_images-ipadhd.png +0 -0
- data/resources/fps_images.png +0 -0
- data/spec/lib/joybox/cocos2d/cocos2d_spec.rb +7 -0
- data/spec/lib/joybox/cocos2d/macros_spec.rb +37 -0
- data/spec/main_spec.rb +9 -0
- data/vendor/Box2D.framework/Box2D +0 -0
- data/vendor/Box2D.framework/Box2D.framework.bridgesupport +166 -0
- data/vendor/Box2D.framework/Versions/A/Box2D +0 -0
- data/vendor/Box2D.framework/Versions/A/Headers/Collision/B2DContactListener.h +25 -0
- data/vendor/Box2D.framework/Versions/A/Headers/Collision/Shapes/B2DEdgeShape.h +17 -0
- data/vendor/Box2D.framework/Versions/A/Headers/Collision/Shapes/B2DPolygonShape.h +16 -0
- data/vendor/Box2D.framework/Versions/A/Headers/Collision/Shapes/B2DShape.h +15 -0
- data/vendor/Box2D.framework/Versions/A/Headers/Dynamics/B2DBody.h +43 -0
- data/vendor/Box2D.framework/Versions/A/Headers/Dynamics/B2DWorld.h +41 -0
- data/vendor/Box2D.framework/Versions/A/Resources/Box2DConfig.cmake +3 -0
- data/vendor/Box2D.framework/Versions/A/Resources/CMakeLists.txt +205 -0
- data/vendor/Cocos2D/Cocos2D.bridgesupport +7808 -0
- data/vendor/Cocos2D/include/CCAction.h +195 -0
- data/vendor/Cocos2D/include/CCActionCamera.h +73 -0
- data/vendor/Cocos2D/include/CCActionCatmullRom.h +139 -0
- data/vendor/Cocos2D/include/CCActionEase.h +159 -0
- data/vendor/Cocos2D/include/CCActionGrid.h +165 -0
- data/vendor/Cocos2D/include/CCActionGrid3D.h +205 -0
- data/vendor/Cocos2D/include/CCActionInstant.h +227 -0
- data/vendor/Cocos2D/include/CCActionInterval.h +431 -0
- data/vendor/Cocos2D/include/CCActionManager.h +113 -0
- data/vendor/Cocos2D/include/CCActionPageTurn3D.h +42 -0
- data/vendor/Cocos2D/include/CCActionProgressTimer.h +59 -0
- data/vendor/Cocos2D/include/CCActionTiledGrid.h +211 -0
- data/vendor/Cocos2D/include/CCActionTween.h +62 -0
- data/vendor/Cocos2D/include/CCAnimation.h +150 -0
- data/vendor/Cocos2D/include/CCAnimationCache.h +74 -0
- data/vendor/Cocos2D/include/CCArray.h +119 -0
- data/vendor/Cocos2D/include/CCAtlasNode.h +96 -0
- data/vendor/Cocos2D/include/CCCamera.h +98 -0
- data/vendor/Cocos2D/include/CCConfiguration.h +126 -0
- data/vendor/Cocos2D/include/CCDirector.h +344 -0
- data/vendor/Cocos2D/include/CCDirectorIOS.h +104 -0
- data/vendor/Cocos2D/include/CCDrawingPrimitives.h +139 -0
- data/vendor/Cocos2D/include/CCES2Renderer.h +83 -0
- data/vendor/Cocos2D/include/CCESRenderer.h +54 -0
- data/vendor/Cocos2D/include/CCFileUtils.h +188 -0
- data/vendor/Cocos2D/include/CCGL.h +72 -0
- data/vendor/Cocos2D/include/CCGLProgram.h +150 -0
- data/vendor/Cocos2D/include/CCGLView.h +160 -0
- data/vendor/Cocos2D/include/CCGrabber.h +44 -0
- data/vendor/Cocos2D/include/CCGrid.h +130 -0
- data/vendor/Cocos2D/include/CCLabelAtlas.h +68 -0
- data/vendor/Cocos2D/include/CCLabelBMFont.h +216 -0
- data/vendor/Cocos2D/include/CCLabelTTF.h +132 -0
- data/vendor/Cocos2D/include/CCLayer.h +280 -0
- data/vendor/Cocos2D/include/CCMenu.h +100 -0
- data/vendor/Cocos2D/include/CCMenuItem.h +423 -0
- data/vendor/Cocos2D/include/CCMotionStreak.h +87 -0
- data/vendor/Cocos2D/include/CCNS.h +54 -0
- data/vendor/Cocos2D/include/CCNode+Debug.h +39 -0
- data/vendor/Cocos2D/include/CCNode.h +569 -0
- data/vendor/Cocos2D/include/CCParallaxNode.h +50 -0
- data/vendor/Cocos2D/include/CCParticleBatchNode.h +99 -0
- data/vendor/Cocos2D/include/CCParticleExamples.h +95 -0
- data/vendor/Cocos2D/include/CCParticleSystem.h +453 -0
- data/vendor/Cocos2D/include/CCParticleSystemQuad.h +73 -0
- data/vendor/Cocos2D/include/CCProfiling.h +89 -0
- data/vendor/Cocos2D/include/CCProgressTimer.h +94 -0
- data/vendor/Cocos2D/include/CCProtocols.h +132 -0
- data/vendor/Cocos2D/include/CCRenderTexture.h +139 -0
- data/vendor/Cocos2D/include/CCScene.h +43 -0
- data/vendor/Cocos2D/include/CCScheduler.h +230 -0
- data/vendor/Cocos2D/include/CCShaderCache.h +60 -0
- data/vendor/Cocos2D/include/CCSprite.h +288 -0
- data/vendor/Cocos2D/include/CCSpriteBatchNode.h +138 -0
- data/vendor/Cocos2D/include/CCSpriteFrame.h +126 -0
- data/vendor/Cocos2D/include/CCSpriteFrameCache.h +121 -0
- data/vendor/Cocos2D/include/CCTMXLayer.h +164 -0
- data/vendor/Cocos2D/include/CCTMXObjectGroup.h +67 -0
- data/vendor/Cocos2D/include/CCTMXTiledMap.h +145 -0
- data/vendor/Cocos2D/include/CCTMXXMLParser.h +217 -0
- data/vendor/Cocos2D/include/CCTexture2D.h +357 -0
- data/vendor/Cocos2D/include/CCTextureAtlas.h +188 -0
- data/vendor/Cocos2D/include/CCTextureCache.h +146 -0
- data/vendor/Cocos2D/include/CCTexturePVR.h +129 -0
- data/vendor/Cocos2D/include/CCTileMapAtlas.h +83 -0
- data/vendor/Cocos2D/include/CCTouchDelegateProtocol.h +75 -0
- data/vendor/Cocos2D/include/CCTouchDispatcher.h +120 -0
- data/vendor/Cocos2D/include/CCTouchHandler.h +93 -0
- data/vendor/Cocos2D/include/CCTransition.h +296 -0
- data/vendor/Cocos2D/include/CCTransitionPageTurn.h +60 -0
- data/vendor/Cocos2D/include/CCTransitionProgress.h +62 -0
- data/vendor/Cocos2D/include/CCVertex.h +36 -0
- data/vendor/Cocos2D/include/CGPointExtension.h +344 -0
- data/vendor/Cocos2D/include/CocosDenshion/CDAudioManager.h +243 -0
- data/vendor/Cocos2D/include/CocosDenshion/CDConfig.h +60 -0
- data/vendor/Cocos2D/include/CocosDenshion/CDOpenALSupport.h +77 -0
- data/vendor/Cocos2D/include/CocosDenshion/CDXPropertyModifierAction.h +45 -0
- data/vendor/Cocos2D/include/CocosDenshion/CocosDenshion.h +440 -0
- data/vendor/Cocos2D/include/CocosDenshion/SimpleAudioEngine.h +90 -0
- data/vendor/Cocos2D/include/NSThread+performBlock.h +22 -0
- data/vendor/Cocos2D/include/OpenGL_Internal.h +86 -0
- data/vendor/Cocos2D/include/RubyMotionSchedule.h +7 -0
- data/vendor/Cocos2D/include/TGAlib.h +55 -0
- data/vendor/Cocos2D/include/TransformUtils.h +36 -0
- data/vendor/Cocos2D/include/ZipUtils.h +91 -0
- data/vendor/Cocos2D/include/base64.h +33 -0
- data/vendor/Cocos2D/include/ccCArray.h +229 -0
- data/vendor/Cocos2D/include/ccConfig.h +245 -0
- data/vendor/Cocos2D/include/ccDeprecated.h +300 -0
- data/vendor/Cocos2D/include/ccGLStateCache.h +138 -0
- data/vendor/Cocos2D/include/ccMacros.h +353 -0
- data/vendor/Cocos2D/include/ccShader_PositionColor_frag.h +12 -0
- data/vendor/Cocos2D/include/ccShader_PositionColor_vert.h +17 -0
- data/vendor/Cocos2D/include/ccShader_PositionTextureA8Color_frag.h +16 -0
- data/vendor/Cocos2D/include/ccShader_PositionTextureA8Color_vert.h +21 -0
- data/vendor/Cocos2D/include/ccShader_PositionTextureColorAlphaTest_frag.h +23 -0
- data/vendor/Cocos2D/include/ccShader_PositionTextureColor_frag.h +14 -0
- data/vendor/Cocos2D/include/ccShader_PositionTextureColor_vert.h +22 -0
- data/vendor/Cocos2D/include/ccShader_PositionTexture_frag.h +13 -0
- data/vendor/Cocos2D/include/ccShader_PositionTexture_uColor_frag.h +16 -0
- data/vendor/Cocos2D/include/ccShader_PositionTexture_uColor_vert.h +18 -0
- data/vendor/Cocos2D/include/ccShader_PositionTexture_vert.h +17 -0
- data/vendor/Cocos2D/include/ccShader_Position_uColor_frag.h +12 -0
- data/vendor/Cocos2D/include/ccShader_Position_uColor_vert.h +19 -0
- data/vendor/Cocos2D/include/ccShaders.h +45 -0
- data/vendor/Cocos2D/include/ccTypes.h +374 -0
- data/vendor/Cocos2D/include/ccUtils.h +36 -0
- data/vendor/Cocos2D/include/cocos2d.h +178 -0
- data/vendor/Cocos2D/include/kazmath/GL/mat4stack.h +51 -0
- data/vendor/Cocos2D/include/kazmath/GL/matrix.h +58 -0
- data/vendor/Cocos2D/include/kazmath/aabb.h +53 -0
- data/vendor/Cocos2D/include/kazmath/kazmath.h +39 -0
- data/vendor/Cocos2D/include/kazmath/mat3.h +75 -0
- data/vendor/Cocos2D/include/kazmath/mat4.h +93 -0
- data/vendor/Cocos2D/include/kazmath/neon_matrix_impl.h +41 -0
- data/vendor/Cocos2D/include/kazmath/plane.h +70 -0
- data/vendor/Cocos2D/include/kazmath/quaternion.h +113 -0
- data/vendor/Cocos2D/include/kazmath/ray2.h +50 -0
- data/vendor/Cocos2D/include/kazmath/utility.h +74 -0
- data/vendor/Cocos2D/include/kazmath/vec2.h +64 -0
- data/vendor/Cocos2D/include/kazmath/vec3.h +68 -0
- data/vendor/Cocos2D/include/kazmath/vec4.h +68 -0
- data/vendor/Cocos2D/include/uthash.h +972 -0
- data/vendor/Cocos2D/include/utlist.h +490 -0
- data/vendor/Cocos2D/libCocosDenshion.a +0 -0
- data/vendor/Cocos2D/libcocos2d.a +0 -0
- metadata +277 -0
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (c) 2010 Steve Oldmeadow
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in
|
|
12
|
+
all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
20
|
+
THE SOFTWARE.
|
|
21
|
+
|
|
22
|
+
$Id$
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
#import "CocosDenshion.h"
|
|
26
|
+
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 30000
|
|
27
|
+
#import <AVFoundation/AVFoundation.h>
|
|
28
|
+
#else
|
|
29
|
+
#import "CDXMacOSXSupport.h"
|
|
30
|
+
#endif
|
|
31
|
+
|
|
32
|
+
/** Different modes of the engine */
|
|
33
|
+
typedef enum {
|
|
34
|
+
kAMM_FxOnly, //!Other apps will be able to play audio
|
|
35
|
+
kAMM_FxPlusMusic, //!Only this app will play audio
|
|
36
|
+
kAMM_FxPlusMusicIfNoOtherAudio, //!If another app is playing audio at start up then allow it to continue and don't play music
|
|
37
|
+
kAMM_MediaPlayback, //!This app takes over audio e.g music player app
|
|
38
|
+
kAMM_PlayAndRecord //!App takes over audio and has input and output
|
|
39
|
+
} tAudioManagerMode;
|
|
40
|
+
|
|
41
|
+
/** Possible states of the engine */
|
|
42
|
+
typedef enum {
|
|
43
|
+
kAMStateUninitialised, //!Audio manager has not been initialised - do not use
|
|
44
|
+
kAMStateInitialising, //!Audio manager is in the process of initialising - do not use
|
|
45
|
+
kAMStateInitialised //!Audio manager is initialised - safe to use
|
|
46
|
+
} tAudioManagerState;
|
|
47
|
+
|
|
48
|
+
typedef enum {
|
|
49
|
+
kAMRBDoNothing, //Audio manager will not do anything on resign or becoming active
|
|
50
|
+
kAMRBStopPlay, //Background music is stopped on resign and resumed on become active
|
|
51
|
+
kAMRBStop //Background music is stopped on resign but not resumed - maybe because you want to do this from within your game
|
|
52
|
+
} tAudioManagerResignBehavior;
|
|
53
|
+
|
|
54
|
+
/** Notifications */
|
|
55
|
+
extern NSString * const kCDN_AudioManagerInitialised;
|
|
56
|
+
|
|
57
|
+
@interface CDAsynchInitialiser : NSOperation {}
|
|
58
|
+
@end
|
|
59
|
+
|
|
60
|
+
/** CDAudioManager supports two long audio source channels called left and right*/
|
|
61
|
+
typedef enum {
|
|
62
|
+
kASC_Left = 0,
|
|
63
|
+
kASC_Right = 1
|
|
64
|
+
} tAudioSourceChannel;
|
|
65
|
+
|
|
66
|
+
typedef enum {
|
|
67
|
+
kLAS_Init,
|
|
68
|
+
kLAS_Loaded,
|
|
69
|
+
kLAS_Playing,
|
|
70
|
+
kLAS_Paused,
|
|
71
|
+
kLAS_Stopped,
|
|
72
|
+
} tLongAudioSourceState;
|
|
73
|
+
|
|
74
|
+
@class CDLongAudioSource;
|
|
75
|
+
@protocol CDLongAudioSourceDelegate <NSObject>
|
|
76
|
+
@optional
|
|
77
|
+
/** The audio source completed playing */
|
|
78
|
+
- (void) cdAudioSourceDidFinishPlaying:(CDLongAudioSource *) audioSource;
|
|
79
|
+
/** The file used to load the audio source has changed */
|
|
80
|
+
- (void) cdAudioSourceFileDidChange:(CDLongAudioSource *) audioSource;
|
|
81
|
+
@end
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
CDLongAudioSource represents an audio source that has a long duration which makes
|
|
85
|
+
it costly to load into memory for playback as an effect using CDSoundEngine. Examples
|
|
86
|
+
include background music and narration tracks. The audio file may or may not be compressed.
|
|
87
|
+
Bear in mind that current iDevices can only use hardware to decode a single compressed
|
|
88
|
+
audio file at a time and playing multiple compressed files will result in a performance drop
|
|
89
|
+
as software decompression will take place.
|
|
90
|
+
@since v0.99
|
|
91
|
+
*/
|
|
92
|
+
@interface CDLongAudioSource : NSObject <AVAudioPlayerDelegate, CDAudioInterruptProtocol>{
|
|
93
|
+
AVAudioPlayer *audioSourcePlayer;
|
|
94
|
+
NSString *audioSourceFilePath;
|
|
95
|
+
NSInteger numberOfLoops;
|
|
96
|
+
float volume;
|
|
97
|
+
id<CDLongAudioSourceDelegate> delegate;
|
|
98
|
+
BOOL mute;
|
|
99
|
+
BOOL enabled_;
|
|
100
|
+
BOOL backgroundMusic;
|
|
101
|
+
@public
|
|
102
|
+
BOOL systemPaused;//Used for auto resign handling
|
|
103
|
+
NSTimeInterval systemPauseLocation;//Used for auto resign handling
|
|
104
|
+
@protected
|
|
105
|
+
tLongAudioSourceState state;
|
|
106
|
+
}
|
|
107
|
+
@property (readonly) AVAudioPlayer *audioSourcePlayer;
|
|
108
|
+
@property (readonly) NSString *audioSourceFilePath;
|
|
109
|
+
@property (readwrite, nonatomic) NSInteger numberOfLoops;
|
|
110
|
+
@property (readwrite, nonatomic) float volume;
|
|
111
|
+
@property (assign) id<CDLongAudioSourceDelegate> delegate;
|
|
112
|
+
/* This long audio source functions as background music */
|
|
113
|
+
@property (readwrite, nonatomic) BOOL backgroundMusic;
|
|
114
|
+
|
|
115
|
+
/** Loads the file into the audio source */
|
|
116
|
+
-(void) load:(NSString*) filePath;
|
|
117
|
+
/** Plays the audio source */
|
|
118
|
+
-(void) play;
|
|
119
|
+
/** Stops playing the audio soruce */
|
|
120
|
+
-(void) stop;
|
|
121
|
+
/** Pauses the audio source */
|
|
122
|
+
-(void) pause;
|
|
123
|
+
/** Rewinds the audio source */
|
|
124
|
+
-(void) rewind;
|
|
125
|
+
/** Resumes playing the audio source if it was paused */
|
|
126
|
+
-(void) resume;
|
|
127
|
+
/** Returns whether or not the audio source is playing */
|
|
128
|
+
-(BOOL) isPlaying;
|
|
129
|
+
|
|
130
|
+
@end
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
CDAudioManager manages audio requirements for a game. It provides access to a CDSoundEngine object
|
|
134
|
+
for playing sound effects. It provides access to two CDLongAudioSource object (left and right channel)
|
|
135
|
+
for playing long duration audio such as background music and narration tracks. Additionally it manages
|
|
136
|
+
the audio session to take care of things like audio session interruption and interacting with the audio
|
|
137
|
+
of other apps that are running on the device.
|
|
138
|
+
|
|
139
|
+
Requirements:
|
|
140
|
+
- Firmware: OS 2.2 or greater
|
|
141
|
+
- Files: CDAudioManager.*, CocosDenshion.*
|
|
142
|
+
- Frameworks: OpenAL, AudioToolbox, AVFoundation
|
|
143
|
+
@since v0.8
|
|
144
|
+
*/
|
|
145
|
+
@interface CDAudioManager : NSObject <CDLongAudioSourceDelegate, CDAudioInterruptProtocol, AVAudioSessionDelegate> {
|
|
146
|
+
CDSoundEngine *soundEngine;
|
|
147
|
+
CDLongAudioSource *backgroundMusic;
|
|
148
|
+
NSMutableArray *audioSourceChannels;
|
|
149
|
+
NSString* _audioSessionCategory;
|
|
150
|
+
BOOL _audioWasPlayingAtStartup;
|
|
151
|
+
tAudioManagerMode _mode;
|
|
152
|
+
SEL backgroundMusicCompletionSelector;
|
|
153
|
+
id backgroundMusicCompletionListener;
|
|
154
|
+
BOOL willPlayBackgroundMusic;
|
|
155
|
+
BOOL _mute;
|
|
156
|
+
BOOL _resigned;
|
|
157
|
+
BOOL _interrupted;
|
|
158
|
+
BOOL _audioSessionActive;
|
|
159
|
+
BOOL enabled_;
|
|
160
|
+
|
|
161
|
+
//For handling resign/become active
|
|
162
|
+
BOOL _isObservingAppEvents;
|
|
163
|
+
tAudioManagerResignBehavior _resignBehavior;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
@property (readonly) CDSoundEngine *soundEngine;
|
|
167
|
+
@property (readonly) CDLongAudioSource *backgroundMusic;
|
|
168
|
+
@property (readonly) BOOL willPlayBackgroundMusic;
|
|
169
|
+
|
|
170
|
+
/** Returns the shared singleton */
|
|
171
|
+
+ (CDAudioManager *) sharedManager;
|
|
172
|
+
+ (tAudioManagerState) sharedManagerState;
|
|
173
|
+
/** Configures the shared singleton with a mode*/
|
|
174
|
+
+ (void) configure: (tAudioManagerMode) mode;
|
|
175
|
+
/** Initializes the engine asynchronously with a mode */
|
|
176
|
+
+ (void) initAsynchronously: (tAudioManagerMode) mode;
|
|
177
|
+
/** Initializes the engine synchronously with a mode, channel definition and a total number of channels */
|
|
178
|
+
- (id) init: (tAudioManagerMode) mode;
|
|
179
|
+
-(void) audioSessionInterrupted;
|
|
180
|
+
-(void) audioSessionResumed;
|
|
181
|
+
-(void) setResignBehavior:(tAudioManagerResignBehavior) resignBehavior autoHandle:(BOOL) autoHandle;
|
|
182
|
+
/** Returns true is audio is muted at a hardware level e.g user has ringer switch set to off */
|
|
183
|
+
-(BOOL) isDeviceMuted;
|
|
184
|
+
/** Returns true if another app is playing audio such as the iPod music player */
|
|
185
|
+
-(BOOL) isOtherAudioPlaying;
|
|
186
|
+
/** Sets the way the audio manager interacts with the operating system such as whether it shares output with other apps or obeys the mute switch */
|
|
187
|
+
-(void) setMode:(tAudioManagerMode) mode;
|
|
188
|
+
/** Shuts down the shared audio manager instance so that it can be reinitialised */
|
|
189
|
+
+(void) end;
|
|
190
|
+
|
|
191
|
+
/** Call if you want to use built in resign behavior but need to do some additional audio processing on resign active. */
|
|
192
|
+
- (void) applicationWillResignActive;
|
|
193
|
+
/** Call if you want to use built in resign behavior but need to do some additional audio processing on become active. */
|
|
194
|
+
- (void) applicationDidBecomeActive;
|
|
195
|
+
|
|
196
|
+
//New AVAudioPlayer API
|
|
197
|
+
/** Loads the data from the specified file path to the channel's audio source */
|
|
198
|
+
-(CDLongAudioSource*) audioSourceLoad:(NSString*) filePath channel:(tAudioSourceChannel) channel;
|
|
199
|
+
/** Retrieves the audio source for the specified channel */
|
|
200
|
+
-(CDLongAudioSource*) audioSourceForChannel:(tAudioSourceChannel) channel;
|
|
201
|
+
|
|
202
|
+
//Legacy AVAudioPlayer API
|
|
203
|
+
/** Plays music in background. The music can be looped or not
|
|
204
|
+
It is recommended to use .aac files as background music since they are decoded by the device (hardware).
|
|
205
|
+
*/
|
|
206
|
+
-(void) playBackgroundMusic:(NSString*) filePath loop:(BOOL) loop;
|
|
207
|
+
/** Preloads a background music */
|
|
208
|
+
-(void) preloadBackgroundMusic:(NSString*) filePath;
|
|
209
|
+
/** Stops playing the background music */
|
|
210
|
+
-(void) stopBackgroundMusic;
|
|
211
|
+
/** Pauses the background music */
|
|
212
|
+
-(void) pauseBackgroundMusic;
|
|
213
|
+
/** Rewinds the background music */
|
|
214
|
+
-(void) rewindBackgroundMusic;
|
|
215
|
+
/** Resumes playing the background music */
|
|
216
|
+
-(void) resumeBackgroundMusic;
|
|
217
|
+
/** Returns whether or not the background music is playing */
|
|
218
|
+
-(BOOL) isBackgroundMusicPlaying;
|
|
219
|
+
|
|
220
|
+
-(void) setBackgroundMusicCompletionListener:(id) listener selector:(SEL) selector;
|
|
221
|
+
|
|
222
|
+
@end
|
|
223
|
+
|
|
224
|
+
/** Fader for long audio source objects */
|
|
225
|
+
@interface CDLongAudioSourceFader : CDPropertyModifier{}
|
|
226
|
+
@end
|
|
227
|
+
|
|
228
|
+
static const int kCDNoBuffer = -1;
|
|
229
|
+
|
|
230
|
+
/** Allows buffers to be associated with file names */
|
|
231
|
+
@interface CDBufferManager:NSObject{
|
|
232
|
+
NSMutableDictionary* loadedBuffers;
|
|
233
|
+
NSMutableArray *freedBuffers;
|
|
234
|
+
CDSoundEngine *soundEngine;
|
|
235
|
+
int nextBufferId;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
-(id) initWithEngine:(CDSoundEngine *) theSoundEngine;
|
|
239
|
+
-(int) bufferForFile:(NSString*) filePath create:(BOOL) create;
|
|
240
|
+
-(void) releaseBufferForFile:(NSString *) filePath;
|
|
241
|
+
|
|
242
|
+
@end
|
|
243
|
+
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (c) 2010 Steve Oldmeadow
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in
|
|
12
|
+
all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
20
|
+
THE SOFTWARE.
|
|
21
|
+
|
|
22
|
+
$Id$
|
|
23
|
+
*/
|
|
24
|
+
#define COCOSDENSHION_VERSION "Aphex.rc"
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
If enabled code useful for debugging such as parameter check assertions will be performed.
|
|
29
|
+
If you experience any problems you should enable this and test your code with a debug build.
|
|
30
|
+
*/
|
|
31
|
+
//#define CD_DEBUG 1
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
The total number of sounds/buffers that can be loaded assuming memory is sufficient
|
|
35
|
+
*/
|
|
36
|
+
//Number of buffers slots that will be initially created
|
|
37
|
+
#define CD_BUFFERS_START 64
|
|
38
|
+
//Number of buffers that will be added
|
|
39
|
+
#define CD_BUFFERS_INCREMENT 16
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
If enabled, OpenAL code will use static buffers. When static buffers are used the audio
|
|
43
|
+
data is managed outside of OpenAL, this eliminates a memcpy operation which leads to
|
|
44
|
+
higher performance when loading sounds.
|
|
45
|
+
|
|
46
|
+
However, the downside is that when the audio data is freed you must
|
|
47
|
+
be certain that it is no longer being accessed otherwise your app will crash. Testing on OS 2.2.1
|
|
48
|
+
and 3.1.2 has shown that this may occur if a buffer is being used by a source with state = AL_PLAYING
|
|
49
|
+
when the buffer is deleted. If the data is freed too quickly after the source is stopped then
|
|
50
|
+
a crash will occur. The implemented workaround is that when static buffers are used the unloadBuffer code will wait for
|
|
51
|
+
any playing sources to finish playing before the associated buffer and data are deleted, however, this delay may negate any
|
|
52
|
+
performance gains that are achieved during loading.
|
|
53
|
+
|
|
54
|
+
Performance tests on a 1st gen iPod running OS 2.2.1 loading the CocosDenshionDemo sounds were ~0.14 seconds without
|
|
55
|
+
static buffers and ~0.12 seconds when using static buffers.
|
|
56
|
+
|
|
57
|
+
*/
|
|
58
|
+
//#define CD_USE_STATIC_BUFFERS 1
|
|
59
|
+
|
|
60
|
+
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/*
|
|
2
|
+
|
|
3
|
+
Disclaimer: IMPORTANT: This Apple software is supplied to you by
|
|
4
|
+
Apple Inc. ("Apple") in consideration of your agreement to the
|
|
5
|
+
following terms, and your use, installation, modification or
|
|
6
|
+
redistribution of this Apple software constitutes acceptance of these
|
|
7
|
+
terms. If you do not agree with these terms, please do not use,
|
|
8
|
+
install, modify or redistribute this Apple software.
|
|
9
|
+
|
|
10
|
+
In consideration of your agreement to abide by the following terms, and
|
|
11
|
+
subject to these terms, Apple grants you a personal, non-exclusive
|
|
12
|
+
license, under Apple's copyrights in this original Apple software (the
|
|
13
|
+
"Apple Software"), to use, reproduce, modify and redistribute the Apple
|
|
14
|
+
Software, with or without modifications, in source and/or binary forms;
|
|
15
|
+
provided that if you redistribute the Apple Software in its entirety and
|
|
16
|
+
without modifications, you must retain this notice and the following
|
|
17
|
+
text and disclaimers in all such redistributions of the Apple Software.
|
|
18
|
+
Neither the name, trademarks, service marks or logos of Apple Inc.
|
|
19
|
+
may be used to endorse or promote products derived from the Apple
|
|
20
|
+
Software without specific prior written permission from Apple. Except
|
|
21
|
+
as expressly stated in this notice, no other rights or licenses, express
|
|
22
|
+
or implied, are granted by Apple herein, including but not limited to
|
|
23
|
+
any patent rights that may be infringed by your derivative works or by
|
|
24
|
+
other works in which the Apple Software may be incorporated.
|
|
25
|
+
|
|
26
|
+
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
|
|
27
|
+
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
|
|
28
|
+
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
|
|
29
|
+
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
|
|
30
|
+
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
|
|
31
|
+
|
|
32
|
+
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
|
|
33
|
+
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
34
|
+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
35
|
+
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
|
|
36
|
+
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
|
|
37
|
+
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
|
|
38
|
+
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
|
|
39
|
+
POSSIBILITY OF SUCH DAMAGE.
|
|
40
|
+
|
|
41
|
+
Copyright (C) 2009 Apple Inc. All Rights Reserved.
|
|
42
|
+
|
|
43
|
+
$Id$
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
/*
|
|
47
|
+
This file contains code from version 1.1 and 1.4 of MyOpenALSupport.h taken from Apple's oalTouch version.
|
|
48
|
+
The 1.4 version code is used for loading IMA4 files, however, this code causes very noticeable clicking
|
|
49
|
+
when used to load wave files that are looped so the 1.1 version code is used specifically for loading
|
|
50
|
+
wav files.
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
#ifndef __CD_OPENAL_H
|
|
54
|
+
#define __CD_OPENAL_H
|
|
55
|
+
|
|
56
|
+
#ifdef __cplusplus
|
|
57
|
+
extern "C" {
|
|
58
|
+
#endif
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
#import <OpenAL/al.h>
|
|
62
|
+
#import <OpenAL/alc.h>
|
|
63
|
+
#import <CoreFoundation/CFURL.h>
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
//Taken from oalTouch MyOpenALSupport 1.1
|
|
67
|
+
void* CDloadWaveAudioData(CFURLRef inFileURL, ALsizei *outDataSize, ALenum *outDataFormat, ALsizei* outSampleRate);
|
|
68
|
+
void* CDloadCafAudioData(CFURLRef inFileURL, ALsizei *outDataSize, ALenum *outDataFormat, ALsizei* outSampleRate);
|
|
69
|
+
void* CDGetOpenALAudioData(CFURLRef inFileURL, ALsizei *outDataSize, ALenum *outDataFormat, ALsizei* outSampleRate);
|
|
70
|
+
|
|
71
|
+
#ifdef __cplusplus
|
|
72
|
+
}
|
|
73
|
+
#endif
|
|
74
|
+
|
|
75
|
+
#endif
|
|
76
|
+
|
|
77
|
+
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (c) 2010 Steve Oldmeadow
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in
|
|
12
|
+
all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
20
|
+
THE SOFTWARE.
|
|
21
|
+
|
|
22
|
+
$Id$
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
#import "cocos2d.h"
|
|
26
|
+
#import "SimpleAudioEngine.h"
|
|
27
|
+
|
|
28
|
+
/** Base class for actions that modify audio properties
|
|
29
|
+
@since v 1.0
|
|
30
|
+
*/
|
|
31
|
+
@interface CDXPropertyModifierAction : CCActionInterval {
|
|
32
|
+
CDPropertyModifier *modifier;
|
|
33
|
+
float lastSetValue;
|
|
34
|
+
}
|
|
35
|
+
/** creates the action */
|
|
36
|
+
+(id) actionWithDuration:(ccTime)t modifier:(CDPropertyModifier*) aModifier;
|
|
37
|
+
|
|
38
|
+
/** initializes the action */
|
|
39
|
+
-(id) initWithDuration:(ccTime)t modifier:(CDPropertyModifier*) aModifier;
|
|
40
|
+
|
|
41
|
+
+(void) fadeSoundEffects:(ccTime)t finalVolume:(float)endVol curveType:(tCDInterpolationType)curve shouldStop:(BOOL) stop;
|
|
42
|
+
+(void) fadeSoundEffect:(ccTime)t finalVolume:(float)endVol curveType:(tCDInterpolationType)curve shouldStop:(BOOL) stop effect:(CDSoundSource*) effect;
|
|
43
|
+
+(void) fadeBackgroundMusic:(ccTime)t finalVolume:(float)endVol curveType:(tCDInterpolationType) curve shouldStop:(BOOL) stop;
|
|
44
|
+
|
|
45
|
+
@end
|
|
@@ -0,0 +1,440 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (c) 2010 Steve Oldmeadow
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in
|
|
12
|
+
all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
20
|
+
THE SOFTWARE.
|
|
21
|
+
|
|
22
|
+
$Id$
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
@file
|
|
29
|
+
@b IMPORTANT
|
|
30
|
+
There are 3 different ways of using CocosDenshion. Depending on which you choose you
|
|
31
|
+
will need to include different files and frameworks.
|
|
32
|
+
|
|
33
|
+
@par SimpleAudioEngine
|
|
34
|
+
This is recommended for basic audio requirements. If you just want to play some sound fx
|
|
35
|
+
and some background music and have no interest in learning the lower level workings then
|
|
36
|
+
this is the interface to use.
|
|
37
|
+
|
|
38
|
+
Requirements:
|
|
39
|
+
- Firmware: OS 2.2 or greater
|
|
40
|
+
- Files: SimpleAudioEngine.*, CocosDenshion.*
|
|
41
|
+
- Frameworks: OpenAL, AudioToolbox, AVFoundation
|
|
42
|
+
|
|
43
|
+
@par CDAudioManager
|
|
44
|
+
CDAudioManager is basically a thin wrapper around an AVAudioPlayer object used for playing
|
|
45
|
+
background music and a CDSoundEngine object used for playing sound effects. It manages the
|
|
46
|
+
audio session for you deals with audio session interruption. It is fairly low level and it
|
|
47
|
+
is expected you have some understanding of the underlying technologies. For example, for
|
|
48
|
+
many use cases regarding background music it is expected you will work directly with the
|
|
49
|
+
backgroundMusic AVAudioPlayer which is exposed as a property.
|
|
50
|
+
|
|
51
|
+
Requirements:
|
|
52
|
+
- Firmware: OS 2.2 or greater
|
|
53
|
+
- Files: CDAudioManager.*, CocosDenshion.*
|
|
54
|
+
- Frameworks: OpenAL, AudioToolbox, AVFoundation
|
|
55
|
+
|
|
56
|
+
@par CDSoundEngine
|
|
57
|
+
CDSoundEngine is a sound engine built upon OpenAL and derived from Apple's oalTouch
|
|
58
|
+
example. It can playback up to 32 sounds simultaneously with control over pitch, pan
|
|
59
|
+
and gain. It can be set up to handle audio session interruption automatically. You
|
|
60
|
+
may decide to use CDSoundEngine directly instead of CDAudioManager or SimpleAudioEngine
|
|
61
|
+
because you require OS 2.0 compatibility.
|
|
62
|
+
|
|
63
|
+
Requirements:
|
|
64
|
+
- Firmware: OS 2.0 or greater
|
|
65
|
+
- Files: CocosDenshion.*
|
|
66
|
+
- Frameworks: OpenAL, AudioToolbox
|
|
67
|
+
|
|
68
|
+
*/
|
|
69
|
+
|
|
70
|
+
#import <OpenAL/al.h>
|
|
71
|
+
#import <OpenAL/alc.h>
|
|
72
|
+
#import <AudioToolbox/AudioToolbox.h>
|
|
73
|
+
#import <Foundation/Foundation.h>
|
|
74
|
+
#import "CDConfig.h"
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
#if !defined(CD_DEBUG) || CD_DEBUG == 0
|
|
78
|
+
#define CDLOG(...) do {} while (0)
|
|
79
|
+
#define CDLOGINFO(...) do {} while (0)
|
|
80
|
+
|
|
81
|
+
#elif CD_DEBUG == 1
|
|
82
|
+
#define CDLOG(...) NSLog(__VA_ARGS__)
|
|
83
|
+
#define CDLOGINFO(...) do {} while (0)
|
|
84
|
+
|
|
85
|
+
#elif CD_DEBUG > 1
|
|
86
|
+
#define CDLOG(...) NSLog(__VA_ARGS__)
|
|
87
|
+
#define CDLOGINFO(...) NSLog(__VA_ARGS__)
|
|
88
|
+
#endif // CD_DEBUG
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
#import "CDOpenALSupport.h"
|
|
92
|
+
|
|
93
|
+
//Tested source limit on 2.2.1 and 3.1.2 with up to 128 sources and appears to work. Older OS versions e.g 2.2 may support only 32
|
|
94
|
+
#define CD_SOURCE_LIMIT 32 //Total number of sources we will ever want, may actually get less
|
|
95
|
+
#define CD_NO_SOURCE 0xFEEDFAC //Return value indicating playback failed i.e. no source
|
|
96
|
+
#define CD_IGNORE_AUDIO_SESSION 0xBEEFBEE //Used internally to indicate audio session will not be handled
|
|
97
|
+
#define CD_MUTE 0xFEEDBAB //Return value indicating sound engine is muted or non functioning
|
|
98
|
+
#define CD_NO_SOUND = -1;
|
|
99
|
+
|
|
100
|
+
#define CD_SAMPLE_RATE_HIGH 44100
|
|
101
|
+
#define CD_SAMPLE_RATE_MID 22050
|
|
102
|
+
#define CD_SAMPLE_RATE_LOW 16000
|
|
103
|
+
#define CD_SAMPLE_RATE_BASIC 8000
|
|
104
|
+
#define CD_SAMPLE_RATE_DEFAULT 44100
|
|
105
|
+
|
|
106
|
+
extern NSString * const kCDN_BadAlContext;
|
|
107
|
+
extern NSString * const kCDN_AsynchLoadComplete;
|
|
108
|
+
|
|
109
|
+
extern float const kCD_PitchDefault;
|
|
110
|
+
extern float const kCD_PitchLowerOneOctave;
|
|
111
|
+
extern float const kCD_PitchHigherOneOctave;
|
|
112
|
+
extern float const kCD_PanDefault;
|
|
113
|
+
extern float const kCD_PanFullLeft;
|
|
114
|
+
extern float const kCD_PanFullRight;
|
|
115
|
+
extern float const kCD_GainDefault;
|
|
116
|
+
|
|
117
|
+
enum bufferState {
|
|
118
|
+
CD_BS_EMPTY = 0,
|
|
119
|
+
CD_BS_LOADED = 1,
|
|
120
|
+
CD_BS_FAILED = 2
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
typedef struct _sourceGroup {
|
|
124
|
+
int startIndex;
|
|
125
|
+
int currentIndex;
|
|
126
|
+
int totalSources;
|
|
127
|
+
bool enabled;
|
|
128
|
+
bool nonInterruptible;
|
|
129
|
+
int *sourceStatuses;//pointer into array of source status information
|
|
130
|
+
} sourceGroup;
|
|
131
|
+
|
|
132
|
+
typedef struct _bufferInfo {
|
|
133
|
+
ALuint bufferId;
|
|
134
|
+
int bufferState;
|
|
135
|
+
void* bufferData;
|
|
136
|
+
ALenum format;
|
|
137
|
+
ALsizei sizeInBytes;
|
|
138
|
+
ALsizei frequencyInHertz;
|
|
139
|
+
} bufferInfo;
|
|
140
|
+
|
|
141
|
+
typedef struct _sourceInfo {
|
|
142
|
+
bool usable;
|
|
143
|
+
ALuint sourceId;
|
|
144
|
+
ALuint attachedBufferId;
|
|
145
|
+
} sourceInfo;
|
|
146
|
+
|
|
147
|
+
#pragma mark CDAudioTransportProtocol
|
|
148
|
+
|
|
149
|
+
@protocol CDAudioTransportProtocol <NSObject>
|
|
150
|
+
/** Play the audio */
|
|
151
|
+
-(BOOL) play;
|
|
152
|
+
/** Pause the audio, retain resources */
|
|
153
|
+
-(BOOL) pause;
|
|
154
|
+
/** Stop the audio, release resources */
|
|
155
|
+
-(BOOL) stop;
|
|
156
|
+
/** Return playback to beginning */
|
|
157
|
+
-(BOOL) rewind;
|
|
158
|
+
@end
|
|
159
|
+
|
|
160
|
+
#pragma mark CDAudioInterruptProtocol
|
|
161
|
+
|
|
162
|
+
@protocol CDAudioInterruptProtocol <NSObject>
|
|
163
|
+
/** Is audio mute */
|
|
164
|
+
-(BOOL) mute;
|
|
165
|
+
/** If YES then audio is silenced but not stopped, calls to start new audio will proceed but silently */
|
|
166
|
+
-(void) setMute:(BOOL) muteValue;
|
|
167
|
+
/** Is audio enabled */
|
|
168
|
+
-(BOOL) enabled;
|
|
169
|
+
/** If NO then all audio is stopped and any calls to start new audio will be ignored */
|
|
170
|
+
-(void) setEnabled:(BOOL) enabledValue;
|
|
171
|
+
@end
|
|
172
|
+
|
|
173
|
+
#pragma mark CDUtilities
|
|
174
|
+
/**
|
|
175
|
+
Collection of utilities required by CocosDenshion
|
|
176
|
+
*/
|
|
177
|
+
@interface CDUtilities : NSObject
|
|
178
|
+
{
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** Fundamentally the same as the corresponding method is CCFileUtils but added to break binding to cocos2d */
|
|
182
|
+
+(NSString*) fullPathFromRelativePath:(NSString*) relPath;
|
|
183
|
+
|
|
184
|
+
@end
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
#pragma mark CDSoundEngine
|
|
188
|
+
|
|
189
|
+
/** CDSoundEngine is built upon OpenAL and works with SDK 2.0.
|
|
190
|
+
CDSoundEngine is a sound engine built upon OpenAL and derived from Apple's oalTouch
|
|
191
|
+
example. It can playback up to 32 sounds simultaneously with control over pitch, pan
|
|
192
|
+
and gain. It can be set up to handle audio session interruption automatically. You
|
|
193
|
+
may decide to use CDSoundEngine directly instead of CDAudioManager or SimpleAudioEngine
|
|
194
|
+
because you require OS 2.0 compatibility.
|
|
195
|
+
|
|
196
|
+
Requirements:
|
|
197
|
+
- Firmware: OS 2.0 or greater
|
|
198
|
+
- Files: CocosDenshion.*
|
|
199
|
+
- Frameworks: OpenAL, AudioToolbox
|
|
200
|
+
|
|
201
|
+
@since v0.8
|
|
202
|
+
*/
|
|
203
|
+
@class CDSoundSource;
|
|
204
|
+
@interface CDSoundEngine : NSObject <CDAudioInterruptProtocol> {
|
|
205
|
+
|
|
206
|
+
bufferInfo *_buffers;
|
|
207
|
+
sourceInfo *_sources;
|
|
208
|
+
sourceGroup *_sourceGroups;
|
|
209
|
+
ALCcontext *context;
|
|
210
|
+
NSUInteger _sourceGroupTotal;
|
|
211
|
+
UInt32 _audioSessionCategory;
|
|
212
|
+
BOOL _handleAudioSession;
|
|
213
|
+
ALfloat _preMuteGain;
|
|
214
|
+
NSObject *_mutexBufferLoad;
|
|
215
|
+
BOOL mute_;
|
|
216
|
+
BOOL enabled_;
|
|
217
|
+
|
|
218
|
+
ALenum lastErrorCode_;
|
|
219
|
+
BOOL functioning_;
|
|
220
|
+
float asynchLoadProgress_;
|
|
221
|
+
BOOL getGainWorks_;
|
|
222
|
+
|
|
223
|
+
//For managing dynamic allocation of sources and buffers
|
|
224
|
+
int sourceTotal_;
|
|
225
|
+
int bufferTotal;
|
|
226
|
+
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
@property (readwrite, nonatomic) ALfloat masterGain;
|
|
230
|
+
@property (readonly) ALenum lastErrorCode;//Last OpenAL error code that was generated
|
|
231
|
+
@property (readonly) BOOL functioning;//Is the sound engine functioning
|
|
232
|
+
@property (readwrite) float asynchLoadProgress;
|
|
233
|
+
@property (readonly) BOOL getGainWorks;//Does getting the gain for a source work
|
|
234
|
+
/** Total number of sources available */
|
|
235
|
+
@property (readonly) int sourceTotal;
|
|
236
|
+
/** Total number of source groups that have been defined */
|
|
237
|
+
@property (readonly) NSUInteger sourceGroupTotal;
|
|
238
|
+
|
|
239
|
+
/** Sets the sample rate for the audio mixer. For best performance this should match the sample rate of your audio content */
|
|
240
|
+
+(void) setMixerSampleRate:(Float32) sampleRate;
|
|
241
|
+
|
|
242
|
+
/** Initializes the engine with a group definition and a total number of groups */
|
|
243
|
+
-(id)init;
|
|
244
|
+
|
|
245
|
+
/** Plays a sound in a channel group with a pitch, pan and gain. The sound could played looped or not */
|
|
246
|
+
-(ALuint) playSound:(int) soundId sourceGroupId:(int)sourceGroupId pitch:(float) pitch pan:(float) pan gain:(float) gain loop:(BOOL) loop;
|
|
247
|
+
|
|
248
|
+
/** Creates and returns a sound source object for the specified sound within the specified source group.
|
|
249
|
+
*/
|
|
250
|
+
-(CDSoundSource *) soundSourceForSound:(int) soundId sourceGroupId:(int) sourceGroupId;
|
|
251
|
+
|
|
252
|
+
/** Stops playing a sound */
|
|
253
|
+
- (void) stopSound:(ALuint) sourceId;
|
|
254
|
+
/** Stops playing a source group */
|
|
255
|
+
- (void) stopSourceGroup:(int) sourceGroupId;
|
|
256
|
+
/** Stops all playing sounds */
|
|
257
|
+
-(void) stopAllSounds;
|
|
258
|
+
-(void) defineSourceGroups:(NSArray*) sourceGroupDefinitions;
|
|
259
|
+
-(void) defineSourceGroups:(int[]) sourceGroupDefinitions total:(NSUInteger) total;
|
|
260
|
+
-(void) setSourceGroupNonInterruptible:(int) sourceGroupId isNonInterruptible:(BOOL) isNonInterruptible;
|
|
261
|
+
-(void) setSourceGroupEnabled:(int) sourceGroupId enabled:(BOOL) enabled;
|
|
262
|
+
-(BOOL) sourceGroupEnabled:(int) sourceGroupId;
|
|
263
|
+
-(BOOL) loadBufferFromData:(int) soundId soundData:(ALvoid*) soundData format:(ALenum) format size:(ALsizei) size freq:(ALsizei) freq;
|
|
264
|
+
-(BOOL) loadBuffer:(int) soundId filePath:(NSString*) filePath;
|
|
265
|
+
-(void) loadBuffersAsynchronously:(NSArray *) loadRequests;
|
|
266
|
+
-(BOOL) unloadBuffer:(int) soundId;
|
|
267
|
+
-(ALCcontext *) openALContext;
|
|
268
|
+
|
|
269
|
+
/** Returns the duration of the buffer in seconds or a negative value if the buffer id is invalid */
|
|
270
|
+
-(float) bufferDurationInSeconds:(int) soundId;
|
|
271
|
+
/** Returns the size of the buffer in bytes or a negative value if the buffer id is invalid */
|
|
272
|
+
-(ALsizei) bufferSizeInBytes:(int) soundId;
|
|
273
|
+
/** Returns the sampling frequency of the buffer in hertz or a negative value if the buffer id is invalid */
|
|
274
|
+
-(ALsizei) bufferFrequencyInHertz:(int) soundId;
|
|
275
|
+
|
|
276
|
+
/** Used internally, never call unless you know what you are doing */
|
|
277
|
+
-(void) _soundSourcePreRelease:(CDSoundSource *) soundSource;
|
|
278
|
+
|
|
279
|
+
@end
|
|
280
|
+
|
|
281
|
+
#pragma mark CDSoundSource
|
|
282
|
+
/** CDSoundSource is a wrapper around an OpenAL sound source.
|
|
283
|
+
It allows you to manipulate properties such as pitch, gain, pan and looping while the
|
|
284
|
+
sound is playing. CDSoundSource is based on the old CDSourceWrapper class but with much
|
|
285
|
+
added functionality.
|
|
286
|
+
|
|
287
|
+
@since v1.0
|
|
288
|
+
*/
|
|
289
|
+
@interface CDSoundSource : NSObject <CDAudioTransportProtocol, CDAudioInterruptProtocol> {
|
|
290
|
+
ALenum lastError;
|
|
291
|
+
@public
|
|
292
|
+
ALuint _sourceId;
|
|
293
|
+
ALuint _sourceIndex;
|
|
294
|
+
CDSoundEngine* _engine;
|
|
295
|
+
int _soundId;
|
|
296
|
+
float _preMuteGain;
|
|
297
|
+
BOOL enabled_;
|
|
298
|
+
BOOL mute_;
|
|
299
|
+
}
|
|
300
|
+
@property (readwrite, nonatomic) float pitch;
|
|
301
|
+
@property (readwrite, nonatomic) float gain;
|
|
302
|
+
@property (readwrite, nonatomic) float pan;
|
|
303
|
+
@property (readwrite, nonatomic) BOOL looping;
|
|
304
|
+
@property (readonly) BOOL isPlaying;
|
|
305
|
+
@property (readwrite, nonatomic) int soundId;
|
|
306
|
+
/** Returns the duration of the attached buffer in seconds or a negative value if the buffer is invalid */
|
|
307
|
+
@property (readonly) float durationInSeconds;
|
|
308
|
+
|
|
309
|
+
/** Stores the last error code that occurred. Check against AL_NO_ERROR */
|
|
310
|
+
@property (readonly) ALenum lastError;
|
|
311
|
+
/** Do not init yourself, get an instance from the sourceForSound factory method on CDSoundEngine */
|
|
312
|
+
-(id)init:(ALuint) theSourceId sourceIndex:(int) index soundEngine:(CDSoundEngine*) engine;
|
|
313
|
+
|
|
314
|
+
@end
|
|
315
|
+
|
|
316
|
+
#pragma mark CDAudioInterruptTargetGroup
|
|
317
|
+
|
|
318
|
+
/** Container for objects that implement audio interrupt protocol i.e. they can be muted and enabled.
|
|
319
|
+
Setting mute and enabled for the group propagates to all children.
|
|
320
|
+
Designed to be used with your CDSoundSource objects to get them to comply with global enabled and mute settings
|
|
321
|
+
if that is what you want to do.*/
|
|
322
|
+
@interface CDAudioInterruptTargetGroup : NSObject <CDAudioInterruptProtocol> {
|
|
323
|
+
BOOL mute_;
|
|
324
|
+
BOOL enabled_;
|
|
325
|
+
NSMutableArray *children_;
|
|
326
|
+
}
|
|
327
|
+
-(void) addAudioInterruptTarget:(NSObject<CDAudioInterruptProtocol>*) interruptibleTarget;
|
|
328
|
+
@end
|
|
329
|
+
|
|
330
|
+
#pragma mark CDAsynchBufferLoader
|
|
331
|
+
|
|
332
|
+
/** CDAsynchBufferLoader
|
|
333
|
+
TODO
|
|
334
|
+
*/
|
|
335
|
+
@interface CDAsynchBufferLoader : NSOperation {
|
|
336
|
+
NSArray *_loadRequests;
|
|
337
|
+
CDSoundEngine *_soundEngine;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
-(id) init:(NSArray *)loadRequests soundEngine:(CDSoundEngine *) theSoundEngine;
|
|
341
|
+
|
|
342
|
+
@end
|
|
343
|
+
|
|
344
|
+
#pragma mark CDBufferLoadRequest
|
|
345
|
+
|
|
346
|
+
/** CDBufferLoadRequest */
|
|
347
|
+
@interface CDBufferLoadRequest: NSObject
|
|
348
|
+
{
|
|
349
|
+
NSString *filePath;
|
|
350
|
+
int soundId;
|
|
351
|
+
//id loader;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
@property (readonly) NSString *filePath;
|
|
355
|
+
@property (readonly) int soundId;
|
|
356
|
+
|
|
357
|
+
- (id)init:(int) theSoundId filePath:(const NSString *) theFilePath;
|
|
358
|
+
@end
|
|
359
|
+
|
|
360
|
+
/** Interpolation type */
|
|
361
|
+
typedef enum {
|
|
362
|
+
kIT_Linear, //!Straight linear interpolation fade
|
|
363
|
+
kIT_SCurve, //!S curved interpolation
|
|
364
|
+
kIT_Exponential //!Exponential interpolation
|
|
365
|
+
} tCDInterpolationType;
|
|
366
|
+
|
|
367
|
+
#pragma mark CDFloatInterpolator
|
|
368
|
+
@interface CDFloatInterpolator: NSObject
|
|
369
|
+
{
|
|
370
|
+
float start;
|
|
371
|
+
float end;
|
|
372
|
+
float lastValue;
|
|
373
|
+
tCDInterpolationType interpolationType;
|
|
374
|
+
}
|
|
375
|
+
@property (readwrite, nonatomic) float start;
|
|
376
|
+
@property (readwrite, nonatomic) float end;
|
|
377
|
+
@property (readwrite, nonatomic) tCDInterpolationType interpolationType;
|
|
378
|
+
|
|
379
|
+
/** Return a value between min and max based on t which represents fractional progress where 0 is the start
|
|
380
|
+
and 1 is the end */
|
|
381
|
+
-(float) interpolate:(float) t;
|
|
382
|
+
-(id) init:(tCDInterpolationType) type startVal:(float) startVal endVal:(float) endVal;
|
|
383
|
+
|
|
384
|
+
@end
|
|
385
|
+
|
|
386
|
+
#pragma mark CDPropertyModifier
|
|
387
|
+
|
|
388
|
+
/** Base class for classes that modify properties such as pitch, pan and gain */
|
|
389
|
+
@interface CDPropertyModifier: NSObject
|
|
390
|
+
{
|
|
391
|
+
CDFloatInterpolator *interpolator;
|
|
392
|
+
float startValue;
|
|
393
|
+
float endValue;
|
|
394
|
+
id target;
|
|
395
|
+
BOOL stopTargetWhenComplete;
|
|
396
|
+
|
|
397
|
+
}
|
|
398
|
+
@property (readwrite, nonatomic) BOOL stopTargetWhenComplete;
|
|
399
|
+
@property (readwrite, nonatomic) float startValue;
|
|
400
|
+
@property (readwrite, nonatomic) float endValue;
|
|
401
|
+
@property (readwrite, nonatomic) tCDInterpolationType interpolationType;
|
|
402
|
+
|
|
403
|
+
-(id) init:(id) theTarget interpolationType:(tCDInterpolationType) type startVal:(float) startVal endVal:(float) endVal;
|
|
404
|
+
/** Set to a fractional value between 0 and 1 where 0 equals the start and 1 equals the end*/
|
|
405
|
+
-(void) modify:(float) t;
|
|
406
|
+
|
|
407
|
+
-(void) _setTargetProperty:(float) newVal;
|
|
408
|
+
-(float) _getTargetProperty;
|
|
409
|
+
-(void) _stopTarget;
|
|
410
|
+
-(Class) _allowableType;
|
|
411
|
+
|
|
412
|
+
@end
|
|
413
|
+
|
|
414
|
+
#pragma mark CDSoundSourceFader
|
|
415
|
+
|
|
416
|
+
/** Fader for CDSoundSource objects */
|
|
417
|
+
@interface CDSoundSourceFader : CDPropertyModifier{}
|
|
418
|
+
@end
|
|
419
|
+
|
|
420
|
+
#pragma mark CDSoundSourcePanner
|
|
421
|
+
|
|
422
|
+
/** Panner for CDSoundSource objects */
|
|
423
|
+
@interface CDSoundSourcePanner : CDPropertyModifier{}
|
|
424
|
+
@end
|
|
425
|
+
|
|
426
|
+
#pragma mark CDSoundSourcePitchBender
|
|
427
|
+
|
|
428
|
+
/** Pitch bender for CDSoundSource objects */
|
|
429
|
+
@interface CDSoundSourcePitchBender : CDPropertyModifier{}
|
|
430
|
+
@end
|
|
431
|
+
|
|
432
|
+
#pragma mark CDSoundEngineFader
|
|
433
|
+
|
|
434
|
+
/** Fader for CDSoundEngine objects */
|
|
435
|
+
@interface CDSoundEngineFader : CDPropertyModifier{}
|
|
436
|
+
@end
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
|