ManaPlus
Public Member Functions | Protected Attributes
SoundEffect Class Reference

#include <soundeffect.h>

Inheritance diagram for SoundEffect:
Resource MemoryCounter

Public Member Functions

 SoundEffect (Mix_Chunk *const soundEffect, const std::string &name)
 
 ~SoundEffect ()
 
bool play (const int loops, const int volume, const int channel) const
 
int calcMemoryLocal () const
 
std::string getCounterName () const
 
- Public Member Functions inherited from Resource
 Resource ()
 
 ~Resource ()
 
virtual void incRef ()
 
virtual void decRef ()
 
- Public Member Functions inherited from MemoryCounter
 MemoryCounter ()
 
virtual ~MemoryCounter ()
 
int calcMemory (const int level) const
 
virtual int calcMemoryChilds (const int level) const
 

Protected Attributes

std::string mName
 
Mix_Chunk * mChunk
 

Additional Inherited Members

- Data Fields inherited from Resource
time_t mTimeStamp
 
std::string mIdPath
 
std::string mSource
 
unsigned int mRefCount
 
bool mProtected
 
bool mNotCount
 

Detailed Description

Defines a class for loading and storing sound effects.

Definition at line 39 of file soundeffect.h.

Constructor & Destructor Documentation

◆ SoundEffect()

SoundEffect::SoundEffect ( Mix_Chunk *const  soundEffect,
const std::string &  name 
)
inline

Constructor.

Definition at line 45 of file soundeffect.h.

46  :
47  Resource(),
48  mName(name),
49  mChunk(soundEffect)
50  { }
Resource()
Definition: resource.h:40
Mix_Chunk * mChunk
Definition: soundeffect.h:80
std::string mName
Definition: soundeffect.h:79

Referenced by calcMemoryLocal().

◆ ~SoundEffect()

SoundEffect::~SoundEffect ( )

Destructor.

Definition at line 28 of file soundeffect.cpp.

29 {
30  Mix_FreeChunk(mChunk);
31 }

References mChunk.

Member Function Documentation

◆ calcMemoryLocal()

int SoundEffect::calcMemoryLocal ( ) const
virtual

Reimplemented from Resource.

Definition at line 41 of file soundeffect.cpp.

42 {
43  return static_cast<int>(sizeof(SoundEffect) +
44  sizeof(SDL_AudioSpec)) +
46 }
int calcMemoryLocal() const
Definition: resource.cpp:76
SoundEffect(Mix_Chunk *const soundEffect, const std::string &name)
Definition: soundeffect.h:45

References Resource::calcMemoryLocal(), and SoundEffect().

◆ getCounterName()

std::string SoundEffect::getCounterName ( ) const
inlinevirtual

Reimplemented from Resource.

Definition at line 75 of file soundeffect.h.

76  { return mName; }

References mName.

◆ play()

bool SoundEffect::play ( const int  loops,
const int  volume,
const int  channel 
) const

Plays the sample.

Parameters
loopsNumber of times to repeat the playback.
volumeSample playback volume.
channelSample playback channel.
Returns
true if the playback started properly false otherwise.

Definition at line 33 of file soundeffect.cpp.

35 {
36  Mix_VolumeChunk(mChunk, volume);
37 
38  return Mix_PlayChannelTimed(channel, mChunk, loops, -1) != -1;
39 }

References mChunk.

Referenced by SoundManager::playGuiSfx(), and SoundManager::playSfx().

Field Documentation

◆ mChunk

Mix_Chunk* SoundEffect::mChunk
protected

Definition at line 80 of file soundeffect.h.

Referenced by play(), and ~SoundEffect().

◆ mName

std::string SoundEffect::mName
protected

Definition at line 79 of file soundeffect.h.

Referenced by getCounterName().


The documentation for this class was generated from the following files: