Make the resampler type an enum class

master
Chris Robinson 2019-09-22 21:19:19 -07:00
parent 95996effaf
commit 24db8a3f4b
8 changed files with 36 additions and 35 deletions

View File

@ -1295,7 +1295,7 @@ bool SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a
case AL_SOURCE_RESAMPLER_SOFT:
CHECKSIZE(values, 1);
CHECKVAL(values[0] >= 0 && values[0] <= ResamplerMax);
CHECKVAL(values[0] >= 0 && values[0] <= static_cast<int>(Resampler::Max));
Source->mResampler = static_cast<Resampler>(values[0]);
return UpdateSourceProps(Source, Context);
@ -1836,7 +1836,7 @@ bool GetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a
case AL_SOURCE_RESAMPLER_SOFT:
CHECKSIZE(values, 1);
values[0] = Source->mResampler;
values[0] = static_cast<int>(Source->mResampler);
return true;
case AL_SOURCE_SPATIALIZE_SOFT:

View File

@ -196,7 +196,7 @@ START_API_FUNC
break;
case AL_DEFAULT_RESAMPLER_SOFT:
value = ResamplerDefault ? AL_TRUE : AL_FALSE;
value = static_cast<int>(ResamplerDefault) ? AL_TRUE : AL_FALSE;
break;
default:
@ -243,7 +243,7 @@ START_API_FUNC
break;
case AL_NUM_RESAMPLERS_SOFT:
value = static_cast<ALdouble>(ResamplerMax + 1);
value = static_cast<ALdouble>(Resampler::Max) + 1.0;
break;
case AL_DEFAULT_RESAMPLER_SOFT:
@ -294,7 +294,7 @@ START_API_FUNC
break;
case AL_NUM_RESAMPLERS_SOFT:
value = static_cast<ALfloat>(ResamplerMax + 1);
value = static_cast<ALfloat>(Resampler::Max) + 1.0f;
break;
case AL_DEFAULT_RESAMPLER_SOFT:
@ -345,11 +345,11 @@ START_API_FUNC
break;
case AL_NUM_RESAMPLERS_SOFT:
value = ResamplerMax + 1;
value = static_cast<int>(Resampler::Max) + 1;
break;
case AL_DEFAULT_RESAMPLER_SOFT:
value = ResamplerDefault;
value = static_cast<int>(ResamplerDefault);
break;
default:
@ -396,7 +396,7 @@ START_API_FUNC
break;
case AL_NUM_RESAMPLERS_SOFT:
value = static_cast<ALint64SOFT>(ResamplerMax + 1);
value = static_cast<ALint64SOFT>(Resampler::Max) + 1;
break;
case AL_DEFAULT_RESAMPLER_SOFT:
@ -801,7 +801,8 @@ START_API_FUNC
alCubicResampler, alBSinc12Resampler,
alBSinc24Resampler,
};
static_assert(al::size(ResamplerNames) == ResamplerMax+1, "Incorrect ResamplerNames list");
static_assert(al::size(ResamplerNames) == static_cast<ALuint>(Resampler::Max)+1,
"Incorrect ResamplerNames list");
ContextRef context{GetContextRef()};
if UNLIKELY(!context) return nullptr;

View File

