|
YARP
Yet Another Robot Platform
|
|
Go to the documentation of this file.
27 constexpr
size_t DEFAULT_MIN_NUMBER_OF_SAMPLES_OVER_NETWORK = 11250;
28 constexpr
size_t DEFAULT_MAX_NUMBER_OF_SAMPLES_OVER_NETWORK = 11250;
29 constexpr
double DEFAULT_GETSOUND_TIMEOUT = 1.0;
31 #ifdef DEBUG_TIME_SPENT
41 m_min_number_of_samples_over_network(DEFAULT_MIN_NUMBER_OF_SAMPLES_OVER_NETWORK),
42 m_max_number_of_samples_over_network(DEFAULT_MAX_NUMBER_OF_SAMPLES_OVER_NETWORK),
43 m_getSound_timeout(DEFAULT_GETSOUND_TIMEOUT),
44 m_isDeviceOwned(false)
62 if (config.
check(
"period"))
67 if (config.
check(
"subdevice"))
76 yCError(AUDIORECORDERWRAPPER) <<
"Failed to open subdevice.. check params";
80 driverlist.
push(&m_driver,
"1");
83 yCError(AUDIORECORDERWRAPPER) <<
"Failed to open subdevice.. check params";
86 m_isDeviceOwned =
true;
91 yCError(AUDIORECORDERWRAPPER,
"Failed to open IAudioGrabberSound interface");
96 if (config.
check(
"min_samples_over_network"))
98 m_min_number_of_samples_over_network = config.
find(
"min_samples_over_network").
asInt64();
100 if (config.
check(
"max_samples_over_network"))
102 m_max_number_of_samples_over_network = config.
find(
"max_samples_over_network").
asInt64();
104 yCInfo(AUDIORECORDERWRAPPER) <<
"Wrapper configured to produce packets with the following size (in samples): " <<
105 m_min_number_of_samples_over_network <<
" < samples < " << m_max_number_of_samples_over_network;
109 if (config.
check(
"max_samples_timeout"))
111 m_getSound_timeout = config.
find(
"max_samples_timeout").
asFloat64();
113 yCInfo(AUDIORECORDERWRAPPER) <<
"Wrapper configured with max_samples_timeout: " << m_getSound_timeout <<
"s";
116 std::string portname =
"/audioRecorderWrapper";
117 if (config.
check(
"name"))
121 if (m_streamingPort.
open(portname +
"/audio:o") ==
false)
123 yCError(AUDIORECORDERWRAPPER) <<
"Unable to open port" << portname;
128 if (m_rpcPort.
open(portname +
"/rpc") ==
false)
130 yCError(AUDIORECORDERWRAPPER) <<
"Unable to open port" << portname +
"/rpc";
136 if (config.
check(
"start")) {
146 if (m_mic !=
nullptr)
148 PeriodicThread::stop();
153 m_streamingPort.
close();
164 #ifdef DEBUG_TIME_SPENT
166 yCDebug(AUDIORECORDERWRAPPER) << current_time - m_last_time;
167 m_last_time = current_time;
170 if (m_mic ==
nullptr)
172 yCError(AUDIORECORDERWRAPPER) <<
"The IAudioGrabberSound interface is not available yet!";
176 #ifdef PRINT_DEBUG_MESSAGES
178 audio_buffer_size buf_max;
179 audio_buffer_size buf_cur;
180 mic->getRecordingAudioBufferMaxSize(buf_max);
181 mic->getRecordingAudioBufferCurrentSize(buf_cur);
182 yCDebug(AUDIORECORDERWRAPPER) <<
"BEFORE Buffer status:" << buf_cur.getBytes() <<
"/" << buf_max.getBytes() <<
"bytes";
187 m_mic->
getSound(snd, m_min_number_of_samples_over_network, m_max_number_of_samples_over_network, m_getSound_timeout);
189 if (snd.
getSamples() < m_min_number_of_samples_over_network ||
190 snd.
getSamples() < m_max_number_of_samples_over_network)
192 yCWarning(AUDIORECORDERWRAPPER) <<
"subdevice->getSound() is not producing sounds of the requested size ("
193 << m_min_number_of_samples_over_network <<
"<"
195 << m_max_number_of_samples_over_network <<
") failed";
198 #ifdef PRINT_DEBUG_MESSAGES
200 audio_buffer_size buf_max;
201 audio_buffer_size buf_cur;
202 mic->getRecordingAudioBufferMaxSize(buf_max);
203 mic->getRecordingAudioBufferCurrentSize(buf_cur);
204 yCDebug(AUDIORECORDERWRAPPER) <<
"AFTER Buffer status:" << buf_cur.getBytes() <<
"/" << buf_max.getBytes() <<
"bytes";
207 #ifdef PRINT_DEBUG_MESSAGES
219 yCError(AUDIORECORDERWRAPPER) <<
"Subdevice produced sound of 0 samples!";
224 yCError(AUDIORECORDERWRAPPER) <<
"Subdevice produced sound of 0 channels!";
229 yCError(AUDIORECORDERWRAPPER) <<
"Subdevice produced sound with 0 frequency!";
234 m_streamingPort.
write(snd);
241 bool ok = command.
read(connection);
242 if (!ok)
return false;
269 yCError(AUDIORECORDERWRAPPER) <<
"Invalid command";
274 if (returnToSender !=
nullptr)
276 reply.
write(*returnToSender);
283 if (device2attach.
size() != 1)
285 yCError(AUDIORECORDERWRAPPER,
"Cannot attach more than one device");
293 Idevice2attach->
view(m_mic);
296 if (
nullptr == m_mic)
298 yCError(AUDIORECORDERWRAPPER,
"Subdevice passed to attach method is invalid");
303 PeriodicThread::setPeriod(m_period);
304 return PeriodicThread::start();
309 if (PeriodicThread::isRunning())
311 PeriodicThread::stop();
324 if (PeriodicThread::isRunning())
326 PeriodicThread::stop();
void close() override
Stop port activity.
yarp::rosmsg::std_msgs::Time Time
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.
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
void clear()
Empties the bottle of any objects it contains.
A base class for nested structures that can be searched.
int getFrequency() const
Get the frequency of the sound (i.e.
#define yCWarning(component,...)
size_t getSamples() const
Get the number of samples contained in the sound.
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.
bool isValid() const
Check if device is valid.
#define YARP_LOG_COMPONENT(name,...)
bool attachAll(const yarp::dev::PolyDriverList &p) override
Attach to a list of objects.
bool view(T *&x)
Get an interface to the device driver.
size_t getChannels() const
Get the number of channels of the sound.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
bool close() override
Close the DeviceDriver.
virtual bool startRecording()=0
Start the recording.
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.
bool detachAll() override
Detach the object (you must have first called attach).
bool setEnvelope(PortWriter &envelope) override
Set an envelope (e.g., a timestamp) to the next message which will be sent.
void push(PolyDriver *p, const char *k)
Read a YARP-format sound block from a device.
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.
void attach(yarp::dev::IAudioGrabberSound *igrab)
static void delaySystem(double seconds)
virtual std::string asString() const
Get string value.
A container for a device driver.
bool threadInit() override
Initialization method.
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.
~AudioRecorderWrapper() override
virtual ConnectionWriter * getWriter()=0
Gets a way to reply to the message, if possible.
virtual bool resetRecordingAudioBuffer()=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.
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,...)
bool write(const PortWriter &writer, const PortWriter *callback=nullptr) const override
Write an object to the port.
void update()
Set the timestamp to the current time, and increment the sequence number (wrapping to 0 if the sequen...
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
#define yCInfo(component,...)
#define yCDebug(component,...)
Class for storing sounds.
#define DEFAULT_THREAD_PERIOD
virtual bool getSound(yarp::sig::Sound &sound, size_t min_number_of_samples, size_t max_number_of_samples, double max_samples_timeout_s)=0
Get a sound from a device.
The main, catch-all namespace for YARP.
void run() override
Loop function.
void threadRelease() override
Release method.
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.
virtual bool stopRecording()=0
Stop the recording.
size_t getBytesPerSample() const
Get the number of bytes per sample.
AudioRecorderWrapper()
Constructor.
virtual yarp::conf::float64_t asFloat64() const
Get 64-bit floating point value.
virtual std::int64_t asInt64() const
Get 64-bit integer value.
constexpr yarp::conf::vocab32_t VOCAB_OK
A class for storing options and configuration information.