Skip to content

Commit

Permalink
avoid some float conversions or make them explicit when needed
Browse files Browse the repository at this point in the history
  • Loading branch information
gisogrimm committed Jan 24, 2025
1 parent a597354 commit 38b6869
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 37 deletions.
3 changes: 3 additions & 0 deletions libtascar/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ all: build ver lib symlink testbin
include ../config.mk
include ../rules.mk

#CXXFLAGS += -Wconversion -Werror
#-Waddress -Warray-bounds -Wsign-compare -Wuninitialized

#
# versioning:
#
Expand Down
4 changes: 2 additions & 2 deletions libtascar/include/acousticmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ namespace TASCAR {
class reflector_t : public diffractor_t {
public:
reflector_t();
void apply_reflectionfilter(TASCAR::wave_t& audio, double& lpstate) const;
void apply_reflectionfilter(TASCAR::wave_t& audio, float& lpstate) const;
void read_xml(TASCAR::xml_element_t& e);
bool active;
float reflectivity;
Expand Down Expand Up @@ -378,7 +378,7 @@ namespace TASCAR {
const source_t* primary; ///< Primary source
const reflector_t* reflector; ///< Reflector, which created new sound path
///< from parent, or NULL for primary
std::vector<double>
std::vector<float>
reflectionfilterstates; ///< Filter states for first-order reflection
///< filters
bool visible;
Expand Down
44 changes: 24 additions & 20 deletions libtascar/src/acousticmodel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -208,19 +208,19 @@ uint32_t acoustic_model_t::process(const TASCAR::transport_t& tp)
float dairabsorption((next_air_absorption - air_absorption) * dt);
apply_reflectionfilter(audio);
if(receiver_->muteonstop && (!tp.rolling)) {
gain = 0.0;
dgain = 0.0;
gain = 0.0f;
dgain = 0.0f;
}
for(uint32_t k = 0; k < chunksize; ++k) {
float& current_sample(audio[k]);
distance += ddistance;
gain += dgain;
// calculate layer fade gain:
if(layeractive) {
if(layergain < 1.0)
if(layergain < 1.0f)
layergain += dlayergain;
} else {
if(layergain > 0.0)
if(layergain > 0.0f)
layergain -= dlayergain;
}
if(src_->delayline)
Expand All @@ -242,13 +242,13 @@ uint32_t acoustic_model_t::process(const TASCAR::transport_t& tp)
distance = new_distance_with_delaycomp;
gain = nextgain;
air_absorption = next_air_absorption;
if(((gain != 0) || (dgain != 0))) {
if(src_->minlevel > 0) {
if(((gain != 0.0f) || (dgain != 0.0f))) {
if(src_->minlevel > 0.0f) {
if(audio.rms() <= src_->minlevel)
return 0;
}
// add scattering:
float scattering(0.0);
float scattering(0.0f);
if(reflector)
scattering = reflector->scattering;
// add to receiver:
Expand Down Expand Up @@ -289,13 +289,13 @@ void reflector_t::read_xml(TASCAR::xml_element_t& e)
}

void reflector_t::apply_reflectionfilter(TASCAR::wave_t& audio,
double& lpstate) const
float& lpstate) const
{
double c1(reflectivity * (1.0 - damping));
float c1 = reflectivity * (1.0f - damping);
float* p_begin(audio.d);
float* p_end(p_begin + audio.n);
for(float* pf = p_begin; pf != p_end; ++pf)
*pf = (float)(lpstate = lpstate * damping + *pf * c1);
*pf = (lpstate = lpstate * damping + *pf * c1);
}

receiver_graph_t::receiver_graph_t(
Expand Down Expand Up @@ -488,7 +488,7 @@ diffuse_acoustic_model_t::diffuse_acoustic_model_t(float fs, uint32_t chunksize,
pos_t prel;
float d = 1.0f;
float gain = 1.0f;
float nflimit(0.1);
float nflimit = 0.1f;
float traveltime_in_m = 1.0f;
receiver_->update_refpoint(src_->center, src_->center, prel, d,
traveltime_in_m, gain, false, GAIN_INVR, nflimit);
Expand All @@ -508,7 +508,7 @@ uint32_t diffuse_acoustic_model_t::process(const TASCAR::transport_t&)
pos_t prel;
float d = 0.0f;
float nextgain = 1.0f;
float nflimit(0.1);
float nflimit = 0.1f;
float nexttraveltime_in_m = 1.0f;
// calculate relative geometry between source and receiver:
receiver_->update_refpoint(src_->center, src_->center, prel, d,
Expand Down Expand Up @@ -635,31 +635,35 @@ void receiver_t::configure()
new TASCAR::fdn_t(scatterreflections, (uint32_t)f_sample, true,
TASCAR::fdn_t::mean, false, {0.0f, 0.0f, 0.0f, 0.0f});
scatterfilter->set_scatterpar(
scatterspread, f_sample * (0.1f * scatterstructuresize / 340.0f),
f_sample * (scatterstructuresize / 340.0f), f_sample,
scatterspread, (float)f_sample * (0.1f * scatterstructuresize / 340.0f),
(float)f_sample * (scatterstructuresize / 340.0f), (float)f_sample,
std::max(0.0f, std::min(0.999f, scatterdamping)));
scatterallpass_w.resize(scatterreflections);
scatterallpass_x.resize(scatterreflections);
scatterallpass_y.resize(scatterreflections);
scatterallpass_z.resize(scatterreflections);
size_t k = 1;
for(auto& flt : scatterallpass_x) {
flt.set_allpass(0.89f, TASCAR_2PI * 0.25 * k / scatterreflections);
flt.set_allpass(0.89f, TASCAR_2PIf * 0.25f * (float)k /
(float)scatterreflections);
++k;
}
k = 1;
for(auto& flt : scatterallpass_y) {
flt.set_allpass(0.9f, TASCAR_2PI * 0.25 * k / scatterreflections);
flt.set_allpass(0.9f, TASCAR_2PIf * 0.25f * (float)k /
(float)scatterreflections);
++k;
}
k = 1;
for(auto& flt : scatterallpass_z) {
flt.set_allpass(0.905f, TASCAR_2PI * 0.25 * k / scatterreflections);
flt.set_allpass(0.905f, TASCAR_2PIf * 0.25f * (float)k /
(float)scatterreflections);
++k;
}
k = 1;
for(auto& flt : scatterallpass_w) {
flt.set_allpass(0.91f, TASCAR_2PI * 0.25 * k / scatterreflections);
flt.set_allpass(0.91f, TASCAR_2PIf * 0.25f * (float)k /
(float)scatterreflections);
++k;
}
}
Expand Down Expand Up @@ -739,7 +743,7 @@ void receiver_t::postproc(std::vector<wave_t>& output)
{
// apply scatter buffer diffusion:
if(scatterfilter) {
for(size_t k = 0; k < n_fragment; ++k) {
for(uint32_t k = 0; k < n_fragment; ++k) {
TASCAR::foa_sample_t x(scatterbuffer->w()[k], scatterbuffer->x()[k],
scatterbuffer->y()[k], scatterbuffer->z()[k]);
size_t kflt = 0;
Expand Down Expand Up @@ -988,7 +992,7 @@ source_t::source_t(tsccfg::node_t xmlsrc, const std::string& name,
const std::string& parentname)
: sourcemod_t(xmlsrc), licensed_component_t(typeid(*this).name()),
ismmin(0), ismmax(2147483647), layers(0xffffffff), maxdist(3700),
minlevel(0), nearfieldlimit(0.1), sincorder(0), gainmodel(GAIN_INVR),
minlevel(0), nearfieldlimit(0.1f), sincorder(0), gainmodel(GAIN_INVR),
airabsorption(true), delayline(true), size(0), active(true),
// is_prepared(false),
plugins(xmlsrc, name, parentname)
Expand Down
4 changes: 2 additions & 2 deletions libtascar/src/coordinates.cc
Original file line number Diff line number Diff line change
Expand Up @@ -542,15 +542,15 @@ void TASCAR::vector_get_mean_std(const std::vector<double>& v, double& mean,
if(v.size() == 0)
return;
double sum = std::accumulate(v.begin(), v.end(), 0.0);
mean = sum / v.size();
mean = sum / (double)(v.size());
if(v.size() == 1)
return;
std::vector<double> diff(v.size());
std::transform(v.begin(), v.end(), diff.begin(),
[mean](double x) { return x - mean; });
double sq_sum =
std::inner_product(diff.begin(), diff.end(), diff.begin(), 0.0);
stdev = std::sqrt(sq_sum / (v.size() - 1));
stdev = std::sqrt(sq_sum / ((double)(v.size()) - 1.0));
}

/*
Expand Down
4 changes: 2 additions & 2 deletions libtascar/src/filterclass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,7 @@ int TASCAR::alpha2rflt(float& reflectivity, float& damping,

TASCAR::o1flt_lowpass_t::o1flt_lowpass_t(const std::vector<float>& tau,
float fs, float startval)
: TASCAR::o1_ar_filter_t(tau.size(), fs)
: TASCAR::o1_ar_filter_t((unsigned int)(tau.size()), fs)
{
for(unsigned int k = 0; k < tau.size(); k++) {
d[k] = startval;
Expand All @@ -922,7 +922,7 @@ TASCAR::o1flt_lowpass_t::o1flt_lowpass_t(const std::vector<float>& tau,
TASCAR::o1flt_lowpass_t::o1flt_lowpass_t(const std::vector<float>& tau,
float fs,
const std::vector<float>& startval)
: TASCAR::o1_ar_filter_t(tau.size(), fs)
: TASCAR::o1_ar_filter_t((unsigned int)(tau.size()), fs)
{
if(tau.size() != startval.size())
throw ErrMsg(
Expand Down
23 changes: 12 additions & 11 deletions libtascar/src/receivermod.cc
Original file line number Diff line number Diff line change
Expand Up @@ -359,18 +359,18 @@ spatial_error_t TASCAR::receivermod_base_speaker_t::get_spatial_error(
err.abs_elev_rV_error += fabs(rV.elev() - pos.elev());
err.abs_elev_rE_error += fabs(rE.elev() - pos.elev());
}
err.abs_rV_error = sqrt(err.abs_rV_error / srcpos.size());
err.abs_rE_error = sqrt(err.abs_rE_error / srcpos.size());
err.abs_rV_error = sqrt(err.abs_rV_error / (double)(srcpos.size()));
err.abs_rE_error = sqrt(err.abs_rE_error / (double)(srcpos.size()));
vector_get_mean_std(vang_rV, err.angular_rV_error, err.angular_rV_error_std);
vector_get_mean_std(vang_rE, err.angular_rE_error, err.angular_rE_error_std);
err.azim_rV_error /= srcpos.size();
err.azim_rE_error /= srcpos.size();
err.elev_rV_error /= srcpos.size();
err.elev_rE_error /= srcpos.size();
err.abs_azim_rV_error /= srcpos.size();
err.abs_azim_rE_error /= srcpos.size();
err.abs_elev_rV_error /= srcpos.size();
err.abs_elev_rE_error /= srcpos.size();
err.azim_rV_error /= (double)(srcpos.size());
err.azim_rE_error /= (double)(srcpos.size());
err.elev_rV_error /= (double)(srcpos.size());
err.elev_rE_error /= (double)(srcpos.size());
err.abs_azim_rV_error /= (double)(srcpos.size());
err.abs_azim_rE_error /= (double)(srcpos.size());
err.abs_elev_rV_error /= (double)(srcpos.size());
err.abs_elev_rE_error /= (double)(srcpos.size());
err.median_azim_rV_error = TASCAR::median(vaz_rV.begin(), vaz_rV.end());
err.median_azim_rE_error = TASCAR::median(vaz_rE.begin(), vaz_rE.end());
err.median_elev_rV_error = TASCAR::median(vel_rV.begin(), vel_rV.end());
Expand All @@ -395,7 +395,8 @@ void TASCAR::receivermod_base_speaker_t::post_prepare()
std::vector<TASCAR::pos_t> ring;
ring.resize(360);
for(size_t k = 0; k < ring.size(); ++k)
ring[k].set_sphere(1.0, k * TASCAR_2PI / (double)ring.size(), 0.0);
ring[k].set_sphere(1.0, (double)k * TASCAR_2PI / (double)ring.size(),
0.0);
spatial_error_t err = get_spatial_error(ring);
std::cout << "% spatial error:\n";
std::cout << "e.layout = '" << spkpos.layout << "';\n";
Expand Down

0 comments on commit 38b6869

Please sign in to comment.