Leviathan  0.8.0.0
Leviathan game engine
Leviathan::ProceduralSoundData Class Reference

The main usable class for doing procedural audio. More...

#include <ProceduralSound.h>

+ Inheritance diagram for Leviathan::ProceduralSoundData:

Classes

struct  SoundProperties
 

Public Member Functions

DLLEXPORT ~ProceduralSoundData ()
 
DLLEXPORT int ReadAudioData (void *output, int amount)
 
DLLEXPORT bool IsValid () const
 
DLLEXPORT void Detach ()
 Permanently detaches this source from the callback. More...
 
 REFERENCE_COUNTED_PTR_TYPE (ProceduralSoundData)
 
- Public Member Functions inherited from Leviathan::ReferenceCounted
 ReferenceCounted (const ReferenceCounted &other)=delete
 
ReferenceCountedoperator= (const ReferenceCounted &other)=delete
 
FORCE_INLINE void AddRef ()
 
FORCE_INLINE void Release ()
 removes a reference and deletes the object if reference count reaches zero More...
 
int32_t GetRefCount () const
 Returns the reference count. More...
 
- Public Member Functions inherited from Leviathan::ThreadSafeGeneric< MutexType >
DLLEXPORT ThreadSafeGeneric ()
 
DLLEXPORT ~ThreadSafeGeneric ()
 
FORCE_INLINE void VerifyLock (RecursiveLock &guard) const
 
FORCE_INLINE void VerifyLock (Lock &lockit) const
 

Public Attributes

const SoundProperties Properties
 Properties for the ProceduralSoundStream to retrieve when needed. More...
 

Protected Member Functions

DLLEXPORT ProceduralSoundData (std::function< int(void *, int)> datacallback, SoundProperties &&properties)
 
- Protected Member Functions inherited from Leviathan::ReferenceCounted
DLLEXPORT ReferenceCounted ()
 
virtual DLLEXPORT ~ReferenceCounted ()
 

Protected Attributes

friend ReferenceCounted
 
std::atomic< bool > Detached = false
 
std::function< int(void *, int)> DataCallback
 Called each time the underlying audio stream requests more data. More...
 
- Protected Attributes inherited from Leviathan::ThreadSafeGeneric< MutexType >
MutexType ObjectsLock
 

Additional Inherited Members

- 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

The main usable class for doing procedural audio.

This can be passed to SoundDevice to get a playing stream that plays this data

Note
The stream will end if the callback doesn't return any data (so if you expect more data later return couple thousand 0s)
Todo:
Move all the other classes from this file to SoundInternalTypes.h

Definition at line 24 of file ProceduralSound.h.

Constructor & Destructor Documentation

◆ ProceduralSoundData()

DLLEXPORT ProceduralSoundData::ProceduralSoundData ( std::function< int(void *, int)>  datacallback,
SoundProperties &&  properties 
)
protected
See also
readAudioData for details about the datacallback

Definition at line 6 of file ProceduralSound.cpp.

7  :
8  Properties(properties),
9  DataCallback(datacallback)
10 {
11 }
std::function< int(void *, int)> DataCallback
Called each time the underlying audio stream requests more data.
const SoundProperties Properties
Properties for the ProceduralSoundStream to retrieve when needed.

◆ ~ProceduralSoundData()

DLLEXPORT ProceduralSoundData::~ProceduralSoundData ( )

Definition at line 13 of file ProceduralSound.cpp.

13 {}

Member Function Documentation

◆ Detach()

DLLEXPORT void ProceduralSoundData::Detach ( )

Permanently detaches this source from the callback.

After this call finishes the callback won't be called again

Definition at line 15 of file ProceduralSound.cpp.

16 {
17  GUARD_LOCK();
18 
19  Detached = true;
20 }
std::atomic< bool > Detached
#define GUARD_LOCK()
Definition: ThreadSafe.h:97

◆ IsValid()

DLLEXPORT bool Leviathan::ProceduralSoundData::IsValid ( ) const
inline

Definition at line 67 of file ProceduralSound.h.

68  {
69  return !Detached;
70  }
std::atomic< bool > Detached

◆ ReadAudioData()

DLLEXPORT int Leviathan::ProceduralSoundData::ReadAudioData ( void *  output,
int  amount 
)
inline

Reads a section of data out of the audio stream by running the callback

Parameters
outputPointer to the buffer to put the decoded audio
amountAmount of data in bytes to ask the decoder to output. This is also the size of output
Returns
Number of bytes of audio data actually written to output

Definition at line 60 of file ProceduralSound.h.

61  {
62  GUARD_LOCK();
63 
64  return DataCallback(output, amount);
65  }
std::function< int(void *, int)> DataCallback
Called each time the underlying audio stream requests more data.
#define GUARD_LOCK()
Definition: ThreadSafe.h:97

◆ REFERENCE_COUNTED_PTR_TYPE()

Leviathan::ProceduralSoundData::REFERENCE_COUNTED_PTR_TYPE ( ProceduralSoundData  )

Member Data Documentation

◆ DataCallback

std::function<int(void*, int)> Leviathan::ProceduralSoundData::DataCallback
protected

Called each time the underlying audio stream requests more data.

Definition at line 89 of file ProceduralSound.h.

◆ Detached

std::atomic<bool> Leviathan::ProceduralSoundData::Detached = false
protected

If set to true then this will no longer call the data callback. This can be used to safely let go of a procedural audio before destroying the whatever source that DataCallback uses

Definition at line 86 of file ProceduralSound.h.

◆ Properties

const SoundProperties Leviathan::ProceduralSoundData::Properties

Properties for the ProceduralSoundStream to retrieve when needed.

Definition at line 80 of file ProceduralSound.h.

◆ ReferenceCounted

friend Leviathan::ProceduralSoundData::ReferenceCounted
protected

Definition at line 46 of file ProceduralSound.h.


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