YARP
Yet Another Robot Platform
PortAudioPlayerDeviceDriver Class Reference

portaudioPlayer: A device driver for an audio playback device wrapped by PortAudio library. More...

#include <portaudioPlayer/PortAudioPlayerDeviceDriver.h>

+ Inheritance diagram for PortAudioPlayerDeviceDriver:

Public Member Functions

 PortAudioPlayerDeviceDriver ()
 
 PortAudioPlayerDeviceDriver (const PortAudioPlayerDeviceDriver &)=delete
 
 PortAudioPlayerDeviceDriver (PortAudioPlayerDeviceDriver &&)=delete
 
PortAudioPlayerDeviceDriveroperator= (const PortAudioPlayerDeviceDriver &)=delete
 
PortAudioPlayerDeviceDriveroperator= (PortAudioPlayerDeviceDriver &&)=delete
 
 ~PortAudioPlayerDeviceDriver () override
 
bool open (yarp::os::Searchable &config) override
 Open the DeviceDriver. More...
 
bool close () override
 Close the DeviceDriver. More...
 
void waitUntilPlaybackStreamIsComplete () override
 
bool setHWGain (double gain) override
 Sets the hardware gain of the playback device (if supported by the hardware) More...
 
bool interruptDeviceAndClose () override
 
bool startPlayback () override
 Start the playback. More...
 
bool stopPlayback () override
 Stop the playback. More...
 
void threadRelease () override
 Release method. More...
 
bool threadInit () override
 Initialization method. More...
 
void run () override
 Main body of the new thread. More...
 