@ -947,9 +947,9 @@ void CalcNonAttnSourceParams(ALvoice *voice, const ALvoicePropsBase *props, cons
voice->mStep = MAX_PITCH<<FRACTIONBITS;
else
voice->mStep = maxu(fastf2u(Pitch * FRACTIONONE), 1);
if(props->mResampler == BSinc24Resampler)
if(props->mResampler == Resampler::BSinc24)
BsincPrepare(voice->mStep, &voice->mResampleState.bsinc, &bsinc24);
else if(props->mResampler == BSinc12Resampler)
else if(props->mResampler == Resampler::BSinc12)
BsincPrepare(voice->mStep, &voice->mResampleState.bsinc, &bsinc12);
voice->mResampler = SelectResampler(props->mResampler);
@ -1277,9 +1277,9 @@ void CalcAttnSourceParams(ALvoice *voice, const ALvoicePropsBase *props, const A
voice->mStep = MAX_PITCH<<FRACTIONBITS;
else
voice->mStep = maxu(fastf2u(Pitch * FRACTIONONE), 1);
if(props->mResampler == BSinc24Resampler)
if(props->mResampler == Resampler::BSinc24)
BsincPrepare(voice->mStep, &voice->mResampleState.bsinc, &bsinc24);
else if(props->mResampler == BSinc12Resampler)
else if(props->mResampler == Resampler::BSinc12)
BsincPrepare(voice->mStep, &voice->mResampleState.bsinc, &bsinc12);
voice->mResampler = SelectResampler(props->mResampler);

View File

@ -42,14 +42,14 @@ enum SpatializeMode {
SpatializeAuto = AL_AUTO_SOFT
};
enum Resampler {
PointResampler,
LinearResampler,
FIR4Resampler,
BSinc12Resampler,
BSinc24Resampler,
enum class Resampler {
Point,
Linear,
Cubic,
BSinc12,
BSinc24,
ResamplerMax = BSinc24Resampler
Max = BSinc24
};
extern Resampler ResamplerDefault;

View File

@ -618,7 +618,7 @@ ALCenum CoreAudioCapture::open(const ALCchar *name)
if(outputFormat.mSampleRate != mDevice->Frequency)
mConverter = CreateSampleConverter(mDevice->FmtType, mDevice->FmtType,
mFormat.mChannelsPerFrame, static_cast<ALuint>(hardwareFormat.mSampleRate),
mDevice->Frequency, BSinc24Resampler);
mDevice->Frequency, Resampler::BSinc24);
mRing = CreateRingBuffer(outputFrameCount, mFrameSize, false);
if(!mRing) return ALC_INVALID_VALUE;

View File

@ -1568,7 +1568,7 @@ HRESULT WasapiCapture::resetProxy()
if(mDevice->Frequency != OutputType.Format.nSamplesPerSec || mDevice->FmtType != srcType)
{
mSampleConv = CreateSampleConverter(srcType, mDevice->FmtType, mDevice->channelsFromFmt(),
OutputType.Format.nSamplesPerSec, mDevice->Frequency, BSinc24Resampler);
OutputType.Format.nSamplesPerSec, mDevice->Frequency, Resampler::BSinc24);
if(!mSampleConv)
{
ERR("Failed to create converter for %s format, dst: %s %uhz, src: %s %luhz\n",

View File

@ -167,9 +167,9 @@ SampleConverterPtr CreateSampleConverter(DevFmtType srcType, DevFmtType dstType,
converter->mResample = Resample_<CopyTag,CTag>;
else
{
if(resampler == BSinc24Resampler)
if(resampler == Resampler::BSinc24)
BsincPrepare(converter->mIncrement, &converter->mState.bsinc, &bsinc24);
else if(resampler == BSinc12Resampler)
else if(resampler == Resampler::BSinc12)
BsincPrepare(converter->mIncrement, &converter->mState.bsinc, &bsinc12);
converter->mResample = SelectResampler(resampler);
}

View File

@ -70,7 +70,7 @@ static_assert((INT_MAX>>FRACTIONBITS)/MAX_PITCH > BUFFERSIZE,
static_assert(MAX_RESAMPLE_PADDING >= 24, "MAX_RESAMPLE_PADDING must be at least 24!");
Resampler ResamplerDefault = LinearResampler;
Resampler ResamplerDefault{Resampler::Linear};
MixerFunc MixSamples = Mix_<CTag>;
RowMixerFunc MixRowSamples = MixRow_<CTag>;
@ -139,9 +139,9 @@ ResamplerFunc SelectResampler(Resampler resampler)
{
switch(resampler)
{
case PointResampler:
case Resampler::Point:
return Resample_<PointTag,CTag>;
case LinearResampler:
case Resampler::Linear:
#ifdef HAVE_NEON
if((CPUCapFlags&CPU_CAP_NEON))
return Resample_<LerpTag,NEONTag>;
@ -155,10 +155,10 @@ ResamplerFunc SelectResampler(Resampler resampler)
return Resample_<LerpTag,SSE2Tag>;
#endif
return Resample_<LerpTag,CTag>;
case FIR4Resampler:
case Resampler::Cubic:
return Resample_<CubicTag,CTag>;
case BSinc12Resampler:
case BSinc24Resampler:
case Resampler::BSinc12:
case Resampler::BSinc24:
#ifdef HAVE_NEON
if((CPUCapFlags&CPU_CAP_NEON))
return Resample_<BSincTag,NEONTag>;
@ -183,11 +183,11 @@ void aluInitMixer()
const Resampler resampler;
};
constexpr ResamplerEntry ResamplerList[]{
{ "none", PointResampler },
{ "point", PointResampler },
{ "cubic", FIR4Resampler },
{ "bsinc12", BSinc12Resampler },
{ "bsinc24", BSinc24Resampler },
{ "none", Resampler::Point },
{ "point", Resampler::Point },
{ "cubic", Resampler::Cubic },
{ "bsinc12", Resampler::BSinc12 },
{ "bsinc24", Resampler::BSinc24 },
};
const char *str{resopt->c_str()};