YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
PlayerModule Class Reference
+ Inheritance diagram for PlayerModule:

Public Member Functions

bool play (const std::string &filename) override
 Play the given audio file.
 
bool test (const std::string &type, const double duration, const double frequency, const std::int16_t amplitude, const std::int16_t sampling_rate, const std::int16_t channels) override
 Generate and send a test sound.
 
- Public Member Functions inherited from yarp::os::RFModule
 RFModule ()
 Constructor.
 
virtual ~RFModule ()
 Destructor.
 
virtual int runModule ()
 Calls updateModule() until that returns false.
 
virtual int runModule (yarp::os::ResourceFinder &rf)
 Simple helper method to call configure() and then runModule().
 
virtual int runModuleThreaded ()
 Calls updateModule() on a separate thread until that returns false.
 
virtual int runModuleThreaded (yarp::os::ResourceFinder &rf)
 Simple helper method to call configure() and then runModule() on a separate thread.
 
virtual int getThreadKey ()
 return the Thread unique identifier
 
virtual bool respond (const Bottle &command, Bottle &reply)
 Respond to a message.
 
virtual bool attach (yarp::os::Port &source)
 Make any input from a Port object go to the respond() method.
 
virtual bool attach (yarp::os::RpcServer &source)
 Make any input from an RpcServer object go to the respond() method.
 
bool attachTerminal ()
 Make any input from standard input (usually the keyboard) go to the respond() method.
 
bool detachTerminal ()
 Detach terminal.
 
virtual bool interruptModule ()
 Try to halt any ongoing operations by threads managed by the module.
 
void stopModule (bool wait=false)
 Ask the module to stop.
 
bool isStopping ()
 Check if the module should stop.
 
bool joinModule (double seconds=-1)
 The function returns when the thread execution has completed.
 
std::string getName (const std::string &subName="")
 Return name of module, as set with setName().
 
void setName (const char *name)
 Set the name of the module.
 
bool safeRespond (const Bottle &command, Bottle &reply)
 Wrapper around respond() that is guaranteed to process system messages.
 
- Public Member Functions inherited from yarpAudioPlayer_IDL
virtual yarp::os::ApplicationNetworkProtocolVersion getLocalProtocolVersion ()
 
virtual yarp::os::ApplicationNetworkProtocolVersion getRemoteProtocolVersion ()
 
virtual bool checkProtocolVersion ()
 
 yarpAudioPlayer_IDL ()
 
virtual std::vector< std::string > help (const std::string &functionName="--all")
 
bool read (yarp::os::ConnectionReader &connection) override
 Read this object from a network connection.
 
- Public Member Functions inherited from yarp::os::Wire
yarp::os::WireLink & yarp ()
 Get YARP state associated with this object.
 
const yarp::os::WireLink & yarp () const
 Get YARP state associated with this object (const version).
 
- Public Member Functions inherited from yarp::os::PortReader
virtual ~PortReader ()
 Destructor.
 
virtual Type getReadType () const
 

Protected Member Functions

bool openFile (const std::string &file_name)
 
bool send ()
 
bool configure (yarp::os::ResourceFinder &rf) override
 Configure the module, pass a ResourceFinder object to the module.
 
bool close () override
 Close function.
 
virtual double getPeriod () override
 You can override this to control the approximate periodicity at which updateModule() is called by runModule().
 
bool updateModule () override
 Override this to do whatever your module needs to do.
 

Protected Attributes

std::string m_name = "/yarpAudioPlayer"
 
yarp::sig::Sound m_audioFile
 
yarp::os::Port m_audioPort
 
yarp::os::Port m_rpcPort
 
size_t m_split_size = 16000
 

Detailed Description

Definition at line 18 of file yarpAudioPlayer.cpp.

Member Function Documentation

◆ close()

bool PlayerModule::close ( )
inlineoverrideprotectedvirtual

Close function.

This is called automatically when the module closes, after the last call to updateModule. Override this to cleanup memory allocated in the configure() function or perform other activities that ensure graceful shutdown.

Returns
true/false on success failure.

Reimplemented from yarp::os::RFModule.

Definition at line 73 of file yarpAudioPlayer.cpp.

◆ configure()

bool PlayerModule::configure ( yarp::os::ResourceFinder &  rf)
inlineoverrideprotectedvirtual

Configure the module, pass a ResourceFinder object to the module.

This function can perform initialization including object creation and memory allocation; returns false to notify that initialization was not successful and that the module should not start. Cleanup should be performed by the function close(). In case of failure during the initialization and before returning false, the function configure() should cleanup memory and resources allocated.

Parameters
rfa previously initialized ResourceFinder
Returns
true/false upon success/failure
Note
attachTerminal() is no longer called automatically. You can call it in the configure function.

Reimplemented from yarp::os::RFModule.

Definition at line 36 of file yarpAudioPlayer.cpp.

◆ getPeriod()

virtual double PlayerModule::getPeriod ( )
inlineoverrideprotectedvirtual

You can override this to control the approximate periodicity at which updateModule() is called by runModule().

By default, it returns 1.0. Time here is in seconds.

Returns
the desired period between successive calls to updateModule()

Reimplemented from yarp::os::RFModule.

Definition at line 80 of file yarpAudioPlayer.cpp.

◆ openFile()

bool PlayerModule::openFile ( const std::string &  file_name)
protected

Definition at line 148 of file yarpAudioPlayer.cpp.

◆ play()

bool PlayerModule::play ( const std::string &  filename)
overridevirtual

Play the given audio file.

Returns
true/false on success/failure

Reimplemented from yarpAudioPlayer_IDL.

Definition at line 114 of file yarpAudioPlayer.cpp.

◆ send()

bool PlayerModule::send ( )
protected

Definition at line 168 of file yarpAudioPlayer.cpp.

◆ test()

bool PlayerModule::test ( const std::string &  type,
const double  duration,
const double  frequency,
const std::int16_t  amplitude,
const std::int16_t  sampling_rate,
const std::int16_t  channels 
)
overridevirtual

Generate and send a test sound.

Parameters
typecan be "sine" , "sawtooth" , "squarewave"
durationthe duration of the sound in seconds
frequencythe signal in hertz
amplitudethe amplitude of the signal (16 bit)
channelsnumber of channels
sampling_ratesignal sampling rate (samples/s)
Returns
true/false on success/failure

Reimplemented from yarpAudioPlayer_IDL.

Definition at line 125 of file yarpAudioPlayer.cpp.

◆ updateModule()

bool PlayerModule::updateModule ( )
inlineoverrideprotectedvirtual

Override this to do whatever your module needs to do.

When your module wants to stop, return false. The module's actual work could be done during this call, or it could just check the state of a thread running in the background.

The thread calls the updateModule() function every <period> seconds. At the end of each run, the thread will sleep the amounth of time required, taking into account the time spent inside the loop function. Example: requested period is 10ms, the updateModule() function take 3ms to be executed, the thread will sleep for 7ms.

Note: after each run is completed, the thread will call a yield() in order to facilitate other threads to run.

Returns
true iff module should continue

Implements yarp::os::RFModule.

Definition at line 85 of file yarpAudioPlayer.cpp.

Member Data Documentation

◆ m_audioFile

yarp::sig::Sound PlayerModule::m_audioFile
protected

Definition at line 22 of file yarpAudioPlayer.cpp.

◆ m_audioPort

yarp::os::Port PlayerModule::m_audioPort
protected

Definition at line 23 of file yarpAudioPlayer.cpp.

◆ m_name

std::string PlayerModule::m_name = "/yarpAudioPlayer"
protected

Definition at line 21 of file yarpAudioPlayer.cpp.

◆ m_rpcPort

yarp::os::Port PlayerModule::m_rpcPort
protected

Definition at line 24 of file yarpAudioPlayer.cpp.

◆ m_split_size

size_t PlayerModule::m_split_size = 16000
protected

Definition at line 25 of file yarpAudioPlayer.cpp.


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