00001
00002
00003
00004
00005
00006
00007
00008
00009 #import "SoundEffect.h"
00010
00011
00012 @implementation SoundEffect
00013
00014 - (id) init {
00015 self = [super init];
00016 if (self != nil) {
00017 sound = nil;
00018 name = nil;
00019 }
00020 return self;
00021 }
00022
00023 -(id) initSound:(QTMovie *)newSound withName:(NSString *)newName {
00024 self = [self init];
00025 if (self != nil) {
00026 sound = newSound;
00027 name = newName;
00028 }
00029 return self;
00030 }
00031
00032 - (bool) loadSoundWithName:(NSString*)soundName {
00033
00034
00035 NSString *pathToResources = [[NSBundle mainBundle] resourcePath];
00036 NSString *pathToSound = [NSString stringWithFormat:@"%@/%@.au", pathToResources, soundName];
00037 [self setName:soundName];
00038
00039 [self setSound:[QTMovie movieWithFile:pathToSound error:nil]];
00040 if (sound != nil) {
00041 return YES;
00042 } else {
00043 NSLog(@"SoundEffect.loadSoundWithName %@ failed", soundName);
00044 return NO;
00045 }
00046 }
00047
00048 -(QTMovie *)sound {
00049 return sound;
00050 }
00051
00052 -(NSString *)name {
00053 return name;
00054 }
00055
00056 -(void) setSound:(QTMovie *)newSound {
00057 [sound release];
00058 sound = newSound;
00059 [sound retain];
00060 }
00061
00062 -(void) setName:(NSString *)newName {
00063 [name release];
00064 name = newName;
00065 [name retain];
00066 }
00067
00068 -(void) play {
00069 NSLog(@"SoundEffect.play sound %@", name);
00070 [sound play];
00071 }
00072
00073 -(void) playWithVolume:(float)vol {
00074 [sound setVolume:vol];
00075 [sound gotoBeginning];
00076 NSLog(@"SoundEffect.playWithVolume %f sound %@", vol, name);
00077 [sound play];
00078 }
00079
00080 -(void) playWithVolume:(float)vol balance:(float)bal {
00081
00082
00083 short balance = 127 * bal;
00084
00085
00086 MediaSetSoundBalance((void*)sound, balance);
00087 [sound setVolume:vol];
00088 NSLog(@"SoundEffect.playWithVolume %f balance %f (%d) sound %@", vol, bal, balance, name);
00089 [sound play];
00090 }
00091
00092 @end