Store the resampler as part of the source

This commit is contained in:
Chris Robinson 2017-04-21 00:06:40 -07:00
parent 1e8ea59564
commit 26b49c54af
5 changed files with 22 additions and 17 deletions

View File

@ -455,6 +455,7 @@ static void CalcNonAttnSourceParams(ALvoice *voice, const struct ALvoiceProps *p
else else
voice->Step = maxi(fastf2i(Pitch*FRACTIONONE + 0.5f), 1); voice->Step = maxi(fastf2i(Pitch*FRACTIONONE + 0.5f), 1);
BsincPrepare(voice->Step, &voice->ResampleState.bsinc); BsincPrepare(voice->Step, &voice->ResampleState.bsinc);
voice->Resampler = SelectResampler(props->Resampler);
/* Calculate gains */ /* Calculate gains */
DryGain = clampf(SourceVolume, MinVolume, MaxVolume); DryGain = clampf(SourceVolume, MinVolume, MaxVolume);
@ -1095,6 +1096,7 @@ static void CalcAttnSourceParams(ALvoice *voice, const struct ALvoiceProps *prop
else else
voice->Step = maxi(fastf2i(Pitch*FRACTIONONE + 0.5f), 1); voice->Step = maxi(fastf2i(Pitch*FRACTIONONE + 0.5f), 1);
BsincPrepare(voice->Step, &voice->ResampleState.bsinc); BsincPrepare(voice->Step, &voice->ResampleState.bsinc);
voice->Resampler = SelectResampler(props->Resampler);
voice->Flags &= ~(VOICE_IS_HRTF | VOICE_HAS_NFC); voice->Flags &= ~(VOICE_IS_HRTF | VOICE_HAS_NFC);
if(Device->Render_Mode == HrtfRender) if(Device->Render_Mode == HrtfRender)

View File

@ -53,7 +53,6 @@ enum Resampler ResamplerDefault = LinearResampler;
static MixerFunc MixSamples = Mix_C; static MixerFunc MixSamples = Mix_C;
static HrtfMixerFunc MixHrtfSamples = MixHrtf_C; static HrtfMixerFunc MixHrtfSamples = MixHrtf_C;
static ResamplerFunc ResampleSamples = Resample_point32_C;
MixerFunc SelectMixer(void) MixerFunc SelectMixer(void)
{ {
@ -177,7 +176,6 @@ void aluInitMixer(void)
MixHrtfSamples = SelectHrtfMixer(); MixHrtfSamples = SelectHrtfMixer();
MixSamples = SelectMixer(); MixSamples = SelectMixer();
ResampleSamples = SelectResampler(ResamplerDefault);
} }
@ -295,7 +293,7 @@ ALboolean MixSource(ALvoice *voice, ALsource *Source, ALCdevice *Device, ALsizei
IrSize = (Device->HrtfHandle ? Device->HrtfHandle->irSize : 0); IrSize = (Device->HrtfHandle ? Device->HrtfHandle->irSize : 0);
Resample = ((increment == FRACTIONONE && DataPosFrac == 0) ? Resample = ((increment == FRACTIONONE && DataPosFrac == 0) ?
Resample_copy32_C : ResampleSamples); Resample_copy32_C : voice->Resampler);
Counter = (voice->Flags&VOICE_IS_MOVING) ? SamplesToDo : 0; Counter = (voice->Flags&VOICE_IS_MOVING) ? SamplesToDo : 0;
OutPos = 0; OutPos = 0;

View File

@ -43,6 +43,7 @@ typedef struct ALsource {
ALboolean HeadRelative; ALboolean HeadRelative;
ALboolean Looping; ALboolean Looping;
enum DistanceModel DistanceModel; enum DistanceModel DistanceModel;
enum Resampler Resampler;
ALboolean DirectChannels; ALboolean DirectChannels;
ALboolean DryGainHFAuto; ALboolean DryGainHFAuto;

View File

@ -40,6 +40,14 @@ struct ALvoice;
struct ALeffectslot; struct ALeffectslot;
enum Resampler {
PointResampler,
LinearResampler,
FIR4Resampler,
BSincResampler,
};
extern enum Resampler ResamplerDefault;
/* The number of distinct scale and phase intervals within the filter table. */ /* The number of distinct scale and phase intervals within the filter table. */
#define BSINC_SCALE_BITS 4 #define BSINC_SCALE_BITS 4
#define BSINC_SCALE_COUNT (1<<BSINC_SCALE_BITS) #define BSINC_SCALE_COUNT (1<<BSINC_SCALE_BITS)
@ -66,6 +74,11 @@ typedef union InterpState {
BsincState bsinc; BsincState bsinc;
} InterpState; } InterpState;
typedef const ALfloat* (*ResamplerFunc)(const InterpState *state,
const ALfloat *restrict src, ALsizei frac, ALint increment,
ALfloat *restrict dst, ALsizei dstlen
);
typedef union aluVector { typedef union aluVector {
alignas(16) ALfloat v[4]; alignas(16) ALfloat v[4];
@ -172,6 +185,7 @@ struct ALvoiceProps {
ALfloat Orientation[2][3]; ALfloat Orientation[2][3];
ALboolean HeadRelative; ALboolean HeadRelative;
enum DistanceModel DistanceModel; enum DistanceModel DistanceModel;
enum Resampler Resampler;
ALboolean DirectChannels; ALboolean DirectChannels;
ALboolean DryGainHFAuto; ALboolean DryGainHFAuto;
@ -245,6 +259,8 @@ typedef struct ALvoice {
/** Current target parameters used for mixing. */ /** Current target parameters used for mixing. */
ALint Step; ALint Step;
ResamplerFunc Resampler;
ALuint Flags; ALuint Flags;
ALuint Offset; /* Number of output samples mixed since starting. */ ALuint Offset; /* Number of output samples mixed since starting. */
@ -272,11 +288,6 @@ typedef struct ALvoice {
void DeinitVoice(ALvoice *voice); void DeinitVoice(ALvoice *voice);
typedef const ALfloat* (*ResamplerFunc)(const InterpState *state,
const ALfloat *restrict src, ALsizei frac, ALint increment,
ALfloat *restrict dst, ALsizei dstlen
);
typedef void (*MixerFunc)(const ALfloat *data, ALsizei OutChans, typedef void (*MixerFunc)(const ALfloat *data, ALsizei OutChans,
ALfloat (*restrict OutBuffer)[BUFFERSIZE], ALfloat *CurrentGains, ALfloat (*restrict OutBuffer)[BUFFERSIZE], ALfloat *CurrentGains,
const ALfloat *TargetGains, ALsizei Counter, ALsizei OutPos, const ALfloat *TargetGains, ALsizei Counter, ALsizei OutPos,
@ -364,21 +375,12 @@ inline ALfloat resample_fir4(ALfloat val0, ALfloat val1, ALfloat val2, ALfloat v
} }
enum Resampler {
PointResampler,
LinearResampler,
FIR4Resampler,
BSincResampler,
};
extern enum Resampler ResamplerDefault;
enum HrtfRequestMode { enum HrtfRequestMode {
Hrtf_Default = 0, Hrtf_Default = 0,
Hrtf_Enable = 1, Hrtf_Enable = 1,
Hrtf_Disable = 2, Hrtf_Disable = 2,
}; };
void aluInitMixer(void); void aluInitMixer(void);
MixerFunc SelectMixer(void); MixerFunc SelectMixer(void);

View File

@ -2946,6 +2946,7 @@ static void InitSourceParams(ALsource *Source, ALsizei num_sends)
Source->HeadRelative = AL_FALSE; Source->HeadRelative = AL_FALSE;
Source->Looping = AL_FALSE; Source->Looping = AL_FALSE;
Source->DistanceModel = DefaultDistanceModel; Source->DistanceModel = DefaultDistanceModel;
Source->Resampler = ResamplerDefault;
Source->DirectChannels = AL_FALSE; Source->DirectChannels = AL_FALSE;
Source->StereoPan[0] = DEG2RAD( 30.0f); Source->StereoPan[0] = DEG2RAD( 30.0f);
@ -3054,6 +3055,7 @@ static void UpdateSourceProps(ALsource *source, ALvoice *voice, ALsizei num_send
} }
props->HeadRelative = source->HeadRelative; props->HeadRelative = source->HeadRelative;
props->DistanceModel = source->DistanceModel; props->DistanceModel = source->DistanceModel;
props->Resampler = source->Resampler;
props->DirectChannels = source->DirectChannels; props->DirectChannels = source->DirectChannels;
props->DryGainHFAuto = source->DryGainHFAuto; props->DryGainHFAuto = source->DryGainHFAuto;