diff options
author | Adrian Suciu <adrian.suciu@analog.com> | 2018-11-15 17:26:22 +0200 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2018-11-15 21:40:54 -0800 |
commit | d3801c39375ac10ab68b5b8725f6867015f2bc40 (patch) | |
tree | f609841b34d8f1463d21e3b1918efb162456b944 | |
parent | b29afca2de4e9a32c22a43b00c219c05f5c117e9 (diff) |
analog: sig_source: Add phase parameter
Note: This does not include GRC bindings.
Signed-off-by: Adrian Suciu <adrian.suciu@analog.com>
Signed-off-by: Martin Braun <martin.braun@ettus.com>
-rw-r--r-- | gr-analog/include/gnuradio/analog/sig_source.h | 33 | ||||
-rw-r--r-- | gr-analog/lib/sig_source_impl.cc | 17 | ||||
-rw-r--r-- | gr-analog/lib/sig_source_impl.h | 5 |
3 files changed, 49 insertions, 6 deletions
diff --git a/gr-analog/include/gnuradio/analog/sig_source.h b/gr-analog/include/gnuradio/analog/sig_source.h index 759f93754c..915433a5ab 100644 --- a/gr-analog/include/gnuradio/analog/sig_source.h +++ b/gr-analog/include/gnuradio/analog/sig_source.h @@ -54,19 +54,50 @@ template<class T> static sptr make(double sampling_freq, gr::analog::gr_waveform_t waveform, double wave_freq, - double ampl, T offset = 0); + double ampl, T offset = 0, float phase = 0); virtual double sampling_freq() const = 0; virtual gr::analog::gr_waveform_t waveform() const = 0; virtual double frequency() const = 0; virtual double amplitude() const = 0; virtual T offset() const = 0; + virtual float phase() const = 0; + /*! + * Sets the sampling frequency of the signal. + * \param sampling_freq sampling frequency + */ virtual void set_sampling_freq(double sampling_freq) = 0; + + /*! + * Sets the waveform type of signal. + * \param waveform waveform type + */ virtual void set_waveform(gr::analog::gr_waveform_t waveform) = 0; + + /*! + * Sets the frequency of a periodic signal. + * \param frequency frequency of the signal + */ virtual void set_frequency(double frequency) = 0; + + /*! + * Sets the amplitude of a signal. + * \param amplitude of the signal + */ virtual void set_amplitude(double ampl) = 0; + + /*! + * Sets the DC offset of a signal. + * \param offset DC offset of the signal + */ virtual void set_offset(T offset) = 0; + + /*! + * Sets the phase of a periodic signal. + * \param phase phase of the signal + */ + virtual void set_phase(float phase) = 0; }; typedef sig_source<std::int16_t> sig_source_s; diff --git a/gr-analog/lib/sig_source_impl.cc b/gr-analog/lib/sig_source_impl.cc index 0f7ced0eb2..1b3aa82e44 100644 --- a/gr-analog/lib/sig_source_impl.cc +++ b/gr-analog/lib/sig_source_impl.cc @@ -38,19 +38,19 @@ namespace analog { template <class T> typename sig_source<T>::sptr sig_source<T>::make( - double sampling_freq, gr_waveform_t waveform, double frequency, double ampl, T offset) { + double sampling_freq, gr_waveform_t waveform, double frequency, double ampl, T offset, float phase) { return gnuradio::get_initial_sptr( - new sig_source_impl<T>(sampling_freq, waveform, frequency, ampl, offset)); + new sig_source_impl<T>(sampling_freq, waveform, frequency, ampl, offset, phase)); } template <class T> sig_source_impl<T>::sig_source_impl( - double sampling_freq, gr_waveform_t waveform, double frequency, double ampl, T offset) + double sampling_freq, gr_waveform_t waveform, double frequency, double ampl, T offset, float phase) : sync_block("sig_source", io_signature::make(0, 0, 0), io_signature::make(1, 1, sizeof(T))), d_sampling_freq(sampling_freq), d_waveform(waveform), d_frequency(frequency), d_ampl(ampl), d_offset(offset) { this->set_frequency(frequency); - + this->set_phase(phase); this->message_port_register_in(pmt::mp("freq")); this->set_msg_handler(pmt::mp("freq"), boost::bind(&sig_source_impl<T>::set_frequency_msg, this, _1)); } @@ -92,6 +92,7 @@ int sig_source_impl<T>::work(int noutput_items, gr_vector_void_star& output_items) { T* optr = (T*)output_items[0]; T t; + gr::thread::scoped_lock l(this->d_setlock); switch (d_waveform) { case GR_CONST_WAVE: @@ -165,6 +166,7 @@ int sig_source_impl<gr_complex>::work(int noutput_items, gr_vector_void_star& output_items) { gr_complex* optr = (gr_complex*)output_items[0]; gr_complex t; + gr::thread::scoped_lock l(this->d_setlock); switch (d_waveform) { case GR_CONST_WAVE: @@ -279,6 +281,13 @@ void sig_source_impl<T>::set_offset(T offset) { d_offset = offset; } +template <class T> +void sig_source_impl<T>::set_phase(float phase) { + gr::thread::scoped_lock l(this->d_setlock); + d_nco.set_phase(phase); +} + + template class sig_source<std::int16_t>; template class sig_source<std::int32_t>; template class sig_source<float>; diff --git a/gr-analog/lib/sig_source_impl.h b/gr-analog/lib/sig_source_impl.h index 9fd26582fa..616ce72b88 100644 --- a/gr-analog/lib/sig_source_impl.h +++ b/gr-analog/lib/sig_source_impl.h @@ -44,7 +44,7 @@ template<class T> public: sig_source_impl(double sampling_freq, gr_waveform_t waveform, - double wave_freq, double ampl, T offset = 0); + double wave_freq, double ampl, T offset = 0, float phase = 0); ~sig_source_impl(); virtual int work(int noutput_items, @@ -56,6 +56,7 @@ template<class T> double frequency() const { return d_frequency; } double amplitude() const { return d_ampl; } T offset() const { return d_offset; } + float phase() const { return d_nco.get_phase(); } void set_sampling_freq(double sampling_freq); void set_waveform(gr_waveform_t waveform); @@ -63,6 +64,8 @@ template<class T> void set_frequency(double frequency); void set_amplitude(double ampl); void set_offset(T offset); + void set_phase(float phase); + }; } /* namespace analog */ |