58 m_fadeInStartTimestamp(0),
59 m_fadeInEndTimestamp(0),
60 m_fadeOutStartTimestamp(0),
61 m_fadeOutEndTimestamp(0),
62 m_playCheckDifference(0) {
84 alSourcei(
m_source, AL_BUFFER, AL_NONE);
125 alGetSourcei(
m_source, AL_BUFFERS_PROCESSED, &procs);
129 float samplesOffset, newOffset;
130 alGetSourcef(
m_source, AL_SAMPLE_OFFSET, &samplesOffset);
132 alSourceUnqueueBuffers(
m_source, 1, &buffer);
134 alGetSourcef(
m_source, AL_SAMPLE_OFFSET, &newOffset);
145 alGetSourcei(
m_source, AL_BUFFERS_QUEUED, &bufs);
152 alSourceQueueBuffers(
m_source, 1, &buffer);
164 alSourcei(
m_source, AL_SOURCE_RELATIVE, relative ? AL_TRUE : AL_FALSE);
175 ALfloat vec[3] = {
static_cast<ALfloat
>(direction.
x), static_cast<ALfloat>(direction.
y),
static_cast<ALfloat
>(direction.
z) };
176 alSourcefv(
m_source, AL_DIRECTION, vec);
188 alSourcef(
m_source, AL_PITCH, pitch);
200 alSourcef(
m_source, AL_ROLLOFF_FACTOR, rolloff);
214 std::vector<SoundEffect*>effects =
m_effects;
215 for (std::vector<SoundEffect*>::iterator it = effects.begin(); it != effects.end(); ++it) {
223 alSourcei(
m_source, AL_BUFFER, AL_NONE);
301 alSourcei(
m_source, AL_LOOPING, AL_FALSE);
317 alSourcei(
m_source, AL_BUFFER, AL_NONE);
331 alSourcei(
m_source, AL_LOOPING, loop ? AL_TRUE : AL_FALSE);
333 alSourcei(
m_source, AL_LOOPING, AL_FALSE);
427 alSourcef(
m_source, AL_MAX_GAIN, gain);
438 alSourcef(
m_source, AL_MIN_GAIN, gain);
478 double samplerate =
static_cast<double>(
getSampleRate()) / 1000.0;
482 double stereo = (
isStereo() ? 2.0 : 1.0);
483 double time = ( size / (samplerate * bitres) ) / stereo;
485 return static_cast<uint64_t
>(time);
518 alSourcef(
m_source, AL_BYTE_OFFSET, value);
521 alSourcef(
m_source, AL_SAMPLE_OFFSET, value);
524 alSourcef(
m_source, AL_SEC_OFFSET, value);
541 alGetSourcei(
m_source, AL_SOURCE_STATE, &state);
542 if (state == AL_PLAYING || state == AL_PAUSED) {
555 if (state == AL_PLAYING) {
572 alGetSourcef(
m_source, AL_BYTE_OFFSET, &pos);
575 alGetSourcef(
m_source, AL_SAMPLE_OFFSET, &pos);
578 alGetSourcef(
m_source, AL_SEC_OFFSET, &pos);
603 alSource3f(
m_source, AL_POSITION, static_cast<ALfloat>(position.
x), static_cast<ALfloat>(position.
y), static_cast<ALfloat>(position.
z));
619 alSourcef(
m_source, AL_REFERENCE_DISTANCE, distance);
630 alSourcef(
m_source, AL_MAX_DISTANCE, distance);
641 alSource3f(
m_source, AL_VELOCITY, static_cast<ALfloat>(velocity.
x), static_cast<ALfloat>(velocity.
y), static_cast<ALfloat>(velocity.
z));
652 alSourcef(
m_source, AL_CONE_INNER_ANGLE, inner);
663 alSourcef(
m_source, AL_CONE_OUTER_ANGLE, outer);
674 alSourcef(
m_source, AL_CONE_OUTER_GAIN, gain);
688 alGetSourcei(
m_source, AL_SOURCE_STATE, &state);
745 float time =
static_cast<float>(timediff) / 1000.0f;
795 gain = std::max(gain, 0.0f);
803 for (std::vector<SoundEffect*>::iterator it =
m_effects.begin(); it !=
m_effects.end(); ++it) {
816 for (std::vector<SoundEffect*>::iterator it =
m_effects.begin(); it !=
m_effects.end(); ++it) {
826 for (std::vector<SoundEffect*>::iterator it =
m_effects.begin(); it !=
m_effects.end(); ++it) {
836 for (std::vector<SoundEffect*>::iterator it =
m_effects.begin(); it !=
m_effects.end(); ++it) {
854 for (std::vector<SoundEffect*>::iterator it =
m_effects.begin(); it !=
m_effects.end(); ++it) {
865 for (std::vector<SoundEffect*>::iterator it =
m_effects.begin(); it !=
m_effects.end(); ++it) {
886 std::vector<SoundEmitterListener*>::iterator i =
m_listeners.begin();
888 if ((*i) == listener) {
899 std::vector<SoundEmitterListener*>::iterator i =
m_listeners.begin();
uint32_t getPlayTimestamp()
Returns timestamp of the last play start in milliseconds.
#define FL_WARN(logger, msg)
uint32_t m_emitterId
The emitter-id.
void setSource(ALuint source)
Sets openAl-source.
uint32_t getId() const
Returns the emitter-id.
uint32_t m_fadeOutStartTimestamp
fade out start time
void setPosition(const AudioSpaceCoordinate &position)
Sets the position of the SoundEmitter in the virtual audio space.
bool getStream(uint32_t streamid, ALuint buffer)
Refill a processed buffer with new data.
float m_origGain
original gain
void activateEffects()
Activates effects if the Emitter got the openAL-source.
float getGain() const
Returns the gain of the emitter.
void setGain(float gain)
Sets the gain of the emitter.
void checkFade()
Updates fade in and out.
void removeFromGroup(SoundEmitter *emitter)
Removes the emitter from group.
void setConeOuterAngle(float outer)
Sets outer angle of the sound cone, in degrees.
std::vector< SoundEffect * > m_effects
holds pointer to applied SoundEffects
void setPitch(float pitch)
Sets pitch multiplier.
uint32_t getTime() const
Get the time.
void setConeOuterGain(float gain)
Sets the gain when outside the oriented cone.
float getMaxGain() const
Returns the max.
AudioSpaceCoordinate getDirection() const
Return the direction of the SoundEmitter in the virtual audio space.
SoundStateType
State of the audio file.
void removeEffect(SoundEffect *effect)
Removes effect.
SoundStateType getState()
Returns the state of the audio file.
void reset(bool defaultall=false)
Reset the emitter, free all internal buffers.
uint64_t getSampleRate() const
Returns the sample rate.
SoundClipPtr m_soundClip
The attached sound clip.
void setRelativePositioning(bool relative)
Sets Positioning-Type Default is false.
bool isPosition() const
Return if it is a positional SoundEmitter.
void reset(T *ptr=0)
reset this pointer to a null shared pointer this can be used to lower the reference count of the shar...
void update()
Called once a frame from the SoundManager.
const std::string & getGroup()
Return the group name.
std::vector< SoundEmitterListener * > m_listeners
listeners for sound related events
void setCheckDifference()
Sets the time difference between play and the first check if it's playable.
float getMaxDistance() const
Return the max distance.
bool m_fadeOut
fade out clip
uint32_t m_fadeInStartTimestamp
fade in start time
void pause()
Pauses playing the audio file.
uint32_t m_fadeInEndTimestamp
fade in end time
Base class for Efx sound effects.
float getPitch() const
Return pitch multiplier.
The class defines filters.
Listener interface for SoundEmitter.
float getMinGain() const
Returns the min.
DoublePoint3D AudioSpaceCoordinate
bool isStereo()
Tests if the audio data is stereo data or mono.
uint32_t m_streamId
The id of the stream.
static Logger _log(LM_AUDIO)
#define CHECK_OPENAL_LOG(logger, level, msg)
SoundDecoder * getDecoder() const
Returns the attached decoder.
bool isActive() const
Return if the Emitter is active / have an openAl-source.
AudioSpaceCoordinate direction
AudioSpaceCoordinate getVelocity() const
Return the velocity of the SoundEmitter in the virtual audio space.
void detachSoundClip()
Internal function to detach a SoundClip from the source.
static SoundClipManager * instance()
void activateEffect(SoundEffect *effect, SoundEmitter *emitter)
Internal function to do the OpenAL calls to activate the SoundEffect for the SoundEmitter.
void release()
Releases the emitter.
float getConeOuterGain() const
Return the gain when outside the oriented cone.
struct FIFE::SoundEmitter::internData m_internData
void setCursor(SoundPositionType type, float value)
Sets the cursor position in the audio file.
uint8_t getEffectCount()
Return the number of effects.
std::string m_group
the group name
void acquireStream(uint32_t streamid)
Fills the streaming-buffers with initial data.
void setMaxDistance(float distance)
Sets the max distance used with the Inverse Clamped Distance Model to set the distance where there wi...
uint64_t getSampleRate()
Returns the sample rate.
void deactivateEffect(SoundEffect *effect, SoundEmitter *emitter)
Internal function to do the OpenAL calls to deactivate the SoundEffect for the SoundEmitter.
float getRolloff() const
Return the AL_ROLEOFF_FACTOR.
ALuint m_source
The openAL-source.
SoundPositionType
Different types of audio-file positions.
void attachSoundClip()
Internal function to attach a SoundClip to the source.
void syncData()
Updates OpenAL with collected data.
static bool Equal(T _val1, T _val2)
void setDirectFilter(SoundFilter *filter)
Sets the direct filter.
void deactivateFilter(SoundFilter *filter, SoundEmitter *emitter)
Internal function to do the OpenAL calls to deactivate the SoundFilter for the SoundEmitter.
void removeEmitterFromSoundEffect(SoundEffect *effect, SoundEmitter *emitter)
Removes given SoundEmitter from the specific SoundEffect.
void play()
Plays the associated audio file.
uint32_t countBuffers() const
Returns the number of buffers used by the SoundClip (only for non-streaming sound clips) ...
bool isStereo() const
Tests if the audio data is stereo data or mono.
virtual uint64_t getDecodedLength() const =0
Returns the decoded length of the file in bytes.
bool isStream() const
Does this SoundClip require a streaming mechanism?
void setGroup(const std::string &group)
Sets the group name.
SoundFilter * m_directFilter
Applied direct sound filter.
bool isLooping() const
Return playing mode.
ALuint getSource() const
Return openAl-source.
uint32_t m_fadeOutEndTimestamp
fade out end time
float getCursor(SoundPositionType type)
Returns the cursor position in the audio file.
void setMaxGain(float gain)
Sets the max.
void setLooping(bool loop)
Sets the playing mode.
int16_t getBitResolution()
Returns the bit resolution.
void addToGroup(SoundEmitter *emitter)
Adds the emitter to group.
float getConeInnerAngle() const
Return inner angle of the sound cone, in degrees.
void addListener(SoundEmitterListener *listener)
Adds new SoundEmitter listener.
void releaseSource(SoundEmitter *emitter)
Release the source handle.
float m_samplesOffset
saves sample offset for played stream parts
bool isRelativePositioning() const
Return Positioning-Type.
void removeListener(SoundEmitterListener *listener)
Removes associated SoundEmitter listener.
std::iterator_traits< octet_iterator >::difference_type distance(octet_iterator first, octet_iterator last)
SoundStateType soundState
virtual SoundClipPtr get(const std::string &name)
Gets a shared pointer to the SoundClip.
bool m_fadeIn
fade in clip
void callOnSoundFinished()
Calls the Listeners if a sound finished.
uint64_t getDuration()
Returns the duration of the sound clip in milliseconds.
void quitStreaming(uint32_t streamid)
Quits Streaming.
void addEffect(SoundEffect *effect)
Adds effect.
ALuint * getBuffers(uint32_t streamid=0) const
Returns the array of buffers for queuing.
void setReferenceDistance(float distance)
Sets the distance under which the volume for the SoundEmitter would normally drop by half (before bei...
void activateFilter(SoundFilter *filter, SoundEmitter *emitter)
Internal function to do the OpenAL calls to activate the SoundFilter for the SoundEmitter.
int16_t getBitResolution() const
Returns the bit resolution.
float getConeOuterAngle() const
Return outer angle of the sound cone, in degrees.
void setDirection(const AudioSpaceCoordinate &direction)
Sets the direction of the SoundEmitter in the virtual audio space.
uint64_t getDecodedLength()
Returns the length of the decoded length in bytes.
SoundClipPtr getSoundClip()
Get the current sound clip used by this emitter.
void rewind()
Rewinds the associated audio file.
void setMinGain(float gain)
Sets the min.
AudioSpaceCoordinate position
uint8_t getEffectNumber(SoundEffect *effect)
Return the number of the given effect.
void releaseEmitter(uint32_t emitterId)
Release an emitter-instance given by emitter-id.
uint32_t m_playCheckDifference
time difference between play and first check
void resetInternData()
Resets collected data to defaults.
SoundEmitter(SoundManager *manager, uint32_t uid)
uint32_t m_soundClipId
Id of the attached sound clip.
SoundManager * m_manager
Access to the SoundManager.
void setConeInnerAngle(float inner)
Sets inner angle of the sound cone, in degrees.
void stop()
Stops playing the audio file and rewinds to the beginning.
ResourceHandle getHandle()
AudioSpaceCoordinate getPosition() const
Return the position of the SoundEmitter in the virtual audio space.
void setRolloff(float rolloff)
Sets the AL_ROLEOFF_FACTOR.
void setVelocity(const AudioSpaceCoordinate &velocity)
Sets the velocity of the SoundEmitter in the virtual audio space.
void setSoundClip(SoundClipPtr soundClip)
Sets the sound clip to be used by this emitter.
float getReferenceDistance() const
Return the reference distance.
bool setStreamPos(uint32_t streamid, SoundPositionType type, float value)
Sets the stream position.
uint32_t beginStreaming()
Starts streaming the soundclip.
AudioSpaceCoordinate velocity
bool isActive() const
Returns true if audio module is active.
void deactivateEffects()
Deactivates effects if the Emitter loses the openAL-source.
SoundFilter * getDirectFilter()
Return the direct filter.
bool isFinished()
Returns true if clip is finished.