19 #define _USE_MATH_DEFINES
50 if(config.
check(
"period"))
54 yCInfo(FAKEMICROPHONE) <<
"Using chosen period of " << period <<
" s";
61 size_t tmp_freq = 44100;
62 size_t tmp_channels = 2;
63 if (config.
check(
"channels"))
68 if (config.
check(
"sampling_frequency"))
73 if (config.
check(
"signal_frequency"))
75 m_sig_freq = config.
find(
"signal_frequency").
asInt32();
78 if (config.
check(
"waveform"))
80 std::string waveform = config.
find(
"waveform").
asString();
81 if (config.
find(
"waveform").
toString() ==
"sine") { m_waveform = waveform_t::sine; }
82 else if (config.
find(
"waveform").
toString() ==
"sawtooth") { m_waveform = waveform_t::sawtooth; }
83 else if (config.
find(
"waveform").
toString() ==
"square") { m_waveform = waveform_t::square; }
84 else if (config.
find(
"waveform").
toString() ==
"constant") { m_waveform = waveform_t::constant; }
85 else if (config.
check(
"waveform")) {
yError() <<
"Unsupported value for waveform parameter";
return false; }
87 if (m_waveform == waveform_t::sine) {
yCInfo(FAKEMICROPHONE) <<
"Using sine waveform, signal amplitude=" << m_wave_amplitude <<
", signal frequency=" << m_sig_freq; }
88 else if (m_waveform == waveform_t::sawtooth) {
yCInfo(FAKEMICROPHONE) <<
"Using sawtooth waveform, signal amplitude=" << m_wave_amplitude <<
", signal frequency=" << m_sig_freq; }
89 else if (m_waveform == waveform_t::square) {
yCInfo(FAKEMICROPHONE) <<
"Using square waveform, signal amplitude=" << m_wave_amplitude <<
", signal frequency=" << m_sig_freq; }
90 else if (m_waveform == waveform_t::constant) {
yCInfo(FAKEMICROPHONE) <<
"Using constant waveform, signal amplitude="<< m_wave_amplitude <<
", signal frequency=" << m_sig_freq; }
99 const size_t EXTRA_SPACE = 2;
125 bool fakeMicrophone::threadInit()
131 void fakeMicrophone::run()
148 if (m_waveform == waveform_t::sine)
153 unsigned short elem1 = double(m_wave_amplitude * sin(
double(m_counter[i]) / m_max_count[i] * 2 *
M_PI));
156 if (m_counter[i] >= m_max_count[i]) m_counter[i] = 0;
159 else if(m_waveform == waveform_t::sawtooth)
164 unsigned short elem1 = m_wave_amplitude * 2 * (double(m_counter[i])/ m_max_count[i]) - m_wave_amplitude;
167 if (m_counter[i] >= m_max_count[i]) m_counter[i] = 0;
170 else if (m_waveform == waveform_t::square)
175 unsigned short elem1 = m_counter[i] < m_max_count[i]/2 ? m_wave_amplitude : 0;
178 if (m_counter[i] >= m_max_count[i]) m_counter[i] = 0;
181 else if (m_waveform == waveform_t::constant)
187 if (m_counter[i] >= m_max_count[i]) m_counter[i] = 0;
192 yCInfo(FAKEMICROPHONE) <<
"Not implemented/unreachable code";