|
YARP
Yet Another Robot Platform
|
|
Go to the documentation of this file.
19 #define _USE_MATH_DEFINES
39 constexpr
double DEFAULT_BUFFER_DELAY = 5.0;
46 m_buffer_delay(DEFAULT_BUFFER_DELAY),
47 m_isDeviceOwned(false),
48 m_debug_enabled(false)
63 if (device2attach.
size() != 1)
65 yCError(AUDIOPLAYERWRAPPER,
"Cannot attach more than one device");
73 Idevice2attach->
view(m_irender);
76 if (
nullptr == m_irender)
78 yCError(AUDIOPLAYERWRAPPER,
"Subdevice passed to attach method is invalid");
83 PeriodicThread::setPeriod(m_period);
84 return PeriodicThread::start();
89 if (PeriodicThread::isRunning())
91 PeriodicThread::stop();
104 if (PeriodicThread::isRunning())
106 PeriodicThread::stop();
115 bool ok = command.
read(connection);
147 yCError(AUDIOPLAYERWRAPPER) <<
"Invalid command";
152 if (returnToSender !=
nullptr)
154 reply.
write(*returnToSender);
169 if (config.
check(
"debug"))
171 m_debug_enabled =
true;
174 if (config.
check(
"period"))
179 string name =
"/audioPlayerWrapper";
180 if (config.
check(
"name"))
184 m_audioInPortName = name +
"/audio:i";
185 m_rpcPortName = name +
"/rpc:i";
186 m_statusPortName = name +
"/status:o";
188 if(!initialize_YARP(config) )
190 yCError(AUDIOPLAYERWRAPPER) <<
"Error initializing YARP ports";
194 if (config.
check(
"playback_network_buffer_size"))
196 m_buffer_delay = config.
find(
"playback_network_buffer_size").
asFloat64();
198 yCInfo(AUDIOPLAYERWRAPPER) <<
"Using a 'playback_network_buffer_size' of" << m_buffer_delay <<
"s";
199 yCInfo(AUDIOPLAYERWRAPPER) <<
"Increase this value to robustify the real-time audio stream (it will increase latency too)";
201 if(config.
check(
"subdevice"))
210 yCError(AUDIOPLAYERWRAPPER) <<
"Failed to open subdevice.. check params";
214 driverlist.
push(&m_driver,
"1");
217 yCError(AUDIOPLAYERWRAPPER) <<
"Failed to open subdevice.. check params";
220 m_isDeviceOwned =
true;
223 if (config.
check(
"start"))
229 if (m_irender ==
nullptr)
231 yCError(AUDIOPLAYERWRAPPER,
"m_irender is null\n");
238 yCError(AUDIOPLAYERWRAPPER,
"getPlaybackAudioBufferMaxSize failed\n");
247 if (!m_audioInPort.
open(m_audioInPortName))
249 yCError(AUDIOPLAYERWRAPPER,
"Failed to open port %s", m_audioInPortName.c_str());
252 if (!m_statusPort.
open(m_statusPortName))
254 yCError(AUDIOPLAYERWRAPPER,
"Failed to open port %s", m_statusPortName.c_str());
257 if (!m_rpcPort.
open(m_rpcPortName))
259 yCError(AUDIOPLAYERWRAPPER,
"Failed to open port %s", m_rpcPortName.c_str());
269 m_audioInPort.
close();
273 m_statusPort.
close();
283 scheduled_sound_type ss;
286 ss.scheduled_time = current_time + m_buffer_delay;
289 ss.scheduled_time = current_time + 5.0 * s.
getDuration();
291 ss.scheduled_time = current_time + m_buffer_delay > 5.0 * s.
getDuration() ? (m_buffer_delay) : (5.0 * s.
getDuration());
294 m_sound_buffer.push(ss);
297 if (!m_sound_buffer.empty() && current_time > m_sound_buffer.front().scheduled_time)
299 m_irender->
renderSound(m_sound_buffer.front().sound_data);
300 m_sound_buffer.pop();
317 yCTrace(AUDIOPLAYERWRAPPER,
"AudioPlayerWrapper::Close");
318 if (PeriodicThread::isRunning())
320 PeriodicThread::stop();
void close() override
Stop port activity.
void attach(yarp::dev::IAudioRender *irend)
A simple collection of objects that can be described and transmitted in a portable way.
void put(const std::string &key, const std::string &value)
Associate the given key with the given string.
virtual bool renderSound(const yarp::sig::Sound &sound)=0
Render a sound using a device (i.e.
void clear()
Empties the bottle of any objects it contains.
A base class for nested structures that can be searched.
void run() override
Loop function.
T * read(bool shouldWait=true) override
Read an available object from the port.
bool attachAll(const yarp::dev::PolyDriverList &p) override
Specify which sensor this thread has to read from.
virtual std::string toString() const =0
Return a standard text representation of the content of the object.
void fromString(const std::string &txt, bool wipe=true)
Interprets a string as a list of properties.
~AudioPlayerWrapper() override
bool isValid() const
Check if device is valid.
#define YARP_LOG_COMPONENT(name,...)
void interrupt() override
Interrupt any current reads or writes attached to the port.
bool view(T *&x)
Get an interface to the device driver.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
bool threadInit() override
Initialization method.
define control board standard interfaces
bool open(const std::string &txt)
Construct and configure a device by its common name.
double now()
Return the current time in seconds, relative to an arbitrary starting point.
An interface for the device drivers.
void push(PolyDriver *p, const char *k)
virtual bool getPlaybackAudioBufferMaxSize(yarp::dev::AudioBufferSize &size)=0
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
bool write(ConnectionWriter &writer) const override
Output a representation of the bottle to a network connection.
An interface for writing to a network connection.
virtual bool getPlaybackAudioBufferCurrentSize(yarp::dev::AudioBufferSize &size)=0
virtual std::string asString() const
Get string value.
bool close() override
Close the DeviceDriver.
A container for a device driver.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
virtual Value & find(const std::string &key) const =0
Gets a value corresponding to a given keyword.
NetInt32 encode(const std::string &str)
Convert a string into a vocabulary identifier.
bool open(yarp::os::Searchable ¶ms) override
Open the DeviceDriver.
virtual ConnectionWriter * getWriter()=0
Gets a way to reply to the message, if possible.
virtual bool resetPlaybackAudioBuffer()=0
void addString(const char *str)
Places a string in the bottle, at the end of the list.
void setReader(PortReader &reader) override
Set an external reader for port data.
An abstraction for a periodic thread.
void addVocab(int x)
Places a vocabulary item in the bottle, at the end of the list.
constexpr yarp::conf::vocab32_t VOCAB_ERR
An interface for reading from a network connection.
#define yCError(component,...)
virtual bool startPlayback()=0
Start the playback.
double getDuration() const
Get the duration of sound in seconds.
#define yCInfo(component,...)
An interface to the operating system, including Port based communication.
#define yCDebug(component,...)
Class for storing sounds.
#define DEFAULT_THREAD_PERIOD
void threadRelease() override
Release method.
virtual bool stopPlayback()=0
Stop the playback.
void close() override
Stop port activity.
bool read(ConnectionReader &reader) override
Set the bottle's value based on input from a network connection.
void interrupt() override
Interrupt any current reads or writes attached to the port.
bool detachAll() override
Detach the object (you must have first called attach).
#define yCTrace(component,...)
virtual yarp::conf::float64_t asFloat64() const
Get 64-bit floating point value.
constexpr yarp::conf::vocab32_t VOCAB_OK
A class for storing options and configuration information.