Skip to content

Commit

Permalink
Fix linter warnings and typos in binauralrenderer.h and brsrenderer.h
Browse files Browse the repository at this point in the history
  • Loading branch information
HaHeho committed Feb 15, 2024
1 parent f99dbb6 commit 0532023
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 39 deletions.
61 changes: 35 additions & 26 deletions src/binauralrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#ifndef SSR_BINAURALRENDERER_H
#define SSR_BINAURALRENDERER_H

#include <memory> // for std::unique_ptr, std::make_unique

#include "rendererbase.h"
#include "apf/iterator.h" // for apf::cast_proxy, apf::make_cast_proxy
#include "apf/convolver.h" // for apf::conv::*
Expand All @@ -50,7 +52,7 @@ namespace ssr
class BinauralRenderer : public SourceToOutput<BinauralRenderer, RendererBase>
{
private:
using _base = SourceToOutput<BinauralRenderer, ssr::RendererBase>;
using _base = SourceToOutput<BinauralRenderer, RendererBase>;

public:
static const char* name()
Expand All @@ -63,10 +65,13 @@ class BinauralRenderer : public SourceToOutput<BinauralRenderer, RendererBase>
class Output;
class RenderFunction;

BinauralRenderer(const apf::parameter_map& params)
explicit BinauralRenderer(const apf::parameter_map& params)
: _base(params)
// WARNING "instantiation of member function requested here"
// (I don't think this can be fixed without refactoring APF)
, _fade(this->block_size())
, _partitions(0)
, _angles(0)
{}

void load_reproduction_setup();
Expand Down Expand Up @@ -106,15 +111,15 @@ class BinauralRenderer::SourceChannel
, public apf::has_begin_and_end<float*>
{
public:
SourceChannel(const apf::conv::Input& input)
explicit SourceChannel(const apf::conv::Input& input)
: apf::conv::Output(input)
, temporary_hrtf(input.block_size(), input.partitions())
, _block_size(input.block_size())
{}

void convolve_and_more(sample_type weight)
void convolve_and_more(sample_type _weight)
{
_begin = this->convolve(weight);
_begin = this->convolve(_weight);
_end = _begin + _block_size;
}

Expand All @@ -125,16 +130,16 @@ class BinauralRenderer::SourceChannel

apf::conv::Filter temporary_hrtf;

sample_type weight;
apf::CombineChannelsResult::type crossfade_mode;
sample_type weight{};
apf::CombineChannelsResult::type crossfade_mode{};

private:
const size_t _block_size;
};

void BinauralRenderer::_load_hrtfs(const std::string& filename, size_t size)
{
auto idx = filename.find_last_of(".");
auto idx = filename.find_last_of('.');
if (idx != std::string::npos)
{
auto ext = filename.substr(idx + 1);
Expand Down Expand Up @@ -173,17 +178,18 @@ void BinauralRenderer::_load_wav(const std::string& filename, size_t size)

if (size == 0) size = hrir_file.frames();

// Deinterleave channels and transform to FFT domain
// De-interleave channels and transform to FFT domain

auto transpose = apf::fixed_matrix<float>(size, no_of_channels);

size = hrir_file.readf(transpose.data(), size);
size = hrir_file.readf(transpose.data(), static_cast<sf_count_t>(size));

_partitions = apf::conv::min_partitions(this->block_size(), size);

auto temp = apf::conv::Transform(this->block_size());

_hrtfs.reset(new hrtf_set_t(no_of_channels, this->block_size(), _partitions));
_hrtfs = std::make_unique<hrtf_set_t>(
no_of_channels, this->block_size(), _partitions);

auto target = _hrtfs->begin();
for (const auto& slice: transpose.slices)
Expand All @@ -193,7 +199,8 @@ void BinauralRenderer::_load_wav(const std::string& filename, size_t size)

// prepare neutral filter (dirac impulse) for interpolation around the head

// get index of absolute maximum in first channel (frontal direcion, left)
// get index of the absolute maximum in the first channel
// (frontal direction, left)
apf::fixed_matrix<sample_type>::slice_iterator maximum = std::max_element(
transpose.slices.begin()->begin(),
transpose.slices.begin()->end(),
Expand All @@ -205,9 +212,9 @@ void BinauralRenderer::_load_wav(const std::string& filename, size_t size)
auto impulse = apf::fixed_vector<sample_type>(index + 1);
impulse.back() = 1;

_neutral_filter.reset(
new apf::conv::Filter(this->block_size(), impulse.begin(), impulse.end()));
// Number of partitions may be different from _hrtfs!
_neutral_filter = std::make_unique<apf::conv::Filter>(
this->block_size(), impulse.begin(), impulse.end());
// the number of partitions may be different from _hrtfs!
}

#ifdef ENABLE_SOFA
Expand Down Expand Up @@ -239,7 +246,8 @@ void BinauralRenderer::_load_sofa(const std::string& filename, size_t size)
throw std::logic_error("SOFA files with delays are not (yet?) supported");
}
}
err = mysofa_resample(hrir_file.get(), this->sample_rate());
err = mysofa_resample(
hrir_file.get(), static_cast<float>(this->sample_rate()));
if (err != MYSOFA_OK)
{
throw std::runtime_error("SOFA resample error: " + std::to_string(err));
Expand Down Expand Up @@ -291,14 +299,14 @@ void BinauralRenderer::_load_sofa(const std::string& filename, size_t size)

_neutral_filter = std::make_unique<apf::conv::Filter>(
this->block_size(), impulse.begin(), impulse.end());
// Number of partitions may be different from _hrtfs!
// the number of partitions may be different from _hrtfs!
}
#endif

class BinauralRenderer::RenderFunction
{
public:
RenderFunction() : _in(0) {}
RenderFunction() : _in(nullptr) {}

apf::CombineChannelsResult::type select(SourceChannel& in)
{
Expand All @@ -319,7 +327,7 @@ class BinauralRenderer::RenderFunction
class BinauralRenderer::Output : public _base::Output
{
public:
Output(const Params& p)
explicit Output(const Params& p)
: _base::Output(p)
, _combiner(this->sourcechannels, this->buffer, this->parent._fade)
{}
Expand Down Expand Up @@ -354,14 +362,14 @@ void BinauralRenderer::load_reproduction_setup()

const std::string prefix = this->params.get("system_output_prefix", "");

if (prefix != "")
if (!prefix.empty())
{
// TODO: read target from proper reproduction file
params.set("connect-to", prefix + "1");
}
this->add(params);

if (prefix != "")
if (!prefix.empty())
{
params.set("connect-to", prefix + "2");
}
Expand All @@ -376,7 +384,7 @@ class BinauralRenderer::Source
void _process();

public:
Source(const Params& p)
explicit Source(const Params& p)
// TODO: assert that p.parent != 0?
: apf::conv::Input(p.parent->block_size(), p.parent->_partitions)
, _base::Source(p, 2, *this)
Expand Down Expand Up @@ -434,9 +442,9 @@ void BinauralRenderer::Source::_process()
{
// Relative source rotation, as seen from the reference
auto rel_rot = anti_ref_rot * src_rot;
// Vector corresponding to that rotation (roll angle is ignored)
// Vector corresponding to that rotation (roll angles are ignored)
selector = transform(rel_rot, {0.0f, 1.0f, 0.0f});
// Plane wave orientation points into direction of propagation,
// Plane wave orientation points into the direction of propagation,
// we want to point to where it comes from:
selector = -selector;
}
Expand All @@ -445,7 +453,8 @@ void BinauralRenderer::Source::_process()
// Vector of incidence, as seen from the reference
selector = transform(anti_ref_rot, (src_pos - ref_pos));
}
// Rotate selector 90 degrees clockwise to align main direction with x-axis
// Rotate the selector 90 degrees clockwise to align the main direction with
// the x-axis
selector = transform(
gml::qrotate(gml::radians(-90.0f), {0.0f, 0.0f, 1.0f}), selector);

Expand All @@ -471,7 +480,7 @@ void BinauralRenderer::Source::_process()
#endif

using namespace apf::CombineChannelsResult;
auto crossfade_mode = apf::CombineChannelsResult::type();
type crossfade_mode;

// Check on one channel only, filters are always changed in parallel
bool queues_empty = this->sourcechannels[0].queues_empty();
Expand Down
32 changes: 19 additions & 13 deletions src/brsrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#ifndef SSR_BRSRENDERER_H
#define SSR_BRSRENDERER_H

#include <memory>

#include "rendererbase.h"
#include "legacy_orientation.h"

Expand Down Expand Up @@ -57,8 +59,10 @@ class BrsRenderer : public SourceToOutput<BrsRenderer, RendererBase>
class Output;
class RenderFunction;

BrsRenderer(const apf::parameter_map& params)
explicit BrsRenderer(const apf::parameter_map& params)
: _base(params)
// WARNING "instantiation of member function requested here"
// (I don't think this can be fixed without refactoring APF)
, _fade(this->block_size())
{}

Expand All @@ -84,14 +88,14 @@ struct BrsRenderer::SourceChannel
void update();
void convolve_and_more(sample_type weight);

apf::CombineChannelsResult::type crossfade_mode;
sample_type new_weighting_factor;
apf::CombineChannelsResult::type crossfade_mode{};
sample_type new_weighting_factor{};
};

class BrsRenderer::Source : public _base::Source
{
public:
Source(const Params& p)
explicit Source(const Params& p)
: _base::Source(p)
, _weighting_factor(-1.0f)
, _brtf_index(size_t(-1))
Expand All @@ -116,15 +120,16 @@ class BrsRenderer::Source : public _base::Source
auto ir_data = matrix_t(size, no_of_channels);

// TODO: check return value?
ir_file.readf(ir_data.data(), size);
ir_file.readf(ir_data.data(), static_cast<sf_count_t>(size));

size_t block_size = this->parent.block_size();

auto temp = apf::conv::Transform(block_size);

size_t partitions = apf::conv::min_partitions(block_size, size);

_brtf_set.reset(new brtf_set_t(no_of_channels, block_size, partitions));
_brtf_set = std::make_unique<brtf_set_t>(
no_of_channels, block_size, partitions);

auto target = _brtf_set->begin();
for (const auto& slice: ir_data.slices)
Expand All @@ -134,7 +139,8 @@ class BrsRenderer::Source : public _base::Source

assert(target == _brtf_set->end());

_convolver_input.reset(new apf::conv::Input(block_size, partitions));
_convolver_input = std::make_unique<apf::conv::Input>(
block_size, partitions);

this->sourcechannels.reserve(2);
this->sourcechannels.emplace_back(*_convolver_input);
Expand All @@ -154,12 +160,12 @@ class BrsRenderer::Source : public _base::Source

// get BRTF index from listener orientation
// (source positions are NOT considered!)
// 90 degree is in the middle of index 0
// 90 degrees is in the middle of index 0
_brtf_index = size_t(apf::math::wrap(
(azi - 90.0f) * float(_angles) / 360.0f + 0.5f, float(_angles)));

using namespace apf::CombineChannelsResult;
auto crossfade_mode = apf::CombineChannelsResult::type();
type crossfade_mode;

// Check on one channel only, filters are always changed in parallel
bool queues_empty = this->sourcechannels[0].queues_empty();
Expand Down Expand Up @@ -238,7 +244,7 @@ void BrsRenderer::SourceChannel::convolve_and_more(sample_type weight)
class BrsRenderer::RenderFunction
{
public:
RenderFunction() : _in(0) {}
RenderFunction() : _in(nullptr) {}

apf::CombineChannelsResult::type select(SourceChannel& in)
{
Expand All @@ -259,7 +265,7 @@ class BrsRenderer::RenderFunction
class BrsRenderer::Output : public _base::Output
{
public:
Output(const Params& p)
explicit Output(const Params& p)
: _base::Output(p)
, _combiner(this->sourcechannels, this->buffer, this->parent._fade)
{}
Expand Down Expand Up @@ -287,14 +293,14 @@ void BrsRenderer::load_reproduction_setup()

const std::string prefix = this->params.get("system_output_prefix", "");

if (prefix != "")
if (!prefix.empty())
{
// TODO: read target from proper reproduction file
params.set("connect-to", prefix + "1");
}
this->add(params);

if (prefix != "")
if (!prefix.empty())
{
params.set("connect-to", prefix + "2");
}
Expand Down

0 comments on commit 0532023

Please sign in to comment.