Main Page | Modules | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

ark::SoundPlayer Class Reference

#include <SoundPlayer.h>

Inheritance diagram for ark::SoundPlayer:

ark::Observer< impl::_SoundPlayerNotification > List of all members.

Public Types

typedef impl::_SoundPlayerNotification Notification
 This is the sound notification type. It contains all necessary data to update observers.
typedef GenericCommand< SoundPlayerCommand
 Used to issue commands to the realtime thread context.
typedef AsyncNotifier< Notification,
Observer< Notification >,
SoundPlayer
Notifier
typedef Overflow_Template<
Command
ParamOverflow
 These exceptions are only thrown from a NON realtime NON render thread.
enum  NotificationType {
  PlayingDidChange, PlayPositionDidChange, PlayingDidLoop, LoopingDidChange,
  AmplitudeModDidChange, BalanceDidChange, SelectedRegionDidChange, StreamErrorOccured
}
enum  StreamError { UnknownError, UnderflowError, ParamError }

Public Member Functions

 SoundPlayer ()
 ~SoundPlayer ()
void receiveNotification (Notification const &note)
void initialize ()
void uninitialize ()
void open (std::string const &path)
void setResource (boost::shared_ptr< SoundResource > const &rsrc)
void setResource (SoundChunk const &chunk, unsigned sampleRate)
bool isOpen () const
void close ()
void setLive (bool b)
bool isLive () const
void setAmplitudeMod (float mod)
float amplitudeMod () const
void setBalance (float mod)
float balance () const
unsigned frameCount () const
unsigned channelCount () const
unsigned sampleRate () const
void play ()
void pause (bool wait=false)
bool togglePlaying ()
void stop (bool wait=false)
bool isPlaying () const
unsigned playPosition () const
void setPlayPosition (unsigned pos)
void setLooping (bool b)
bool isLooping () const
bool toggleLooping ()
void setMute (bool b)
bool isMute () const
bool toggleMute ()
unsigned nextChunk (SoundChunk &chunk, unsigned frames, SoundTime const &time)

Static Public Member Functions

static unsigned defaultRenderFrames ()
static void setDefaultRenderFrames (unsigned)
static unsigned defaultCacheFrames ()
static void setDefaultCacheFrames (unsigned)
static bool doesNotifyByDefault ()
static void setNotifiesByDefault (bool)
static boost::shared_ptr<
Notifier
notifier ()

Protected Types

typedef boost::mutex::scoped_lock scoped_lock

Private Member Functions

void _rtSetPlayPosition (Notification const &)
void _rtSetSelectedRegion (Notification const &)
void _rtSetAmpMod (Notification const &)
void _rtSetBalance (Notification const &)
void _rtSetCurrentTime (SoundTime const &t)
void _rtIncrementTime (unsigned frames)
SoundTime const & _rtCurrentTime () const
void _resetState ()
void _scheduleNotification (Notification const &)
void _rtStreamMaintenance (SoundTime const &)
bool _rtReceiveFromStreamer ()
void _rtUpdateParams ()
void _rtApplyParams (SoundChunk &)
void _rtStop (Notification const &)
void _rtSendNotification (Notification const &)

Private Attributes

boost::mutex _genMutex
 Generic instance mutex.
boost::shared_ptr< SoundStreamer_streamer
boost::shared_ptr< Fifo< SoundStreamerChunk > > _streamQueue
SoundChunk _cacheChunk
 Cached data.
unsigned _renderChunkSize
 The size of the chunk the render thread will request.
unsigned _cacheChunkSize
 The size of the cache, in frames.
SoundRegion _cacheReg
 The region of sound that the cache stores.
unsigned _minCacheSpace
 The threshold for ordering more chunks.
volatile bool _waitingForCache
 True if we are waiting for a chunk from the feeder.
unsigned _playPos
 The read head of the sound player.
volatile unsigned _rt_playPos
unsigned _playerRate
 The sample rate of the player.
Atomic< bool > _play
 True if we should keep playing.
Atomic< bool > _loop
 True if we should loop.
Atomic< bool > _mute
Atomic< bool > _doNotify
double _logicFrameMod
Fifo< Command_paramPort
 This sends the parameter changes to the realtime context.
Semaphore _fromRtSem
 This is a generic signal semaphore for RT to USER communication.
Atomic< bool > _didSignal
SoundRegion _selectedReg
SoundRegion _rt_selectedReg
SoundRegion _pendingReg
bool _regIsPending
float _ampMod
float _rt_ampMod
float _rt_lastAmp
float _balance
float _rt_balance
float _rt_lastBal
SoundTime _rt_curTime

Static Private Attributes

static boost::shared_ptr<
Notifier
_notifier = shared_ptr<SoundPlayer::Notifier>()
static boost::shared_ptr<
MessagePort< Notification > > 
_noteQueue = shared_ptr<MessagePort<SoundPlayer::Notification> >()
static MemoryGate _rtGate = MemoryGate<>(ARK_SOUNDPLAYER_GATE_QUEUE_SIZE)
static MemoryDeallocServer _rtDeallocServer
static boost::mutex _sharedMutex
static const unsigned _paramTransFrames = 256
static unsigned _defaultRenderFrames = ARK_SOUNDPLAYER_DEFAULT_RENDER_FRAMES
static unsigned _defaultCacheFrames = ARK_SOUNDPLAYER_DEFAULT_CACHE_FRAMES
static bool _doesNotifyByDefault = ARK_SOUNDPLAYER_DOES_NOTIFY_BY_DEFAULT
static boost::mutex _staticDataMutex

Detailed Description

SoundPlayer


Member Typedef Documentation

typedef GenericCommand<SoundPlayer> ark::SoundPlayer::Command
 

Used to issue commands to the realtime thread context.

typedef impl::_SoundPlayerNotification ark::SoundPlayer::Notification
 

This is the sound notification type. It contains all necessary data to update observers.

Types

typedef AsyncNotifier<Notification, Observer<Notification>, SoundPlayer> ark::SoundPlayer::Notifier
 

typedef Overflow_Template<Command> ark::SoundPlayer::ParamOverflow
 

These exceptions are only thrown from a NON realtime NON render thread.

typedef boost::mutex::scoped_lock ark::SoundPlayer::scoped_lock [protected]
 


Member Enumeration Documentation

enum ark::SoundPlayer::NotificationType
 

Enumerator:
PlayingDidChange  bool param is playing status.
PlayPositionDidChange  unsigned param is new play position, in logical frames.
PlayingDidLoop  tells us that the play cursor was reset, no parameter
LoopingDidChange  bool param is looping status.
AmplitudeModDidChange  float param is new amplitude mod.
BalanceDidChange  float param is new balance.
SelectedRegionDidChange  Region param is new region.
StreamErrorOccured  cast int param to StreamError.

enum ark::SoundPlayer::StreamError
 

Enumerator:
UnknownError 
UnderflowError 
ParamError 


Constructor & Destructor Documentation

SoundPlayer::SoundPlayer  ) 
 

SoundPlayer::~SoundPlayer  ) 
 


Member Function Documentation

void SoundPlayer::_resetState  )  [private]
 

void SoundPlayer::_rtApplyParams SoundChunk  )  [private]
 

SoundTime const & SoundPlayer::_rtCurrentTime  )  const [inline, private]
 

void SoundPlayer::_rtIncrementTime unsigned  frames  )  [inline, private]
 

bool SoundPlayer::_rtReceiveFromStreamer  )  [private]
 

void SoundPlayer::_rtSendNotification Notification const &   )  [private]
 

void SoundPlayer::_rtSetAmpMod Notification const &   )  [inline, private]
 

void SoundPlayer::_rtSetBalance Notification const &   )  [inline, private]
 

void SoundPlayer::_rtSetCurrentTime SoundTime const &  t  )  [inline, private]
 

void SoundPlayer::_rtSetPlayPosition Notification const &   )  [private]
 

void SoundPlayer::_rtSetSelectedRegion Notification const &   )  [inline, private]
 

void SoundPlayer::_rtStop Notification const &   )  [private]
 

void SoundPlayer::_rtStreamMaintenance SoundTime const &   )  [private]
 

void SoundPlayer::_rtUpdateParams  )  [private]
 

void SoundPlayer::_scheduleNotification Notification const &   )  [private]
 

float SoundPlayer::amplitudeMod  )  const
 

amplitudeMod

Returns:
The amplitude mod for this player
See also:
setAmplitudeMod()

float SoundPlayer::balance  )  const
 

balance

Returns:
The balance for this player
See also:
setBalance()

unsigned SoundPlayer::channelCount  )  const
 

channelCount

Returns:
The channel count for the loaded resource, or 0 if no resource is loaded

void SoundPlayer::close  ) 
 

close Stops the player and closes any open resources. This function blocks while waiting for stop confirmation.

See also:
open()

setResource()

stop()

unsigned SoundPlayer::defaultCacheFrames  )  [static]
 

unsigned SoundPlayer::defaultRenderFrames  )  [static]
 

bool SoundPlayer::doesNotifyByDefault  )  [static]
 

unsigned SoundPlayer::frameCount  )  const
 

frameCount

Returns:
The frame count for the loaded resource, or 0 if no resource is loaded

void SoundPlayer::initialize  ) 
 

initialize Initializes the player to a state in which the play() function will succeed.

See also:
uninitialize()

bool SoundPlayer::isLive  )  const
 

isLive

Returns:
True if the player is attached to a live audio sink
See also:
setLive()

bool SoundPlayer::isLooping  )  const
 

isLooping

Returns:
True if the player is looping
See also:
setLooping()

bool SoundPlayer::isMute  )  const
 

isMute

Returns:
True if this player is muted
See also:
setMute()

bool SoundPlayer::isOpen  )  const
 

isOpen

Returns:
True if the sound player has a sound resource to play.
See also:
open()

setResource()

close()

bool SoundPlayer::isPlaying  )  const
 

isPlaying

Returns:
True if the player is playing.
See also:
play()

pause()

stop()

unsigned SoundPlayer::nextChunk SoundChunk chunk,
unsigned  frames,
SoundTime const &  time
 

nextChunk Copies the next chunk in the sound to the passed chunk memory.

Parameters:
chunk The chunk of memory to copy the next sound chunk to
frames The amount of frames to copy
time The time according to the sound stream
Returns:
The number of frames put in the chunk

shared_ptr< SoundPlayer::Notifier > SoundPlayer::notifier  )  [static]
 

void ark::SoundPlayer::open std::string const &  path  ) 
 

open Opens the file at the specififed path. Stops and closes any currently open resource. This function blocks while waiting for stop confirmation.

Parameters:
path The file path of the sound resource to open
See also:
setResource()

close()

void SoundPlayer::pause bool  wait = false  ) 
 

pause Sets up the player so that the next call to nextChunk() will clear the passed chunk and return immediatly. If wait is true, pause blocks until it receives confirmation that the player is paused.

Parameters:
wait Whether to wait for pause confirmation or not
See also:
play()

stop()

void SoundPlayer::play  ) 
 

play Sets the player up so that on the next call to nextChunk() it will return a chunk from it's loaded resource (if any).

See also:
pause()

stop()

unsigned SoundPlayer::playPosition  )  const
 

playPosition

Returns:
The position of the play cursor, in range (0, this->frameCount()]
See also:
setPlayPosition()

void SoundPlayer::receiveNotification Notification const &  note  )  [virtual]
 

receiveNotification Receives a notification concerning this from the standard notifier thread. Checks for param changes and propogates them to user readable objects in a thread-safe manner. This should NEVER be called from the realtime context.

Parameters:
note The notification received

Implements ark::Observer< impl::_SoundPlayerNotification >.

unsigned SoundPlayer::sampleRate  )  const
 

sampleRate

Returns:
The sample rate of this player

void SoundPlayer::setAmplitudeMod float  mod  ) 
 

setAmplitudeMod

Parameters:
mod The new amplitude mod for this player
See also:
amplitudeMod()

void SoundPlayer::setBalance float  mod  ) 
 

setBalance

Parameters:
mod The new balance for this player
See also:
balance()

void SoundPlayer::setDefaultCacheFrames unsigned   )  [static]
 

void SoundPlayer::setDefaultRenderFrames unsigned   )  [static]
 

void SoundPlayer::setLive bool  b  ) 
 

setLive Sets whether the player is attached to a live sink, that is if it receives periodic 'pull' requests. If live is false, a worker thread is marshalled to keep the player queues moving, thus allowing offline editing.

Parameters:
b True if the player is attached to a live audio sink

void SoundPlayer::setLooping bool  b  ) 
 

setLooping

Parameters:
b Whether to loop the sound or not
See also:
isLooping()

void SoundPlayer::setMute bool  b  ) 
 

setMute

Parameters:
b Whether this player should be mute or not
See also:
isMute()

void SoundPlayer::setNotifiesByDefault bool   )  [static]
 

void SoundPlayer::setPlayPosition unsigned  pos  ) 
 

setPlayPosition

Parameters:
pos The new position of the play cursor, must be in range (0, this->frameCount()]
See also:
playPosition()

void SoundPlayer::setResource SoundChunk const &  chunk,
unsigned  sampleRate
 

setResource Stops and closes any currently open resource, and sets the passed chunk to be the in memory data source. Note that a side effect is that the streamer thread will be terminated. This function blocks while waiting for stop confirmation.

Parameters:
chunk The chunk of data sto use as the sound source buffer
sampleRate The sample rate of the passed sound buffer
See also:
open()

close()

void ark::SoundPlayer::setResource boost::shared_ptr< SoundResource > const &  rsrc  ) 
 

setResource Stops and closes any currently open resource, and uses the passed resource as the new sound data source. This function blocks while waiting for stop confirmation.

Parameters:
rsrc The resource to use as the sound data source
See also:
open()

close()

void SoundPlayer::stop bool  wait = false  ) 
 

stop Sets up the player so that the play position is 0 and the next call to nextChunk() will clear the passed chunk and return immediatly. If wait is true, pause blocks until it receives confirmation that the player is stopped.

Parameters:
wait Whether to wait for stop confirmation or not
See also:
play()

pause()

bool SoundPlayer::toggleLooping  ) 
 

toggleLooping Toggles looping and returns loop status.

Returns:
True if the player is looping after this call
See also:
setLooping()

bool SoundPlayer::toggleMute  ) 
 

toggleMute Toggles muting and returns mute status.

Returns:
True if the player is muted after this call
See also:
setMute()

bool SoundPlayer::togglePlaying  ) 
 

togglePlaying Toggles playback and returns play status.

Returns:
True if the player is playing after this call
See also:
play()

pause()

void SoundPlayer::uninitialize  ) 
 

uinitialize Uninitializes the player to a state in which all supporting structures are uninitailized.

See also:
initialize()


Member Data Documentation

float ark::SoundPlayer::_ampMod [private]
 

float ark::SoundPlayer::_balance [private]
 

SoundChunk ark::SoundPlayer::_cacheChunk [private]
 

Cached data.

unsigned ark::SoundPlayer::_cacheChunkSize [private]
 

The size of the cache, in frames.

SoundRegion ark::SoundPlayer::_cacheReg [private]
 

The region of sound that the cache stores.

unsigned SoundPlayer::_defaultCacheFrames = ARK_SOUNDPLAYER_DEFAULT_CACHE_FRAMES [static, private]
 

unsigned SoundPlayer::_defaultRenderFrames = ARK_SOUNDPLAYER_DEFAULT_RENDER_FRAMES [static, private]
 

Atomic<bool> ark::SoundPlayer::_didSignal [private]
 

bool SoundPlayer::_doesNotifyByDefault = ARK_SOUNDPLAYER_DOES_NOTIFY_BY_DEFAULT [static, private]
 

Atomic<bool> ark::SoundPlayer::_doNotify [private]
 

Semaphore ark::SoundPlayer::_fromRtSem [private]
 

This is a generic signal semaphore for RT to USER communication.

boost::mutex ark::SoundPlayer::_genMutex [mutable, private]
 

Generic instance mutex.

double ark::SoundPlayer::_logicFrameMod [private]
 

Multiply this by the _streamer->frameCount() to get the amount of frames after any time distorting operations, like sample rate conversion or time stretching.

Atomic<bool> ark::SoundPlayer::_loop [private]
 

True if we should loop.

unsigned ark::SoundPlayer::_minCacheSpace [private]
 

The threshold for ordering more chunks.

Atomic<bool> ark::SoundPlayer::_mute [private]
 

shared_ptr< MessagePort< SoundPlayer::Notification > > SoundPlayer::_noteQueue = shared_ptr<MessagePort<SoundPlayer::Notification> >() [static, private]
 

shared_ptr< SoundPlayer::Notifier > SoundPlayer::_notifier = shared_ptr<SoundPlayer::Notifier>() [static, private]
 

Fifo<Command> ark::SoundPlayer::_paramPort [private]
 

This sends the parameter changes to the realtime context.

const unsigned SoundPlayer::_paramTransFrames = 256 [static, private]
 

SoundRegion ark::SoundPlayer::_pendingReg [private]
 

Atomic<bool> ark::SoundPlayer::_play [private]
 

True if we should keep playing.

unsigned ark::SoundPlayer::_playerRate [private]
 

The sample rate of the player.

unsigned ark::SoundPlayer::_playPos [private]
 

The read head of the sound player.

bool ark::SoundPlayer::_regIsPending [private]
 

unsigned ark::SoundPlayer::_renderChunkSize [private]
 

The size of the chunk the render thread will request.

float ark::SoundPlayer::_rt_ampMod [private]
 

float ark::SoundPlayer::_rt_balance [private]
 

SoundTime ark::SoundPlayer::_rt_curTime [private]
 

float ark::SoundPlayer::_rt_lastAmp [private]
 

float ark::SoundPlayer::_rt_lastBal [private]
 

volatile unsigned ark::SoundPlayer::_rt_playPos [private]
 

SoundRegion ark::SoundPlayer::_rt_selectedReg [private]
 

MemoryDeallocServer SoundPlayer::_rtDeallocServer [static, private]
 

MemoryGate SoundPlayer::_rtGate = MemoryGate<>(ARK_SOUNDPLAYER_GATE_QUEUE_SIZE) [static, private]
 

SoundRegion ark::SoundPlayer::_selectedReg [private]
 

mutex SoundPlayer::_sharedMutex [static, private]
 

mutex SoundPlayer::_staticDataMutex [static, private]
 

boost::shared_ptr<SoundStreamer> ark::SoundPlayer::_streamer [private]
 

boost::shared_ptr<Fifo<SoundStreamerChunk> > ark::SoundPlayer::_streamQueue [private]
 

volatile bool ark::SoundPlayer::_waitingForCache [private]
 

True if we are waiting for a chunk from the feeder.


The documentation for this class was generated from the following files:
Generated on Tue Sep 6 14:54:42 2005 for Arkonnekt Sound by  doxygen 1.4.4