Leviathan  0.8.0.0
Leviathan game engine
Leviathan::AudioSource Class Reference

Small ReferenceCounted wrapper around an audio source. More...

#include <AudioSource.h>

+ Inheritance diagram for Leviathan::AudioSource:

Public Member Functions

DLLEXPORT ~AudioSource ()
 
DLLEXPORT bool HasInternalSource () const
 
DLLEXPORT void Play2D (const Sound::AudioBuffer::pointer &buffer)
 
DLLEXPORT void PlayWithDecoder (const Sound::ProceduralSoundData::pointer &data, size_t chunksize=12000, size_t chunkstoqueue=4)
 
DLLEXPORT void Resume ()
 
DLLEXPORT void Stop ()
 
DLLEXPORT void Pause ()
 
DLLEXPORT bool IsPlaying () const
 Also returns true if the source will start playing once a buffer is loaded. More...
 
DLLEXPORT void SetVolume (float volume)
 
DLLEXPORT void SetGain (float gain)
 
DLLEXPORT void SetLooping (bool looping)
 
 REFERENCE_COUNTED_PTR_TYPE (AudioSource)
 
- Public Member Functions inherited from Leviathan::GUI::JSProxyable
 JSProxyable (int id=IDFactory::GetID())
 
virtual ~JSProxyable ()
 
int GetID () const
 
- Public Member Functions inherited from Leviathan::ReferenceCounted
 ReferenceCounted (const ReferenceCounted &other)=delete
 
ReferenceCountedoperator= (const ReferenceCounted &other)=delete
 
FORCE_INLINE void AddRef () const
 
FORCE_INLINE void Release () const
 removes a reference and deletes the object if reference count reaches zero More...
 
FORCE_INLINE void AddRef ()
 
FORCE_INLINE void Release ()
 
int32_t GetRefCount () const
 Returns the reference count. More...
 

Protected Member Functions

DLLEXPORT AudioSource (alure::Source sourcetowrap)
 
- Protected Member Functions inherited from Leviathan::ReferenceCounted
DLLEXPORT ReferenceCounted ()
 
virtual DLLEXPORT ~ReferenceCounted ()
 

Protected Attributes

friend ReferenceCounted
 
- Protected Attributes inherited from Leviathan::GUI::JSProxyable
const int ID
 

Additional Inherited Members

- Public Types inherited from Leviathan::GUI::JSProxyable
using pointer = boost::intrusive_ptr< JSProxyable >
 
- Public Types inherited from Leviathan::ReferenceCounted
using basepointer = boost::intrusive_ptr< ReferenceCounted >
 
using refcountedpointer = boost::intrusive_ptr< ReferenceCounted >
 
- Static Public Member Functions inherited from Leviathan::ReferenceCounted
template<class ActualType >
static boost::intrusive_ptr< ActualType > WrapPtr (ActualType *ptr)
 Creates an intrusive_ptr from raw pointer. More...
 
template<class ActualType , class... Args>
static boost::intrusive_ptr< ActualType > MakeShared (Args &&... args)
 Constructs a new instance and wraps it. More...
 

Detailed Description

Small ReferenceCounted wrapper around an audio source.

Definition at line 16 of file AudioSource.h.

Constructor & Destructor Documentation

◆ AudioSource()

DLLEXPORT AudioSource::AudioSource ( alure::Source  sourcetowrap)
protected

Definition at line 8 of file AudioSource.cpp.

8 : Source(sourcetowrap) {}

◆ ~AudioSource()

DLLEXPORT AudioSource::~AudioSource ( )

Definition at line 10 of file AudioSource.cpp.

11 {
12  if(Source) {
13 
14  if(Engine::Get()->IsOnMainThread()) {
15 
16  Source.destroy();
17 
18  } else {
19  Engine::Get()->Invoke([source = Source]() mutable { source.destroy(); });
20  }
21 
22  Source = nullptr;
23  }
24 
25  PlayedBuffer.reset();
26 }
DLLEXPORT void Invoke(const std::function< void()> &function)
Runs function on the main thread before the next tick.
Definition: Engine.cpp:1169
static DLLEXPORT Engine * Get()
Definition: Engine.cpp:86

