diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/hrtf.cpp | 21 | ||||
-rw-r--r-- | core/mastering.cpp | 12 | ||||
-rw-r--r-- | core/mastering.h | 1 | ||||
-rw-r--r-- | core/voice.cpp | 6 |
4 files changed, 20 insertions, 20 deletions
diff --git a/core/hrtf.cpp b/core/hrtf.cpp index e0ab8f0a..74483c26 100644 --- a/core/hrtf.cpp +++ b/core/hrtf.cpp @@ -368,19 +368,18 @@ std::unique_ptr<HrtfStore> CreateHrtfStore(uint rate, ushort irSize, const al::span<const HrtfStore::Elevation> elevs, const HrirArray *coeffs, const ubyte2 *delays, const char *filename) { - std::unique_ptr<HrtfStore> Hrtf; - const size_t irCount{size_t{elevs.back().azCount} + elevs.back().irOffset}; size_t total{sizeof(HrtfStore)}; total = RoundUp(total, alignof(HrtfStore::Field)); /* Align for field infos */ - total += sizeof(HrtfStore::Field)*fields.size(); + total += sizeof(std::declval<HrtfStore&>().field[0])*fields.size(); total = RoundUp(total, alignof(HrtfStore::Elevation)); /* Align for elevation infos */ - total += sizeof(Hrtf->elev[0])*elevs.size(); + total += sizeof(std::declval<HrtfStore&>().elev[0])*elevs.size(); total = RoundUp(total, 16); /* Align for coefficients using SIMD */ - total += sizeof(Hrtf->coeffs[0])*irCount; - total += sizeof(Hrtf->delays[0])*irCount; + total += sizeof(std::declval<HrtfStore&>().coeffs[0])*irCount; + total += sizeof(std::declval<HrtfStore&>().delays[0])*irCount; - Hrtf.reset(new (al_calloc(16, total)) HrtfStore{}); + void *ptr{al_calloc(16, total)}; + std::unique_ptr<HrtfStore> Hrtf{al::construct_at(static_cast<HrtfStore*>(ptr))}; if(!Hrtf) ERR("Out of memory allocating storage for %s.\n", filename); else @@ -412,10 +411,10 @@ std::unique_ptr<HrtfStore> CreateHrtfStore(uint rate, ushort irSize, assert(offset == total); /* Copy input data to storage. */ - std::copy(fields.cbegin(), fields.cend(), field_); - std::copy(elevs.cbegin(), elevs.cend(), elev_); - std::copy_n(coeffs, irCount, coeffs_); - std::copy_n(delays, irCount, delays_); + std::uninitialized_copy(fields.cbegin(), fields.cend(), field_); + std::uninitialized_copy(elevs.cbegin(), elevs.cend(), elev_); + std::uninitialized_copy_n(coeffs, irCount, coeffs_); + std::uninitialized_copy_n(delays, irCount, delays_); /* Finally, assign the storage pointers. */ Hrtf->field = field_; diff --git a/core/mastering.cpp b/core/mastering.cpp index e0cb2ca7..3a577109 100644 --- a/core/mastering.cpp +++ b/core/mastering.cpp @@ -334,7 +334,7 @@ std::unique_ptr<Compressor> Compressor::Create(const size_t NumChans, const floa size += sizeof(*Compressor::mHold); } - auto Comp = std::unique_ptr<Compressor>{new (al_calloc(16, size)) Compressor{}}; + auto Comp = CompressorPtr{al::construct_at(static_cast<Compressor*>(al_calloc(16, size)))}; Comp->mNumChans = NumChans; Comp->mAuto.Knee = AutoKnee; Comp->mAuto.Attack = AutoAttack; @@ -361,17 +361,15 @@ std::unique_ptr<Compressor> Compressor::Create(const size_t NumChans, const floa { if(hold > 1) { - Comp->mHold = ::new (static_cast<void*>(Comp.get() + 1)) SlidingHold{}; + Comp->mHold = al::construct_at(reinterpret_cast<SlidingHold*>(Comp.get() + 1)); Comp->mHold->mValues[0] = -std::numeric_limits<float>::infinity(); Comp->mHold->mExpiries[0] = hold; Comp->mHold->mLength = hold; - Comp->mDelay = ::new(static_cast<void*>(Comp->mHold + 1)) FloatBufferLine[NumChans]; + Comp->mDelay = reinterpret_cast<FloatBufferLine*>(Comp->mHold + 1); } else - { - Comp->mDelay = ::new(static_cast<void*>(Comp.get() + 1)) FloatBufferLine[NumChans]; - } - std::fill_n(Comp->mDelay, NumChans, FloatBufferLine{}); + Comp->mDelay = reinterpret_cast<FloatBufferLine*>(Comp.get() + 1); + std::uninitialized_fill_n(Comp->mDelay, NumChans, FloatBufferLine{}); } Comp->mCrestCoeff = std::exp(-1.0f / (0.200f * SampleRate)); // 200ms diff --git a/core/mastering.h b/core/mastering.h index 322d3654..1a36937c 100644 --- a/core/mastering.h +++ b/core/mastering.h @@ -100,5 +100,6 @@ struct Compressor { const float ThresholdDb, const float Ratio, const float KneeDb, const float AttackTime, const float ReleaseTime); }; +using CompressorPtr = std::unique_ptr<Compressor>; #endif /* CORE_MASTERING_H */ diff --git a/core/voice.cpp b/core/voice.cpp index ea99f8ad..fd2b7089 100644 --- a/core/voice.cpp +++ b/core/voice.cpp @@ -164,7 +164,8 @@ void SendSourceStoppedEvent(ContextBase *context, uint id) auto evt_vec = ring->getWriteVector(); if(evt_vec.first.len < 1) return; - AsyncEvent *evt{::new(evt_vec.first.buf) AsyncEvent{EventType_SourceStateChange}}; + AsyncEvent *evt{al::construct_at(reinterpret_cast<AsyncEvent*>(evt_vec.first.buf), + EventType_SourceStateChange)}; evt->u.srcstate.id = id; evt->u.srcstate.state = AsyncEvent::SrcState::Stop; @@ -792,7 +793,8 @@ void Voice::mix(const State vstate, ContextBase *Context, const uint SamplesToDo auto evt_vec = ring->getWriteVector(); if(evt_vec.first.len > 0) { - AsyncEvent *evt{::new(evt_vec.first.buf) AsyncEvent{EventType_BufferCompleted}}; + AsyncEvent *evt{al::construct_at(reinterpret_cast<AsyncEvent*>(evt_vec.first.buf), + EventType_BufferCompleted)}; evt->u.bufcomp.id = SourceID; evt->u.bufcomp.count = buffers_done; ring->writeAdvance(1); |