Skip to content

Commit

Permalink
Merge pull request #188 from anarkiwi/volk
Browse files Browse the repository at this point in the history
use volk operations.
  • Loading branch information
anarkiwi authored Jan 18, 2024
2 parents 617d753 + 8457240 commit 12dcb7c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
32 changes: 17 additions & 15 deletions lib/retune_fft_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@
#include <iostream>
#include <sstream>
#include <stdexcept>
#include <volk/volk.h>

namespace gr {
namespace iqtlabs {
Expand Down Expand Up @@ -251,24 +252,25 @@ retune_fft_impl::retune_fft_impl(
retuner_impl(freq_start, freq_end, tune_step_hz, tune_step_fft,
skip_tune_step_fft, tuning_ranges),
tag_(pmt::intern(tag)), vlen_(vlen), nfft_(nfft), samp_rate_(samp_rate),
fft_min_(fft_min), fft_max_(fft_max), sample_(nfft), sample_count_(0),
sdir_(sdir), write_step_fft_(write_step_fft),
write_step_fft_count_(write_step_fft), bucket_range_(bucket_range),
description_(description), rotate_secs_(rotate_secs), pre_fft_(pre_fft),
tag_now_(tag_now), low_power_hold_down_(low_power_hold_down),
fft_min_(fft_min), fft_max_(fft_max), sample_count_(0), sdir_(sdir),
write_step_fft_(write_step_fft), write_step_fft_count_(write_step_fft),
bucket_range_(bucket_range), description_(description),
rotate_secs_(rotate_secs), pre_fft_(pre_fft), tag_now_(tag_now),
low_power_hold_down_(low_power_hold_down),
peak_fft_range_(peak_fft_range), in_hold_down_(false) {
bucket_offset_ = round(float((vlen_ - round(bucket_range_ * vlen_)) / 2));
unsigned int alignment = volk_get_alignment();
sample_.reset((float *)volk_malloc(sizeof(float) * nfft_, alignment));
mean_.reset((float *)volk_malloc(sizeof(float) * nfft_, alignment));
peak_.reset((float *)volk_malloc(sizeof(float) * nfft_, alignment));
in_max_pos_.reset((uint16_t *)volk_malloc(sizeof(uint16_t), alignment));
outbuf_p.reset(new boost::iostreams::filtering_ostream());
message_port_register_out(TUNE_KEY);
message_port_register_out(JSON_KEY);
message_port_register_in(CMD_KEY);
set_msg_handler(CMD_KEY,
[this](const pmt::pmt_t &msg) { next_retune_(host_now_()); });
set_tag_propagation_policy(TPP_DONT);
for (size_t i = 0; i < nfft_; ++i) {
sample_.push_back(0);
peak_.push_back(fft_min_);
}
reset_items_();
}

Expand All @@ -281,9 +283,10 @@ void retune_fft_impl::reset_items_() {
}

void retune_fft_impl::calc_peaks_() {
volk_32f_s32f_multiply_32f(mean_.get(), (const float *)sample_.get(),
1 / float(sample_count_), nfft_);
for (size_t k = 0; k < nfft_; ++k) {
float mean = sample_[k] / sample_count_;
mean = std::min(std::max(mean, fft_min_), fft_max_);
float mean = std::min(std::max(mean_[k], fft_min_), fft_max_);
peak_[k] = std::max(mean, peak_[k]);
sample_[k] = 0;
}
Expand Down Expand Up @@ -337,9 +340,7 @@ void retune_fft_impl::write_items_(const input_type *in) {
}

void retune_fft_impl::sum_items_(const input_type *in) {
for (size_t k = 0; k < nfft_; ++k) {
sample_[k] += *in++;
}
volk_32f_x2_add_32f(sample_.get(), (const float *)sample_.get(), in, nfft_);
if (peak_fft_range_ && sample_count_ && sample_count_ == peak_fft_range_) {
calc_peaks_();
}
Expand Down Expand Up @@ -368,7 +369,8 @@ void retune_fft_impl::process_items_(size_t c, const input_type *&in,
// Discard windows where max power, is less than requested minimum.
// Ettus radios periodically output low power after retuning. This
// avoids having to use a static skip_fft_count setting.
input_type in_max = *std::max_element(in, in + nfft_);
volk_32f_index_max_16u(in_max_pos_.get(), in, nfft_);
float in_max = in[*in_max_pos_];
if (in_max < fft_min_) {
if (in_hold_down_) {
in_hold_down_ = false;
Expand Down
7 changes: 5 additions & 2 deletions lib/retune_fft_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@
#include <boost/iostreams/device/file.hpp>
#include <boost/iostreams/filter/zstd.hpp>
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/scoped_array.hpp>
#include <boost/scoped_ptr.hpp>
#include <gnuradio/iqtlabs/retune_fft.h>

Expand Down Expand Up @@ -260,13 +261,15 @@ class retune_fft_impl : public retune_fft, base_impl, retuner_impl {
float fft_max_;

std::deque<output_type> out_buf_;
std::vector<float> sample_;
std::vector<float> peak_;
size_t sample_count_;
uint64_t write_step_fft_count_;
size_t bucket_offset_;
bool in_hold_down_;

boost::scoped_array<float> sample_;
boost::scoped_array<float> mean_;
boost::scoped_array<float> peak_;
boost::scoped_ptr<uint16_t> in_max_pos_;
boost::scoped_ptr<boost::iostreams::filtering_ostream> outbuf_p;
std::string file_;

Expand Down

0 comments on commit 12dcb7c

Please sign in to comment.