Avoid dynamically allocating ChannelConverter

This commit is contained in:
Chris Robinson
2019-09-10 23:01:33 -07:00
parent 19e1cd7430
commit 65374dc5d0
3 changed files with 7 additions and 33 deletions
+6 -16
View File
@@ -1166,7 +1166,7 @@ struct WasapiCapture final : public BackendBase, WasapiProxy {
IAudioCaptureClient *mCapture{nullptr};
HANDLE mNotifyEvent{nullptr};
ChannelConverterPtr mChannelConv;
ChannelConverter mChannelConv{};
SampleConverterPtr mSampleConv;
RingBufferPtr mRing;
@@ -1216,10 +1216,10 @@ FORCE_ALIGN int WasapiCapture::recordProc()
ERR("Failed to get capture buffer: 0x%08lx\n", hr);
else
{
if(mChannelConv)
if(mChannelConv.is_active())
{
samples.resize(numsamples*2);
mChannelConv->convert(rdata, samples.data(), numsamples);
mChannelConv.convert(rdata, samples.data(), numsamples);
rdata = reinterpret_cast<BYTE*>(samples.data());
}
@@ -1487,7 +1487,7 @@ HRESULT WasapiCapture::resetProxy()
}
mSampleConv = nullptr;
mChannelConv = nullptr;
mChannelConv = {};
if(wfx != nullptr)
{
@@ -1546,12 +1546,7 @@ HRESULT WasapiCapture::resetProxy()
if(mDevice->FmtChans == DevFmtMono && OutputType.Format.nChannels == 2)
{
mChannelConv = CreateChannelConverter(srcType, DevFmtStereo, mDevice->FmtChans);
if(!mChannelConv)
{
ERR("Failed to create %s stereo-to-mono converter\n", DevFmtTypeString(srcType));
return E_FAIL;
}
mChannelConv = ChannelConverter{srcType, DevFmtStereo, mDevice->FmtChans};
TRACE("Created %s stereo-to-mono converter\n", DevFmtTypeString(srcType));
/* The channel converter always outputs float, so change the input type
* for the resampler/type-converter.
@@ -1560,12 +1555,7 @@ HRESULT WasapiCapture::resetProxy()
}
else if(mDevice->FmtChans == DevFmtStereo && OutputType.Format.nChannels == 1)
{
mChannelConv = CreateChannelConverter(srcType, DevFmtMono, mDevice->FmtChans);
if(!mChannelConv)
{
ERR("Failed to create %s mono-to-stereo converter\n", DevFmtTypeString(srcType));
return E_FAIL;
}
mChannelConv = ChannelConverter{srcType, DevFmtMono, mDevice->FmtChans};
TRACE("Created %s mono-to-stereo converter\n", DevFmtTypeString(srcType));
srcType = DevFmtFloat;
}
-8
View File
@@ -327,14 +327,6 @@ ALuint SampleConverter::convert(const ALvoid **src, ALuint *srcframes, ALvoid *d
}
ChannelConverterPtr CreateChannelConverter(DevFmtType srcType, DevFmtChannels srcChans, DevFmtChannels dstChans)
{
if(srcChans != dstChans && !((srcChans == DevFmtMono && dstChans == DevFmtStereo) ||
(srcChans == DevFmtStereo && dstChans == DevFmtMono)))
return nullptr;
return al::make_unique<ChannelConverter>(srcType, srcChans, dstChans);
}
void ChannelConverter::convert(const ALvoid *src, ALfloat *dst, ALuint frames) const
{
if(mSrcChans == DevFmtStereo && mDstChans == DevFmtMono)
+1 -9
View File
@@ -58,17 +58,9 @@ struct ChannelConverter {
DevFmtChannels mSrcChans;
DevFmtChannels mDstChans;
ChannelConverter(DevFmtType srctype, DevFmtChannels srcchans, DevFmtChannels dstchans)
: mSrcType(srctype), mSrcChans(srcchans), mDstChans(dstchans)
{ }
bool is_active() const noexcept { return mSrcChans != mDstChans; }
void convert(const ALvoid *src, ALfloat *dst, ALuint frames) const;
DEF_NEWDEL(ChannelConverter)
};
using ChannelConverterPtr = std::unique_ptr<ChannelConverter>;
ChannelConverterPtr CreateChannelConverter(DevFmtType srcType, DevFmtChannels srcChans,
DevFmtChannels dstChans);
#endif /* CONVERTER_H */