- Public Member Functions inherited from yarp::dev::AudioPlayerDeviceBase
virtual bool renderSound (const yarp::sig::Sound &sound) override
 Render a sound using a device (i.e. More...
 
virtual bool isPlaying (bool &playback_enabled) override
 Check if the playback has been enabled (e.g. More...
 
virtual bool getPlaybackAudioBufferMaxSize (yarp::dev::AudioBufferSize &size) override
 
virtual bool getPlaybackAudioBufferCurrentSize (yarp::dev::AudioBufferSize &size) override
 
virtual bool resetPlaybackAudioBuffer () override
 
virtual bool setSWGain (double gain) override
 Sets a software gain for the played audio. More...
 
virtual ~AudioPlayerDeviceBase ()
 
- Public Member Functions inherited from yarp::dev::IAudioRender
virtual ~IAudioRender ()
 Destructor. More...
 
- Public Member Functions inherited from yarp::dev::DeviceDriver
 ~DeviceDriver () override=default
 Destructor. More...
 
template<class T >
bool view (T *&x)
 Get an interface to the device driver. More...
 
virtual DeviceDrivergetImplementation ()
 Some drivers are bureaucrats, pointing at others. More...
 
- Public Member Functions inherited from yarp::os::IConfig
virtual ~IConfig ()
 Destructor. More...
 
virtual bool configure (Searchable &config)
 Change online parameters. More...
 
- Public Member Functions inherited from yarp::os::Thread
 Thread ()
 Constructor. More...
 
virtual ~Thread ()
 Destructor. More...
 
virtual void onStop ()
 Call-back, called while halting the thread (before join). More...
 
bool start ()
 Start the new thread running. More...
 
bool stop ()
 Stop the thread. More...
 
virtual void beforeStart ()
 Called just before a new thread starts. More...
 
virtual void afterStart (bool success)
 Called just after a new thread starts (or fails to start), this is executed by the same thread that calls start(). More...
 
bool isStopping ()
 Returns true if the thread is stopping (Thread::stop has been called). More...
 
bool isRunning ()
 Returns true if the thread is running (Thread::start has been called successfully and the thread has not stopped). More...
 
long int getKey ()
 Get a unique identifier for the thread. More...
 
int setPriority (int priority, int policy=-1)
 Set the priority and scheduling policy of the thread, if the OS supports that. More...
 
int getPriority ()
 Query the current priority of the thread, if the OS supports that. More...
 
int getPolicy ()
 Query the current scheduling policy of the thread, if the OS supports that. More...
 
bool join (double seconds=-1)
 The function returns when the thread execution has completed. More...
 
void setOptions (int stackSize=0)
 Set the stack size for the new thread. More...
 

Protected Member Functions

void handleError ()
 
- Protected Member Functions inherited from yarp::dev::AudioPlayerDeviceBase
virtual bool immediateSound (const yarp::sig::Sound &sound)
 
virtual bool appendSound (const yarp::sig::Sound &sound)
 
bool configurePlayerAudioDevice (yarp::os::Searchable &config, std::string device_name)
 

Protected Attributes

void * m_system_resource
 
int m_device_id
 
int m_driver_frame_size
 
- Protected Attributes inherited from yarp::dev::AudioPlayerDeviceBase
bool m_enable_buffer_autoclear = false
 
bool m_playback_enabled = false
 
std::recursive_mutex m_mutex
 
yarp::dev::CircularAudioBuffer_16tm_outputBuffer = nullptr
 
AudioDeviceDriverSettings m_audioplayer_cfg
 
double m_sw_gain = 1.0
 
double m_hw_gain = 1.0
 
bool m_audiobase_debug = false
 
enum yarp::dev::AudioPlayerDeviceBase:: { ... }  m_renderMode = RENDER_APPEND
 

Additional Inherited Members

- Static Public Member Functions inherited from yarp::os::Thread
static int getCount ()
 Check how many threads are running. More...
 
static long int getKeyOfCaller ()
 Get a unique identifier for the calling thread. More...
 
static void yield ()
 Reschedule the execution of current thread, allowing other threads to run. More...
 
static void setDefaultStackSize (int stackSize)
 Set the default stack size for all threads created after this point. More...
 
- Protected Types inherited from yarp::dev::AudioPlayerDeviceBase
enum  {
  RENDER_APPEND = 0 ,
  RENDER_IMMEDIATE = 1
}
 

Detailed Description

portaudioPlayer: A device driver for an audio playback device wrapped by PortAudio library.

Requires the PortAudio library (http://www.portaudio.com), at least v19. Only 16bits sample format is currently supported by this device. This device driver derives from AudioPlayerDeviceBase base class. Please check its documentation for additional details.

Parameters used by this device are:

Parameter name SubParameter Type Units Default Value Required Description Notes
AUDIO_BASE *** - - No For the documentation of AUDIO_BASE group, please refer to the documentation of the base class AudioPlayerDeviceBase
id - int - - No The device id, if multiple sound cards are present if not specified, the default system device will be used

| driver_frame_size | - | int | samples | 512 | No | the number of samples to process on each iteration of the main thread | - | *

See Audio in YARP for additional documentation on YARP audio.

Definition at line 36 of file PortAudioPlayerDeviceDriver.h.

Constructor & Destructor Documentation

◆ PortAudioPlayerDeviceDriver() [1/3]

PortAudioPlayerDeviceDriver::PortAudioPlayerDeviceDriver ( )

Definition at line 171 of file PortAudioPlayerDeviceDriver.cpp.

◆ PortAudioPlayerDeviceDriver() [2/3]

PortAudioPlayerDeviceDriver::PortAudioPlayerDeviceDriver ( const PortAudioPlayerDeviceDriver )
delete

◆ PortAudioPlayerDeviceDriver() [3/3]

PortAudioPlayerDeviceDriver::PortAudioPlayerDeviceDriver ( PortAudioPlayerDeviceDriver &&  )
delete

◆ ~PortAudioPlayerDeviceDriver()

PortAudioPlayerDeviceDriver::~PortAudioPlayerDeviceDriver ( )
override

Definition at line 179 of file PortAudioPlayerDeviceDriver.cpp.

Member Function Documentation

◆ close()

bool PortAudioPlayerDeviceDriver::close ( )
overridevirtual

Close the DeviceDriver.

Returns
true/false on success/failure.

Reimplemented from yarp::dev::DeviceDriver.

Definition at line 286 of file PortAudioPlayerDeviceDriver.cpp.

◆ handleError()

void PortAudioPlayerDeviceDriver::handleError ( )
protected

Definition at line 273 of file PortAudioPlayerDeviceDriver.cpp.

◆ interruptDeviceAndClose()

bool PortAudioPlayerDeviceDriver::interruptDeviceAndClose ( )
overridevirtual

Implements yarp::dev::AudioPlayerDeviceBase.

Definition at line 184 of file PortAudioPlayerDeviceDriver.cpp.

◆ open()

bool PortAudioPlayerDeviceDriver::open ( yarp::os::Searchable config)
overridevirtual

Open the DeviceDriver.

Parameters
configis a list of parameters for the device. Which parameters are effective for your device can vary. See device invocation examples. If there is no example for your device, you can run the "yarpdev" program with the verbose flag set to probe what parameters the device is checking. If that fails too, you'll need to read the source code (please nag one of the yarp developers to add documentation for your device).
Returns
true/false upon success/failure

Reimplemented from yarp::dev::DeviceDriver.

Definition at line 250 of file PortAudioPlayerDeviceDriver.cpp.

◆ operator=() [1/2]

PortAudioPlayerDeviceDriver& PortAudioPlayerDeviceDriver::operator= ( const PortAudioPlayerDeviceDriver )
delete

◆ operator=() [2/2]

PortAudioPlayerDeviceDriver& PortAudioPlayerDeviceDriver::operator= ( PortAudioPlayerDeviceDriver &&  )
delete

◆ run()

void PortAudioPlayerDeviceDriver::run ( )
overridevirtual

Main body of the new thread.

Override this method to do what you want. After Thread::start is called, this method will start running in a separate thread. It is important that this method either keeps checking Thread::isStopping to see if it should stop, or you override the Thread::onStop method to interact with it in some way to shut the new thread down. There is no really reliable, portable way to stop a thread cleanly unless that thread cooperates.

Implements yarp::os::Thread.

Definition at line 141 of file PortAudioPlayerDeviceDriver.cpp.

◆ setHWGain()

bool PortAudioPlayerDeviceDriver::setHWGain ( double  gain)
overridevirtual

Sets the hardware gain of the playback device (if supported by the hardware)

Parameters
gainthe audio gain (1.0 is the default value)
Returns
true/false upon success/failure

Implements yarp::dev::IAudioRender.

Definition at line 307 of file PortAudioPlayerDeviceDriver.cpp.

◆ startPlayback()

bool PortAudioPlayerDeviceDriver::startPlayback ( )
overridevirtual

Start the playback.

Returns
true/false upon success/failure

Reimplemented from yarp::dev::AudioPlayerDeviceBase.

Definition at line 325 of file PortAudioPlayerDeviceDriver.cpp.

◆ stopPlayback()

bool PortAudioPlayerDeviceDriver::stopPlayback ( )
overridevirtual

Stop the playback.

Returns
true/false upon success/failure

Reimplemented from yarp::dev::AudioPlayerDeviceBase.

Definition at line 334 of file PortAudioPlayerDeviceDriver.cpp.

◆ threadInit()

bool PortAudioPlayerDeviceDriver::threadInit ( )
overridevirtual

Initialization method.

The thread executes this function when it starts and before "run". This is a good place to perform initialization tasks that need to be done by the thread itself (device drivers initialization, memory allocation etc). If the function returns false the thread quits and never calls "run". The return value of threadInit() is notified to the class and passed as a parameter to afterStart(). Note that afterStart() is called by the same thread that is executing the "start" method.

Reimplemented from yarp::os::Thread.

Definition at line 135 of file PortAudioPlayerDeviceDriver.cpp.

◆ threadRelease()

void PortAudioPlayerDeviceDriver::threadRelease ( )
overridevirtual

Release method.

The thread executes this function once when it exits, after the last "run". This is a good place to release resources that were initialized in threadInit() (release memory, and device driver resources).

Reimplemented from yarp::os::Thread.

Definition at line 131 of file PortAudioPlayerDeviceDriver.cpp.

◆ waitUntilPlaybackStreamIsComplete()

void PortAudioPlayerDeviceDriver::waitUntilPlaybackStreamIsComplete ( )
overridevirtual

Reimplemented from yarp::dev::AudioPlayerDeviceBase.

Definition at line 313 of file PortAudioPlayerDeviceDriver.cpp.

Member Data Documentation

◆ m_device_id

int PortAudioPlayerDeviceDriver::m_device_id
protected

Definition at line 77 of file PortAudioPlayerDeviceDriver.h.

◆ m_driver_frame_size

int PortAudioPlayerDeviceDriver::m_driver_frame_size
protected

Definition at line 78 of file PortAudioPlayerDeviceDriver.h.

◆ m_system_resource

void* PortAudioPlayerDeviceDriver::m_system_resource
protected

Definition at line 75 of file PortAudioPlayerDeviceDriver.h.


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