16 #define _USE_MATH_DEFINES
45 if (config.
check(
"help"))
47 yCInfo(FAKEMICROPHONE,
"Some examples:");
48 yCInfo(FAKEMICROPHONE,
"yarpdev --device fakeMicrophone --help");
49 yCInfo(FAKEMICROPHONE,
"yarpdev --device AudioRecorderWrapper --subdevice fakeMicrophone --start");
50 yCInfo(FAKEMICROPHONE,
"yarpdev --device AudioRecorderWrapper --subdevice fakeMicrophone --start --signal_frequency 400 --waveform sine");
51 yCInfo(FAKEMICROPHONE,
"yarpdev --device AudioRecorderWrapper --subdevice fakeMicrophone --start --signal_frequency 400 --waveform sawtooth");
52 yCInfo(FAKEMICROPHONE,
"yarpdev --device AudioRecorderWrapper --subdevice fakeMicrophone --start --signal_frequency 400 --waveform square");
53 yCInfo(FAKEMICROPHONE,
"yarpdev --device AudioRecorderWrapper --subdevice fakeMicrophone --start --waveform constant");
58 if (!b) {
return false; }
61 if(config.
check(
"period"))
65 yCInfo(FAKEMICROPHONE) <<
"Using chosen period of " << period <<
" s";
72 if (config.
check(
"signal_frequency"))
74 m_sig_freq = config.
find(
"signal_frequency").
asInt32();
77 if (config.
check(
"amplitude"))
79 m_wave_amplitude = config.
find(
"amplitude").
asInt32();
83 if (config.
check(
"driver_frame_size"))
85 m_samples_to_be_copied = config.
find(
"driver_frame_size").
asFloat64();
87 yCDebug(FAKEMICROPHONE) << m_samples_to_be_copied <<
" will be processed every iteration";
89 if (config.
check(
"waveform"))
91 std::string waveform = config.
find(
"waveform").
asString();
92 if (config.
find(
"waveform").
toString() ==
"sine") { m_waveform = waveform_t::sine; }
93 else if (config.
find(
"waveform").
toString() ==
"sawtooth") { m_waveform = waveform_t::sawtooth; }
94 else if (config.
find(
"waveform").
toString() ==
"square") { m_waveform = waveform_t::square; }
95 else if (config.
find(
"waveform").
toString() ==
"constant") { m_waveform = waveform_t::constant; }
96 else if (config.
check(
"waveform")) {
yError() <<
"Unsupported value for waveform parameter";
return false; }
98 if (m_waveform == waveform_t::sine) {
yCInfo(FAKEMICROPHONE) <<
"Using sine waveform, signal amplitude=" << m_wave_amplitude <<
", signal frequency=" << m_sig_freq; }
99 else if (m_waveform == waveform_t::sawtooth) {
yCInfo(FAKEMICROPHONE) <<
"Using sawtooth waveform, signal amplitude=" << m_wave_amplitude <<
", signal frequency=" << m_sig_freq; }
100 else if (m_waveform == waveform_t::square) {
yCInfo(FAKEMICROPHONE) <<
"Using square waveform, signal amplitude=" << m_wave_amplitude <<
", signal frequency=" << m_sig_freq; }
101 else if (m_waveform == waveform_t::constant) {
yCInfo(FAKEMICROPHONE) <<
"Using constant waveform, signal amplitude="<< m_wave_amplitude <<
", signal frequency=" << m_sig_freq; }
129 std::lock_guard<std::mutex> lock(
m_mutex);
138 bool fakeMicrophone::threadInit()
144 void fakeMicrophone::run()
156 for (
size_t i = 0; i < m_samples_to_be_copied; i++)
163 if (m_waveform == waveform_t::sine)
168 double elem1 = double(m_wave_amplitude * sin(
double(m_counter[i]) / m_max_count[i] * 2 *
M_PI));
171 if (m_counter[i] >= m_max_count[i]) {
176 else if(m_waveform == waveform_t::sawtooth)
181 double elem1 = m_wave_amplitude * 2 * (double(m_counter[i])/ m_max_count[i]) - m_wave_amplitude;
184 if (m_counter[i] >= m_max_count[i]) {
189 else if (m_waveform == waveform_t::square)
194 double elem1 = m_counter[i] < m_max_count[i]/2 ? m_wave_amplitude : 0;
197 if (m_counter[i] >= m_max_count[i]) {
202 else if (m_waveform == waveform_t::constant)
208 if (m_counter[i] >= m_max_count[i]) {
215 yCInfo(FAKEMICROPHONE) <<
"Not implemented/unreachable code";
bool setHWGain(double gain) override
Sets the hardware gain of the grabbing device (if supported by the hardware)
bool close() override
Close the DeviceDriver.
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
~fakeMicrophone() override
yarp::dev::CircularAudioBuffer_16t * m_inputBuffer
bool configureRecorderAudioDevice(yarp::os::Searchable &config, std::string device_name)
AudioDeviceDriverSettings m_audiorecorder_cfg
An abstraction for a periodic thread.
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...
A base class for nested structures that can be searched.
virtual Value & find(const std::string &key) const =0
Gets a value corresponding to a given keyword.
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
virtual Bottle & findGroup(const std::string &key) const =0
Gets a list corresponding to a given keyword.
virtual yarp::conf::float64_t asFloat64() const
Get 64-bit floating point value.
virtual std::int32_t asInt32() const
Get 32-bit integer value.
std::string toString() const override
Return a standard text representation of the content of the object.
virtual std::string asString() const
Get string value.
constexpr double c_DEFAULT_PERIOD
unsigned short int audio_sample_16t
#define yCInfo(component,...)
#define yCDebug(component,...)
#define YARP_LOG_COMPONENT(name,...)
An interface for the device drivers.
An interface to the operating system, including Port based communication.