1
0
mirror of https://github.com/thes3m/XNI synced 2024-12-26 13:26:06 +01:00
XNI/Classes/Retronator/Xni/Framework/Audio/SoundEffectInstance.m
Matej Jan d04d7bf8f3 All around update and fixes
git-svn-id: http://xni.googlecode.com/svn/XNI@104 ac433895-eea3-a490-d80a-17149a75e588
2012-05-14 08:40:49 +00:00

96 lines
1.6 KiB
Objective-C

//
// SoundEffectInstance.m
// XNI
//
// Created by Matej Jan on 15.12.10.
// Copyright 2010 Retronator. All rights reserved.
//
#import "SoundEffectInstance.h"
#import "SoundEffectInstance+Internal.h"
#import "SoundEffect+Internal.h"
@implementation SoundEffectInstance
- (id) initWithSoundEffect:(SoundEffect *)soundEffect
{
self = [super init];
if (self != nil) {
parent = [soundEffect retain];
// grab a source ID from openAL
alGenSources(1, &sourceID);
// attach the buffer to the source
alSourcei(sourceID, AL_BUFFER, parent.bufferID);
// set some basic source prefs
alSourcef(sourceID, AL_PITCH, 1.0f);
alSourcef(sourceID, AL_GAIN, 1.0f);
}
return self;
}
@synthesize isLooped, pan, pitch, volume;
- (void) setIsLooped:(BOOL)value {
isLooped = value;
alSourcei(sourceID, AL_LOOPING, isLooped);
}
- (SoundState) state {
ALenum state;
alGetSourcei(sourceID, AL_SOURCE_STATE, &state);
return state;
}
- (void) setPan:(float)value {
pan = value;
alSource3f(sourceID, AL_POSITION, pan, 0, 0);
}
- (void) setPitch:(float)value {
pitch = value;
float alPitch = pow(2, value);
alSourcef(sourceID, AL_PITCH, alPitch);
}
- (void) setVolume:(float)value {
volume = value;
alSourcef(sourceID, AL_GAIN, volume);
}
- (void) play {
alSourcePlay(sourceID);
}
- (void) pause {
alSourcePause(sourceID);
}
- (void) resume {
alSourcePlay(sourceID);
}
- (void) stop {
[self stopImmediate:YES];
}
- (void) stopImmediate:(BOOL)immediate {
if (immediate) {
alSourceStop(sourceID);
}
}
- (void) dealloc
{
alDeleteSources(1, &sourceID);
[parent release];
[super dealloc];
}
@end