Add and use a make_unique function

This commit is contained in:
Chris Robinson 2019-01-01 14:33:01 -08:00
parent c36798fd07
commit 2f1566e0b4
6 changed files with 21 additions and 15 deletions

View File

@ -3453,7 +3453,7 @@ ALC_API ALCcontext* ALC_APIENTRY alcCreateContext(ALCdevice *device, const ALCin
if(DefaultEffect.type != AL_EFFECT_NULL && dev->Type == Playback)
{
ALContext->DefaultSlot.reset(new ALeffectslot{});
ALContext->DefaultSlot = al::make_unique<ALeffectslot>();
if(InitEffectSlot(ALContext->DefaultSlot.get()) == AL_NO_ERROR)
aluInitEffectPanning(ALContext->DefaultSlot.get());
else
@ -3652,7 +3652,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName)
))
deviceName = nullptr;
std::unique_ptr<ALCdevice> device{new ALCdevice{Playback}};
auto device = al::make_unique<ALCdevice>(Playback);
//Set output format
device->FmtChans = DevFmtChannelsDefault;
@ -3896,7 +3896,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcCaptureOpenDevice(const ALCchar *deviceName,
if(deviceName && (!deviceName[0] || strcasecmp(deviceName, alcDefaultName) == 0 || strcasecmp(deviceName, "openal-soft") == 0))
deviceName = nullptr;
std::unique_ptr<ALCdevice> device{new ALCdevice{Capture}};
auto device = al::make_unique<ALCdevice>(Capture);
device->Frequency = frequency;
device->Flags |= DEVICE_FREQUENCY_REQUEST;
@ -4060,7 +4060,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcLoopbackOpenDeviceSOFT(const ALCchar *deviceN
return nullptr;
}
std::unique_ptr<ALCdevice> device{new ALCdevice{Loopback}};
auto device = al::make_unique<ALCdevice>(Loopback);
device->SourcesMax = 256;
device->AuxiliaryEffectSlotMax = 64;

View File

@ -1198,14 +1198,14 @@ HrtfEntry *GetLoadedHrtf(HrtfHandle *handle)
ERR("Could not get resource %u, %s\n", residx, name);
return nullptr;
}
stream.reset(new idstream{res.data, res.data+res.size});
stream = al::make_unique<idstream>(res.data, res.data+res.size);
}
else
{
name = handle->filename;
TRACE("Loading %s...\n", handle->filename);
std::unique_ptr<al::ifstream> fstr{new al::ifstream{handle->filename, std::ios::binary}};
auto fstr = al::make_unique<al::ifstream>(handle->filename, std::ios::binary);
if(!fstr->is_open())
{
ERR("Could not open %s\n", handle->filename);

View File

@ -358,20 +358,19 @@ std::unique_ptr<Compressor> CompressorInit(const ALsizei NumChans, const ALuint
clampf(std::round(LookAheadTime*SampleRate), 0.0f, BUFFERSIZE-1));
auto hold = static_cast<ALsizei>(clampf(std::round(HoldTime*SampleRate), 0.0f, BUFFERSIZE-1));
std::unique_ptr<Compressor> Comp;
size_t size{sizeof(Compressor)};
if(lookAhead > 0)
{
size += sizeof(*Comp->mDelay) * NumChans;
size += sizeof(*Compressor::mDelay) * NumChans;
/* The sliding hold implementation doesn't handle a length of 1. A 1-
* sample hold is useless anyway, it would only ever give back what was
* just given to it.
*/
if(hold > 1)
size += sizeof(*Comp->mHold);
size += sizeof(*Compressor::mHold);
}
Comp = std::unique_ptr<Compressor>{new (al_calloc(16, size)) Compressor{}};
auto Comp = std::unique_ptr<Compressor>{new (al_calloc(16, size)) Compressor{}};
Comp->mNumChans = NumChans;
Comp->mSampleRate = SampleRate;
Comp->mAuto.Knee = AutoKnee != AL_FALSE;
@ -388,7 +387,7 @@ std::unique_ptr<Compressor> CompressorInit(const ALsizei NumChans, const ALuint
Comp->mAttack = maxf(1.0f, AttackTime * SampleRate);
Comp->mRelease = maxf(1.0f, ReleaseTime * SampleRate);
/* Knee width automation actually treats the compressor as a limiter. By
/* Knee width automation actually treats the compressor as a limiter. By
* varying the knee width, it can effectively be seen as applying
* compression over a wide range of ratios.
*/

View File

@ -956,12 +956,12 @@ void aluInitRenderer(ALCdevice *device, ALint hrtf_id, HrtfRequestMode hrtf_appr
case DevFmtX71:
if(GetConfigValueBool(devname, nullptr, "front-stablizer", 0))
{
auto stablizer = al::make_unique<FrontStablizer>();
/* Initialize band-splitting filters for the front-left and
* front-right channels, with a crossover at 5khz (could be
* higher).
*/
ALfloat scale = (ALfloat)(5000.0 / device->Frequency);
std::unique_ptr<FrontStablizer> stablizer{new FrontStablizer{}};
const ALfloat scale{(ALfloat)(5000.0 / device->Frequency)};
stablizer->LFilter.init(scale);
stablizer->RFilter = stablizer->LFilter;
@ -969,7 +969,7 @@ void aluInitRenderer(ALCdevice *device, ALint hrtf_id, HrtfRequestMode hrtf_appr
/* Initialize all-pass filters for all other channels. */
stablizer->APFilter[0].init(scale);
std::fill(std::begin(stablizer->APFilter)+1, std::end(stablizer->APFilter),
stablizer->APFilter[0]);
stablizer->APFilter[0]);
device->Stablizer = std::move(stablizer);
}

View File

@ -213,7 +213,7 @@ AL_API ALvoid AL_APIENTRY alGenAuxiliaryEffectSlots(ALsizei n, ALuint *effectslo
iter = context->EffectSlotList.end() - 1;
}
*iter = std::unique_ptr<ALeffectslot>(new ALeffectslot{});
*iter = al::make_unique<ALeffectslot>();
ALenum err{InitEffectSlot(iter->get())};
if(err != AL_NO_ERROR)
{

View File

@ -83,6 +83,13 @@ inline T* assume_aligned(T *ptr) noexcept
#endif
}
/* std::make_unique was added with C++14, so until we rely on that, make our
* own version.
*/
template<typename T, typename ...ArgsT>
std::unique_ptr<T> make_unique(ArgsT&&...args)
{ return std::unique_ptr<T>{new T{std::forward<ArgsT>(args)...}}; }
} // namespace al
#endif /* AL_MALLOC_H */