45 if (config.
check(
"period"))
47 m_period = config.
find(
"period").asFloat64();
51 if (config.
check(
"min_samples_over_network"))
53 m_min_number_of_samples_over_network = config.
find(
"min_samples_over_network").asInt64();
55 if (config.
check(
"max_samples_over_network"))
57 m_max_number_of_samples_over_network = config.
find(
"max_samples_over_network").asInt64();
60 m_min_number_of_samples_over_network <<
" < samples < " << m_max_number_of_samples_over_network;
63 if (config.
check(
"max_samples_timeout"))
65 m_getSound_timeout = config.
find(
"max_samples_timeout").asFloat64();
70 std::string
portname =
"/audioRecorderWrapper";
71 if (config.
check(
"name"))
75 if (m_streamingPort.
open(
portname +
"/audio:o") ==
false)
101 m_streamingPort.
close();
105 m_statusPort.
close();
110 m_dataThread =
nullptr;
114 delete m_statusThread;
115 m_statusThread =
nullptr;
142 else if (command.
get(0).
asString() ==
"sw_audio_gain")
156 else if (command.
get(0).
asString() ==
"hw_audio_gain")
205 if (
nullptr == m_mic)
214 m_dataThread->
start();
215 m_statusThread->
start();
218 if (m_config.
check(
"start")) {
232 m_dataThread->
stop();
236 m_statusThread->
stop();
254 if (
m_ARW->m_debug_enabled)
285 if (
m_ARW->m_mic ==
nullptr)
291#ifdef PRINT_DEBUG_MESSAGES
296 mic->getRecordingAudioBufferCurrentSize(
buf_cur);
302 m_ARW->m_mic->
getSound(snd,
m_ARW->m_min_number_of_samples_over_network,
m_ARW->m_max_number_of_samples_over_network,
m_ARW->m_getSound_timeout);
308 <<
m_ARW->m_min_number_of_samples_over_network <<
"<"
310 <<
m_ARW->m_max_number_of_samples_over_network <<
") failed";
313#ifdef PRINT_DEBUG_MESSAGES
318 mic->getRecordingAudioBufferCurrentSize(
buf_cur);
322#ifdef PRINT_DEBUG_MESSAGES
constexpr yarp::conf::vocab32_t VOCAB_OK
constexpr yarp::conf::vocab32_t VOCAB_ERR
void run() override
Loop function.
AudioRecorderWrapper * m_ARW
AudioRecorderWrapper * m_ARW
void run() override
Loop function.
AudioRecorderWrapper: A Wrapper which streams audio over the network, after grabbing it from a device
bool attach(yarp::dev::PolyDriver *driver) override
Attach to another object.
friend class AudioRecorderDataThread
bool close() override
Close the DeviceDriver.
friend class AudioRecorderStatusThread
~AudioRecorderWrapper() override
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
bool detach() override
Detach the object (you must have first called attach).
bool view(T *&x)
Get an interface to the device driver.
virtual yarp::dev::ReturnValue getRecordingAudioBufferCurrentSize(yarp::sig::AudioBufferSize &size)=0
virtual yarp::dev::ReturnValue 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.
virtual yarp::dev::ReturnValue stopRecording()=0
Stop the recording.
virtual yarp::dev::ReturnValue resetRecordingAudioBuffer()=0
virtual yarp::dev::ReturnValue isRecording(bool &recording_enabled)=0
Check if the recording has been enabled (e.g.
virtual yarp::dev::ReturnValue setHWGain(double gain)=0
Sets the hardware gain of the grabbing device (if supported by the hardware)
virtual yarp::dev::ReturnValue startRecording()=0
Start the recording.
virtual yarp::dev::ReturnValue setSWGain(double gain)=0
Sets a software gain for the grabbed audio.
virtual yarp::dev::ReturnValue getRecordingAudioBufferMaxSize(yarp::sig::AudioBufferSize &size)=0
A container for a device driver.
bool isValid() const
Check if device is valid.
A simple collection of objects that can be described and transmitted in a portable way.
void addVocab32(yarp::conf::vocab32_t x)
Places a vocabulary item in the bottle, at the end of the list.
bool read(ConnectionReader &reader) override
Set the bottle's value based on input from a network connection.
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
void clear()
Empties the bottle of any objects it contains.
bool write(ConnectionWriter &writer) const override
Output a representation of the bottle to a network connection.
void addString(const char *str)
Places a string in the bottle, at the end of the list.
A mini-server for performing network communication in the background.
An interface for reading from a network connection.
An interface for writing to a network connection.
bool setPeriod(double period)
Set the (new) period of the thread.
bool start()
Call this to start the thread.
void stop()
Call this to stop the thread, this call blocks until the thread is terminated (and releaseThread() ca...
bool write(const PortWriter &writer, const PortWriter *callback=nullptr) const override
Write an object to the port.
void setReader(PortReader &reader) override
Set an external reader for port data.
void interrupt() override
Interrupt any current reads or writes attached to the port.
bool setEnvelope(PortWriter &envelope) override
Set an envelope (e.g., a timestamp) to the next message which will be sent.
void close() override
Stop port activity.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
void fromString(const std::string &txt, bool wipe=true)
Interprets a string as a list of properties.
bool check(const std::string &key) const override
Check if there exists a property of the given name.
A base class for nested structures that can be searched.
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
virtual std::string toString() const =0
Return a standard text representation of the content of the object.
virtual Value & find(const std::string &key) const =0
Gets a value corresponding to a given keyword.
void update()
Set the timestamp to the current time, and increment the sequence number (wrapping to 0 if the sequen...
static void delaySystem(double seconds)
virtual yarp::conf::float64_t asFloat64() const
Get 64-bit floating point value.
virtual std::string asString() const
Get string value.
AudioRecorderStatus: A class used to describe the status of an audio recorder device.
size_t current_buffer_size
the size of the audio buffer [samples]
size_t max_buffer_size
the max_size of the audio buffer [samples]
bool enabled
true if the playback is currently enabled
Class for storing sounds See Audio in YARP for additional documentation on YARP audio.
size_t getBytesPerSample() const
Get the number of bytes per sample.
size_t getChannels() const
Get the number of channels of the sound.
int getFrequency() const
Get the frequency of the sound (i.e.
size_t getSamples() const
Get the number of samples contained in the sound.
#define yCInfo(component,...)
#define yCError(component,...)
#define yCWarning(component,...)
#define yCDebug(component,...)
#define YARP_LOG_COMPONENT(name,...)
For streams capable of holding different kinds of content, check what they actually have.
double now()
Return the current time in seconds, relative to an arbitrary starting point.
An interface to the operating system, including Port based communication.