Member Function Documentation

◆ HasInternalSource()

DLLEXPORT bool Leviathan::AudioSource::HasInternalSource ( ) const
inline

Definition at line 32 of file AudioSource.h.

33  {
34  // Returns true if the source has the impl pointer set
35  return Source.operator bool();
36  }

◆ IsPlaying()

DLLEXPORT bool Leviathan::AudioSource::IsPlaying ( ) const
inline

Also returns true if the source will start playing once a buffer is loaded.

Definition at line 59 of file AudioSource.h.

60  {
61  return Source.isPlayingOrPending();
62  }

◆ Pause()

DLLEXPORT void Leviathan::AudioSource::Pause ( )
inline

Definition at line 53 of file AudioSource.h.

54  {
55  Source.pause();
56  }

◆ Play2D()

DLLEXPORT void AudioSource::Play2D ( const Sound::AudioBuffer::pointer &  buffer)

Definition at line 28 of file AudioSource.cpp.

29 {
31 
32  PlayedBuffer = buffer;
33 
34  if(PlayedBuffer && PlayedBuffer->GetBuffer()) {
35 
36  Source.set3DSpatialize(alure::Spatialize::Off);
37  Source.play(PlayedBuffer->GetBuffer());
38 
39  } else {
40  Source.stop();
41  }
42 }
static DLLEXPORT Engine * Get()
Definition: Engine.cpp:86
DLLEXPORT void AssertIfNotMainThread() const
Asserts if not called on the main thread.
Definition: Engine.h:111

◆ PlayWithDecoder()

DLLEXPORT void AudioSource::PlayWithDecoder ( const Sound::ProceduralSoundData::pointer data,
size_t  chunksize = 12000,
size_t  chunkstoqueue = 4 
)

Definition at line 44 of file AudioSource.cpp.

46 {
48 
49  PlayedBuffer.reset();
50 
51  if(data) {
52 
53  Source.play(data, chunksize, chunkstoqueue);
54 
55  } else {
56  Source.stop();
57  }
58 }
static DLLEXPORT Engine * Get()
Definition: Engine.cpp:86
DLLEXPORT void AssertIfNotMainThread() const
Asserts if not called on the main thread.
Definition: Engine.h:111

◆ REFERENCE_COUNTED_PTR_TYPE()

Leviathan::AudioSource::REFERENCE_COUNTED_PTR_TYPE ( AudioSource  )

◆ Resume()

DLLEXPORT void Leviathan::AudioSource::Resume ( )
inline

Definition at line 43 of file AudioSource.h.

44  {
45  Source.resume();
46  }

◆ SetGain()

DLLEXPORT void Leviathan::AudioSource::SetGain ( float  gain)
inline

Definition at line 70 of file AudioSource.h.

71  {
72  Source.setGain(gain);
73  }

◆ SetLooping()

DLLEXPORT void Leviathan::AudioSource::SetLooping ( bool  looping)
inline

Definition at line 75 of file AudioSource.h.

76  {
77  Source.setLooping(looping);
78  }

◆ SetVolume()

DLLEXPORT void Leviathan::AudioSource::SetVolume ( float  volume)
inline
Parameters
volume0-1.f is normal range

Definition at line 65 of file AudioSource.h.

66  {
67  Source.setGain(volume);
68  }

◆ Stop()

DLLEXPORT void Leviathan::AudioSource::Stop ( )
inline

Definition at line 48 of file AudioSource.h.

49  {
50  Source.stop();
51  }

Member Data Documentation

◆ ReferenceCounted

friend Leviathan::AudioSource::ReferenceCounted
protected

Definition at line 20 of file AudioSource.h.


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