20#define AUTOMATIC_REC_START 0
21#define DEBUG_TIME_SPENT 0
24#define DEFAULT_SAMPLE_RATE (44100)
25#define DEFAULT_NUM_CHANNELS (2)
26#define DEFAULT_SAMPLE_SIZE (2)
28bool AudioRecorderDeviceBase::getSound(
yarp::sig::Sound& sound,
size_t min_number_of_samples,
size_t max_number_of_samples,
double max_samples_timeout_s)
32 #if AUTOMATIC_REC_START
33 if (m_isRecording ==
false)
55 if (max_number_of_samples < min_number_of_samples)
73 if (buff_size >= max_number_of_samples) {
break; }
74 if (buff_size >= min_number_of_samples &&
yarp::os::Time::now() - start_time > max_samples_timeout_s) {
break; }
86 size_t samples_to_be_copied = buff_size;
87 if (samples_to_be_copied > max_number_of_samples) {
88 samples_to_be_copied = max_number_of_samples;
90 if (sound.
getChannels() != this->m_audiorecorder_cfg.numChannels && sound.
getSamples() != samples_to_be_copied)
100 for (
size_t i = 0; i < samples_to_be_copied; i++)
105 if (s > (std::numeric_limits<int16_t>::max() -
m_cliptol) ||
106 s < (std::numeric_limits<int16_t>::min() +
m_cliptol))
152 std::lock_guard<std::mutex> lock(
m_mutex);
168 std::lock_guard<std::mutex> lock(
m_mutex);
176 std::lock_guard<std::mutex> lock(
m_mutex);
188 std::lock_guard<std::mutex> lock(
m_mutex);
214 m_audiorecorder_cfg.
numSamples = config.
check(
"samples",
Value(0),
"number of samples per network packet (0=automatic). For chunks of 1 second of recording set samples=rate. Channels number is handled internally.").asInt32();
#define DEFAULT_NUM_CHANNELS
const yarp::os::LogComponent & AUDIORECORDER_BASE()
#define DEFAULT_SAMPLE_RATE
constexpr double c_sleep_time
yarp::dev::CircularAudioBuffer_16t * m_inputBuffer
virtual bool getRecordingAudioBufferCurrentSize(yarp::dev::AudioBufferSize &size) override
virtual bool setSWGain(double gain) override
Sets a software gain for the grabbed audio.
virtual ~AudioRecorderDeviceBase()
virtual bool resetRecordingAudioBuffer() override
virtual bool stopRecording() override
Stop the recording.
virtual bool startRecording() override
Start the recording.
virtual bool getRecordingAudioBufferMaxSize(yarp::dev::AudioBufferSize &size) override
bool configureRecorderAudioDevice(yarp::os::Searchable &config, std::string device_name)
virtual bool isRecording(bool &recording_enabled) override
Check if the recording has been enabled (e.g.
bool m_enable_buffer_autoclear
AudioDeviceDriverSettings m_audiorecorder_cfg
yarp::dev::AudioBufferSize getMaxSize()
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.
static void delaySystem(double seconds)
A single value (typically within a Bottle).
Class for storing sounds See Audio in YARP for additional documentation on YARP audio.
void setFrequency(int freq)
Set the frequency of the sound (i.e.
std::vector< std::reference_wrapper< audio_sample > > getInterleavedAudioRawData() const
Returns a serialized version of the sound, in interleaved format, e.g.
size_t getChannels() const
Get the number of channels of the sound.
void amplify(double gain)
amplify a sound
void resize(size_t samples, size_t channels=1)
Set the sound size.
void set(audio_sample value, size_t sample, size_t channel=0)
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,...)
#define yCWarningThrottle(component, period,...)
For streams capable of holding different kinds of content, check what they actually have.
yarp::dev::CircularAudioBuffer< unsigned short int > CircularAudioBuffer_16t
double now()
Return the current time in seconds, relative to an arbitrary starting point.
An interface to the operating system, including Port based communication.