gr-fosphor: Add the overlap block
This will probably be integrated as part of fosphor itself. But until it is, then this block is useful to overlap several FFT windows. Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
This commit is contained in:
parent
974ab2fe54
commit
ef5070200f
|
@ -9,6 +9,6 @@ list_cond_append(ENABLE_GLFW fosphor_grc fosphor_glfw_sink_c.block.yml)
|
|||
list_cond_append(ENABLE_QT fosphor_grc fosphor_qt_sink_c.block.yml)
|
||||
|
||||
install(FILES
|
||||
fosphor.tree.yml ${fosphor_grc}
|
||||
fosphor.tree.yml overlap_cc.block.yml ${fosphor_grc}
|
||||
DESTINATION share/gnuradio/grc/blocks
|
||||
)
|
||||
|
|
|
@ -4,3 +4,5 @@
|
|||
- fosphor_qt_sink_c
|
||||
- GLFW:
|
||||
- fosphor_glfw_sink_c
|
||||
- Stream Operators:
|
||||
- overlap_cc
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
id: overlap_cc
|
||||
label: FFT Overlap
|
||||
|
||||
parameters:
|
||||
- id: wlen
|
||||
label: Window length
|
||||
dtype: int
|
||||
default: '1024'
|
||||
- id: overlap
|
||||
label: Overlap ratio
|
||||
dtype: int
|
||||
default: '1'
|
||||
|
||||
inputs:
|
||||
- domain: stream
|
||||
dtype: complex
|
||||
|
||||
outputs:
|
||||
- domain: stream
|
||||
dtype: complex
|
||||
|
||||
templates:
|
||||
imports: |-
|
||||
from gnuradio import fosphor
|
||||
make: |-
|
||||
fosphor.overlap_cc(${wlen}, ${overlap})
|
||||
callbacks:
|
||||
- set_overlap_ratio(${overlap})
|
||||
|
||||
file_format: 1
|
|
@ -11,6 +11,7 @@
|
|||
list(APPEND fosphor_headers
|
||||
api.h
|
||||
base_sink_c.h
|
||||
overlap_cc.h
|
||||
)
|
||||
|
||||
list_cond_append(ENABLE_GLFW fosphor_headers glfw_sink_c.h)
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
/* -*- c++ -*- */
|
||||
/*
|
||||
* Copyright 2013-2021 Sylvain Munaut <tnt@246tNt.com>
|
||||
*
|
||||
* This file is part of gr-fosphor
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <gnuradio/fosphor/api.h>
|
||||
|
||||
#include <gnuradio/sync_interpolator.h>
|
||||
#include <gnuradio/fft/window.h>
|
||||
|
||||
namespace gr {
|
||||
namespace fosphor {
|
||||
|
||||
/*!
|
||||
* \brief Block preparing an overlapped version of the stream
|
||||
* \ingroup fosphor
|
||||
*/
|
||||
class GR_FOSPHOR_API overlap_cc : virtual public gr::sync_interpolator
|
||||
{
|
||||
public:
|
||||
typedef std::shared_ptr<overlap_cc> sptr;
|
||||
|
||||
static sptr make(int wlen, int overlap);
|
||||
|
||||
virtual void set_overlap_ratio(const int overlap) = 0;
|
||||
};
|
||||
|
||||
} // namespace fosphor
|
||||
} // namespace gr
|
|
@ -35,6 +35,7 @@ list(APPEND fosphor_sources
|
|||
fosphor/resource_data.c
|
||||
fifo.cc
|
||||
base_sink_c_impl.cc
|
||||
overlap_cc_impl.cc
|
||||
)
|
||||
|
||||
list_cond_append(ENABLE_GLFW fosphor_sources glfw_sink_c_impl.cc)
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
/* -*- c++ -*- */
|
||||
/*
|
||||
* Copyright 2013-2021 Sylvain Munaut <tnt@246tNt.com>
|
||||
*
|
||||
* This file is part of gr-fosphor
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <gnuradio/io_signature.h>
|
||||
|
||||
#include "overlap_cc_impl.h"
|
||||
|
||||
|
||||
namespace gr {
|
||||
namespace fosphor {
|
||||
|
||||
overlap_cc::sptr
|
||||
overlap_cc::make(int wlen, int overlap)
|
||||
{
|
||||
return gnuradio::get_initial_sptr(
|
||||
new overlap_cc_impl(wlen, overlap)
|
||||
);
|
||||
}
|
||||
|
||||
overlap_cc_impl::overlap_cc_impl(int wlen, int overlap)
|
||||
: gr::sync_interpolator("overlap_cc",
|
||||
gr::io_signature::make(1, 1, sizeof(gr_complex)),
|
||||
gr::io_signature::make(1, 1, sizeof(gr_complex)),
|
||||
overlap),
|
||||
d_wlen(wlen)
|
||||
{
|
||||
this->set_overlap_ratio(overlap);
|
||||
}
|
||||
|
||||
overlap_cc_impl::~overlap_cc_impl()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
overlap_cc_impl::set_overlap_ratio(const int overlap)
|
||||
{
|
||||
/* Save the new ratio */
|
||||
this->d_overlap = overlap;
|
||||
|
||||
/* Adapt the interpolation factor accordingly */
|
||||
this->set_interpolation(overlap);
|
||||
|
||||
/* Always keep an history of a full window to properly
|
||||
* support overlap ratio changes */
|
||||
this->set_history(this->d_wlen);
|
||||
|
||||
/* Always output entire windows */
|
||||
this->set_output_multiple(this->d_wlen);
|
||||
}
|
||||
|
||||
int
|
||||
overlap_cc_impl::work(
|
||||
int noutput_items,
|
||||
gr_vector_const_void_star &input_items,
|
||||
gr_vector_void_star &output_items)
|
||||
{
|
||||
const gr_complex *in = (const gr_complex *) input_items[0];
|
||||
gr_complex *out = (gr_complex *) output_items[0];
|
||||
int ii, oi;
|
||||
|
||||
for (ii=0,oi=0; oi<noutput_items; ii+=this->d_wlen/this->d_overlap,oi+=this->d_wlen) {
|
||||
memcpy(&out[oi], &in[ii], this->d_wlen * sizeof(gr_complex));
|
||||
}
|
||||
|
||||
return noutput_items;
|
||||
}
|
||||
|
||||
} /* namespace fosphor */
|
||||
} /* namespace gr */
|
|
@ -0,0 +1,43 @@
|
|||
/* -*- c++ -*- */
|
||||
/*
|
||||
* Copyright 2013-2021 Sylvain Munaut <tnt@246tNt.com>
|
||||
*
|
||||
* This file is part of gr-fosphor
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <gnuradio/fosphor/overlap_cc.h>
|
||||
|
||||
struct fosphor;
|
||||
struct fosphor_render;
|
||||
|
||||
namespace gr {
|
||||
namespace fosphor {
|
||||
|
||||
/*!
|
||||
* \brief Block preparing an overlapped version of the stream
|
||||
* \ingroup fosphor
|
||||
*/
|
||||
class overlap_cc_impl : public overlap_cc
|
||||
{
|
||||
private:
|
||||
int d_wlen;
|
||||
int d_overlap;
|
||||
|
||||
public:
|
||||
overlap_cc_impl(int wlen, int overlap);
|
||||
virtual ~overlap_cc_impl();
|
||||
|
||||
void set_overlap_ratio(const int overlap);
|
||||
|
||||
/* gr::sync_interpolator implementation */
|
||||
int work (int noutput_items,
|
||||
gr_vector_const_void_star &input_items,
|
||||
gr_vector_void_star &output_items);
|
||||
};
|
||||
|
||||
} // namespace fosphor
|
||||
} // namespace gr
|
|
@ -56,6 +56,7 @@ list(APPEND fosphor_python_files
|
|||
base_sink_c_python.cc
|
||||
glfw_sink_c_python.cc
|
||||
qt_sink_c_python.cc
|
||||
overlap_cc_python.cc
|
||||
python_bindings.cc)
|
||||
|
||||
GR_PYBIND_MAKE(fosphor
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright 2013-2021 Sylvain Munaut <tnt@246tNt.com>
|
||||
*
|
||||
* This file is part of gr-fosphor
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
#include <pybind11/complex.h>
|
||||
#include <pybind11/pybind11.h>
|
||||
#include <pybind11/stl.h>
|
||||
|
||||
namespace py = pybind11;
|
||||
|
||||
#include <gnuradio/fosphor/overlap_cc.h>
|
||||
|
||||
#define D(...) ""
|
||||
|
||||
void bind_overlap_cc(py::module& m)
|
||||
{
|
||||
using overlap_cc = gr::fosphor::overlap_cc;
|
||||
|
||||
py::class_<overlap_cc,
|
||||
gr::sync_block,
|
||||
gr::block,
|
||||
gr::basic_block,
|
||||
std::shared_ptr<overlap_cc>>(m, "overlap_cc", D(overlap_cc))
|
||||
|
||||
.def(py::init(&overlap_cc::make),
|
||||
py::arg("wlen"),
|
||||
py::arg("overlap"),
|
||||
D(overlap_cc,make)
|
||||
)
|
||||
|
||||
.def("set_overlap_ration",
|
||||
&overlap_cc::set_overlap_ratio,
|
||||
py::arg("overlap"),
|
||||
D(overlap_cc, set_overlap_ratio)
|
||||
)
|
||||
|
||||
;
|
||||
}
|
|
@ -17,6 +17,7 @@ namespace py = pybind11;
|
|||
void bind_base_sink_c(py::module& m);
|
||||
void bind_glfw_sink_c(py::module& m);
|
||||
void bind_qt_sink_c(py::module& m);
|
||||
void bind_overlap_cc(py::module& m);
|
||||
|
||||
// We need this hack because import_array() returns NULL
|
||||
// for newer Python versions.
|
||||
|
@ -40,4 +41,5 @@ PYBIND11_MODULE(fosphor_python, m)
|
|||
bind_base_sink_c(m);
|
||||
bind_glfw_sink_c(m);
|
||||
bind_qt_sink_c(m);
|
||||
bind_overlap_cc(m);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue