aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/converter.cpp
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2018-12-27 12:55:43 -0800
committerChris Robinson <[email protected]>2018-12-27 12:55:43 -0800
commit1a4387d137acb57f69a2b5d073faf55d4a4c32ed (patch)
tree70b19a7ffa44c148c76996e3f715b0dff795dd4c /Alc/converter.cpp
parent323cf58f02bd2a8a92006a5ee20014d2eb8ff3a9 (diff)
Return unique_ptrs instead of raw pointers
For the ring buffer, channel converter, and sample converter.
Diffstat (limited to 'Alc/converter.cpp')
-rw-r--r--Alc/converter.cpp31
1 files changed, 6 insertions, 25 deletions
diff --git a/Alc/converter.cpp b/Alc/converter.cpp
index 66627879..52472bde 100644
--- a/Alc/converter.cpp
+++ b/Alc/converter.cpp
@@ -135,14 +135,14 @@ void Stereo2Mono(ALfloat *RESTRICT dst, const void *src, ALsizei frames)
} // namespace
-SampleConverter *CreateSampleConverter(DevFmtType srcType, DevFmtType dstType, ALsizei numchans,
- ALsizei srcRate, ALsizei dstRate, Resampler resampler)
+SampleConverterPtr CreateSampleConverter(DevFmtType srcType, DevFmtType dstType, ALsizei numchans,
+ ALsizei srcRate, ALsizei dstRate, Resampler resampler)
{
if(numchans <= 0 || srcRate <= 0 || dstRate <= 0)
return nullptr;
- size_t alloc_size{FAM_SIZE(SampleConverter, Chan, numchans)};
- auto converter = new (al_calloc(16, alloc_size)) SampleConverter{};
+ const size_t alloc_size{FAM_SIZE(SampleConverter, Chan, numchans)};
+ SampleConverterPtr converter{new (al_calloc(16, alloc_size)) SampleConverter{}};
converter->mSrcType = srcType;
converter->mDstType = dstType;
converter->mNumChannels = numchans;
@@ -171,16 +171,6 @@ SampleConverter *CreateSampleConverter(DevFmtType srcType, DevFmtType dstType, A
return converter;
}
-void DestroySampleConverter(SampleConverter **converter)
-{
- if(converter)
- {
- delete *converter;
- *converter = nullptr;
- }
-}
-
-
ALsizei SampleConverterAvailableOut(SampleConverter *converter, ALsizei srcframes)
{
ALint prepcount{converter->mSrcPrepCount};
@@ -339,22 +329,13 @@ ALsizei SampleConverterInput(SampleConverter *converter, const ALvoid **src, ALs
}
-ChannelConverter *CreateChannelConverter(DevFmtType srcType, DevFmtChannels srcChans, DevFmtChannels dstChans)
+ChannelConverterPtr CreateChannelConverter(DevFmtType srcType, DevFmtChannels srcChans, DevFmtChannels dstChans)
{
if(srcChans != dstChans && !((srcChans == DevFmtMono && dstChans == DevFmtStereo) ||
(srcChans == DevFmtStereo && dstChans == DevFmtMono)))
return nullptr;
- return new ChannelConverter{srcType, srcChans, dstChans};
-}
-
-void DestroyChannelConverter(ChannelConverter **converter)
-{
- if(converter)
- {
- delete *converter;
- *converter = nullptr;
- }
+ return ChannelConverterPtr{new ChannelConverter{srcType, srcChans, dstChans}};
}
void ChannelConverterInput(ChannelConverter *converter, const ALvoid *src, ALfloat *dst, ALsizei frames)