author | raptor <buckyballreaction@gmail.com> |
Tue, 13 Aug 2019 13:10:12 -0600 | |
changeset 15317 | 5b2dec63f4cf |
parent 12877 | 00215a7ec5f5 |
permissions | -rw-r--r-- |
6000
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff
changeset
|
1 |
/* |
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff
changeset
|
2 |
* Hedgewars-iOS, a Hedgewars port for iOS devices |
6700 | 3 |
* Copyright (c) 2009-2012 Vittorio Giovara <vittorio.giovara@gmail.com> |
6000
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff
changeset
|
4 |
* |
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff
changeset
|
5 |
* This program is free software; you can redistribute it and/or modify |
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff
changeset
|
6 |
* it under the terms of the GNU General Public License as published by |
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff
changeset
|
7 |
* the Free Software Foundation; version 2 of the License |
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff
changeset
|
8 |
* |
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff
changeset
|
12 |
* GNU General Public License for more details. |
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff
changeset
|
13 |
* |
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff
changeset
|
15 |
* along with this program; if not, write to the Free Software |
10108
c68cf030eded
update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents:
8441
diff
changeset
|
16 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
6000
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff
changeset
|
17 |
*/ |
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff
changeset
|
18 |
|
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff
changeset
|
19 |
|
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff
changeset
|
20 |
#import "AudioManagerController.h" |
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff
changeset
|
21 |
#import "AVFoundation/AVAudioPlayer.h" |
6656
6aeaba3ee584
ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents:
6208
diff
changeset
|
22 |
#import "MXAudioPlayerFadeOperation.h" |
6000
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff
changeset
|
23 |
|
6832 | 24 |
|
6869
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
25 |
#define DEFAULT_VOLUME 0.45f |
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
26 |
#define FADEOUT_DURATION 3.0f |
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
27 |
#define FADEIN_DURATION 2.0f |
6000
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff
changeset
|
28 |
|
6869
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
29 |
static AudioManagerController *mainInstance; |
6656
6aeaba3ee584
ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents:
6208
diff
changeset
|
30 |
|
6000
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff
changeset
|
31 |
@implementation AudioManagerController |
6869
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
32 |
@synthesize backgroundMusic, clickSound, backSound, selSound, audioFaderQueue; |
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
33 |
|
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
34 |
+(id) mainManager { |
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
35 |
if (mainInstance == nil) |
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
36 |
mainInstance = [[self alloc] init]; |
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
37 |
return mainInstance; |
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
38 |
} |
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
39 |
|
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
40 |
- (id)init { |
6908
896ed2afcfb8
ios: turn on more warning messages and start correcting them
koda
parents:
6871
diff
changeset
|
41 |
if ((self = [super init])) { |
6869
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
42 |
self.backgroundMusic = nil; |
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
43 |
self.clickSound = -1; |
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
44 |
self.backSound = -1; |
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
45 |
self.selSound = -1; |
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
46 |
|
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
47 |
self.audioFaderQueue = nil; |
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
48 |
} |
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
49 |
return self; |
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
50 |
} |
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
51 |
|
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
52 |
- (void)dealloc { |
6869
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
53 |
[self unloadSounds]; |
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
54 |
mainInstance = nil; |
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
55 |
} |
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
56 |
|
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
57 |
- (void)didReceiveMemoryWarning { |
6869
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
58 |
if (self.backgroundMusic.playing == NO) |
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
59 |
self.backgroundMusic = nil; |
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
60 |
if ([self.audioFaderQueue operationCount] == 0) |
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
61 |
self.audioFaderQueue = nil; |
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
62 |
|
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
63 |
[self unloadSounds]; |
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
64 |
MSG_MEMCLEAN(); |
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
65 |
} |
6000
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff
changeset
|
66 |
|
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff
changeset
|
67 |
#pragma mark - |
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff
changeset
|
68 |
#pragma mark background music control |
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
69 |
- (void)playBackgroundMusic { |
6000
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff
changeset
|
70 |
if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"music"] boolValue] == NO) |
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff
changeset
|
71 |
return; |
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff
changeset
|
72 |
|
6869
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
73 |
if (self.backgroundMusic == nil) { |
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
74 |
NSString *musicString = [[NSBundle mainBundle] pathForResource:@"hwclassic" ofType:@"mp3"]; |
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
75 |
self.backgroundMusic = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:musicString] error:nil]; |
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
76 |
self.backgroundMusic.delegate = nil; |
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
77 |
self.backgroundMusic.numberOfLoops = -1; |
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
78 |
} |
8441 | 79 |
|
6869
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
80 |
self.backgroundMusic.volume = DEFAULT_VOLUME; |
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
81 |
[self.backgroundMusic play]; |
6000
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff
changeset
|
82 |
} |
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff
changeset
|
83 |
|
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
84 |
- (void)pauseBackgroundMusic { |
6869
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
85 |
[self.backgroundMusic pause]; |
6000
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff
changeset
|
86 |
} |
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff
changeset
|
87 |
|
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
88 |
- (void)stopBackgroundMusic { |
6869
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
89 |
[self.backgroundMusic stop]; |
6000
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff
changeset
|
90 |
} |
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff
changeset
|
91 |
|
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
92 |
- (void)fadeOutBackgroundMusic { |
6667
142fe596e75e
ios check for music preference also for fading methods
koda
parents:
6656
diff
changeset
|
93 |
if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"music"] boolValue] == NO) |
142fe596e75e
ios check for music preference also for fading methods
koda
parents:
6656
diff
changeset
|
94 |
return; |
142fe596e75e
ios check for music preference also for fading methods
koda
parents:
6656
diff
changeset
|
95 |
|
6869
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
96 |
if (self.audioFaderQueue == nil) |
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
97 |
self.audioFaderQueue = [[NSOperationQueue alloc] init]; |
8441 | 98 |
|
6869
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
99 |
MXAudioPlayerFadeOperation *fadeOut = [[MXAudioPlayerFadeOperation alloc] initFadeWithAudioPlayer:self.backgroundMusic |
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
100 |
toVolume:0.0 |
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
101 |
overDuration:FADEOUT_DURATION]; |
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
102 |
[self.audioFaderQueue addOperation:fadeOut]; |
6656
6aeaba3ee584
ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents:
6208
diff
changeset
|
103 |
} |
6aeaba3ee584
ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents:
6208
diff
changeset
|
104 |
|
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
105 |
- (void)fadeInBackgroundMusic { |
6667
142fe596e75e
ios check for music preference also for fading methods
koda
parents:
6656
diff
changeset
|
106 |
if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"music"] boolValue] == NO) |
142fe596e75e
ios check for music preference also for fading methods
koda
parents:
6656
diff
changeset
|
107 |
return; |
142fe596e75e
ios check for music preference also for fading methods
koda
parents:
6656
diff
changeset
|
108 |
|
6869
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
109 |
if (self.audioFaderQueue == nil) |
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
110 |
self.audioFaderQueue = [[NSOperationQueue alloc] init]; |
6656
6aeaba3ee584
ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents:
6208
diff
changeset
|
111 |
|
6869
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
112 |
[self playBackgroundMusic]; |
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
113 |
MXAudioPlayerFadeOperation *fadeIn = [[MXAudioPlayerFadeOperation alloc] initFadeWithAudioPlayer:self.backgroundMusic |
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
114 |
toVolume:DEFAULT_VOLUME |
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
115 |
overDuration:FADEIN_DURATION]; |
6656
6aeaba3ee584
ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents:
6208
diff
changeset
|
116 |
[audioFaderQueue addOperation:fadeIn]; |
6aeaba3ee584
ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents:
6208
diff
changeset
|
117 |
} |
6aeaba3ee584
ios: added MXAudioPlayerFadeOperation to allow easy fade in and out of background music
koda
parents:
6208
diff
changeset
|
118 |
|
6000
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff
changeset
|
119 |
#pragma mark - |
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff
changeset
|
120 |
#pragma mark sound effects control |
6869
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
121 |
-(SystemSoundID) loadSound:(NSString *)snd { |
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
122 |
SystemSoundID soundID; |
6000
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff
changeset
|
123 |
|
6869
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
124 |
// get the filename of the sound file in a NSURL format |
6871
5aadbfe02613
ios: resample the sound effects in CAF as suggested in ios sdk (100kB of space saved)
koda
parents:
6869
diff
changeset
|
125 |
NSString *path = [[NSBundle mainBundle] pathForResource:snd ofType:@"caf"]; |
6000
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff
changeset
|
126 |
NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO]; |
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff
changeset
|
127 |
|
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff
changeset
|
128 |
// use audio sevices to create and play the sound |
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
129 |
AudioServicesCreateSystemSoundID((__bridge CFURLRef)filePath, &soundID); |
6000
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff
changeset
|
130 |
return soundID; |
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff
changeset
|
131 |
} |
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff
changeset
|
132 |
|
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
133 |
- (void)unloadSounds { |
6869
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
134 |
AudioServicesDisposeSystemSoundID(clickSound), clickSound = -1; |
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
135 |
AudioServicesDisposeSystemSoundID(backSound), backSound = -1; |
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
136 |
AudioServicesDisposeSystemSoundID(selSound), selSound = -1; |
6000
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff
changeset
|
137 |
} |
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff
changeset
|
138 |
|
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
139 |
- (void)playClickSound { |
6000
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff
changeset
|
140 |
if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"sound"] boolValue] == NO) |
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff
changeset
|
141 |
return; |
8441 | 142 |
|
6869
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
143 |
if (self.clickSound == -1) |
6871
5aadbfe02613
ios: resample the sound effects in CAF as suggested in ios sdk (100kB of space saved)
koda
parents:
6869
diff
changeset
|
144 |
self.clickSound = [self loadSound:@"clickSound"]; |
8441 | 145 |
|
6869
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
146 |
AudioServicesPlaySystemSound(self.clickSound); |
6000
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff
changeset
|
147 |
} |
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff
changeset
|
148 |
|
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
149 |
- (void)playBackSound { |
6000
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff
changeset
|
150 |
if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"sound"] boolValue] == NO) |
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff
changeset
|
151 |
return; |
8441 | 152 |
|
6869
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
153 |
if (self.backSound == -1) |
6871
5aadbfe02613
ios: resample the sound effects in CAF as suggested in ios sdk (100kB of space saved)
koda
parents:
6869
diff
changeset
|
154 |
self.backSound = [self loadSound:@"backSound"]; |
8441 | 155 |
|
6869
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
156 |
AudioServicesPlaySystemSound(self.backSound); |
6000
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff
changeset
|
157 |
} |
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff
changeset
|
158 |
|
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
159 |
- (void)playSelectSound { |
6869
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
160 |
if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"sound"] boolValue] == NO) |
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
161 |
return; |
8441 | 162 |
|
6869
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
163 |
if (self.selSound == -1) |
6871
5aadbfe02613
ios: resample the sound effects in CAF as suggested in ios sdk (100kB of space saved)
koda
parents:
6869
diff
changeset
|
164 |
self.selSound = [self loadSound:@"selSound"]; |
8441 | 165 |
|
6869
a187c280dd3d
ios: convert audio operation from class to instance, plays better with memory
koda
parents:
6832
diff
changeset
|
166 |
AudioServicesPlaySystemSound(self.selSound); |
6000
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff
changeset
|
167 |
} |
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff
changeset
|
168 |
|
dbcebcd3d79f
ios frontend: sounds and music have their own class now (with caching\!) instead of being spread here and there (exploiting class methods like a true oop pro)
koda
parents:
diff
changeset
|
169 |
@end |