Skip to content

Commit

Permalink
Be a bit safer and less explicit with spans
Browse files Browse the repository at this point in the history
  • Loading branch information
kcat committed Apr 3, 2024
1 parent f1606c4 commit 7f0a625
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
12 changes: 6 additions & 6 deletions alc/panning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstddef>
#include <cstdio>
#include <cstdint>
#include <functional>
#include <iterator>
#include <memory>
#include <numeric>
#include <optional>
Expand All @@ -42,7 +42,6 @@
#include "AL/alext.h"

#include "alc/context.h"
#include "almalloc.h"
#include "alnumbers.h"
#include "alnumeric.h"
#include "alspan.h"
Expand Down Expand Up @@ -372,7 +371,7 @@ DecoderView MakeDecoderView(ALCdevice *device, const AmbDecConf *conf,
const auto lfmatrix = conf->LFMatrix;

uint chan_count{0};
for(auto &speaker : al::span<const AmbDecConf::SpeakerConf>{conf->Speakers})
for(auto &speaker : al::span{std::as_const(conf->Speakers)})
{
/* NOTE: AmbDec does not define any standard speaker names, however
* for this to work we have to by able to find the output channel
Expand Down Expand Up @@ -673,8 +672,8 @@ void InitPanning(ALCdevice *device, const bool hqdec=false, const bool stablize=
device->mAmbiOrder = decoder.mOrder;
device->m2DMixing = !decoder.mIs3D;

const al::span<const uint8_t> acnmap{decoder.mIs3D ? AmbiIndex::FromACN.data() :
AmbiIndex::FromACN2D.data(), ambicount};
const auto acnmap = decoder.mIs3D ? al::span{AmbiIndex::FromACN}.first(ambicount)
: al::span{AmbiIndex::FromACN2D}.first(ambicount);
const auto coeffscale = GetAmbiScales(decoder.mScaling);
std::transform(acnmap.begin(), acnmap.end(), device->Dry.AmbiMap.begin(),
[coeffscale](const uint8_t &acn) noexcept
Expand Down Expand Up @@ -1012,7 +1011,8 @@ void aluInitRenderer(ALCdevice *device, int hrtf_id, std::optional<StereoEncodin
decoder_store = std::make_unique<DecoderConfig<DualBand,MaxOutputChannels>>();
decoder = MakeDecoderView(device, &conf, *decoder_store);

const auto confspeakers = al::span{conf.Speakers.cbegin(), decoder.mChannels.size()};
const auto confspeakers = al::span{std::as_const(conf.Speakers)}
.first(decoder.mChannels.size());
std::transform(confspeakers.cbegin(), confspeakers.cend(), speakerdists.begin(),
std::mem_fn(&AmbDecConf::SpeakerConf::Distance));
return true;
Expand Down
8 changes: 5 additions & 3 deletions core/mixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@

#include "mixer.h"

#include <algorithm>
#include <cmath>
#include <utility>

#include "alnumbers.h"
#include "devformat.h"
#include "core/ambidefs.h"
#include "device.h"
#include "mixer/defs.h"

Expand Down Expand Up @@ -85,9 +87,9 @@ std::array<float,MaxAmbiChannels> CalcAmbiCoeffs(const float y, const float z, c
void ComputePanGains(const MixParams *mix, const al::span<const float,MaxAmbiChannels> coeffs,
const float ingain, const al::span<float,MaxAmbiChannels> gains)
{
auto ambimap = mix->AmbiMap.cbegin();
auto ambimap = al::span{std::as_const(mix->AmbiMap)}.first(mix->Buffer.size());

auto iter = std::transform(ambimap, ambimap+mix->Buffer.size(), gains.begin(),
auto iter = std::transform(ambimap.begin(), ambimap.end(), gains.begin(),
[coeffs,ingain](const BFChannelConfig &chanmap) noexcept -> float
{ return chanmap.Scale * coeffs[chanmap.Index] * ingain; });
std::fill(iter, gains.end(), 0.0f);
Expand Down
2 changes: 0 additions & 2 deletions core/mixer.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
#include <array>
#include <cmath>
#include <stddef.h>
#include <type_traits>

#include "alspan.h"
#include "ambidefs.h"
#include "bufferline.h"
#include "devformat.h"

struct MixParams;

Expand Down

0 comments on commit 7f0a625

Please sign in to comment.