9 #define _USE_MATH_DEFINES
23 #define DEG2RAD M_PI/180.0
31 #define AUTOMATIC_REC_START 0
32 #define DEBUG_TIME_SPENT 0
33 #define BUFFER_AUTOCLEAR 0
35 bool AudioRecorderDeviceBase::getSound(
yarp::sig::Sound& sound,
size_t min_number_of_samples,
size_t max_number_of_samples,
double max_samples_timeout_s)
39 #if AUTOMATIC_REC_START
40 if (m_isRecording ==
false)
42 this->startRecording();
46 while (m_isRecording ==
false)
62 if (max_number_of_samples < min_number_of_samples)
67 if (max_number_of_samples > this->m_audiorecorder_cfg.numSamples)
69 yCWarning(
AUDIORECORDER_BASE) <<
"max_number_of_samples bigger than the internal audio buffer! It will be truncated to:" << this->m_audiorecorder_cfg.numSamples;
70 max_number_of_samples = this->m_audiorecorder_cfg.numSamples;
79 buff_size = m_inputBuffer->size().getSamples();
80 if (buff_size >= max_number_of_samples) {
break; }
81 if (buff_size >= min_number_of_samples &&
yarp::os::Time::now() - start_time > max_samples_timeout_s) {
break; }
82 if (m_isRecording ==
false) {
break; }
94 size_t samples_to_be_copied = buff_size;
95 if (samples_to_be_copied > max_number_of_samples) samples_to_be_copied = max_number_of_samples;
96 if (sound.
getChannels() != this->m_audiorecorder_cfg.numChannels && sound.
getSamples() != samples_to_be_copied)
98 sound.
resize(samples_to_be_copied, this->m_audiorecorder_cfg.numChannels);
100 sound.
setFrequency(this->m_audiorecorder_cfg.frequency);
106 for (
size_t i = 0; i < samples_to_be_copied; i++)
107 for (
size_t j = 0; j < this->m_audiorecorder_cfg.numChannels; j++)
109 int16_t s = (int16_t)(m_inputBuffer->read());
124 size = this->m_inputBuffer->getMaxSize();
132 size = this->m_inputBuffer->size();
137 bool AudioRecorderDeviceBase::resetRecordingAudioBuffer()
139 std::lock_guard<std::mutex> lock(m_mutex);
140 m_inputBuffer->clear();
145 bool AudioRecorderDeviceBase::startRecording()
147 std::lock_guard<std::mutex> lock(m_mutex);
148 m_isRecording =
true;
150 this->m_recDataBuffer->clear();
157 bool AudioRecorderDeviceBase::stopRecording()
159 std::lock_guard<std::mutex> lock(m_mutex);
160 m_isRecording =
false;
162 this->m_recDataBuffer->clear();
168 AudioRecorderDeviceBase::~AudioRecorderDeviceBase()
170 delete m_inputBuffer;