From 08226bc6b0147b69a1afb74d83c6a8821e93601b Mon Sep 17 00:00:00 2001 From: Filip Gawin Date: Mon, 29 Oct 2018 02:05:45 +0100 Subject: Simplify some statements --- utils/alsoft-config/mainwindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'utils') diff --git a/utils/alsoft-config/mainwindow.cpp b/utils/alsoft-config/mainwindow.cpp index 110fe4ed..56ac4f3f 100644 --- a/utils/alsoft-config/mainwindow.cpp +++ b/utils/alsoft-config/mainwindow.cpp @@ -916,7 +916,7 @@ void MainWindow::saveConfig(const QString &fname) const settings.setValue("channels", getValueFromName(speakerModeList, ui->channelConfigCombo->currentText())); uint rate = ui->sampleRateCombo->currentText().toUInt(); - if(!(rate > 0)) + if(rate <= 0) settings.setValue("frequency", QString()); else settings.setValue("frequency", rate); -- cgit v1.2.3 From 903d878460056737b66c188544d6dc18c7b6dc07 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 29 Oct 2018 11:32:50 -0700 Subject: Replace restrict with RESTRICT --- Alc/ALu.c | 26 +++++++-------- Alc/backends/jack.c | 4 +-- Alc/bformatdec.c | 6 ++-- Alc/bformatdec.h | 6 ++-- Alc/bs2b.c | 2 +- Alc/converter.c | 12 +++---- Alc/effects/autowah.c | 4 +-- Alc/effects/chorus.c | 10 +++--- Alc/effects/compressor.c | 4 +-- Alc/effects/dedicated.c | 4 +-- Alc/effects/distortion.c | 6 ++-- Alc/effects/echo.c | 6 ++-- Alc/effects/equalizer.c | 6 ++-- Alc/effects/fshifter.c | 6 ++-- Alc/effects/modulator.c | 6 ++-- Alc/effects/null.c | 4 +-- Alc/effects/pshifter.c | 6 ++-- Alc/effects/reverb.c | 36 ++++++++++---------- Alc/filters/filter.c | 4 +-- Alc/filters/nfc.c | 6 ++-- Alc/filters/splitter.c | 4 +-- Alc/filters/splitter.h | 4 +-- Alc/hrtf.c | 8 ++--- Alc/mastering.c | 30 ++++++++--------- Alc/mastering.h | 2 +- Alc/mixer/defs.h | 68 +++++++++++++++++++------------------- Alc/mixer/hrtf_inc.c | 12 +++---- Alc/mixer/mixer_c.c | 24 +++++++------- Alc/mixer/mixer_neon.c | 16 ++++----- Alc/mixer/mixer_sse.c | 12 +++---- Alc/mixer/mixer_sse2.c | 4 +-- Alc/mixer/mixer_sse41.c | 4 +-- Alc/mixvoice.c | 8 ++--- Alc/panning.c | 12 +++---- Alc/uhjfilter.c | 4 +-- Alc/uhjfilter.h | 2 +- OpenAL32/Include/alAuxEffectSlot.h | 4 +-- OpenAL32/Include/bs2b.h | 2 +- utils/makehrtf.c | 2 +- 39 files changed, 193 insertions(+), 193 deletions(-) (limited to 'utils') diff --git a/Alc/ALu.c b/Alc/ALu.c index 03abb116..efa78110 100644 --- a/Alc/ALu.c +++ b/Alc/ALu.c @@ -80,7 +80,7 @@ extern inline size_t clampz(size_t val, size_t min, size_t max); extern inline ALfloat lerp(ALfloat val1, ALfloat val2, ALfloat mu); extern inline ALfloat cubic(ALfloat val1, ALfloat val2, ALfloat val3, ALfloat val4, ALfloat mu); -extern inline void aluVectorSet(aluVector *restrict vector, ALfloat x, ALfloat y, ALfloat z, ALfloat w); +extern inline void aluVectorSet(aluVector *RESTRICT vector, ALfloat x, ALfloat y, ALfloat z, ALfloat w); extern inline void aluMatrixfSetRow(aluMatrixf *matrix, ALuint row, ALfloat m0, ALfloat m1, ALfloat m2, ALfloat m3); @@ -1563,12 +1563,12 @@ static void ProcessParamUpdates(ALCcontext *ctx, const struct ALeffectslotArray } -static void ApplyStablizer(FrontStablizer *Stablizer, ALfloat (*restrict Buffer)[BUFFERSIZE], +static void ApplyStablizer(FrontStablizer *Stablizer, ALfloat (*RESTRICT Buffer)[BUFFERSIZE], int lidx, int ridx, int cidx, ALsizei SamplesToDo, ALsizei NumChannels) { - ALfloat (*restrict lsplit)[BUFFERSIZE] = ASSUME_ALIGNED(Stablizer->LSplit, 16); - ALfloat (*restrict rsplit)[BUFFERSIZE] = ASSUME_ALIGNED(Stablizer->RSplit, 16); + ALfloat (*RESTRICT lsplit)[BUFFERSIZE] = ASSUME_ALIGNED(Stablizer->LSplit, 16); + ALfloat (*RESTRICT rsplit)[BUFFERSIZE] = ASSUME_ALIGNED(Stablizer->RSplit, 16); ALsizei i; /* Apply an all-pass to all channels, except the front-left and front- @@ -1611,18 +1611,18 @@ static void ApplyStablizer(FrontStablizer *Stablizer, ALfloat (*restrict Buffer) } } -static void ApplyDistanceComp(ALfloat (*restrict Samples)[BUFFERSIZE], DistanceComp *distcomp, - ALfloat *restrict Values, ALsizei SamplesToDo, ALsizei numchans) +static void ApplyDistanceComp(ALfloat (*RESTRICT Samples)[BUFFERSIZE], DistanceComp *distcomp, + ALfloat *RESTRICT Values, ALsizei SamplesToDo, ALsizei numchans) { ALsizei i, c; Values = ASSUME_ALIGNED(Values, 16); for(c = 0;c < numchans;c++) { - ALfloat *restrict inout = ASSUME_ALIGNED(Samples[c], 16); + ALfloat *RESTRICT inout = ASSUME_ALIGNED(Samples[c], 16); const ALfloat gain = distcomp[c].Gain; const ALsizei base = distcomp[c].Length; - ALfloat *restrict distbuf = ASSUME_ALIGNED(distcomp[c].Buffer, 16); + ALfloat *RESTRICT distbuf = ASSUME_ALIGNED(distcomp[c].Buffer, 16); if(base == 0) { @@ -1654,7 +1654,7 @@ static void ApplyDistanceComp(ALfloat (*restrict Samples)[BUFFERSIZE], DistanceC } } -static void ApplyDither(ALfloat (*restrict Samples)[BUFFERSIZE], ALuint *dither_seed, +static void ApplyDither(ALfloat (*RESTRICT Samples)[BUFFERSIZE], ALuint *dither_seed, const ALfloat quant_scale, const ALsizei SamplesToDo, const ALsizei numchans) { @@ -1671,7 +1671,7 @@ static void ApplyDither(ALfloat (*restrict Samples)[BUFFERSIZE], ALuint *dither_ */ for(c = 0;c < numchans;c++) { - ALfloat *restrict samples = Samples[c]; + ALfloat *RESTRICT samples = Samples[c]; for(i = 0;i < SamplesToDo;i++) { ALfloat val = samples[i] * quant_scale; @@ -1712,7 +1712,7 @@ DECL_TEMPLATE(ALuint, Conv_ALint, 2147483648u) #undef DECL_TEMPLATE #define DECL_TEMPLATE(T, A) \ -static void Write##A(const ALfloat (*restrict InBuffer)[BUFFERSIZE], \ +static void Write##A(const ALfloat (*RESTRICT InBuffer)[BUFFERSIZE], \ ALvoid *OutBuffer, ALsizei Offset, ALsizei SamplesToDo, \ ALsizei numchans) \ { \ @@ -1723,8 +1723,8 @@ static void Write##A(const ALfloat (*restrict InBuffer)[BUFFERSIZE], \ \ for(j = 0;j < numchans;j++) \ { \ - const ALfloat *restrict in = ASSUME_ALIGNED(InBuffer[j], 16); \ - T *restrict out = (T*)OutBuffer + Offset*numchans + j; \ + const ALfloat *RESTRICT in = ASSUME_ALIGNED(InBuffer[j], 16); \ + T *RESTRICT out = (T*)OutBuffer + Offset*numchans + j; \ \ for(i = 0;i < SamplesToDo;i++) \ out[i*numchans] = Conv_##T(in[i]); \ diff --git a/Alc/backends/jack.c b/Alc/backends/jack.c index fdbe93f2..899d5a55 100644 --- a/Alc/backends/jack.c +++ b/Alc/backends/jack.c @@ -266,7 +266,7 @@ static int ALCjackPlayback_process(jack_nframes_t numframes, void *arg) todo = minu(numframes, data[0].len); for(c = 0;c < numchans;c++) { - const ALfloat *restrict in = ((ALfloat*)data[0].buf) + c; + const ALfloat *RESTRICT in = ((ALfloat*)data[0].buf) + c; for(i = 0;(jack_nframes_t)i < todo;i++) out[c][i] = in[i*numchans]; out[c] += todo; @@ -278,7 +278,7 @@ static int ALCjackPlayback_process(jack_nframes_t numframes, void *arg) { for(c = 0;c < numchans;c++) { - const ALfloat *restrict in = ((ALfloat*)data[1].buf) + c; + const ALfloat *RESTRICT in = ((ALfloat*)data[1].buf) + c; for(i = 0;(jack_nframes_t)i < todo;i++) out[c][i] = in[i*numchans]; out[c] += todo; diff --git a/Alc/bformatdec.c b/Alc/bformatdec.c index 5233d06f..91eb8ca8 100644 --- a/Alc/bformatdec.c +++ b/Alc/bformatdec.c @@ -304,7 +304,7 @@ void bformatdec_reset(BFormatDec *dec, const AmbDecConf *conf, ALsizei chancount } -void bformatdec_process(struct BFormatDec *dec, ALfloat (*restrict OutBuffer)[BUFFERSIZE], ALsizei OutChannels, const ALfloat (*restrict InSamples)[BUFFERSIZE], ALsizei SamplesToDo) +void bformatdec_process(struct BFormatDec *dec, ALfloat (*RESTRICT OutBuffer)[BUFFERSIZE], ALsizei OutChannels, const ALfloat (*RESTRICT InSamples)[BUFFERSIZE], ALsizei SamplesToDo) { ALsizei chan, i; @@ -350,7 +350,7 @@ void bformatdec_process(struct BFormatDec *dec, ALfloat (*restrict OutBuffer)[BU } -void bformatdec_upSample(struct BFormatDec *dec, ALfloat (*restrict OutBuffer)[BUFFERSIZE], const ALfloat (*restrict InSamples)[BUFFERSIZE], ALsizei InChannels, ALsizei SamplesToDo) +void bformatdec_upSample(struct BFormatDec *dec, ALfloat (*RESTRICT OutBuffer)[BUFFERSIZE], const ALfloat (*RESTRICT InSamples)[BUFFERSIZE], ALsizei InChannels, ALsizei SamplesToDo) { ALsizei i; @@ -473,7 +473,7 @@ void ambiup_reset(struct AmbiUpsampler *ambiup, const ALCdevice *device, ALfloat } } -void ambiup_process(struct AmbiUpsampler *ambiup, ALfloat (*restrict OutBuffer)[BUFFERSIZE], ALsizei OutChannels, const ALfloat (*restrict InSamples)[BUFFERSIZE], ALsizei SamplesToDo) +void ambiup_process(struct AmbiUpsampler *ambiup, ALfloat (*RESTRICT OutBuffer)[BUFFERSIZE], ALsizei OutChannels, const ALfloat (*RESTRICT InSamples)[BUFFERSIZE], ALsizei SamplesToDo) { ALsizei i, j; diff --git a/Alc/bformatdec.h b/Alc/bformatdec.h index 2d7d1d62..3c081807 100644 --- a/Alc/bformatdec.h +++ b/Alc/bformatdec.h @@ -39,10 +39,10 @@ void bformatdec_free(struct BFormatDec **dec); void bformatdec_reset(struct BFormatDec *dec, const struct AmbDecConf *conf, ALsizei chancount, ALuint srate, const ALsizei chanmap[MAX_OUTPUT_CHANNELS]); /* Decodes the ambisonic input to the given output channels. */ -void bformatdec_process(struct BFormatDec *dec, ALfloat (*restrict OutBuffer)[BUFFERSIZE], ALsizei OutChannels, const ALfloat (*restrict InSamples)[BUFFERSIZE], ALsizei SamplesToDo); +void bformatdec_process(struct BFormatDec *dec, ALfloat (*RESTRICT OutBuffer)[BUFFERSIZE], ALsizei OutChannels, const ALfloat (*RESTRICT InSamples)[BUFFERSIZE], ALsizei SamplesToDo); /* Up-samples a first-order input to the decoder's configuration. */ -void bformatdec_upSample(struct BFormatDec *dec, ALfloat (*restrict OutBuffer)[BUFFERSIZE], const ALfloat (*restrict InSamples)[BUFFERSIZE], ALsizei InChannels, ALsizei SamplesToDo); +void bformatdec_upSample(struct BFormatDec *dec, ALfloat (*RESTRICT OutBuffer)[BUFFERSIZE], const ALfloat (*RESTRICT InSamples)[BUFFERSIZE], ALsizei InChannels, ALsizei SamplesToDo); /* Stand-alone first-order upsampler. Kept here because it shares some stuff @@ -52,6 +52,6 @@ struct AmbiUpsampler *ambiup_alloc(); void ambiup_free(struct AmbiUpsampler **ambiup); void ambiup_reset(struct AmbiUpsampler *ambiup, const ALCdevice *device, ALfloat w_scale, ALfloat xyz_scale); -void ambiup_process(struct AmbiUpsampler *ambiup, ALfloat (*restrict OutBuffer)[BUFFERSIZE], ALsizei OutChannels, const ALfloat (*restrict InSamples)[BUFFERSIZE], ALsizei SamplesToDo); +void ambiup_process(struct AmbiUpsampler *ambiup, ALfloat (*RESTRICT OutBuffer)[BUFFERSIZE], ALsizei OutChannels, const ALfloat (*RESTRICT InSamples)[BUFFERSIZE], ALsizei SamplesToDo); #endif /* BFORMATDEC_H */ diff --git a/Alc/bs2b.c b/Alc/bs2b.c index e235e547..e0ce3249 100644 --- a/Alc/bs2b.c +++ b/Alc/bs2b.c @@ -129,7 +129,7 @@ void bs2b_clear(struct bs2b *bs2b) memset(&bs2b->last_sample, 0, sizeof(bs2b->last_sample)); } /* bs2b_clear */ -void bs2b_cross_feed(struct bs2b *bs2b, float *restrict Left, float *restrict Right, int SamplesToDo) +void bs2b_cross_feed(struct bs2b *bs2b, float *RESTRICT Left, float *RESTRICT Right, int SamplesToDo) { float lsamples[128][2]; float rsamples[128][2]; diff --git a/Alc/converter.c b/Alc/converter.c index ef2eb9af..5080f302 100644 --- a/Alc/converter.c +++ b/Alc/converter.c @@ -72,7 +72,7 @@ static inline ALfloat Sample_ALfloat(ALfloat val) { return val; } #define DECL_TEMPLATE(T) \ -static inline void Load_##T(ALfloat *restrict dst, const T *restrict src, \ +static inline void Load_##T(ALfloat *RESTRICT dst, const T *RESTRICT src, \ ALint srcstep, ALsizei samples) \ { \ ALsizei i; \ @@ -138,7 +138,7 @@ static inline ALfloat ALfloat_Sample(ALfloat val) { return val; } #define DECL_TEMPLATE(T) \ -static inline void Store_##T(T *restrict dst, const ALfloat *restrict src, \ +static inline void Store_##T(T *RESTRICT dst, const ALfloat *RESTRICT src, \ ALint dststep, ALsizei samples) \ { \ ALsizei i; \ @@ -235,8 +235,8 @@ ALsizei SampleConverterInput(SampleConverter *converter, const ALvoid **src, ALs START_MIXER_MODE(); while(pos < dstframes && *srcframes > 0) { - ALfloat *restrict SrcData = ASSUME_ALIGNED(converter->mSrcSamples, 16); - ALfloat *restrict DstData = ASSUME_ALIGNED(converter->mDstSamples, 16); + ALfloat *RESTRICT SrcData = ASSUME_ALIGNED(converter->mSrcSamples, 16); + ALfloat *RESTRICT DstData = ASSUME_ALIGNED(converter->mDstSamples, 16); ALint prepcount = converter->mSrcPrepCount; ALsizei DataPosFrac = converter->mFracOffset; ALuint64 DataSize64; @@ -377,14 +377,14 @@ void DestroyChannelConverter(ChannelConverter **converter) #define DECL_TEMPLATE(T) \ -static void Mono2Stereo##T(ALfloat *restrict dst, const T *src, ALsizei frames)\ +static void Mono2Stereo##T(ALfloat *RESTRICT dst, const T *src, ALsizei frames)\ { \ ALsizei i; \ for(i = 0;i < frames;i++) \ dst[i*2 + 1] = dst[i*2 + 0] = Sample_##T(src[i]) * 0.707106781187f; \ } \ \ -static void Stereo2Mono##T(ALfloat *restrict dst, const T *src, ALsizei frames)\ +static void Stereo2Mono##T(ALfloat *RESTRICT dst, const T *src, ALsizei frames)\ { \ ALsizei i; \ for(i = 0;i < frames;i++) \ diff --git a/Alc/effects/autowah.c b/Alc/effects/autowah.c index ba1180ef..f65f1be6 100644 --- a/Alc/effects/autowah.c +++ b/Alc/effects/autowah.c @@ -69,7 +69,7 @@ typedef struct ALautowahState { static ALvoid ALautowahState_Destruct(ALautowahState *state); static ALboolean ALautowahState_deviceUpdate(ALautowahState *state, ALCdevice *device); static ALvoid ALautowahState_update(ALautowahState *state, const ALCcontext *context, const ALeffectslot *slot, const ALeffectProps *props); -static ALvoid ALautowahState_process(ALautowahState *state, ALsizei SamplesToDo, const ALfloat (*restrict SamplesIn)[BUFFERSIZE], ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALsizei NumChannels); +static ALvoid ALautowahState_process(ALautowahState *state, ALsizei SamplesToDo, const ALfloat (*RESTRICT SamplesIn)[BUFFERSIZE], ALfloat (*RESTRICT SamplesOut)[BUFFERSIZE], ALsizei NumChannels); DECLARE_DEFAULT_ALLOCATORS(ALautowahState) DEFINE_ALEFFECTSTATE_VTABLE(ALautowahState); @@ -134,7 +134,7 @@ static ALvoid ALautowahState_update(ALautowahState *state, const ALCcontext *con state->Chans[i].TargetGains); } -static ALvoid ALautowahState_process(ALautowahState *state, ALsizei SamplesToDo, const ALfloat (*restrict SamplesIn)[BUFFERSIZE], ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALsizei NumChannels) +static ALvoid ALautowahState_process(ALautowahState *state, ALsizei SamplesToDo, const ALfloat (*RESTRICT SamplesIn)[BUFFERSIZE], ALfloat (*RESTRICT SamplesOut)[BUFFERSIZE], ALsizei NumChannels) { const ALfloat attack_rate = state->AttackRate; const ALfloat release_rate = state->ReleaseRate; diff --git a/Alc/effects/chorus.c b/Alc/effects/chorus.c index f2861cf5..725189b3 100644 --- a/Alc/effects/chorus.c +++ b/Alc/effects/chorus.c @@ -66,7 +66,7 @@ typedef struct ALchorusState { static ALvoid ALchorusState_Destruct(ALchorusState *state); static ALboolean ALchorusState_deviceUpdate(ALchorusState *state, ALCdevice *Device); static ALvoid ALchorusState_update(ALchorusState *state, const ALCcontext *Context, const ALeffectslot *Slot, const ALeffectProps *props); -static ALvoid ALchorusState_process(ALchorusState *state, ALsizei SamplesToDo, const ALfloat (*restrict SamplesIn)[BUFFERSIZE], ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALsizei NumChannels); +static ALvoid ALchorusState_process(ALchorusState *state, ALsizei SamplesToDo, const ALfloat (*RESTRICT SamplesIn)[BUFFERSIZE], ALfloat (*RESTRICT SamplesOut)[BUFFERSIZE], ALsizei NumChannels); DECLARE_DEFAULT_ALLOCATORS(ALchorusState) DEFINE_ALEFFECTSTATE_VTABLE(ALchorusState); @@ -188,7 +188,7 @@ static ALvoid ALchorusState_update(ALchorusState *state, const ALCcontext *Conte } } -static void GetTriangleDelays(ALint *restrict delays, ALsizei offset, const ALsizei lfo_range, +static void GetTriangleDelays(ALint *RESTRICT delays, ALsizei offset, const ALsizei lfo_range, const ALfloat lfo_scale, const ALfloat depth, const ALsizei delay, const ALsizei todo) { @@ -200,7 +200,7 @@ static void GetTriangleDelays(ALint *restrict delays, ALsizei offset, const ALsi } } -static void GetSinusoidDelays(ALint *restrict delays, ALsizei offset, const ALsizei lfo_range, +static void GetSinusoidDelays(ALint *RESTRICT delays, ALsizei offset, const ALsizei lfo_range, const ALfloat lfo_scale, const ALfloat depth, const ALsizei delay, const ALsizei todo) { @@ -213,12 +213,12 @@ static void GetSinusoidDelays(ALint *restrict delays, ALsizei offset, const ALsi } -static ALvoid ALchorusState_process(ALchorusState *state, ALsizei SamplesToDo, const ALfloat (*restrict SamplesIn)[BUFFERSIZE], ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALsizei NumChannels) +static ALvoid ALchorusState_process(ALchorusState *state, ALsizei SamplesToDo, const ALfloat (*RESTRICT SamplesIn)[BUFFERSIZE], ALfloat (*RESTRICT SamplesOut)[BUFFERSIZE], ALsizei NumChannels) { const ALsizei bufmask = state->BufferLength-1; const ALfloat feedback = state->feedback; const ALsizei avgdelay = (state->delay + (FRACTIONONE>>1)) >> FRACTIONBITS; - ALfloat *restrict delaybuf = state->SampleBuffer; + ALfloat *RESTRICT delaybuf = state->SampleBuffer; ALsizei offset = state->offset; ALsizei i, c; ALsizei base; diff --git a/Alc/effects/compressor.c b/Alc/effects/compressor.c index 2b4a76b0..d9b9f1e0 100644 --- a/Alc/effects/compressor.c +++ b/Alc/effects/compressor.c @@ -50,7 +50,7 @@ typedef struct ALcompressorState { static ALvoid ALcompressorState_Destruct(ALcompressorState *state); static ALboolean ALcompressorState_deviceUpdate(ALcompressorState *state, ALCdevice *device); static ALvoid ALcompressorState_update(ALcompressorState *state, const ALCcontext *context, const ALeffectslot *slot, const ALeffectProps *props); -static ALvoid ALcompressorState_process(ALcompressorState *state, ALsizei SamplesToDo, const ALfloat (*restrict SamplesIn)[BUFFERSIZE], ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALsizei NumChannels); +static ALvoid ALcompressorState_process(ALcompressorState *state, ALsizei SamplesToDo, const ALfloat (*RESTRICT SamplesIn)[BUFFERSIZE], ALfloat (*RESTRICT SamplesOut)[BUFFERSIZE], ALsizei NumChannels); DECLARE_DEFAULT_ALLOCATORS(ALcompressorState) DEFINE_ALEFFECTSTATE_VTABLE(ALcompressorState); @@ -102,7 +102,7 @@ static ALvoid ALcompressorState_update(ALcompressorState *state, const ALCcontex ComputePanGains(&device->FOAOut, IdentityMatrixf.m[i], slot->Params.Gain, state->Gain[i]); } -static ALvoid ALcompressorState_process(ALcompressorState *state, ALsizei SamplesToDo, const ALfloat (*restrict SamplesIn)[BUFFERSIZE], ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALsizei NumChannels) +static ALvoid ALcompressorState_process(ALcompressorState *state, ALsizei SamplesToDo, const ALfloat (*RESTRICT SamplesIn)[BUFFERSIZE], ALfloat (*RESTRICT SamplesOut)[BUFFERSIZE], ALsizei NumChannels) { ALsizei i, j, k; ALsizei base; diff --git a/Alc/effects/dedicated.c b/Alc/effects/dedicated.c index 0e1fd389..59c13b77 100644 --- a/Alc/effects/dedicated.c +++ b/Alc/effects/dedicated.c @@ -39,7 +39,7 @@ typedef struct ALdedicatedState { static ALvoid ALdedicatedState_Destruct(ALdedicatedState *state); static ALboolean ALdedicatedState_deviceUpdate(ALdedicatedState *state, ALCdevice *device); static ALvoid ALdedicatedState_update(ALdedicatedState *state, const ALCcontext *context, const ALeffectslot *slot, const ALeffectProps *props); -static ALvoid ALdedicatedState_process(ALdedicatedState *state, ALsizei SamplesToDo, const ALfloat (*restrict SamplesIn)[BUFFERSIZE], ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALsizei NumChannels); +static ALvoid ALdedicatedState_process(ALdedicatedState *state, ALsizei SamplesToDo, const ALfloat (*RESTRICT SamplesIn)[BUFFERSIZE], ALfloat (*RESTRICT SamplesOut)[BUFFERSIZE], ALsizei NumChannels); DECLARE_DEFAULT_ALLOCATORS(ALdedicatedState) DEFINE_ALEFFECTSTATE_VTABLE(ALdedicatedState); @@ -107,7 +107,7 @@ static ALvoid ALdedicatedState_update(ALdedicatedState *state, const ALCcontext } } -static ALvoid ALdedicatedState_process(ALdedicatedState *state, ALsizei SamplesToDo, const ALfloat (*restrict SamplesIn)[BUFFERSIZE], ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALsizei NumChannels) +static ALvoid ALdedicatedState_process(ALdedicatedState *state, ALsizei SamplesToDo, const ALfloat (*RESTRICT SamplesIn)[BUFFERSIZE], ALfloat (*RESTRICT SamplesOut)[BUFFERSIZE], ALsizei NumChannels) { MixSamples(SamplesIn[0], NumChannels, SamplesOut, state->CurrentGains, state->TargetGains, SamplesToDo, 0, SamplesToDo); diff --git a/Alc/effects/distortion.c b/Alc/effects/distortion.c index de8da4fe..f2a70bff 100644 --- a/Alc/effects/distortion.c +++ b/Alc/effects/distortion.c @@ -48,7 +48,7 @@ typedef struct ALdistortionState { static ALvoid ALdistortionState_Destruct(ALdistortionState *state); static ALboolean ALdistortionState_deviceUpdate(ALdistortionState *state, ALCdevice *device); static ALvoid ALdistortionState_update(ALdistortionState *state, const ALCcontext *context, const ALeffectslot *slot, const ALeffectProps *props); -static ALvoid ALdistortionState_process(ALdistortionState *state, ALsizei SamplesToDo, const ALfloat (*restrict SamplesIn)[BUFFERSIZE], ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALsizei NumChannels); +static ALvoid ALdistortionState_process(ALdistortionState *state, ALsizei SamplesToDo, const ALfloat (*RESTRICT SamplesIn)[BUFFERSIZE], ALfloat (*RESTRICT SamplesOut)[BUFFERSIZE], ALsizei NumChannels); DECLARE_DEFAULT_ALLOCATORS(ALdistortionState) DEFINE_ALEFFECTSTATE_VTABLE(ALdistortionState); @@ -107,9 +107,9 @@ static ALvoid ALdistortionState_update(ALdistortionState *state, const ALCcontex ComputePanGains(&device->Dry, coeffs, slot->Params.Gain*props->Distortion.Gain, state->Gain); } -static ALvoid ALdistortionState_process(ALdistortionState *state, ALsizei SamplesToDo, const ALfloat (*restrict SamplesIn)[BUFFERSIZE], ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALsizei NumChannels) +static ALvoid ALdistortionState_process(ALdistortionState *state, ALsizei SamplesToDo, const ALfloat (*RESTRICT SamplesIn)[BUFFERSIZE], ALfloat (*RESTRICT SamplesOut)[BUFFERSIZE], ALsizei NumChannels) { - ALfloat (*restrict buffer)[BUFFERSIZE] = state->Buffer; + ALfloat (*RESTRICT buffer)[BUFFERSIZE] = state->Buffer; const ALfloat fc = state->edge_coeff; ALsizei base; ALsizei i, k; diff --git a/Alc/effects/echo.c b/Alc/effects/echo.c index 4570fcb1..5c323986 100644 --- a/Alc/effects/echo.c +++ b/Alc/effects/echo.c @@ -58,7 +58,7 @@ typedef struct ALechoState { static ALvoid ALechoState_Destruct(ALechoState *state); static ALboolean ALechoState_deviceUpdate(ALechoState *state, ALCdevice *Device); static ALvoid ALechoState_update(ALechoState *state, const ALCcontext *context, const ALeffectslot *slot, const ALeffectProps *props); -static ALvoid ALechoState_process(ALechoState *state, ALsizei SamplesToDo, const ALfloat (*restrict SamplesIn)[BUFFERSIZE], ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALsizei NumChannels); +static ALvoid ALechoState_process(ALechoState *state, ALsizei SamplesToDo, const ALfloat (*RESTRICT SamplesIn)[BUFFERSIZE], ALfloat (*RESTRICT SamplesOut)[BUFFERSIZE], ALsizei NumChannels); DECLARE_DEFAULT_ALLOCATORS(ALechoState) DEFINE_ALEFFECTSTATE_VTABLE(ALechoState); @@ -148,12 +148,12 @@ static ALvoid ALechoState_update(ALechoState *state, const ALCcontext *context, ComputePanGains(&device->Dry, coeffs, slot->Params.Gain, state->Gains[1].Target); } -static ALvoid ALechoState_process(ALechoState *state, ALsizei SamplesToDo, const ALfloat (*restrict SamplesIn)[BUFFERSIZE], ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALsizei NumChannels) +static ALvoid ALechoState_process(ALechoState *state, ALsizei SamplesToDo, const ALfloat (*RESTRICT SamplesIn)[BUFFERSIZE], ALfloat (*RESTRICT SamplesOut)[BUFFERSIZE], ALsizei NumChannels) { const ALsizei mask = state->BufferLength-1; const ALsizei tap1 = state->Tap[0].delay; const ALsizei tap2 = state->Tap[1].delay; - ALfloat *restrict delaybuf = state->SampleBuffer; + ALfloat *RESTRICT delaybuf = state->SampleBuffer; ALsizei offset = state->Offset; ALfloat z1, z2, in, out; ALsizei base; diff --git a/Alc/effects/equalizer.c b/Alc/effects/equalizer.c index 17106127..c62f8e80 100644 --- a/Alc/effects/equalizer.c +++ b/Alc/effects/equalizer.c @@ -90,7 +90,7 @@ typedef struct ALequalizerState { static ALvoid ALequalizerState_Destruct(ALequalizerState *state); static ALboolean ALequalizerState_deviceUpdate(ALequalizerState *state, ALCdevice *device); static ALvoid ALequalizerState_update(ALequalizerState *state, const ALCcontext *context, const ALeffectslot *slot, const ALeffectProps *props); -static ALvoid ALequalizerState_process(ALequalizerState *state, ALsizei SamplesToDo, const ALfloat (*restrict SamplesIn)[BUFFERSIZE], ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALsizei NumChannels); +static ALvoid ALequalizerState_process(ALequalizerState *state, ALsizei SamplesToDo, const ALfloat (*RESTRICT SamplesIn)[BUFFERSIZE], ALfloat (*RESTRICT SamplesOut)[BUFFERSIZE], ALsizei NumChannels); DECLARE_DEFAULT_ALLOCATORS(ALequalizerState) DEFINE_ALEFFECTSTATE_VTABLE(ALequalizerState); @@ -176,9 +176,9 @@ static ALvoid ALequalizerState_update(ALequalizerState *state, const ALCcontext state->Chans[i].TargetGains); } -static ALvoid ALequalizerState_process(ALequalizerState *state, ALsizei SamplesToDo, const ALfloat (*restrict SamplesIn)[BUFFERSIZE], ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALsizei NumChannels) +static ALvoid ALequalizerState_process(ALequalizerState *state, ALsizei SamplesToDo, const ALfloat (*RESTRICT SamplesIn)[BUFFERSIZE], ALfloat (*RESTRICT SamplesOut)[BUFFERSIZE], ALsizei NumChannels) { - ALfloat (*restrict temps)[BUFFERSIZE] = state->SampleBuffer; + ALfloat (*RESTRICT temps)[BUFFERSIZE] = state->SampleBuffer; ALsizei c; for(c = 0;c < MAX_EFFECT_CHANNELS;c++) diff --git a/Alc/effects/fshifter.c b/Alc/effects/fshifter.c index 7d72472a..6ada7dfa 100644 --- a/Alc/effects/fshifter.c +++ b/Alc/effects/fshifter.c @@ -64,7 +64,7 @@ typedef struct ALfshifterState { static ALvoid ALfshifterState_Destruct(ALfshifterState *state); static ALboolean ALfshifterState_deviceUpdate(ALfshifterState *state, ALCdevice *device); static ALvoid ALfshifterState_update(ALfshifterState *state, const ALCcontext *context, const ALeffectslot *slot, const ALeffectProps *props); -static ALvoid ALfshifterState_process(ALfshifterState *state, ALsizei SamplesToDo, const ALfloat (*restrict SamplesIn)[BUFFERSIZE], ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALsizei NumChannels); +static ALvoid ALfshifterState_process(ALfshifterState *state, ALsizei SamplesToDo, const ALfloat (*RESTRICT SamplesIn)[BUFFERSIZE], ALfloat (*RESTRICT SamplesOut)[BUFFERSIZE], ALsizei NumChannels); DECLARE_DEFAULT_ALLOCATORS(ALfshifterState) DEFINE_ALEFFECTSTATE_VTABLE(ALfshifterState); @@ -147,10 +147,10 @@ static ALvoid ALfshifterState_update(ALfshifterState *state, const ALCcontext *c ComputePanGains(&device->Dry, coeffs, slot->Params.Gain, state->TargetGains); } -static ALvoid ALfshifterState_process(ALfshifterState *state, ALsizei SamplesToDo, const ALfloat (*restrict SamplesIn)[BUFFERSIZE], ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALsizei NumChannels) +static ALvoid ALfshifterState_process(ALfshifterState *state, ALsizei SamplesToDo, const ALfloat (*RESTRICT SamplesIn)[BUFFERSIZE], ALfloat (*RESTRICT SamplesOut)[BUFFERSIZE], ALsizei NumChannels) { static const ALcomplex complex_zero = { 0.0, 0.0 }; - ALfloat *restrict BufferOut = state->BufferOut; + ALfloat *RESTRICT BufferOut = state->BufferOut; ALsizei j, k, base; for(base = 0;base < SamplesToDo;) diff --git a/Alc/effects/modulator.c b/Alc/effects/modulator.c index e368adb8..dd3d1981 100644 --- a/Alc/effects/modulator.c +++ b/Alc/effects/modulator.c @@ -51,7 +51,7 @@ typedef struct ALmodulatorState { static ALvoid ALmodulatorState_Destruct(ALmodulatorState *state); static ALboolean ALmodulatorState_deviceUpdate(ALmodulatorState *state, ALCdevice *device); static ALvoid ALmodulatorState_update(ALmodulatorState *state, const ALCcontext *context, const ALeffectslot *slot, const ALeffectProps *props); -static ALvoid ALmodulatorState_process(ALmodulatorState *state, ALsizei SamplesToDo, const ALfloat (*restrict SamplesIn)[BUFFERSIZE], ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALsizei NumChannels); +static ALvoid ALmodulatorState_process(ALmodulatorState *state, ALsizei SamplesToDo, const ALfloat (*RESTRICT SamplesIn)[BUFFERSIZE], ALfloat (*RESTRICT SamplesOut)[BUFFERSIZE], ALsizei NumChannels); DECLARE_DEFAULT_ALLOCATORS(ALmodulatorState) DEFINE_ALEFFECTSTATE_VTABLE(ALmodulatorState); @@ -82,7 +82,7 @@ static inline ALfloat One(ALsizei UNUSED(index)) } #define DECL_TEMPLATE(func) \ -static void Modulate##func(ALfloat *restrict dst, ALsizei index, \ +static void Modulate##func(ALfloat *RESTRICT dst, ALsizei index, \ const ALsizei step, ALsizei todo) \ { \ ALsizei i; \ @@ -162,7 +162,7 @@ static ALvoid ALmodulatorState_update(ALmodulatorState *state, const ALCcontext state->Chans[i].TargetGains); } -static ALvoid ALmodulatorState_process(ALmodulatorState *state, ALsizei SamplesToDo, const ALfloat (*restrict SamplesIn)[BUFFERSIZE], ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALsizei NumChannels) +static ALvoid ALmodulatorState_process(ALmodulatorState *state, ALsizei SamplesToDo, const ALfloat (*RESTRICT SamplesIn)[BUFFERSIZE], ALfloat (*RESTRICT SamplesOut)[BUFFERSIZE], ALsizei NumChannels) { const ALsizei step = state->step; ALsizei base; diff --git a/Alc/effects/null.c b/Alc/effects/null.c index e57359e3..6eaa001f 100644 --- a/Alc/effects/null.c +++ b/Alc/effects/null.c @@ -17,7 +17,7 @@ typedef struct ALnullState { static ALvoid ALnullState_Destruct(ALnullState *state); static ALboolean ALnullState_deviceUpdate(ALnullState *state, ALCdevice *device); static ALvoid ALnullState_update(ALnullState *state, const ALCcontext *context, const ALeffectslot *slot, const ALeffectProps *props); -static ALvoid ALnullState_process(ALnullState *state, ALsizei samplesToDo, const ALfloat (*restrict samplesIn)[BUFFERSIZE], ALfloat (*restrict samplesOut)[BUFFERSIZE], ALsizei mumChannels); +static ALvoid ALnullState_process(ALnullState *state, ALsizei samplesToDo, const ALfloat (*RESTRICT samplesIn)[BUFFERSIZE], ALfloat (*RESTRICT samplesOut)[BUFFERSIZE], ALsizei mumChannels); static void *ALnullState_New(size_t size); static void ALnullState_Delete(void *ptr); @@ -64,7 +64,7 @@ static ALvoid ALnullState_update(ALnullState* UNUSED(state), const ALCcontext* U * input to the output buffer. The result should be added to the output buffer, * not replace it. */ -static ALvoid ALnullState_process(ALnullState* UNUSED(state), ALsizei UNUSED(samplesToDo), const ALfloatBUFFERSIZE*restrict UNUSED(samplesIn), ALfloatBUFFERSIZE*restrict UNUSED(samplesOut), ALsizei UNUSED(numChannels)) +static ALvoid ALnullState_process(ALnullState* UNUSED(state), ALsizei UNUSED(samplesToDo), const ALfloatBUFFERSIZE*RESTRICT UNUSED(samplesIn), ALfloatBUFFERSIZE*RESTRICT UNUSED(samplesOut), ALsizei UNUSED(numChannels)) { } diff --git a/Alc/effects/pshifter.c b/Alc/effects/pshifter.c index ed18e9a8..35168eab 100644 --- a/Alc/effects/pshifter.c +++ b/Alc/effects/pshifter.c @@ -82,7 +82,7 @@ typedef struct ALpshifterState { static ALvoid ALpshifterState_Destruct(ALpshifterState *state); static ALboolean ALpshifterState_deviceUpdate(ALpshifterState *state, ALCdevice *device); static ALvoid ALpshifterState_update(ALpshifterState *state, const ALCcontext *context, const ALeffectslot *slot, const ALeffectProps *props); -static ALvoid ALpshifterState_process(ALpshifterState *state, ALsizei SamplesToDo, const ALfloat (*restrict SamplesIn)[BUFFERSIZE], ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALsizei NumChannels); +static ALvoid ALpshifterState_process(ALpshifterState *state, ALsizei SamplesToDo, const ALfloat (*RESTRICT SamplesIn)[BUFFERSIZE], ALfloat (*RESTRICT SamplesOut)[BUFFERSIZE], ALsizei NumChannels); DECLARE_DEFAULT_ALLOCATORS(ALpshifterState) DEFINE_ALEFFECTSTATE_VTABLE(ALpshifterState); @@ -211,7 +211,7 @@ static ALvoid ALpshifterState_update(ALpshifterState *state, const ALCcontext *c ComputePanGains(&device->Dry, coeffs, slot->Params.Gain, state->TargetGains); } -static ALvoid ALpshifterState_process(ALpshifterState *state, ALsizei SamplesToDo, const ALfloat (*restrict SamplesIn)[BUFFERSIZE], ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALsizei NumChannels) +static ALvoid ALpshifterState_process(ALpshifterState *state, ALsizei SamplesToDo, const ALfloat (*RESTRICT SamplesIn)[BUFFERSIZE], ALfloat (*RESTRICT SamplesOut)[BUFFERSIZE], ALsizei NumChannels) { /* Pitch shifter engine based on the work of Stephan Bernsee. * http://blogs.zynaptiq.com/bernsee/pitch-shifting-using-the-ft/ @@ -219,7 +219,7 @@ static ALvoid ALpshifterState_process(ALpshifterState *state, ALsizei SamplesToD static const ALdouble expected = M_PI*2.0 / OVERSAMP; const ALdouble freq_per_bin = state->FreqPerBin; - ALfloat *restrict bufferOut = state->BufferOut; + ALfloat *RESTRICT bufferOut = state->BufferOut; ALsizei count = state->count; ALsizei i, j, k; diff --git a/Alc/effects/reverb.c b/Alc/effects/reverb.c index 8ebc089e..ad4aae5c 100644 --- a/Alc/effects/reverb.c +++ b/Alc/effects/reverb.c @@ -334,7 +334,7 @@ typedef struct ReverbState { static ALvoid ReverbState_Destruct(ReverbState *State); static ALboolean ReverbState_deviceUpdate(ReverbState *State, ALCdevice *Device); static ALvoid ReverbState_update(ReverbState *State, const ALCcontext *Context, const ALeffectslot *Slot, const ALeffectProps *props); -static ALvoid ReverbState_process(ReverbState *State, ALsizei SamplesToDo, const ALfloat (*restrict SamplesIn)[BUFFERSIZE], ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALsizei NumChannels); +static ALvoid ReverbState_process(ReverbState *State, ALsizei SamplesToDo, const ALfloat (*RESTRICT SamplesIn)[BUFFERSIZE], ALfloat (*RESTRICT SamplesOut)[BUFFERSIZE], ALsizei NumChannels); DECLARE_DEFAULT_ALLOCATORS(ReverbState) DEFINE_ALEFFECTSTATE_VTABLE(ReverbState); @@ -1069,7 +1069,7 @@ static inline ALfloat FadedDelayLineOut(const DelayLineI *Delay, const ALsizei o static inline void DelayLineIn(const DelayLineI *Delay, ALsizei offset, const ALsizei c, - const ALfloat *restrict in, ALsizei count) + const ALfloat *RESTRICT in, ALsizei count) { ALsizei i; for(i = 0;i < count;i++) @@ -1114,7 +1114,7 @@ static inline void DelayLineIn(const DelayLineI *Delay, ALsizei offset, const AL * Where D is a diagonal matrix (of x), and S is a triangular matrix (of y) * whose combination of signs are being iterated. */ -static inline void VectorPartialScatter(ALfloat *restrict out, const ALfloat *restrict in, +static inline void VectorPartialScatter(ALfloat *RESTRICT out, const ALfloat *RESTRICT in, const ALfloat xCoeff, const ALfloat yCoeff) { out[0] = xCoeff*in[0] + yCoeff*( in[1] + -in[2] + in[3]); @@ -1128,7 +1128,7 @@ static inline void VectorPartialScatter(ALfloat *restrict out, const ALfloat *re /* Utilizes the above, but reverses the input channels. */ static inline void VectorScatterRevDelayIn(const DelayLineI *Delay, ALint offset, const ALfloat xCoeff, const ALfloat yCoeff, - const ALfloat (*restrict in)[MAX_UPDATE_SAMPLES], + const ALfloat (*RESTRICT in)[MAX_UPDATE_SAMPLES], const ALsizei count) { const DelayLineI delay = *Delay; @@ -1154,7 +1154,7 @@ static inline void VectorScatterRevDelayIn(const DelayLineI *Delay, ALint offset * Two static specializations are used for transitional (cross-faded) delay * line processing and non-transitional processing. */ -static void VectorAllpass_Unfaded(ALfloat (*restrict samples)[MAX_UPDATE_SAMPLES], ALsizei offset, +static void VectorAllpass_Unfaded(ALfloat (*RESTRICT samples)[MAX_UPDATE_SAMPLES], ALsizei offset, const ALfloat xCoeff, const ALfloat yCoeff, ALsizei todo, VecAllpass *Vap) { @@ -1184,7 +1184,7 @@ static void VectorAllpass_Unfaded(ALfloat (*restrict samples)[MAX_UPDATE_SAMPLES ++offset; } } -static void VectorAllpass_Faded(ALfloat (*restrict samples)[MAX_UPDATE_SAMPLES], ALsizei offset, +static void VectorAllpass_Faded(ALfloat (*RESTRICT samples)[MAX_UPDATE_SAMPLES], ALsizei offset, const ALfloat xCoeff, const ALfloat yCoeff, ALfloat fade, ALsizei todo, VecAllpass *Vap) { @@ -1243,9 +1243,9 @@ static void VectorAllpass_Faded(ALfloat (*restrict samples)[MAX_UPDATE_SAMPLES], * line processing and non-transitional processing. */ static void EarlyReflection_Unfaded(ReverbState *State, ALsizei offset, const ALsizei todo, - ALfloat (*restrict out)[MAX_UPDATE_SAMPLES]) + ALfloat (*RESTRICT out)[MAX_UPDATE_SAMPLES]) { - ALfloat (*restrict temps)[MAX_UPDATE_SAMPLES] = State->TempSamples; + ALfloat (*RESTRICT temps)[MAX_UPDATE_SAMPLES] = State->TempSamples; const DelayLineI early_delay = State->Early.Delay; const DelayLineI main_delay = State->Delay; const ALfloat mixX = State->MixX; @@ -1294,9 +1294,9 @@ static void EarlyReflection_Unfaded(ReverbState *State, ALsizei offset, const AL VectorScatterRevDelayIn(&main_delay, late_feed_tap, mixX, mixY, out, todo); } static void EarlyReflection_Faded(ReverbState *State, ALsizei offset, const ALsizei todo, - const ALfloat fade, ALfloat (*restrict out)[MAX_UPDATE_SAMPLES]) + const ALfloat fade, ALfloat (*RESTRICT out)[MAX_UPDATE_SAMPLES]) { - ALfloat (*restrict temps)[MAX_UPDATE_SAMPLES] = State->TempSamples; + ALfloat (*RESTRICT temps)[MAX_UPDATE_SAMPLES] = State->TempSamples; const DelayLineI early_delay = State->Early.Delay; const DelayLineI main_delay = State->Delay; const ALfloat mixX = State->MixX; @@ -1355,7 +1355,7 @@ static void EarlyReflection_Faded(ReverbState *State, ALsizei offset, const ALsi } /* Applies the two T60 damping filter sections. */ -static inline void LateT60Filter(ALfloat *restrict samples, const ALsizei todo, T60Filter *filter) +static inline void LateT60Filter(ALfloat *RESTRICT samples, const ALsizei todo, T60Filter *filter) { ALfloat temp[MAX_UPDATE_SAMPLES]; BiquadFilter_process(&filter->HFFilter, temp, samples, todo); @@ -1377,9 +1377,9 @@ static inline void LateT60Filter(ALfloat *restrict samples, const ALsizei todo, * processing and one for non-transitional processing. */ static void LateReverb_Unfaded(ReverbState *State, ALsizei offset, const ALsizei todo, - ALfloat (*restrict out)[MAX_UPDATE_SAMPLES]) + ALfloat (*RESTRICT out)[MAX_UPDATE_SAMPLES]) { - ALfloat (*restrict temps)[MAX_UPDATE_SAMPLES] = State->TempSamples; + ALfloat (*RESTRICT temps)[MAX_UPDATE_SAMPLES] = State->TempSamples; const DelayLineI late_delay = State->Late.Delay; const DelayLineI main_delay = State->Delay; const ALfloat mixX = State->MixX; @@ -1415,9 +1415,9 @@ static void LateReverb_Unfaded(ReverbState *State, ALsizei offset, const ALsizei VectorScatterRevDelayIn(&late_delay, offset, mixX, mixY, out, todo); } static void LateReverb_Faded(ReverbState *State, ALsizei offset, const ALsizei todo, - const ALfloat fade, ALfloat (*restrict out)[MAX_UPDATE_SAMPLES]) + const ALfloat fade, ALfloat (*RESTRICT out)[MAX_UPDATE_SAMPLES]) { - ALfloat (*restrict temps)[MAX_UPDATE_SAMPLES] = State->TempSamples; + ALfloat (*RESTRICT temps)[MAX_UPDATE_SAMPLES] = State->TempSamples; const DelayLineI late_delay = State->Late.Delay; const DelayLineI main_delay = State->Delay; const ALfloat mixX = State->MixX; @@ -1466,10 +1466,10 @@ static void LateReverb_Faded(ReverbState *State, ALsizei offset, const ALsizei t VectorScatterRevDelayIn(&late_delay, offset, mixX, mixY, temps, todo); } -static ALvoid ReverbState_process(ReverbState *State, ALsizei SamplesToDo, const ALfloat (*restrict SamplesIn)[BUFFERSIZE], ALfloat (*restrict SamplesOut)[BUFFERSIZE], ALsizei NumChannels) +static ALvoid ReverbState_process(ReverbState *State, ALsizei SamplesToDo, const ALfloat (*RESTRICT SamplesIn)[BUFFERSIZE], ALfloat (*RESTRICT SamplesOut)[BUFFERSIZE], ALsizei NumChannels) { - ALfloat (*restrict afmt)[MAX_UPDATE_SAMPLES] = State->TempSamples; - ALfloat (*restrict samples)[MAX_UPDATE_SAMPLES] = State->MixSamples; + ALfloat (*RESTRICT afmt)[MAX_UPDATE_SAMPLES] = State->TempSamples; + ALfloat (*RESTRICT samples)[MAX_UPDATE_SAMPLES] = State->MixSamples; ALsizei fadeCount = State->FadeCount; ALsizei offset = State->Offset; ALsizei base, c; diff --git a/Alc/filters/filter.c b/Alc/filters/filter.c index 2b370f89..d05b0cae 100644 --- a/Alc/filters/filter.c +++ b/Alc/filters/filter.c @@ -8,7 +8,7 @@ #include "defs.h" extern inline void BiquadFilter_clear(BiquadFilter *filter); -extern inline void BiquadFilter_copyParams(BiquadFilter *restrict dst, const BiquadFilter *restrict src); +extern inline void BiquadFilter_copyParams(BiquadFilter *RESTRICT dst, const BiquadFilter *RESTRICT src); extern inline void BiquadFilter_passthru(BiquadFilter *filter, ALsizei numsamples); extern inline ALfloat calc_rcpQ_from_slope(ALfloat gain, ALfloat slope); extern inline ALfloat calc_rcpQ_from_bandwidth(ALfloat f0norm, ALfloat bandwidth); @@ -94,7 +94,7 @@ void BiquadFilter_setParams(BiquadFilter *filter, BiquadType type, ALfloat gain, } -void BiquadFilter_processC(BiquadFilter *filter, ALfloat *restrict dst, const ALfloat *restrict src, ALsizei numsamples) +void BiquadFilter_processC(BiquadFilter *filter, ALfloat *RESTRICT dst, const ALfloat *RESTRICT src, ALsizei numsamples) { const ALfloat a1 = filter->a1; const ALfloat a2 = filter->a2; diff --git a/Alc/filters/nfc.c b/Alc/filters/nfc.c index 8869d1d0..8d61bb37 100644 --- a/Alc/filters/nfc.c +++ b/Alc/filters/nfc.c @@ -222,7 +222,7 @@ void NfcFilterAdjust(NfcFilter *nfc, const float w0) } -void NfcFilterProcess1(NfcFilter *nfc, float *restrict dst, const float *restrict src, const int count) +void NfcFilterProcess1(NfcFilter *nfc, float *RESTRICT dst, const float *RESTRICT src, const int count) { const float gain = nfc->first.gain; const float b1 = nfc->first.b1; @@ -243,7 +243,7 @@ void NfcFilterProcess1(NfcFilter *nfc, float *restrict dst, const float *restric nfc->first.z[0] = z1; } -void NfcFilterProcess2(NfcFilter *nfc, float *restrict dst, const float *restrict src, const int count) +void NfcFilterProcess2(NfcFilter *nfc, float *RESTRICT dst, const float *RESTRICT src, const int count) { const float gain = nfc->second.gain; const float b1 = nfc->second.b1; @@ -269,7 +269,7 @@ void NfcFilterProcess2(NfcFilter *nfc, float *restrict dst, const float *restric nfc->second.z[1] = z2; } -void NfcFilterProcess3(NfcFilter *nfc, float *restrict dst, const float *restrict src, const int count) +void NfcFilterProcess3(NfcFilter *nfc, float *RESTRICT dst, const float *RESTRICT src, const int count) { const float gain = nfc->third.gain; const float b1 = nfc->third.b1; diff --git a/Alc/filters/splitter.c b/Alc/filters/splitter.c index e99f4b95..6aed7493 100644 --- a/Alc/filters/splitter.c +++ b/Alc/filters/splitter.c @@ -27,7 +27,7 @@ void bandsplit_clear(BandSplitter *splitter) splitter->hp_z1 = 0.0f; } -void bandsplit_process(BandSplitter *splitter, ALfloat *restrict hpout, ALfloat *restrict lpout, +void bandsplit_process(BandSplitter *splitter, ALfloat *RESTRICT hpout, ALfloat *RESTRICT lpout, const ALfloat *input, ALsizei count) { ALfloat lp_coeff, hp_coeff, lp_y, hp_y, d; @@ -86,7 +86,7 @@ void splitterap_clear(SplitterAllpass *splitter) splitter->z1 = 0.0f; } -void splitterap_process(SplitterAllpass *splitter, ALfloat *restrict samples, ALsizei count) +void splitterap_process(SplitterAllpass *splitter, ALfloat *RESTRICT samples, ALsizei count) { ALfloat coeff, in, out; ALfloat z1; diff --git a/Alc/filters/splitter.h b/Alc/filters/splitter.h index a788bc3e..b2dc9b4a 100644 --- a/Alc/filters/splitter.h +++ b/Alc/filters/splitter.h @@ -14,7 +14,7 @@ typedef struct BandSplitter { void bandsplit_init(BandSplitter *splitter, ALfloat f0norm); void bandsplit_clear(BandSplitter *splitter); -void bandsplit_process(BandSplitter *splitter, ALfloat *restrict hpout, ALfloat *restrict lpout, +void bandsplit_process(BandSplitter *splitter, ALfloat *RESTRICT hpout, ALfloat *RESTRICT lpout, const ALfloat *input, ALsizei count); /* The all-pass portion of the band splitter. Applies the same phase shift @@ -27,7 +27,7 @@ typedef struct SplitterAllpass { void splitterap_init(SplitterAllpass *splitter, ALfloat f0norm); void splitterap_clear(SplitterAllpass *splitter); -void splitterap_process(SplitterAllpass *splitter, ALfloat *restrict samples, ALsizei count); +void splitterap_process(SplitterAllpass *splitter, ALfloat *RESTRICT samples, ALsizei count); typedef struct FrontStablizer { diff --git a/Alc/hrtf.c b/Alc/hrtf.c index ddbd3a28..ce602ee1 100644 --- a/Alc/hrtf.c +++ b/Alc/hrtf.c @@ -103,7 +103,7 @@ static ALsizei CalcAzIndex(ALsizei azcount, ALfloat az, ALfloat *mu) * and azimuth in radians. The coefficients are normalized. */ void GetHrtfCoeffs(const struct Hrtf *Hrtf, ALfloat elevation, ALfloat azimuth, ALfloat spread, - ALfloat (*restrict coeffs)[2], ALsizei *delays) + ALfloat (*RESTRICT coeffs)[2], ALsizei *delays) { ALsizei evidx, azidx, idx[4]; ALsizei evoffset; @@ -183,7 +183,7 @@ void GetHrtfCoeffs(const struct Hrtf *Hrtf, ALfloat elevation, ALfloat azimuth, } for(c = 0;c < 4;c++) { - const ALfloat (*restrict srccoeffs)[2] = ASSUME_ALIGNED(Hrtf->coeffs+idx[c], 16); + const ALfloat (*RESTRICT srccoeffs)[2] = ASSUME_ALIGNED(Hrtf->coeffs+idx[c], 16); for(i = 0;i < Hrtf->irSize;i++) { coeffs[i][0] += srccoeffs[i][0] * blend[c]; @@ -193,7 +193,7 @@ void GetHrtfCoeffs(const struct Hrtf *Hrtf, ALfloat elevation, ALfloat azimuth, } -void BuildBFormatHrtf(const struct Hrtf *Hrtf, DirectHrtfState *state, ALsizei NumChannels, const struct AngularPoint *AmbiPoints, const ALfloat (*restrict AmbiMatrix)[MAX_AMBI_COEFFS], ALsizei AmbiCount, const ALfloat *restrict AmbiOrderHFGain) +void BuildBFormatHrtf(const struct Hrtf *Hrtf, DirectHrtfState *state, ALsizei NumChannels, const struct AngularPoint *AmbiPoints, const ALfloat (*RESTRICT AmbiMatrix)[MAX_AMBI_COEFFS], ALsizei AmbiCount, const ALfloat *RESTRICT AmbiOrderHFGain) { /* Set this to 2 for dual-band HRTF processing. May require a higher quality * band-splitter, or better calculation of the new IR length to deal with the @@ -202,7 +202,7 @@ void BuildBFormatHrtf(const struct Hrtf *Hrtf, DirectHrtfState *state, ALsizei N #define NUM_BANDS 2 BandSplitter splitter; ALdouble (*tmpres)[HRIR_LENGTH][2]; - ALsizei *restrict idx; + ALsizei *RESTRICT idx; ALsizei min_delay = HRTF_HISTORY_LENGTH; ALsizei max_delay = 0; ALfloat temps[3][HRIR_LENGTH]; diff --git a/Alc/mastering.c b/Alc/mastering.c index 52ff5b23..dd4ed7e1 100644 --- a/Alc/mastering.c +++ b/Alc/mastering.c @@ -83,8 +83,8 @@ static ALfloat UpdateSlidingHold(SlidingHold *Hold, const ALsizei i, const ALflo { const ALsizei mask = BUFFERSIZE - 1; const ALsizei length = Hold->Length; - ALfloat *restrict values = Hold->Values; - ALsizei *restrict expiries = Hold->Expiries; + ALfloat *RESTRICT values = Hold->Values; + ALsizei *RESTRICT expiries = Hold->Expiries; ALsizei lowerIndex = Hold->LowerIndex; ALsizei upperIndex = Hold->UpperIndex; @@ -122,7 +122,7 @@ static ALfloat UpdateSlidingHold(SlidingHold *Hold, const ALsizei i, const ALflo static void ShiftSlidingHold(SlidingHold *Hold, const ALsizei n) { const ALsizei lowerIndex = Hold->LowerIndex; - ALsizei *restrict expiries = Hold->Expiries; + ALsizei *RESTRICT expiries = Hold->Expiries; ALsizei i = Hold->UpperIndex; if(lowerIndex < i) @@ -140,11 +140,11 @@ static void ShiftSlidingHold(SlidingHold *Hold, const ALsizei n) /* Multichannel compression is linked via the absolute maximum of all * channels. */ -static void LinkChannels(Compressor *Comp, const ALsizei SamplesToDo, ALfloat (*restrict OutBuffer)[BUFFERSIZE]) +static void LinkChannels(Compressor *Comp, const ALsizei SamplesToDo, ALfloat (*RESTRICT OutBuffer)[BUFFERSIZE]) { const ALsizei index = Comp->LookAhead; const ALsizei numChans = Comp->NumChans; - ALfloat *restrict sideChain = Comp->SideChain; + ALfloat *RESTRICT sideChain = Comp->SideChain; ALsizei c, i; ASSUME(SamplesToDo > 0); @@ -173,8 +173,8 @@ static void CrestDetector(Compressor *Comp, const ALsizei SamplesToDo) { const ALfloat a_crest = Comp->CrestCoeff; const ALsizei index = Comp->LookAhead; - const ALfloat *restrict sideChain = Comp->SideChain; - ALfloat *restrict crestFactor = Comp->CrestFactor; + const ALfloat *RESTRICT sideChain = Comp->SideChain; + ALfloat *RESTRICT crestFactor = Comp->CrestFactor; ALfloat y2_peak = Comp->LastPeakSq; ALfloat y2_rms = Comp->LastRmsSq; ALsizei i; @@ -202,7 +202,7 @@ static void CrestDetector(Compressor *Comp, const ALsizei SamplesToDo) static void PeakDetector(Compressor *Comp, const ALsizei SamplesToDo) { const ALsizei index = Comp->LookAhead; - ALfloat *restrict sideChain = Comp->SideChain; + ALfloat *RESTRICT sideChain = Comp->SideChain; ALsizei i; ASSUME(SamplesToDo > 0); @@ -223,7 +223,7 @@ static void PeakDetector(Compressor *Comp, const ALsizei SamplesToDo) static void PeakHoldDetector(Compressor *Comp, const ALsizei SamplesToDo) { const ALsizei index = Comp->LookAhead; - ALfloat *restrict sideChain = Comp->SideChain; + ALfloat *RESTRICT sideChain = Comp->SideChain; SlidingHold *hold = Comp->Hold; ALsizei i; @@ -260,8 +260,8 @@ static void GainCompressor(Compressor *Comp, const ALsizei SamplesToDo) const ALfloat release = Comp->Release; const ALfloat c_est = Comp->GainEstimate; const ALfloat a_adp = Comp->AdaptCoeff; - const ALfloat *restrict crestFactor = Comp->CrestFactor; - ALfloat *restrict sideChain = Comp->SideChain; + const ALfloat *RESTRICT crestFactor = Comp->CrestFactor; + ALfloat *RESTRICT sideChain = Comp->SideChain; ALfloat postGain = Comp->PostGain; ALfloat knee = Comp->Knee; ALfloat t_att = attack; @@ -353,13 +353,13 @@ static void GainCompressor(Compressor *Comp, const ALsizei SamplesToDo) * reaching the offending impulse. This is best used when operating as a * limiter. */ -static void SignalDelay(Compressor *Comp, const ALsizei SamplesToDo, ALfloat (*restrict OutBuffer)[BUFFERSIZE]) +static void SignalDelay(Compressor *Comp, const ALsizei SamplesToDo, ALfloat (*RESTRICT OutBuffer)[BUFFERSIZE]) { const ALsizei mask = BUFFERSIZE - 1; const ALsizei numChans = Comp->NumChans; const ALsizei indexIn = Comp->DelayIndex; const ALsizei indexOut = Comp->DelayIndex - Comp->LookAhead; - ALfloat (*restrict delay)[BUFFERSIZE] = Comp->Delay; + ALfloat (*RESTRICT delay)[BUFFERSIZE] = Comp->Delay; ALsizei c, i; ASSUME(SamplesToDo > 0); @@ -481,11 +481,11 @@ Compressor* CompressorInit(const ALsizei NumChans, const ALuint SampleRate, return Comp; } -void ApplyCompression(Compressor *Comp, const ALsizei SamplesToDo, ALfloat (*restrict OutBuffer)[BUFFERSIZE]) +void ApplyCompression(Compressor *Comp, const ALsizei SamplesToDo, ALfloat (*RESTRICT OutBuffer)[BUFFERSIZE]) { const ALsizei numChans = Comp->NumChans; const ALfloat preGain = Comp->PreGain; - ALfloat *restrict sideChain; + ALfloat *RESTRICT sideChain; ALsizei c, i; ASSUME(SamplesToDo > 0); diff --git a/Alc/mastering.h b/Alc/mastering.h index b68b0de1..17f5e8be 100644 --- a/Alc/mastering.h +++ b/Alc/mastering.h @@ -42,7 +42,7 @@ struct Compressor* CompressorInit(const ALsizei NumChans, const ALuint SampleRat const ALfloat AttackTime, const ALfloat ReleaseTime); void ApplyCompression(struct Compressor *Comp, const ALsizei SamplesToDo, - ALfloat (*restrict OutBuffer)[BUFFERSIZE]); + ALfloat (*RESTRICT OutBuffer)[BUFFERSIZE]); ALsizei GetCompressorLookAhead(const struct Compressor *Comp); diff --git a/Alc/mixer/defs.h b/Alc/mixer/defs.h index 8f6e3755..acb8a8c2 100644 --- a/Alc/mixer/defs.h +++ b/Alc/mixer/defs.h @@ -12,57 +12,57 @@ struct MixHrtfParams; struct HrtfState; /* C resamplers */ -const ALfloat *Resample_copy_C(const InterpState *state, const ALfloat *restrict src, ALsizei frac, ALint increment, ALfloat *restrict dst, ALsizei dstlen); -const ALfloat *Resample_point_C(const InterpState *state, const ALfloat *restrict src, ALsizei frac, ALint increment, ALfloat *restrict dst, ALsizei dstlen); -const ALfloat *Resample_lerp_C(const InterpState *state, const ALfloat *restrict src, ALsizei frac, ALint increment, ALfloat *restrict dst, ALsizei dstlen); -const ALfloat *Resample_cubic_C(const InterpState *state, const ALfloat *restrict src, ALsizei frac, ALint increment, ALfloat *restrict dst, ALsizei dstlen); -const ALfloat *Resample_bsinc_C(const InterpState *state, const ALfloat *restrict src, ALsizei frac, ALint increment, ALfloat *restrict dst, ALsizei dstlen); +const ALfloat *Resample_copy_C(const InterpState *state, const ALfloat *RESTRICT src, ALsizei frac, ALint increment, ALfloat *RESTRICT dst, ALsizei dstlen); +const ALfloat *Resample_point_C(const InterpState *state, const ALfloat *RESTRICT src, ALsizei frac, ALint increment, ALfloat *RESTRICT dst, ALsizei dstlen); +const ALfloat *Resample_lerp_C(const InterpState *state, const ALfloat *RESTRICT src, ALsizei frac, ALint increment, ALfloat *RESTRICT dst, ALsizei dstlen); +const ALfloat *Resample_cubic_C(const InterpState *state, const ALfloat *RESTRICT src, ALsizei frac, ALint increment, ALfloat *RESTRICT dst, ALsizei dstlen); +const ALfloat *Resample_bsinc_C(const InterpState *state, const ALfloat *RESTRICT src, ALsizei frac, ALint increment, ALfloat *RESTRICT dst, ALsizei dstlen); /* C mixers */ -void MixHrtf_C(ALfloat *restrict LeftOut, ALfloat *restrict RightOut, +void MixHrtf_C(ALfloat *RESTRICT LeftOut, ALfloat *RESTRICT RightOut, const ALfloat *data, ALsizei Offset, ALsizei OutPos, const ALsizei IrSize, struct MixHrtfParams *hrtfparams, struct HrtfState *hrtfstate, ALsizei BufferSize); -void MixHrtfBlend_C(ALfloat *restrict LeftOut, ALfloat *restrict RightOut, +void MixHrtfBlend_C(ALfloat *RESTRICT LeftOut, ALfloat *RESTRICT RightOut, const ALfloat *data, ALsizei Offset, ALsizei OutPos, const ALsizei IrSize, const HrtfParams *oldparams, MixHrtfParams *newparams, HrtfState *hrtfstate, ALsizei BufferSize); -void MixDirectHrtf_C(ALfloat *restrict LeftOut, ALfloat *restrict RightOut, +void MixDirectHrtf_C(ALfloat *RESTRICT LeftOut, ALfloat *RESTRICT RightOut, const ALfloat *data, ALsizei Offset, const ALsizei IrSize, - const ALfloat (*restrict Coeffs)[2], ALfloat (*restrict Values)[2], + const ALfloat (*RESTRICT Coeffs)[2], ALfloat (*RESTRICT Values)[2], ALsizei BufferSize); -void Mix_C(const ALfloat *data, ALsizei OutChans, ALfloat (*restrict OutBuffer)[BUFFERSIZE], +void Mix_C(const ALfloat *data, ALsizei OutChans, ALfloat (*RESTRICT OutBuffer)[BUFFERSIZE], ALfloat *CurrentGains, const ALfloat *TargetGains, ALsizei Counter, ALsizei OutPos, ALsizei BufferSize); void MixRow_C(ALfloat *OutBuffer, const ALfloat *Gains, - const ALfloat (*restrict data)[BUFFERSIZE], ALsizei InChans, + const ALfloat (*RESTRICT data)[BUFFERSIZE], ALsizei InChans, ALsizei InPos, ALsizei BufferSize); /* SSE mixers */ -void MixHrtf_SSE(ALfloat *restrict LeftOut, ALfloat *restrict RightOut, +void MixHrtf_SSE(ALfloat *RESTRICT LeftOut, ALfloat *RESTRICT RightOut, const ALfloat *data, ALsizei Offset, ALsizei OutPos, const ALsizei IrSize, struct MixHrtfParams *hrtfparams, struct HrtfState *hrtfstate, ALsizei BufferSize); -void MixHrtfBlend_SSE(ALfloat *restrict LeftOut, ALfloat *restrict RightOut, +void MixHrtfBlend_SSE(ALfloat *RESTRICT LeftOut, ALfloat *RESTRICT RightOut, const ALfloat *data, ALsizei Offset, ALsizei OutPos, const ALsizei IrSize, const HrtfParams *oldparams, MixHrtfParams *newparams, HrtfState *hrtfstate, ALsizei BufferSize); -void MixDirectHrtf_SSE(ALfloat *restrict LeftOut, ALfloat *restrict RightOut, +void MixDirectHrtf_SSE(ALfloat *RESTRICT LeftOut, ALfloat *RESTRICT RightOut, const ALfloat *data, ALsizei Offset, const ALsizei IrSize, - const ALfloat (*restrict Coeffs)[2], ALfloat (*restrict Values)[2], + const ALfloat (*RESTRICT Coeffs)[2], ALfloat (*RESTRICT Values)[2], ALsizei BufferSize); -void Mix_SSE(const ALfloat *data, ALsizei OutChans, ALfloat (*restrict OutBuffer)[BUFFERSIZE], +void Mix_SSE(const ALfloat *data, ALsizei OutChans, ALfloat (*RESTRICT OutBuffer)[BUFFERSIZE], ALfloat *CurrentGains, const ALfloat *TargetGains, ALsizei Counter, ALsizei OutPos, ALsizei BufferSize); void MixRow_SSE(ALfloat *OutBuffer, const ALfloat *Gains, - const ALfloat (*restrict data)[BUFFERSIZE], ALsizei InChans, + const ALfloat (*RESTRICT data)[BUFFERSIZE], ALsizei InChans, ALsizei InPos, ALsizei BufferSize); /* SSE resamplers */ -inline void InitiatePositionArrays(ALsizei frac, ALint increment, ALsizei *restrict frac_arr, ALsizei *restrict pos_arr, ALsizei size) +inline void InitiatePositionArrays(ALsizei frac, ALint increment, ALsizei *RESTRICT frac_arr, ALsizei *RESTRICT pos_arr, ALsizei size) { ALsizei i; @@ -76,44 +76,44 @@ inline void InitiatePositionArrays(ALsizei frac, ALint increment, ALsizei *restr } } -const ALfloat *Resample_lerp_SSE2(const InterpState *state, const ALfloat *restrict src, - ALsizei frac, ALint increment, ALfloat *restrict dst, +const ALfloat *Resample_lerp_SSE2(const InterpState *state, const ALfloat *RESTRICT src, + ALsizei frac, ALint increment, ALfloat *RESTRICT dst, ALsizei numsamples); -const ALfloat *Resample_lerp_SSE41(const InterpState *state, const ALfloat *restrict src, - ALsizei frac, ALint increment, ALfloat *restrict dst, +const ALfloat *Resample_lerp_SSE41(const InterpState *state, const ALfloat *RESTRICT src, + ALsizei frac, ALint increment, ALfloat *RESTRICT dst, ALsizei numsamples); -const ALfloat *Resample_bsinc_SSE(const InterpState *state, const ALfloat *restrict src, - ALsizei frac, ALint increment, ALfloat *restrict dst, +const ALfloat *Resample_bsinc_SSE(const InterpState *state, const ALfloat *RESTRICT src, + ALsizei frac, ALint increment, ALfloat *RESTRICT dst, ALsizei dstlen); /* Neon mixers */ -void MixHrtf_Neon(ALfloat *restrict LeftOut, ALfloat *restrict RightOut, +void MixHrtf_Neon(ALfloat *RESTRICT LeftOut, ALfloat *RESTRICT RightOut, const ALfloat *data, ALsizei Offset, ALsizei OutPos, const ALsizei IrSize, struct MixHrtfParams *hrtfparams, struct HrtfState *hrtfstate, ALsizei BufferSize); -void MixHrtfBlend_Neon(ALfloat *restrict LeftOut, ALfloat *restrict RightOut, +void MixHrtfBlend_Neon(ALfloat *RESTRICT LeftOut, ALfloat *RESTRICT RightOut, const ALfloat *data, ALsizei Offset, ALsizei OutPos, const ALsizei IrSize, const HrtfParams *oldparams, MixHrtfParams *newparams, HrtfState *hrtfstate, ALsizei BufferSize); -void MixDirectHrtf_Neon(ALfloat *restrict LeftOut, ALfloat *restrict RightOut, +void MixDirectHrtf_Neon(ALfloat *RESTRICT LeftOut, ALfloat *RESTRICT RightOut, const ALfloat *data, ALsizei Offset, const ALsizei IrSize, - const ALfloat (*restrict Coeffs)[2], ALfloat (*restrict Values)[2], + const ALfloat (*RESTRICT Coeffs)[2], ALfloat (*RESTRICT Values)[2], ALsizei BufferSize); -void Mix_Neon(const ALfloat *data, ALsizei OutChans, ALfloat (*restrict OutBuffer)[BUFFERSIZE], +void Mix_Neon(const ALfloat *data, ALsizei OutChans, ALfloat (*RESTRICT OutBuffer)[BUFFERSIZE], ALfloat *CurrentGains, const ALfloat *TargetGains, ALsizei Counter, ALsizei OutPos, ALsizei BufferSize); void MixRow_Neon(ALfloat *OutBuffer, const ALfloat *Gains, - const ALfloat (*restrict data)[BUFFERSIZE], ALsizei InChans, + const ALfloat (*RESTRICT data)[BUFFERSIZE], ALsizei InChans, ALsizei InPos, ALsizei BufferSize); /* Neon resamplers */ -const ALfloat *Resample_lerp_Neon(const InterpState *state, const ALfloat *restrict src, - ALsizei frac, ALint increment, ALfloat *restrict dst, +const ALfloat *Resample_lerp_Neon(const InterpState *state, const ALfloat *RESTRICT src, + ALsizei frac, ALint increment, ALfloat *RESTRICT dst, ALsizei numsamples); -const ALfloat *Resample_bsinc_Neon(const InterpState *state, const ALfloat *restrict src, - ALsizei frac, ALint increment, ALfloat *restrict dst, +const ALfloat *Resample_bsinc_Neon(const InterpState *state, const ALfloat *RESTRICT src, + ALsizei frac, ALint increment, ALfloat *RESTRICT dst, ALsizei dstlen); #endif /* MIXER_DEFS_H */ diff --git a/Alc/mixer/hrtf_inc.c b/Alc/mixer/hrtf_inc.c index 3ef22f24..21840abd 100644 --- a/Alc/mixer/hrtf_inc.c +++ b/Alc/mixer/hrtf_inc.c @@ -9,13 +9,13 @@ #include "defs.h" -static inline void ApplyCoeffs(ALsizei Offset, ALfloat (*restrict Values)[2], +static inline void ApplyCoeffs(ALsizei Offset, ALfloat (*RESTRICT Values)[2], const ALsizei irSize, - const ALfloat (*restrict Coeffs)[2], + const ALfloat (*RESTRICT Coeffs)[2], ALfloat left, ALfloat right); -void MixHrtf(ALfloat *restrict LeftOut, ALfloat *restrict RightOut, +void MixHrtf(ALfloat *RESTRICT LeftOut, ALfloat *RESTRICT RightOut, const ALfloat *data, ALsizei Offset, ALsizei OutPos, const ALsizei IrSize, MixHrtfParams *hrtfparams, HrtfState *hrtfstate, ALsizei BufferSize) @@ -54,7 +54,7 @@ void MixHrtf(ALfloat *restrict LeftOut, ALfloat *restrict RightOut, hrtfparams->Gain = gain + gainstep*stepcount; } -void MixHrtfBlend(ALfloat *restrict LeftOut, ALfloat *restrict RightOut, +void MixHrtfBlend(ALfloat *RESTRICT LeftOut, ALfloat *RESTRICT RightOut, const ALfloat *data, ALsizei Offset, ALsizei OutPos, const ALsizei IrSize, const HrtfParams *oldparams, MixHrtfParams *newparams, HrtfState *hrtfstate, @@ -103,9 +103,9 @@ void MixHrtfBlend(ALfloat *restrict LeftOut, ALfloat *restrict RightOut, newparams->Gain = newGain + newGainStep*stepcount; } -void MixDirectHrtf(ALfloat *restrict LeftOut, ALfloat *restrict RightOut, +void MixDirectHrtf(ALfloat *RESTRICT LeftOut, ALfloat *RESTRICT RightOut, const ALfloat *data, ALsizei Offset, const ALsizei IrSize, - const ALfloat (*restrict Coeffs)[2], ALfloat (*restrict Values)[2], + const ALfloat (*RESTRICT Coeffs)[2], ALfloat (*RESTRICT Values)[2], ALsizei BufferSize) { ALfloat insample; diff --git a/Alc/mixer/mixer_c.c b/Alc/mixer/mixer_c.c index 14d7c669..ea864dbc 100644 --- a/Alc/mixer/mixer_c.c +++ b/Alc/mixer/mixer_c.c @@ -9,13 +9,13 @@ #include "defs.h" -static inline ALfloat do_point(const InterpState* UNUSED(state), const ALfloat *restrict vals, ALsizei UNUSED(frac)) +static inline ALfloat do_point(const InterpState* UNUSED(state), const ALfloat *RESTRICT vals, ALsizei UNUSED(frac)) { return vals[0]; } -static inline ALfloat do_lerp(const InterpState* UNUSED(state), const ALfloat *restrict vals, ALsizei frac) +static inline ALfloat do_lerp(const InterpState* UNUSED(state), const ALfloat *RESTRICT vals, ALsizei frac) { return lerp(vals[0], vals[1], frac * (1.0f/FRACTIONONE)); } -static inline ALfloat do_cubic(const InterpState* UNUSED(state), const ALfloat *restrict vals, ALsizei frac) +static inline ALfloat do_cubic(const InterpState* UNUSED(state), const ALfloat *RESTRICT vals, ALsizei frac) { return cubic(vals[0], vals[1], vals[2], vals[3], frac * (1.0f/FRACTIONONE)); } -static inline ALfloat do_bsinc(const InterpState *state, const ALfloat *restrict vals, ALsizei frac) +static inline ALfloat do_bsinc(const InterpState *state, const ALfloat *RESTRICT vals, ALsizei frac) { const ALfloat *fil, *scd, *phd, *spd; ALsizei j_f, pi; @@ -42,8 +42,8 @@ static inline ALfloat do_bsinc(const InterpState *state, const ALfloat *restrict } const ALfloat *Resample_copy_C(const InterpState* UNUSED(state), - const ALfloat *restrict src, ALsizei UNUSED(frac), ALint UNUSED(increment), - ALfloat *restrict dst, ALsizei numsamples) + const ALfloat *RESTRICT src, ALsizei UNUSED(frac), ALint UNUSED(increment), + ALfloat *RESTRICT dst, ALsizei numsamples) { #if defined(HAVE_SSE) || defined(HAVE_NEON) /* Avoid copying the source data if it's aligned like the destination. */ @@ -56,8 +56,8 @@ const ALfloat *Resample_copy_C(const InterpState* UNUSED(state), #define DECL_TEMPLATE(Tag, Sampler, O) \ const ALfloat *Resample_##Tag##_C(const InterpState *state, \ - const ALfloat *restrict src, ALsizei frac, ALint increment, \ - ALfloat *restrict dst, ALsizei numsamples) \ + const ALfloat *RESTRICT src, ALsizei frac, ALint increment, \ + ALfloat *RESTRICT dst, ALsizei numsamples) \ { \ const InterpState istate = *state; \ ALsizei i; \ @@ -84,9 +84,9 @@ DECL_TEMPLATE(bsinc, do_bsinc, istate.bsinc.l) #undef DECL_TEMPLATE -static inline void ApplyCoeffs(ALsizei Offset, ALfloat (*restrict Values)[2], +static inline void ApplyCoeffs(ALsizei Offset, ALfloat (*RESTRICT Values)[2], const ALsizei IrSize, - const ALfloat (*restrict Coeffs)[2], + const ALfloat (*RESTRICT Coeffs)[2], ALfloat left, ALfloat right) { ALsizei c; @@ -104,7 +104,7 @@ static inline void ApplyCoeffs(ALsizei Offset, ALfloat (*restrict Values)[2], #include "hrtf_inc.c" -void Mix_C(const ALfloat *data, ALsizei OutChans, ALfloat (*restrict OutBuffer)[BUFFERSIZE], +void Mix_C(const ALfloat *data, ALsizei OutChans, ALfloat (*RESTRICT OutBuffer)[BUFFERSIZE], ALfloat *CurrentGains, const ALfloat *TargetGains, ALsizei Counter, ALsizei OutPos, ALsizei BufferSize) { @@ -150,7 +150,7 @@ void Mix_C(const ALfloat *data, ALsizei OutChans, ALfloat (*restrict OutBuffer)[ * transform. And as the matrices are more or less static once set up, no * stepping is necessary. */ -void MixRow_C(ALfloat *OutBuffer, const ALfloat *Gains, const ALfloat (*restrict data)[BUFFERSIZE], ALsizei InChans, ALsizei InPos, ALsizei BufferSize) +void MixRow_C(ALfloat *OutBuffer, const ALfloat *Gains, const ALfloat (*RESTRICT data)[BUFFERSIZE], ALsizei InChans, ALsizei InPos, ALsizei BufferSize) { ALsizei c, i; diff --git a/Alc/mixer/mixer_neon.c b/Alc/mixer/mixer_neon.c index 9bf5521a..a035abc7 100644 --- a/Alc/mixer/mixer_neon.c +++ b/Alc/mixer/mixer_neon.c @@ -11,8 +11,8 @@ const ALfloat *Resample_lerp_Neon(const InterpState* UNUSED(state), - const ALfloat *restrict src, ALsizei frac, ALint increment, - ALfloat *restrict dst, ALsizei numsamples) + const ALfloat *RESTRICT src, ALsizei frac, ALint increment, + ALfloat *RESTRICT dst, ALsizei numsamples) { const int32x4_t increment4 = vdupq_n_s32(increment*4); const float32x4_t fracOne4 = vdupq_n_f32(1.0f/FRACTIONONE); @@ -67,8 +67,8 @@ const ALfloat *Resample_lerp_Neon(const InterpState* UNUSED(state), } const ALfloat *Resample_bsinc_Neon(const InterpState *state, - const ALfloat *restrict src, ALsizei frac, ALint increment, - ALfloat *restrict dst, ALsizei dstlen) + const ALfloat *RESTRICT src, ALsizei frac, ALint increment, + ALfloat *RESTRICT dst, ALsizei dstlen) { const ALfloat *const filter = state->bsinc.filter; const float32x4_t sf4 = vdupq_n_f32(state->bsinc.sf); @@ -127,9 +127,9 @@ const ALfloat *Resample_bsinc_Neon(const InterpState *state, } -static inline void ApplyCoeffs(ALsizei Offset, ALfloat (*restrict Values)[2], +static inline void ApplyCoeffs(ALsizei Offset, ALfloat (*RESTRICT Values)[2], const ALsizei IrSize, - const ALfloat (*restrict Coeffs)[2], + const ALfloat (*RESTRICT Coeffs)[2], ALfloat left, ALfloat right) { ALsizei c; @@ -163,7 +163,7 @@ static inline void ApplyCoeffs(ALsizei Offset, ALfloat (*restrict Values)[2], #include "hrtf_inc.c" -void Mix_Neon(const ALfloat *data, ALsizei OutChans, ALfloat (*restrict OutBuffer)[BUFFERSIZE], +void Mix_Neon(const ALfloat *data, ALsizei OutChans, ALfloat (*RESTRICT OutBuffer)[BUFFERSIZE], ALfloat *CurrentGains, const ALfloat *TargetGains, ALsizei Counter, ALsizei OutPos, ALsizei BufferSize) { @@ -251,7 +251,7 @@ void Mix_Neon(const ALfloat *data, ALsizei OutChans, ALfloat (*restrict OutBuffe } } -void MixRow_Neon(ALfloat *OutBuffer, const ALfloat *Gains, const ALfloat (*restrict data)[BUFFERSIZE], ALsizei InChans, ALsizei InPos, ALsizei BufferSize) +void MixRow_Neon(ALfloat *OutBuffer, const ALfloat *Gains, const ALfloat (*RESTRICT data)[BUFFERSIZE], ALsizei InChans, ALsizei InPos, ALsizei BufferSize) { ALsizei c; diff --git a/Alc/mixer/mixer_sse.c b/Alc/mixer/mixer_sse.c index 725a5ebc..34055001 100644 --- a/Alc/mixer/mixer_sse.c +++ b/Alc/mixer/mixer_sse.c @@ -12,8 +12,8 @@ #include "defs.h" -const ALfloat *Resample_bsinc_SSE(const InterpState *state, const ALfloat *restrict src, - ALsizei frac, ALint increment, ALfloat *restrict dst, +const ALfloat *Resample_bsinc_SSE(const InterpState *state, const ALfloat *RESTRICT src, + ALsizei frac, ALint increment, ALfloat *RESTRICT dst, ALsizei dstlen) { const ALfloat *const filter = state->bsinc.filter; @@ -75,9 +75,9 @@ const ALfloat *Resample_bsinc_SSE(const InterpState *state, const ALfloat *restr } -static inline void ApplyCoeffs(ALsizei Offset, ALfloat (*restrict Values)[2], +static inline void ApplyCoeffs(ALsizei Offset, ALfloat (*RESTRICT Values)[2], const ALsizei IrSize, - const ALfloat (*restrict Coeffs)[2], + const ALfloat (*RESTRICT Coeffs)[2], ALfloat left, ALfloat right) { const __m128 lrlr = _mm_setr_ps(left, right, left, right); @@ -135,7 +135,7 @@ static inline void ApplyCoeffs(ALsizei Offset, ALfloat (*restrict Values)[2], #include "hrtf_inc.c" -void Mix_SSE(const ALfloat *data, ALsizei OutChans, ALfloat (*restrict OutBuffer)[BUFFERSIZE], +void Mix_SSE(const ALfloat *data, ALsizei OutChans, ALfloat (*RESTRICT OutBuffer)[BUFFERSIZE], ALfloat *CurrentGains, const ALfloat *TargetGains, ALsizei Counter, ALsizei OutPos, ALsizei BufferSize) { @@ -218,7 +218,7 @@ void Mix_SSE(const ALfloat *data, ALsizei OutChans, ALfloat (*restrict OutBuffer } } -void MixRow_SSE(ALfloat *OutBuffer, const ALfloat *Gains, const ALfloat (*restrict data)[BUFFERSIZE], ALsizei InChans, ALsizei InPos, ALsizei BufferSize) +void MixRow_SSE(ALfloat *OutBuffer, const ALfloat *Gains, const ALfloat (*RESTRICT data)[BUFFERSIZE], ALsizei InChans, ALsizei InPos, ALsizei BufferSize) { ALsizei c; diff --git a/Alc/mixer/mixer_sse2.c b/Alc/mixer/mixer_sse2.c index 9cbaeb0a..2432342f 100644 --- a/Alc/mixer/mixer_sse2.c +++ b/Alc/mixer/mixer_sse2.c @@ -28,8 +28,8 @@ const ALfloat *Resample_lerp_SSE2(const InterpState* UNUSED(state), - const ALfloat *restrict src, ALsizei frac, ALint increment, - ALfloat *restrict dst, ALsizei numsamples) + const ALfloat *RESTRICT src, ALsizei frac, ALint increment, + ALfloat *RESTRICT dst, ALsizei numsamples) { const __m128i increment4 = _mm_set1_epi32(increment*4); const __m128 fracOne4 = _mm_set1_ps(1.0f/FRACTIONONE); diff --git a/Alc/mixer/mixer_sse41.c b/Alc/mixer/mixer_sse41.c index e92a3dd0..34b405f8 100644 --- a/Alc/mixer/mixer_sse41.c +++ b/Alc/mixer/mixer_sse41.c @@ -29,8 +29,8 @@ const ALfloat *Resample_lerp_SSE41(const InterpState* UNUSED(state), - const ALfloat *restrict src, ALsizei frac, ALint increment, - ALfloat *restrict dst, ALsizei numsamples) + const ALfloat *RESTRICT src, ALsizei frac, ALint increment, + ALfloat *RESTRICT dst, ALsizei numsamples) { const __m128i increment4 = _mm_set1_epi32(increment*4); const __m128 fracOne4 = _mm_set1_ps(1.0f/FRACTIONONE); diff --git a/Alc/mixvoice.c b/Alc/mixvoice.c index d019b898..587f4a6b 100644 --- a/Alc/mixvoice.c +++ b/Alc/mixvoice.c @@ -45,7 +45,7 @@ static_assert((INT_MAX>>FRACTIONBITS)/MAX_PITCH > BUFFERSIZE, "MAX_PITCH and/or BUFFERSIZE are too large for FRACTIONBITS!"); -extern inline void InitiatePositionArrays(ALsizei frac, ALint increment, ALsizei *restrict frac_arr, ALsizei *restrict pos_arr, ALsizei size); +extern inline void InitiatePositionArrays(ALsizei frac, ALint increment, ALsizei *RESTRICT frac_arr, ALsizei *RESTRICT pos_arr, ALsizei size); /* BSinc24 requires up to 23 extra samples before the current position, and 24 after. */ @@ -228,7 +228,7 @@ static inline ALfloat Sample_ALalaw(ALalaw val) { return aLawDecompressionTable[val] * (1.0f/32768.0f); } #define DECL_TEMPLATE(T) \ -static inline void Load_##T(ALfloat *restrict dst, const T *restrict src, \ +static inline void Load_##T(ALfloat *RESTRICT dst, const T *RESTRICT src, \ ALint srcstep, ALsizei samples) \ { \ ALsizei i; \ @@ -245,7 +245,7 @@ DECL_TEMPLATE(ALalaw) #undef DECL_TEMPLATE -static void LoadSamples(ALfloat *restrict dst, const ALvoid *restrict src, ALint srcstep, +static void LoadSamples(ALfloat *RESTRICT dst, const ALvoid *RESTRICT src, ALint srcstep, enum FmtType srctype, ALsizei samples) { #define HANDLE_FMT(ET, ST) case ET: Load_##ST(dst, src, srcstep, samples); break @@ -263,7 +263,7 @@ static void LoadSamples(ALfloat *restrict dst, const ALvoid *restrict src, ALint static const ALfloat *DoFilters(BiquadFilter *lpfilter, BiquadFilter *hpfilter, - ALfloat *restrict dst, const ALfloat *restrict src, + ALfloat *RESTRICT dst, const ALfloat *RESTRICT src, ALsizei numsamples, enum ActiveFilters type) { ALsizei i; diff --git a/Alc/panning.c b/Alc/panning.c index 79627e78..4328b30f 100644 --- a/Alc/panning.c +++ b/Alc/panning.c @@ -41,7 +41,7 @@ extern inline void CalcDirectionCoeffs(const ALfloat dir[3], ALfloat spread, ALfloat coeffs[MAX_AMBI_COEFFS]); extern inline void CalcAngleCoeffs(ALfloat azimuth, ALfloat elevation, ALfloat spread, ALfloat coeffs[MAX_AMBI_COEFFS]); extern inline float ScaleAzimuthFront(float azimuth, float scale); -extern inline void ComputePanGains(const MixParams *dry, const ALfloat*restrict coeffs, ALfloat ingain, ALfloat gains[MAX_OUTPUT_CHANNELS]); +extern inline void ComputePanGains(const MixParams *dry, const ALfloat*RESTRICT coeffs, ALfloat ingain, ALfloat gains[MAX_OUTPUT_CHANNELS]); static const ALsizei FuMa2ACN[MAX_AMBI_COEFFS] = { @@ -151,7 +151,7 @@ void CalcAmbiCoeffs(const ALfloat y, const ALfloat z, const ALfloat x, const ALf } -void ComputePanningGainsMC(const ChannelConfig *chancoeffs, ALsizei numchans, ALsizei numcoeffs, const ALfloat*restrict coeffs, ALfloat ingain, ALfloat gains[MAX_OUTPUT_CHANNELS]) +void ComputePanningGainsMC(const ChannelConfig *chancoeffs, ALsizei numchans, ALsizei numcoeffs, const ALfloat*RESTRICT coeffs, ALfloat ingain, ALfloat gains[MAX_OUTPUT_CHANNELS]) { ALsizei i, j; @@ -166,7 +166,7 @@ void ComputePanningGainsMC(const ChannelConfig *chancoeffs, ALsizei numchans, AL gains[i] = 0.0f; } -void ComputePanningGainsBF(const BFChannelConfig *chanmap, ALsizei numchans, const ALfloat*restrict coeffs, ALfloat ingain, ALfloat gains[MAX_OUTPUT_CHANNELS]) +void ComputePanningGainsBF(const BFChannelConfig *chanmap, ALsizei numchans, const ALfloat*RESTRICT coeffs, ALfloat ingain, ALfloat gains[MAX_OUTPUT_CHANNELS]) { ALsizei i; @@ -381,7 +381,7 @@ static const ChannelMap MonoCfg[1] = { }; static void InitNearFieldCtrl(ALCdevice *device, ALfloat ctrl_dist, ALsizei order, - const ALsizei *restrict chans_per_order) + const ALsizei *RESTRICT chans_per_order) { const char *devname = alstr_get_cstr(device->DeviceName); ALsizei i; @@ -845,8 +845,8 @@ static void InitHrtfPanning(ALCdevice *device) }; static const ALsizei IndexMap[6] = { 0, 1, 2, 3, 4, 8 }; static const ALsizei ChansPerOrder[MAX_AMBI_ORDER+1] = { 1, 3, 2, 0 }; - const ALfloat (*restrict AmbiMatrix)[MAX_AMBI_COEFFS] = AmbiMatrixFOA; - const ALfloat *restrict AmbiOrderHFGain = AmbiOrderHFGainFOA; + const ALfloat (*RESTRICT AmbiMatrix)[MAX_AMBI_COEFFS] = AmbiMatrixFOA; + const ALfloat *RESTRICT AmbiOrderHFGain = AmbiOrderHFGainFOA; ALsizei count = 4; ALsizei i; diff --git a/Alc/uhjfilter.c b/Alc/uhjfilter.c index 42b0bc40..6ee6fdb0 100644 --- a/Alc/uhjfilter.c +++ b/Alc/uhjfilter.c @@ -16,7 +16,7 @@ static const ALfloat Filter2CoeffSqr[4] = { 0.161758498368f, 0.733028932341f, 0.945349700329f, 0.990599156685f }; -static void allpass_process(AllPassState *state, ALfloat *restrict dst, const ALfloat *restrict src, const ALfloat aa, ALsizei todo) +static void allpass_process(AllPassState *state, ALfloat *RESTRICT dst, const ALfloat *RESTRICT src, const ALfloat aa, ALsizei todo) { ALfloat z1 = state->z[0]; ALfloat z2 = state->z[1]; @@ -55,7 +55,7 @@ static void allpass_process(AllPassState *state, ALfloat *restrict dst, const AL * know which is the intended result. */ -void EncodeUhj2(Uhj2Encoder *enc, ALfloat *restrict LeftOut, ALfloat *restrict RightOut, ALfloat (*restrict InSamples)[BUFFERSIZE], ALsizei SamplesToDo) +void EncodeUhj2(Uhj2Encoder *enc, ALfloat *RESTRICT LeftOut, ALfloat *RESTRICT RightOut, ALfloat (*RESTRICT InSamples)[BUFFERSIZE], ALsizei SamplesToDo) { ALfloat D[MAX_UPDATE_SAMPLES], S[MAX_UPDATE_SAMPLES]; ALfloat temp[2][MAX_UPDATE_SAMPLES]; diff --git a/Alc/uhjfilter.h b/Alc/uhjfilter.h index e773e0a7..9ea1fb44 100644 --- a/Alc/uhjfilter.h +++ b/Alc/uhjfilter.h @@ -44,6 +44,6 @@ typedef struct Uhj2Encoder { /* Encodes a 2-channel UHJ (stereo-compatible) signal from a B-Format input * signal. The input must use FuMa channel ordering and scaling. */ -void EncodeUhj2(Uhj2Encoder *enc, ALfloat *restrict LeftOut, ALfloat *restrict RightOut, ALfloat (*restrict InSamples)[BUFFERSIZE], ALsizei SamplesToDo); +void EncodeUhj2(Uhj2Encoder *enc, ALfloat *RESTRICT LeftOut, ALfloat *RESTRICT RightOut, ALfloat (*RESTRICT InSamples)[BUFFERSIZE], ALsizei SamplesToDo); #endif /* UHJFILTER_H */ diff --git a/OpenAL32/Include/alAuxEffectSlot.h b/OpenAL32/Include/alAuxEffectSlot.h index 03ee97d6..97a3906d 100644 --- a/OpenAL32/Include/alAuxEffectSlot.h +++ b/OpenAL32/Include/alAuxEffectSlot.h @@ -30,7 +30,7 @@ struct ALeffectStateVtable { ALboolean (*const deviceUpdate)(ALeffectState *state, ALCdevice *device); void (*const update)(ALeffectState *state, const ALCcontext *context, const struct ALeffectslot *slot, const union ALeffectProps *props); - void (*const process)(ALeffectState *state, ALsizei samplesToDo, const ALfloat (*restrict samplesIn)[BUFFERSIZE], ALfloat (*restrict samplesOut)[BUFFERSIZE], ALsizei numChannels); + void (*const process)(ALeffectState *state, ALsizei samplesToDo, const ALfloat (*RESTRICT samplesIn)[BUFFERSIZE], ALfloat (*RESTRICT samplesOut)[BUFFERSIZE], ALsizei numChannels); void (*const Delete)(void *ptr); }; @@ -44,7 +44,7 @@ typedef ALfloat ALfloatBUFFERSIZE[BUFFERSIZE]; DECLARE_THUNK(T, ALeffectState, void, Destruct) \ DECLARE_THUNK1(T, ALeffectState, ALboolean, deviceUpdate, ALCdevice*) \ DECLARE_THUNK3(T, ALeffectState, void, update, const ALCcontext*, const ALeffectslot*, const ALeffectProps*) \ -DECLARE_THUNK4(T, ALeffectState, void, process, ALsizei, const ALfloatBUFFERSIZE*restrict, ALfloatBUFFERSIZE*restrict, ALsizei) \ +DECLARE_THUNK4(T, ALeffectState, void, process, ALsizei, const ALfloatBUFFERSIZE*RESTRICT, ALfloatBUFFERSIZE*RESTRICT, ALsizei) \ static void T##_ALeffectState_Delete(void *ptr) \ { return T##_Delete(STATIC_UPCAST(T, ALeffectState, (ALeffectState*)ptr)); } \ \ diff --git a/OpenAL32/Include/bs2b.h b/OpenAL32/Include/bs2b.h index e845d906..13cdf9a6 100644 --- a/OpenAL32/Include/bs2b.h +++ b/OpenAL32/Include/bs2b.h @@ -85,7 +85,7 @@ int bs2b_get_srate(struct bs2b *bs2b); /* Clear buffer */ void bs2b_clear(struct bs2b *bs2b); -void bs2b_cross_feed(struct bs2b *bs2b, float *restrict Left, float *restrict Right, int SamplesToDo); +void bs2b_cross_feed(struct bs2b *bs2b, float *RESTRICT Left, float *RESTRICT Right, int SamplesToDo); #ifdef __cplusplus } /* extern "C" */ diff --git a/utils/makehrtf.c b/utils/makehrtf.c index 0bd36849..eb174c8a 100644 --- a/utils/makehrtf.c +++ b/utils/makehrtf.c @@ -945,7 +945,7 @@ static inline uint dither_rng(uint *seed) // Performs a triangular probability density function dither. The input samples // should be normalized (-1 to +1). -static void TpdfDither(double *restrict out, const double *restrict in, const double scale, +static void TpdfDither(double *RESTRICT out, const double *RESTRICT in, const double scale, const int count, const int step, uint *seed) { static const double PRNG_SCALE = 1.0 / UINT_MAX; -- cgit v1.2.3 From ed5d222eed4b8b464961f53c465ac4d02d5f1980 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sat, 17 Nov 2018 07:50:46 -0800 Subject: Remove the old unused bsincgen.c --- utils/bsincgen.c | 404 ------------------------------------------------------- 1 file changed, 404 deletions(-) delete mode 100644 utils/bsincgen.c (limited to 'utils') diff --git a/utils/bsincgen.c b/utils/bsincgen.c deleted file mode 100644 index 03421da9..00000000 --- a/utils/bsincgen.c +++ /dev/null @@ -1,404 +0,0 @@ -/* - * Sinc interpolator coefficient and delta generator for the OpenAL Soft - * cross platform audio library. - * - * Copyright (C) 2015 by Christopher Fitzgerald. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - * - * Or visit: http://www.gnu.org/licenses/old-licenses/lgpl-2.0.html - * - * -------------------------------------------------------------------------- - * - * This is a modified version of the bandlimited windowed sinc interpolator - * algorithm presented here: - * - * Smith, J.O. "Windowed Sinc Interpolation", in - * Physical Audio Signal Processing, - * https://ccrma.stanford.edu/~jos/pasp/Windowed_Sinc_Interpolation.html, - * online book, - * accessed October 2012. - */ - -#define _UNICODE -#include -#include -#include -#include - -#include "win_main_utf8.h" - - -#ifndef M_PI -#define M_PI (3.14159265358979323846) -#endif - -#if defined(__ANDROID__) && !(defined(_ISOC99_SOURCE) || (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L)) -#define log2(x) (log(x) / log(2.0)) -#endif - -// The number of distinct scale and phase intervals within the filter table. -// Must be the same as in alu.h! -#define BSINC_SCALE_COUNT (16) -#define BSINC_PHASE_COUNT (16) - -/* 48 points includes the doubling for downsampling, so the maximum number of - * base sample points is 24, which is 23rd order. - */ -#define BSINC_POINTS_MAX (48) - -static double MinDouble(double a, double b) -{ return (a <= b) ? a : b; } - -static double MaxDouble(double a, double b) -{ return (a >= b) ? a : b; } - -/* NOTE: This is the normalized (instead of just sin(x)/x) cardinal sine - * function. - * 2 f_t sinc(2 f_t x) - * f_t -- normalized transition frequency (0.5 is nyquist) - * x -- sample index (-N to N) - */ -static double Sinc(const double x) -{ - if(fabs(x) < 1e-15) - return 1.0; - return sin(M_PI * x) / (M_PI * x); -} - -static double BesselI_0(const double x) -{ - double term, sum, last_sum, x2, y; - int i; - - term = 1.0; - sum = 1.0; - x2 = x / 2.0; - i = 1; - - do { - y = x2 / i; - i++; - last_sum = sum; - term *= y * y; - sum += term; - } while(sum != last_sum); - - return sum; -} - -/* NOTE: k is assumed normalized (-1 to 1) - * beta is equivalent to 2 alpha - */ -static double Kaiser(const double b, const double k) -{ - if(!(k >= -1.0 && k <= 1.0)) - return 0.0; - return BesselI_0(b * sqrt(1.0 - k*k)) / BesselI_0(b); -} - -/* Calculates the (normalized frequency) transition width of the Kaiser window. - * Rejection is in dB. - */ -static double CalcKaiserWidth(const double rejection, const int order) -{ - double w_t = 2.0 * M_PI; - - if(rejection > 21.0) - return (rejection - 7.95) / (order * 2.285 * w_t); - /* This enforces a minimum rejection of just above 21.18dB */ - return 5.79 / (order * w_t); -} - -static double CalcKaiserBeta(const double rejection) -{ - if(rejection > 50.0) - return 0.1102 * (rejection - 8.7); - else if(rejection >= 21.0) - return (0.5842 * pow(rejection - 21.0, 0.4)) + - (0.07886 * (rejection - 21.0)); - return 0.0; -} - -/* Generates the coefficient, delta, and index tables required by the bsinc resampler */ -static void BsiGenerateTables(FILE *output, const char *tabname, const double rejection, const int order) -{ - static double filter[BSINC_SCALE_COUNT][BSINC_PHASE_COUNT + 1][BSINC_POINTS_MAX]; - static double scDeltas[BSINC_SCALE_COUNT][BSINC_PHASE_COUNT ][BSINC_POINTS_MAX]; - static double phDeltas[BSINC_SCALE_COUNT][BSINC_PHASE_COUNT + 1][BSINC_POINTS_MAX]; - static double spDeltas[BSINC_SCALE_COUNT][BSINC_PHASE_COUNT ][BSINC_POINTS_MAX]; - static int mt[BSINC_SCALE_COUNT]; - static double at[BSINC_SCALE_COUNT]; - const int num_points_min = order + 1; - double width, beta, scaleBase, scaleRange; - int si, pi, i; - - memset(filter, 0, sizeof(filter)); - memset(scDeltas, 0, sizeof(scDeltas)); - memset(phDeltas, 0, sizeof(phDeltas)); - memset(spDeltas, 0, sizeof(spDeltas)); - - /* Calculate windowing parameters. The width describes the transition - band, but it may vary due to the linear interpolation between scales - of the filter. - */ - width = CalcKaiserWidth(rejection, order); - beta = CalcKaiserBeta(rejection); - scaleBase = width / 2.0; - scaleRange = 1.0 - scaleBase; - - // Determine filter scaling. - for(si = 0; si < BSINC_SCALE_COUNT; si++) - { - const double scale = scaleBase + (scaleRange * si / (BSINC_SCALE_COUNT - 1)); - const double a = MinDouble(floor(num_points_min / (2.0 * scale)), num_points_min); - const int m = 2 * (int)a; - - mt[si] = m; - at[si] = a; - } - - /* Calculate the Kaiser-windowed Sinc filter coefficients for each scale - and phase. - */ - for(si = 0; si < BSINC_SCALE_COUNT; si++) - { - const int m = mt[si]; - const int o = num_points_min - (m / 2); - const int l = (m / 2) - 1; - const double a = at[si]; - const double scale = scaleBase + (scaleRange * si / (BSINC_SCALE_COUNT - 1)); - const double cutoff = (0.5 * scale) - (scaleBase * MaxDouble(0.5, scale)); - - for(pi = 0; pi <= BSINC_PHASE_COUNT; pi++) - { - const double phase = l + ((double)pi / BSINC_PHASE_COUNT); - - for(i = 0; i < m; i++) - { - const double x = i - phase; - filter[si][pi][o + i] = Kaiser(beta, x / a) * 2.0 * cutoff * Sinc(2.0 * cutoff * x); - } - } - } - - /* Linear interpolation between scales is simplified by pre-calculating - the delta (b - a) in: x = a + f (b - a) - - Given a difference in points between scales, the destination points - will be 0, thus: x = a + f (-a) - */ - for(si = 0; si < (BSINC_SCALE_COUNT - 1); si++) - { - const int m = mt[si]; - const int o = num_points_min - (m / 2); - - for(pi = 0; pi < BSINC_PHASE_COUNT; pi++) - { - for(i = 0; i < m; i++) - scDeltas[si][pi][o + i] = filter[si + 1][pi][o + i] - filter[si][pi][o + i]; - } - } - - // Linear interpolation between phases is also simplified. - for(si = 0; si < BSINC_SCALE_COUNT; si++) - { - const int m = mt[si]; - const int o = num_points_min - (m / 2); - - for(pi = 0; pi < BSINC_PHASE_COUNT; pi++) - { - for(i = 0; i < m; i++) - phDeltas[si][pi][o + i] = filter[si][pi + 1][o + i] - filter[si][pi][o + i]; - } - } - - /* This last simplification is done to complete the bilinear equation for - the combination of scale and phase. - */ - for(si = 0; si < (BSINC_SCALE_COUNT - 1); si++) - { - const int m = mt[si]; - const int o = num_points_min - (m / 2); - - for(pi = 0; pi < BSINC_PHASE_COUNT; pi++) - { - for(i = 0; i < m; i++) - spDeltas[si][pi][o + i] = phDeltas[si + 1][pi][o + i] - phDeltas[si][pi][o + i]; - } - } - - // Make sure the number of points is a multiple of 4 (for SIMD). - for(si = 0; si < BSINC_SCALE_COUNT; si++) - mt[si] = (mt[si]+3) & ~3; - - fprintf(output, -"/* This %d%s order filter has a rejection of -%.0fdB, yielding a transition width\n" -" * of ~%.3f (normalized frequency). Order increases when downsampling to a\n" -" * limit of one octave, after which the quality of the filter (transition\n" -" * width) suffers to reduce the CPU cost. The bandlimiting will cut all sound\n" -" * after downsampling by ~%.2f octaves.\n" -" */\n" -"const BSincTable %s = {\n", - order, (((order%100)/10) == 1) ? "th" : - ((order%10) == 1) ? "st" : - ((order%10) == 2) ? "nd" : - ((order%10) == 3) ? "rd" : "th", - rejection, width, log2(1.0/scaleBase), tabname); - - /* The scaleBase is calculated from the Kaiser window transition width. - It represents the absolute limit to the filter before it fully cuts - the signal. The limit in octaves can be calculated by taking the - base-2 logarithm of its inverse: log_2(1 / scaleBase) - */ - fprintf(output, " /* scaleBase */ %.9ef, /* scaleRange */ %.9ef,\n", scaleBase, 1.0 / scaleRange); - - fprintf(output, " /* m */ {"); - fprintf(output, " %d", mt[0]); - for(si = 1; si < BSINC_SCALE_COUNT; si++) - fprintf(output, ", %d", mt[si]); - fprintf(output, " },\n"); - - fprintf(output, " /* filterOffset */ {"); - fprintf(output, " %d", 0); - i = mt[0]*4*BSINC_PHASE_COUNT; - for(si = 1; si < BSINC_SCALE_COUNT; si++) - { - fprintf(output, ", %d", i); - i += mt[si]*4*BSINC_PHASE_COUNT; - } - - fprintf(output, " },\n"); - - // Calculate the table size. - i = 0; - for(si = 0; si < BSINC_SCALE_COUNT; si++) - i += 4 * BSINC_PHASE_COUNT * mt[si]; - - fprintf(output, "\n /* Tab (%d entries) */ {\n", i); - for(si = 0; si < BSINC_SCALE_COUNT; si++) - { - const int m = mt[si]; - const int o = num_points_min - (m / 2); - - for(pi = 0; pi < BSINC_PHASE_COUNT; pi++) - { - fprintf(output, " /* %2d,%2d (%d) */", si, pi, m); - fprintf(output, "\n "); - for(i = 0; i < m; i++) - fprintf(output, " %+14.9ef,", filter[si][pi][o + i]); - fprintf(output, "\n "); - for(i = 0; i < m; i++) - fprintf(output, " %+14.9ef,", scDeltas[si][pi][o + i]); - fprintf(output, "\n "); - for(i = 0; i < m; i++) - fprintf(output, " %+14.9ef,", phDeltas[si][pi][o + i]); - fprintf(output, "\n "); - for(i = 0; i < m; i++) - fprintf(output, " %+14.9ef,", spDeltas[si][pi][o + i]); - fprintf(output, "\n"); - } - } - fprintf(output, " }\n};\n\n"); -} - - -/* These methods generate a much simplified 4-point sinc interpolator using a - * Kaiser window. This is much simpler to process at run-time, but has notably - * more aliasing noise. - */ - -/* Same as in alu.h! */ -#define FRACTIONBITS (12) -#define FRACTIONONE (1< 2) - { - fprintf(stderr, "Usage: %s [output file]\n", argv[0]); - return 1; - } - - if(argc == 2) - { - output = fopen(argv[1], "wb"); - if(!output) - { - fprintf(stderr, "Failed to open %s for writing\n", argv[1]); - return 1; - } - } - else - output = stdout; - - fprintf(output, "/* Generated by bsincgen, do not edit! */\n\n" -"static_assert(BSINC_SCALE_COUNT == %d, \"Unexpected BSINC_SCALE_COUNT value!\");\n" -"static_assert(BSINC_PHASE_COUNT == %d, \"Unexpected BSINC_PHASE_COUNT value!\");\n" -"static_assert(FRACTIONONE == %d, \"Unexpected FRACTIONONE value!\");\n\n" -"typedef struct BSincTable {\n" -" const float scaleBase, scaleRange;\n" -" const int m[BSINC_SCALE_COUNT];\n" -" const int filterOffset[BSINC_SCALE_COUNT];\n" -" alignas(16) const float Tab[];\n" -"} BSincTable;\n\n", BSINC_SCALE_COUNT, BSINC_PHASE_COUNT, FRACTIONONE); - /* A 23rd order filter with a -60dB drop at nyquist. */ - BsiGenerateTables(output, "bsinc24", 60.0, 23); - /* An 11th order filter with a -60dB drop at nyquist. */ - BsiGenerateTables(output, "bsinc12", 60.0, 11); - Sinc4GenerateTables(output, 60.0); - - if(output != stdout) - fclose(output); - output = NULL; - - return 0; -} -- cgit v1.2.3 From 497226f11e811923936e6978a8f68055f5fe7467 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Tue, 25 Dec 2018 17:04:54 -0800 Subject: Add an adjust-latency config option for PulseAudio --- alsoftrc.sample | 8 ++++++++ utils/alsoft-config/mainwindow.cpp | 5 +++++ utils/alsoft-config/mainwindow.ui | 35 +++++++++++++++++++++++++++++------ 3 files changed, 42 insertions(+), 6 deletions(-) (limited to 'utils') diff --git a/alsoftrc.sample b/alsoftrc.sample index 8061ed1c..f18899a0 100644 --- a/alsoftrc.sample +++ b/alsoftrc.sample @@ -345,6 +345,14 @@ surround71 = # PulseAudio server. #fix-rate = false +## adjust-latency: +# Attempts to adjust the overall latency of device playback. Note that this +# may have adverse effects on the resulting internal buffer sizes and mixing +# updates, leading to performance problems and drop-outs. However, if the +# PulseAudio server is creating a lot of latency, enabling this may help make +# it more manageable. +#adjust-latency = false + ## ## ALSA backend stuff ## diff --git a/utils/alsoft-config/mainwindow.cpp b/utils/alsoft-config/mainwindow.cpp index 56ac4f3f..2b873955 100644 --- a/utils/alsoft-config/mainwindow.cpp +++ b/utils/alsoft-config/mainwindow.cpp @@ -387,6 +387,7 @@ MainWindow::MainWindow(QWidget *parent) : connect(ui->pulseAutospawnCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); connect(ui->pulseAllowMovesCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); connect(ui->pulseFixRateCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); + connect(ui->pulseAdjLatencyCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); connect(ui->jackAutospawnCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); connect(ui->jackBufferSizeSlider, SIGNAL(valueChanged(int)), this, SLOT(updateJackBufferSizeEdit(int))); @@ -855,6 +856,7 @@ void MainWindow::loadConfig(const QString &fname) ui->pulseAutospawnCheckBox->setChecked(settings.value("pulse/spawn-server", true).toBool()); ui->pulseAllowMovesCheckBox->setChecked(settings.value("pulse/allow-moves", false).toBool()); ui->pulseFixRateCheckBox->setChecked(settings.value("pulse/fix-rate", false).toBool()); + ui->pulseAdjLatencyCheckBox->setChecked(settings.value("pulse/adjust-latency", false).toBool()); ui->jackAutospawnCheckBox->setChecked(settings.value("jack/spawn-server", false).toBool()); ui->jackBufferSizeLine->setText(settings.value("jack/buffer-size", QString()).toString()); @@ -1081,6 +1083,9 @@ void MainWindow::saveConfig(const QString &fname) const settings.setValue("pulse/fix-rate", ui->pulseFixRateCheckBox->isChecked() ? QString("true") : QString(/*"false"*/) ); + settings.setValue("pulse/adjust-latency", + ui->pulseAdjLatencyCheckBox->isChecked() ? QString("true") : QString(/*"false"*/) + ); settings.setValue("jack/spawn-server", ui->jackAutospawnCheckBox->isChecked() ? QString("true") : QString(/*"false"*/) diff --git a/utils/alsoft-config/mainwindow.ui b/utils/alsoft-config/mainwindow.ui index 9c89cbc7..81f50b4c 100644 --- a/utils/alsoft-config/mainwindow.ui +++ b/utils/alsoft-config/mainwindow.ui @@ -53,7 +53,7 @@ - 5 + 0 @@ -131,8 +131,8 @@ to stereo output. 380 20 - 80 - 20 + 93 + 29 @@ -1185,6 +1185,9 @@ application or system to determine if it should be used. 361 + + 0 + @@ -1319,6 +1322,26 @@ rate to match the PulseAudio device. Fix Sample Rate + + + + 20 + 100 + 111 + 21 + + + + Attempts to adjust the overall latency of device +playback. Note that this may have adverse effects +on the resulting internal buffer sizes and mixing +updates, leading to performance problems and +drop-outs. + + + Adjust Latency + + @@ -2178,8 +2201,8 @@ added by the ALC_EXT_DEDICATED extension. 160 20 - 108 - 20 + 125 + 29 @@ -2348,7 +2371,7 @@ added by the ALC_EXT_DEDICATED extension. 0 0 564 - 21 + 27 -- cgit v1.2.3 From 7d821551ac32c6775d1f02a4631bd050aabcc254 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Thu, 27 Dec 2018 01:18:10 -0800 Subject: Recognize ambix as an alias for acn+sn3d --- Alc/alc.cpp | 2 +- alsoftrc.sample | 4 ++-- utils/alsoft-config/mainwindow.cpp | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'utils') diff --git a/Alc/alc.cpp b/Alc/alc.cpp index 294ba394..27475652 100644 --- a/Alc/alc.cpp +++ b/Alc/alc.cpp @@ -3806,7 +3806,7 @@ ALC_API ALCdevice* ALC_APIENTRY alcOpenDevice(const ALCchar *deviceName) device->mAmbiScale = AmbiNorm::FuMa; } } - else if(strcasecmp(fmt, "acn+sn3d") == 0) + else if(strcasecmp(fmt, "ambix") == 0 || strcasecmp(fmt, "acn+sn3d") == 0) { device->mAmbiLayout = AmbiLayout::ACN; device->mAmbiScale = AmbiNorm::SN3D; diff --git a/alsoftrc.sample b/alsoftrc.sample index f18899a0..1c1e113d 100644 --- a/alsoftrc.sample +++ b/alsoftrc.sample @@ -100,8 +100,8 @@ ## ambi-format: # Specifies the channel order and normalization for the "ambi*" set of channel -# configurations. Valid settings are: fuma, acn+sn3d, acn+n3d -#ambi-format = acn+sn3d +# configurations. Valid settings are: fuma, ambix (or acn+sn3d), acn+n3d +#ambi-format = ambix ## hrtf: # Controls HRTF processing. These filters provide better spatialization of diff --git a/utils/alsoft-config/mainwindow.cpp b/utils/alsoft-config/mainwindow.cpp index 2b873955..449c91e5 100644 --- a/utils/alsoft-config/mainwindow.cpp +++ b/utils/alsoft-config/mainwindow.cpp @@ -119,8 +119,8 @@ static const struct NameValuePair { { "", "" } }, ambiFormatList[] = { { "Default", "" }, - { "ACN + SN3D", "acn+sn3d" }, - { "ACN + N3D", "acn+n3d" }, + { "AmbiX (ACN, SN3D)", "ambix" }, + { "ACN, N3D", "acn+n3d" }, { "Furse-Malham", "fuma" }, { "", "" } -- cgit v1.2.3 From 4c4572ae8a54f4aefd76c1db0b576f6ae37339a0 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 31 Dec 2018 18:23:30 -0800 Subject: Compile makehrtf as C++ --- CMakeLists.txt | 2 +- common/win_main_utf8.h | 4 +- utils/makehrtf.c | 3455 ------------------------------------------------ utils/makehrtf.cpp | 3455 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 3458 insertions(+), 3458 deletions(-) delete mode 100644 utils/makehrtf.c create mode 100644 utils/makehrtf.cpp (limited to 'utils') diff --git a/CMakeLists.txt b/CMakeLists.txt index 3b2be332..f0161048 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1514,7 +1514,7 @@ IF(ALSOFT_UTILS) TARGET_COMPILE_OPTIONS(openal-info PRIVATE ${C_FLAGS}) TARGET_LINK_LIBRARIES(openal-info PRIVATE ${LINKER_FLAGS} OpenAL) - SET(MAKEHRTF_SRCS utils/makehrtf.c) + SET(MAKEHRTF_SRCS utils/makehrtf.cpp) IF(NOT HAVE_GETOPT) SET(MAKEHRTF_SRCS ${MAKEHRTF_SRCS} utils/getopt.c utils/getopt.h) ENDIF() diff --git a/common/win_main_utf8.h b/common/win_main_utf8.h index faddc257..242d3b8a 100644 --- a/common/win_main_utf8.h +++ b/common/win_main_utf8.h @@ -30,7 +30,7 @@ static FILE *my_fopen(const char *fname, const char *mode) return NULL; } - wname = calloc(sizeof(WCHAR), namelen+modelen); + wname = (WCHAR*)calloc(sizeof(WCHAR), namelen+modelen); wmode = wname + namelen; MultiByteToWideChar(CP_UTF8, 0, fname, -1, wname, namelen); MultiByteToWideChar(CP_UTF8, 0, mode, -1, wmode, modelen); @@ -73,7 +73,7 @@ static void GetUnicodeArgs(int *argc, char ***argv) total += WideCharToMultiByte(CP_UTF8, 0, args[i], -1, NULL, 0, NULL, NULL); atexit(cleanup_arglist); - arglist = *argv = calloc(1, total); + arglist = *argv = (char**)calloc(1, total); (*argv)[0] = (char*)(*argv + nargs); for(i = 0;i < nargs-1;i++) { diff --git a/utils/makehrtf.c b/utils/makehrtf.c deleted file mode 100644 index eb174c8a..00000000 --- a/utils/makehrtf.c +++ /dev/null @@ -1,3455 +0,0 @@ -/* - * HRTF utility for producing and demonstrating the process of creating an - * OpenAL Soft compatible HRIR data set. - * - * Copyright (C) 2011-2017 Christopher Fitzgerald - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Or visit: http://www.gnu.org/licenses/old-licenses/gpl-2.0.html - * - * -------------------------------------------------------------------------- - * - * A big thanks goes out to all those whose work done in the field of - * binaural sound synthesis using measured HRTFs makes this utility and the - * OpenAL Soft implementation possible. - * - * The algorithm for diffuse-field equalization was adapted from the work - * done by Rio Emmanuel and Larcher Veronique of IRCAM and Bill Gardner of - * MIT Media Laboratory. It operates as follows: - * - * 1. Take the FFT of each HRIR and only keep the magnitude responses. - * 2. Calculate the diffuse-field power-average of all HRIRs weighted by - * their contribution to the total surface area covered by their - * measurement. - * 3. Take the diffuse-field average and limit its magnitude range. - * 4. Equalize the responses by using the inverse of the diffuse-field - * average. - * 5. Reconstruct the minimum-phase responses. - * 5. Zero the DC component. - * 6. IFFT the result and truncate to the desired-length minimum-phase FIR. - * - * The spherical head algorithm for calculating propagation delay was adapted - * from the paper: - * - * Modeling Interaural Time Difference Assuming a Spherical Head - * Joel David Miller - * Music 150, Musical Acoustics, Stanford University - * December 2, 2001 - * - * The formulae for calculating the Kaiser window metrics are from the - * the textbook: - * - * Discrete-Time Signal Processing - * Alan V. Oppenheim and Ronald W. Schafer - * Prentice-Hall Signal Processing Series - * 1999 - */ - -#include "config.h" - -#define _UNICODE -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef HAVE_STRINGS_H -#include -#endif -#ifdef HAVE_GETOPT -#include -#else -#include "getopt.h" -#endif - -#include "win_main_utf8.h" - -/* Define int64_t and uint64_t types */ -#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L -#include -#elif defined(_WIN32) && defined(__GNUC__) -#include -#elif defined(_WIN32) -typedef __int64 int64_t; -typedef unsigned __int64 uint64_t; -#else -/* Fallback if nothing above works */ -#include -#endif - -#ifndef M_PI -#define M_PI (3.14159265358979323846) -#endif - -#ifndef HUGE_VAL -#define HUGE_VAL (1.0 / 0.0) -#endif - - -// The epsilon used to maintain signal stability. -#define EPSILON (1e-9) - -// Constants for accessing the token reader's ring buffer. -#define TR_RING_BITS (16) -#define TR_RING_SIZE (1 << TR_RING_BITS) -#define TR_RING_MASK (TR_RING_SIZE - 1) - -// The token reader's load interval in bytes. -#define TR_LOAD_SIZE (TR_RING_SIZE >> 2) - -// The maximum identifier length used when processing the data set -// definition. -#define MAX_IDENT_LEN (16) - -// The maximum path length used when processing filenames. -#define MAX_PATH_LEN (256) - -// The limits for the sample 'rate' metric in the data set definition and for -// resampling. -#define MIN_RATE (32000) -#define MAX_RATE (96000) - -// The limits for the HRIR 'points' metric in the data set definition. -#define MIN_POINTS (16) -#define MAX_POINTS (8192) - -// The limit to the number of 'distances' listed in the data set definition. -#define MAX_FD_COUNT (16) - -// The limits to the number of 'azimuths' listed in the data set definition. -#define MIN_EV_COUNT (5) -#define MAX_EV_COUNT (128) - -// The limits for each of the 'azimuths' listed in the data set definition. -#define MIN_AZ_COUNT (1) -#define MAX_AZ_COUNT (128) - -// The limits for the listener's head 'radius' in the data set definition. -#define MIN_RADIUS (0.05) -#define MAX_RADIUS (0.15) - -// The limits for the 'distance' from source to listener for each field in -// the definition file. -#define MIN_DISTANCE (0.05) -#define MAX_DISTANCE (2.50) - -// The maximum number of channels that can be addressed for a WAVE file -// source listed in the data set definition. -#define MAX_WAVE_CHANNELS (65535) - -// The limits to the byte size for a binary source listed in the definition -// file. -#define MIN_BIN_SIZE (2) -#define MAX_BIN_SIZE (4) - -// The minimum number of significant bits for binary sources listed in the -// data set definition. The maximum is calculated from the byte size. -#define MIN_BIN_BITS (16) - -// The limits to the number of significant bits for an ASCII source listed in -// the data set definition. -#define MIN_ASCII_BITS (16) -#define MAX_ASCII_BITS (32) - -// The limits to the FFT window size override on the command line. -#define MIN_FFTSIZE (65536) -#define MAX_FFTSIZE (131072) - -// The limits to the equalization range limit on the command line. -#define MIN_LIMIT (2.0) -#define MAX_LIMIT (120.0) - -// The limits to the truncation window size on the command line. -#define MIN_TRUNCSIZE (16) -#define MAX_TRUNCSIZE (512) - -// The limits to the custom head radius on the command line. -#define MIN_CUSTOM_RADIUS (0.05) -#define MAX_CUSTOM_RADIUS (0.15) - -// The truncation window size must be a multiple of the below value to allow -// for vectorized convolution. -#define MOD_TRUNCSIZE (8) - -// The defaults for the command line options. -#define DEFAULT_FFTSIZE (65536) -#define DEFAULT_EQUALIZE (1) -#define DEFAULT_SURFACE (1) -#define DEFAULT_LIMIT (24.0) -#define DEFAULT_TRUNCSIZE (32) -#define DEFAULT_HEAD_MODEL (HM_DATASET) -#define DEFAULT_CUSTOM_RADIUS (0.0) - -// The four-character-codes for RIFF/RIFX WAVE file chunks. -#define FOURCC_RIFF (0x46464952) // 'RIFF' -#define FOURCC_RIFX (0x58464952) // 'RIFX' -#define FOURCC_WAVE (0x45564157) // 'WAVE' -#define FOURCC_FMT (0x20746D66) // 'fmt ' -#define FOURCC_DATA (0x61746164) // 'data' -#define FOURCC_LIST (0x5453494C) // 'LIST' -#define FOURCC_WAVL (0x6C766177) // 'wavl' -#define FOURCC_SLNT (0x746E6C73) // 'slnt' - -// The supported wave formats. -#define WAVE_FORMAT_PCM (0x0001) -#define WAVE_FORMAT_IEEE_FLOAT (0x0003) -#define WAVE_FORMAT_EXTENSIBLE (0xFFFE) - -// The maximum propagation delay value supported by OpenAL Soft. -#define MAX_HRTD (63.0) - -// The OpenAL Soft HRTF format marker. It stands for minimum-phase head -// response protocol 02. -#define MHR_FORMAT ("MinPHR02") - -// Sample and channel type enum values. -typedef enum SampleTypeT { - ST_S16 = 0, - ST_S24 = 1 -} SampleTypeT; - -// Certain iterations rely on these integer enum values. -typedef enum ChannelTypeT { - CT_NONE = -1, - CT_MONO = 0, - CT_STEREO = 1 -} ChannelTypeT; - -// Byte order for the serialization routines. -typedef enum ByteOrderT { - BO_NONE, - BO_LITTLE, - BO_BIG -} ByteOrderT; - -// Source format for the references listed in the data set definition. -typedef enum SourceFormatT { - SF_NONE, - SF_WAVE, // RIFF/RIFX WAVE file. - SF_BIN_LE, // Little-endian binary file. - SF_BIN_BE, // Big-endian binary file. - SF_ASCII // ASCII text file. -} SourceFormatT; - -// Element types for the references listed in the data set definition. -typedef enum ElementTypeT { - ET_NONE, - ET_INT, // Integer elements. - ET_FP // Floating-point elements. -} ElementTypeT; - -// Head model used for calculating the impulse delays. -typedef enum HeadModelT { - HM_NONE, - HM_DATASET, // Measure the onset from the dataset. - HM_SPHERE // Calculate the onset using a spherical head model. -} HeadModelT; - -// Unsigned integer type. -typedef unsigned int uint; - -// Serialization types. The trailing digit indicates the number of bits. -typedef unsigned char uint8; -typedef int int32; -typedef unsigned int uint32; -typedef uint64_t uint64; - -// Token reader state for parsing the data set definition. -typedef struct TokenReaderT { - FILE *mFile; - const char *mName; - uint mLine; - uint mColumn; - char mRing[TR_RING_SIZE]; - size_t mIn; - size_t mOut; -} TokenReaderT; - -// Source reference state used when loading sources. -typedef struct SourceRefT { - SourceFormatT mFormat; - ElementTypeT mType; - uint mSize; - int mBits; - uint mChannel; - uint mSkip; - uint mOffset; - char mPath[MAX_PATH_LEN+1]; -} SourceRefT; - -// Structured HRIR storage for stereo azimuth pairs, elevations, and fields. -typedef struct HrirAzT { - double mAzimuth; - uint mIndex; - double mDelays[2]; - double *mIrs[2]; -} HrirAzT; - -typedef struct HrirEvT { - double mElevation; - uint mIrCount; - uint mAzCount; - HrirAzT *mAzs; -} HrirEvT; - -typedef struct HrirFdT { - double mDistance; - uint mIrCount; - uint mEvCount; - uint mEvStart; - HrirEvT *mEvs; -} HrirFdT; - -// The HRIR metrics and data set used when loading, processing, and storing -// the resulting HRTF. -typedef struct HrirDataT { - uint mIrRate; - SampleTypeT mSampleType; - ChannelTypeT mChannelType; - uint mIrPoints; - uint mFftSize; - uint mIrSize; - double mRadius; - uint mIrCount; - uint mFdCount; - HrirFdT *mFds; -} HrirDataT; - -// The resampler metrics and FIR filter. -typedef struct ResamplerT { - uint mP, mQ, mM, mL; - double *mF; -} ResamplerT; - - -/**************************************** - *** Complex number type and routines *** - ****************************************/ - -typedef struct { - double Real, Imag; -} Complex; - -static Complex MakeComplex(double r, double i) -{ - Complex c = { r, i }; - return c; -} - -static Complex c_add(Complex a, Complex b) -{ - Complex r; - r.Real = a.Real + b.Real; - r.Imag = a.Imag + b.Imag; - return r; -} - -static Complex c_sub(Complex a, Complex b) -{ - Complex r; - r.Real = a.Real - b.Real; - r.Imag = a.Imag - b.Imag; - return r; -} - -static Complex c_mul(Complex a, Complex b) -{ - Complex r; - r.Real = a.Real*b.Real - a.Imag*b.Imag; - r.Imag = a.Imag*b.Real + a.Real*b.Imag; - return r; -} - -static Complex c_muls(Complex a, double s) -{ - Complex r; - r.Real = a.Real * s; - r.Imag = a.Imag * s; - return r; -} - -static double c_abs(Complex a) -{ - return sqrt(a.Real*a.Real + a.Imag*a.Imag); -} - -static Complex c_exp(Complex a) -{ - Complex r; - double e = exp(a.Real); - r.Real = e * cos(a.Imag); - r.Imag = e * sin(a.Imag); - return r; -} - -/***************************** - *** Token reader routines *** - *****************************/ - -/* Whitespace is not significant. It can process tokens as identifiers, numbers - * (integer and floating-point), strings, and operators. Strings must be - * encapsulated by double-quotes and cannot span multiple lines. - */ - -// Setup the reader on the given file. The filename can be NULL if no error -// output is desired. -static void TrSetup(FILE *fp, const char *filename, TokenReaderT *tr) -{ - const char *name = NULL; - - if(filename) - { - const char *slash = strrchr(filename, '/'); - if(slash) - { - const char *bslash = strrchr(slash+1, '\\'); - if(bslash) name = bslash+1; - else name = slash+1; - } - else - { - const char *bslash = strrchr(filename, '\\'); - if(bslash) name = bslash+1; - else name = filename; - } - } - - tr->mFile = fp; - tr->mName = name; - tr->mLine = 1; - tr->mColumn = 1; - tr->mIn = 0; - tr->mOut = 0; -} - -// Prime the reader's ring buffer, and return a result indicating that there -// is text to process. -static int TrLoad(TokenReaderT *tr) -{ - size_t toLoad, in, count; - - toLoad = TR_RING_SIZE - (tr->mIn - tr->mOut); - if(toLoad >= TR_LOAD_SIZE && !feof(tr->mFile)) - { - // Load TR_LOAD_SIZE (or less if at the end of the file) per read. - toLoad = TR_LOAD_SIZE; - in = tr->mIn&TR_RING_MASK; - count = TR_RING_SIZE - in; - if(count < toLoad) - { - tr->mIn += fread(&tr->mRing[in], 1, count, tr->mFile); - tr->mIn += fread(&tr->mRing[0], 1, toLoad-count, tr->mFile); - } - else - tr->mIn += fread(&tr->mRing[in], 1, toLoad, tr->mFile); - - if(tr->mOut >= TR_RING_SIZE) - { - tr->mOut -= TR_RING_SIZE; - tr->mIn -= TR_RING_SIZE; - } - } - if(tr->mIn > tr->mOut) - return 1; - return 0; -} - -// Error display routine. Only displays when the base name is not NULL. -static void TrErrorVA(const TokenReaderT *tr, uint line, uint column, const char *format, va_list argPtr) -{ - if(!tr->mName) - return; - fprintf(stderr, "Error (%s:%u:%u): ", tr->mName, line, column); - vfprintf(stderr, format, argPtr); -} - -// Used to display an error at a saved line/column. -static void TrErrorAt(const TokenReaderT *tr, uint line, uint column, const char *format, ...) -{ - va_list argPtr; - - va_start(argPtr, format); - TrErrorVA(tr, line, column, format, argPtr); - va_end(argPtr); -} - -// Used to display an error at the current line/column. -static void TrError(const TokenReaderT *tr, const char *format, ...) -{ - va_list argPtr; - - va_start(argPtr, format); - TrErrorVA(tr, tr->mLine, tr->mColumn, format, argPtr); - va_end(argPtr); -} - -// Skips to the next line. -static void TrSkipLine(TokenReaderT *tr) -{ - char ch; - - while(TrLoad(tr)) - { - ch = tr->mRing[tr->mOut&TR_RING_MASK]; - tr->mOut++; - if(ch == '\n') - { - tr->mLine++; - tr->mColumn = 1; - break; - } - tr->mColumn ++; - } -} - -// Skips to the next token. -static int TrSkipWhitespace(TokenReaderT *tr) -{ - char ch; - - while(TrLoad(tr)) - { - ch = tr->mRing[tr->mOut&TR_RING_MASK]; - if(isspace(ch)) - { - tr->mOut++; - if(ch == '\n') - { - tr->mLine++; - tr->mColumn = 1; - } - else - tr->mColumn++; - } - else if(ch == '#') - TrSkipLine(tr); - else - return 1; - } - return 0; -} - -// Get the line and/or column of the next token (or the end of input). -static void TrIndication(TokenReaderT *tr, uint *line, uint *column) -{ - TrSkipWhitespace(tr); - if(line) *line = tr->mLine; - if(column) *column = tr->mColumn; -} - -// Checks to see if a token is (likely to be) an identifier. It does not -// display any errors and will not proceed to the next token. -static int TrIsIdent(TokenReaderT *tr) -{ - char ch; - - if(!TrSkipWhitespace(tr)) - return 0; - ch = tr->mRing[tr->mOut&TR_RING_MASK]; - return ch == '_' || isalpha(ch); -} - - -// Checks to see if a token is the given operator. It does not display any -// errors and will not proceed to the next token. -static int TrIsOperator(TokenReaderT *tr, const char *op) -{ - size_t out, len; - char ch; - - if(!TrSkipWhitespace(tr)) - return 0; - out = tr->mOut; - len = 0; - while(op[len] != '\0' && out < tr->mIn) - { - ch = tr->mRing[out&TR_RING_MASK]; - if(ch != op[len]) break; - len++; - out++; - } - if(op[len] == '\0') - return 1; - return 0; -} - -/* The TrRead*() routines obtain the value of a matching token type. They - * display type, form, and boundary errors and will proceed to the next - * token. - */ - -// Reads and validates an identifier token. -static int TrReadIdent(TokenReaderT *tr, const uint maxLen, char *ident) -{ - uint col, len; - char ch; - - col = tr->mColumn; - if(TrSkipWhitespace(tr)) - { - col = tr->mColumn; - ch = tr->mRing[tr->mOut&TR_RING_MASK]; - if(ch == '_' || isalpha(ch)) - { - len = 0; - do { - if(len < maxLen) - ident[len] = ch; - len++; - tr->mOut++; - if(!TrLoad(tr)) - break; - ch = tr->mRing[tr->mOut&TR_RING_MASK]; - } while(ch == '_' || isdigit(ch) || isalpha(ch)); - - tr->mColumn += len; - if(len < maxLen) - { - ident[len] = '\0'; - return 1; - } - TrErrorAt(tr, tr->mLine, col, "Identifier is too long.\n"); - return 0; - } - } - TrErrorAt(tr, tr->mLine, col, "Expected an identifier.\n"); - return 0; -} - -// Reads and validates (including bounds) an integer token. -static int TrReadInt(TokenReaderT *tr, const int loBound, const int hiBound, int *value) -{ - uint col, digis, len; - char ch, temp[64+1]; - - col = tr->mColumn; - if(TrSkipWhitespace(tr)) - { - col = tr->mColumn; - len = 0; - ch = tr->mRing[tr->mOut&TR_RING_MASK]; - if(ch == '+' || ch == '-') - { - temp[len] = ch; - len++; - tr->mOut++; - } - digis = 0; - while(TrLoad(tr)) - { - ch = tr->mRing[tr->mOut&TR_RING_MASK]; - if(!isdigit(ch)) break; - if(len < 64) - temp[len] = ch; - len++; - digis++; - tr->mOut++; - } - tr->mColumn += len; - if(digis > 0 && ch != '.' && !isalpha(ch)) - { - if(len > 64) - { - TrErrorAt(tr, tr->mLine, col, "Integer is too long."); - return 0; - } - temp[len] = '\0'; - *value = strtol(temp, NULL, 10); - if(*value < loBound || *value > hiBound) - { - TrErrorAt(tr, tr->mLine, col, "Expected a value from %d to %d.\n", loBound, hiBound); - return 0; - } - return 1; - } - } - TrErrorAt(tr, tr->mLine, col, "Expected an integer.\n"); - return 0; -} - -// Reads and validates (including bounds) a float token. -static int TrReadFloat(TokenReaderT *tr, const double loBound, const double hiBound, double *value) -{ - uint col, digis, len; - char ch, temp[64+1]; - - col = tr->mColumn; - if(TrSkipWhitespace(tr)) - { - col = tr->mColumn; - len = 0; - ch = tr->mRing[tr->mOut&TR_RING_MASK]; - if(ch == '+' || ch == '-') - { - temp[len] = ch; - len++; - tr->mOut++; - } - - digis = 0; - while(TrLoad(tr)) - { - ch = tr->mRing[tr->mOut&TR_RING_MASK]; - if(!isdigit(ch)) break; - if(len < 64) - temp[len] = ch; - len++; - digis++; - tr->mOut++; - } - if(ch == '.') - { - if(len < 64) - temp[len] = ch; - len++; - tr->mOut++; - } - while(TrLoad(tr)) - { - ch = tr->mRing[tr->mOut&TR_RING_MASK]; - if(!isdigit(ch)) break; - if(len < 64) - temp[len] = ch; - len++; - digis++; - tr->mOut++; - } - if(digis > 0) - { - if(ch == 'E' || ch == 'e') - { - if(len < 64) - temp[len] = ch; - len++; - digis = 0; - tr->mOut++; - if(ch == '+' || ch == '-') - { - if(len < 64) - temp[len] = ch; - len++; - tr->mOut++; - } - while(TrLoad(tr)) - { - ch = tr->mRing[tr->mOut&TR_RING_MASK]; - if(!isdigit(ch)) break; - if(len < 64) - temp[len] = ch; - len++; - digis++; - tr->mOut++; - } - } - tr->mColumn += len; - if(digis > 0 && ch != '.' && !isalpha(ch)) - { - if(len > 64) - { - TrErrorAt(tr, tr->mLine, col, "Float is too long."); - return 0; - } - temp[len] = '\0'; - *value = strtod(temp, NULL); - if(*value < loBound || *value > hiBound) - { - TrErrorAt(tr, tr->mLine, col, "Expected a value from %f to %f.\n", loBound, hiBound); - return 0; - } - return 1; - } - } - else - tr->mColumn += len; - } - TrErrorAt(tr, tr->mLine, col, "Expected a float.\n"); - return 0; -} - -// Reads and validates a string token. -static int TrReadString(TokenReaderT *tr, const uint maxLen, char *text) -{ - uint col, len; - char ch; - - col = tr->mColumn; - if(TrSkipWhitespace(tr)) - { - col = tr->mColumn; - ch = tr->mRing[tr->mOut&TR_RING_MASK]; - if(ch == '\"') - { - tr->mOut++; - len = 0; - while(TrLoad(tr)) - { - ch = tr->mRing[tr->mOut&TR_RING_MASK]; - tr->mOut++; - if(ch == '\"') - break; - if(ch == '\n') - { - TrErrorAt(tr, tr->mLine, col, "Unterminated string at end of line.\n"); - return 0; - } - if(len < maxLen) - text[len] = ch; - len++; - } - if(ch != '\"') - { - tr->mColumn += 1 + len; - TrErrorAt(tr, tr->mLine, col, "Unterminated string at end of input.\n"); - return 0; - } - tr->mColumn += 2 + len; - if(len > maxLen) - { - TrErrorAt(tr, tr->mLine, col, "String is too long.\n"); - return 0; - } - text[len] = '\0'; - return 1; - } - } - TrErrorAt(tr, tr->mLine, col, "Expected a string.\n"); - return 0; -} - -// Reads and validates the given operator. -static int TrReadOperator(TokenReaderT *tr, const char *op) -{ - uint col, len; - char ch; - - col = tr->mColumn; - if(TrSkipWhitespace(tr)) - { - col = tr->mColumn; - len = 0; - while(op[len] != '\0' && TrLoad(tr)) - { - ch = tr->mRing[tr->mOut&TR_RING_MASK]; - if(ch != op[len]) break; - len++; - tr->mOut++; - } - tr->mColumn += len; - if(op[len] == '\0') - return 1; - } - TrErrorAt(tr, tr->mLine, col, "Expected '%s' operator.\n", op); - return 0; -} - -/* Performs a string substitution. Any case-insensitive occurrences of the - * pattern string are replaced with the replacement string. The result is - * truncated if necessary. - */ -static int StrSubst(const char *in, const char *pat, const char *rep, const size_t maxLen, char *out) -{ - size_t inLen, patLen, repLen; - size_t si, di; - int truncated; - - inLen = strlen(in); - patLen = strlen(pat); - repLen = strlen(rep); - si = 0; - di = 0; - truncated = 0; - while(si < inLen && di < maxLen) - { - if(patLen <= inLen-si) - { - if(strncasecmp(&in[si], pat, patLen) == 0) - { - if(repLen > maxLen-di) - { - repLen = maxLen - di; - truncated = 1; - } - strncpy(&out[di], rep, repLen); - si += patLen; - di += repLen; - } - } - out[di] = in[si]; - si++; - di++; - } - if(si < inLen) - truncated = 1; - out[di] = '\0'; - return !truncated; -} - - -/********************* - *** Math routines *** - *********************/ - -// Provide missing math routines for MSVC versions < 1800 (Visual Studio 2013). -#if defined(_MSC_VER) && _MSC_VER < 1800 -static double round(double val) -{ - if(val < 0.0) - return ceil(val-0.5); - return floor(val+0.5); -} - -static double fmin(double a, double b) -{ - return (ab) ? a : b; -} -#endif - -// Simple clamp routine. -static double Clamp(const double val, const double lower, const double upper) -{ - return fmin(fmax(val, lower), upper); -} - -// Performs linear interpolation. -static double Lerp(const double a, const double b, const double f) -{ - return a + f * (b - a); -} - -static inline uint dither_rng(uint *seed) -{ - *seed = *seed * 96314165 + 907633515; - return *seed; -} - -// Performs a triangular probability density function dither. The input samples -// should be normalized (-1 to +1). -static void TpdfDither(double *RESTRICT out, const double *RESTRICT in, const double scale, - const int count, const int step, uint *seed) -{ - static const double PRNG_SCALE = 1.0 / UINT_MAX; - uint prn0, prn1; - int i; - - for(i = 0;i < count;i++) - { - prn0 = dither_rng(seed); - prn1 = dither_rng(seed); - out[i*step] = round(in[i]*scale + (prn0*PRNG_SCALE - prn1*PRNG_SCALE)); - } -} - -// Allocates an array of doubles. -static double *CreateDoubles(size_t n) -{ - double *a; - - a = calloc(n?n:1, sizeof(*a)); - if(a == NULL) - { - fprintf(stderr, "Error: Out of memory.\n"); - exit(-1); - } - return a; -} - -// Allocates an array of complex numbers. -static Complex *CreateComplexes(size_t n) -{ - Complex *a; - - a = calloc(n?n:1, sizeof(*a)); - if(a == NULL) - { - fprintf(stderr, "Error: Out of memory.\n"); - exit(-1); - } - return a; -} - -/* Fast Fourier transform routines. The number of points must be a power of - * two. - */ - -// Performs bit-reversal ordering. -static void FftArrange(const uint n, Complex *inout) -{ - uint rk, k, m; - - // Handle in-place arrangement. - rk = 0; - for(k = 0;k < n;k++) - { - if(rk > k) - { - Complex temp = inout[rk]; - inout[rk] = inout[k]; - inout[k] = temp; - } - - m = n; - while(rk&(m >>= 1)) - rk &= ~m; - rk |= m; - } -} - -// Performs the summation. -static void FftSummation(const int n, const double s, Complex *cplx) -{ - double pi; - int m, m2; - int i, k, mk; - - pi = s * M_PI; - for(m = 1, m2 = 2;m < n; m <<= 1, m2 <<= 1) - { - // v = Complex (-2.0 * sin (0.5 * pi / m) * sin (0.5 * pi / m), -sin (pi / m)) - double sm = sin(0.5 * pi / m); - Complex v = MakeComplex(-2.0*sm*sm, -sin(pi / m)); - Complex w = MakeComplex(1.0, 0.0); - for(i = 0;i < m;i++) - { - for(k = i;k < n;k += m2) - { - Complex t; - mk = k + m; - t = c_mul(w, cplx[mk]); - cplx[mk] = c_sub(cplx[k], t); - cplx[k] = c_add(cplx[k], t); - } - w = c_add(w, c_mul(v, w)); - } - } -} - -// Performs a forward FFT. -static void FftForward(const uint n, Complex *inout) -{ - FftArrange(n, inout); - FftSummation(n, 1.0, inout); -} - -// Performs an inverse FFT. -static void FftInverse(const uint n, Complex *inout) -{ - double f; - uint i; - - FftArrange(n, inout); - FftSummation(n, -1.0, inout); - f = 1.0 / n; - for(i = 0;i < n;i++) - inout[i] = c_muls(inout[i], f); -} - -/* Calculate the complex helical sequence (or discrete-time analytical signal) - * of the given input using the Hilbert transform. Given the natural logarithm - * of a signal's magnitude response, the imaginary components can be used as - * the angles for minimum-phase reconstruction. - */ -static void Hilbert(const uint n, Complex *inout) -{ - uint i; - - // Handle in-place operation. - for(i = 0;i < n;i++) - inout[i].Imag = 0.0; - - FftInverse(n, inout); - for(i = 1;i < (n+1)/2;i++) - inout[i] = c_muls(inout[i], 2.0); - /* Increment i if n is even. */ - i += (n&1)^1; - for(;i < n;i++) - inout[i] = MakeComplex(0.0, 0.0); - FftForward(n, inout); -} - -/* Calculate the magnitude response of the given input. This is used in - * place of phase decomposition, since the phase residuals are discarded for - * minimum phase reconstruction. The mirrored half of the response is also - * discarded. - */ -static void MagnitudeResponse(const uint n, const Complex *in, double *out) -{ - const uint m = 1 + (n / 2); - uint i; - for(i = 0;i < m;i++) - out[i] = fmax(c_abs(in[i]), EPSILON); -} - -/* Apply a range limit (in dB) to the given magnitude response. This is used - * to adjust the effects of the diffuse-field average on the equalization - * process. - */ -static void LimitMagnitudeResponse(const uint n, const uint m, const double limit, const double *in, double *out) -{ - double halfLim; - uint i, lower, upper; - double ave; - - halfLim = limit / 2.0; - // Convert the response to dB. - for(i = 0;i < m;i++) - out[i] = 20.0 * log10(in[i]); - // Use six octaves to calculate the average magnitude of the signal. - lower = ((uint)ceil(n / pow(2.0, 8.0))) - 1; - upper = ((uint)floor(n / pow(2.0, 2.0))) - 1; - ave = 0.0; - for(i = lower;i <= upper;i++) - ave += out[i]; - ave /= upper - lower + 1; - // Keep the response within range of the average magnitude. - for(i = 0;i < m;i++) - out[i] = Clamp(out[i], ave - halfLim, ave + halfLim); - // Convert the response back to linear magnitude. - for(i = 0;i < m;i++) - out[i] = pow(10.0, out[i] / 20.0); -} - -/* Reconstructs the minimum-phase component for the given magnitude response - * of a signal. This is equivalent to phase recomposition, sans the missing - * residuals (which were discarded). The mirrored half of the response is - * reconstructed. - */ -static void MinimumPhase(const uint n, const double *in, Complex *out) -{ - const uint m = 1 + (n / 2); - double *mags; - uint i; - - mags = CreateDoubles(n); - for(i = 0;i < m;i++) - { - mags[i] = fmax(EPSILON, in[i]); - out[i] = MakeComplex(log(mags[i]), 0.0); - } - for(;i < n;i++) - { - mags[i] = mags[n - i]; - out[i] = out[n - i]; - } - Hilbert(n, out); - // Remove any DC offset the filter has. - mags[0] = EPSILON; - for(i = 0;i < n;i++) - { - Complex a = c_exp(MakeComplex(0.0, out[i].Imag)); - out[i] = c_mul(MakeComplex(mags[i], 0.0), a); - } - free(mags); -} - - -/*************************** - *** Resampler functions *** - ***************************/ - -/* This is the normalized cardinal sine (sinc) function. - * - * sinc(x) = { 1, x = 0 - * { sin(pi x) / (pi x), otherwise. - */ -static double Sinc(const double x) -{ - if(fabs(x) < EPSILON) - return 1.0; - return sin(M_PI * x) / (M_PI * x); -} - -/* The zero-order modified Bessel function of the first kind, used for the - * Kaiser window. - * - * I_0(x) = sum_{k=0}^inf (1 / k!)^2 (x / 2)^(2 k) - * = sum_{k=0}^inf ((x / 2)^k / k!)^2 - */ -static double BesselI_0(const double x) -{ - double term, sum, x2, y, last_sum; - int k; - - // Start at k=1 since k=0 is trivial. - term = 1.0; - sum = 1.0; - x2 = x/2.0; - k = 1; - - // Let the integration converge until the term of the sum is no longer - // significant. - do { - y = x2 / k; - k++; - last_sum = sum; - term *= y * y; - sum += term; - } while(sum != last_sum); - return sum; -} - -/* Calculate a Kaiser window from the given beta value and a normalized k - * [-1, 1]. - * - * w(k) = { I_0(B sqrt(1 - k^2)) / I_0(B), -1 <= k <= 1 - * { 0, elsewhere. - * - * Where k can be calculated as: - * - * k = i / l, where -l <= i <= l. - * - * or: - * - * k = 2 i / M - 1, where 0 <= i <= M. - */ -static double Kaiser(const double b, const double k) -{ - if(!(k >= -1.0 && k <= 1.0)) - return 0.0; - return BesselI_0(b * sqrt(1.0 - k*k)) / BesselI_0(b); -} - -// Calculates the greatest common divisor of a and b. -static uint Gcd(uint x, uint y) -{ - while(y > 0) - { - uint z = y; - y = x % y; - x = z; - } - return x; -} - -/* Calculates the size (order) of the Kaiser window. Rejection is in dB and - * the transition width is normalized frequency (0.5 is nyquist). - * - * M = { ceil((r - 7.95) / (2.285 2 pi f_t)), r > 21 - * { ceil(5.79 / 2 pi f_t), r <= 21. - * - */ -static uint CalcKaiserOrder(const double rejection, const double transition) -{ - double w_t = 2.0 * M_PI * transition; - if(rejection > 21.0) - return (uint)ceil((rejection - 7.95) / (2.285 * w_t)); - return (uint)ceil(5.79 / w_t); -} - -// Calculates the beta value of the Kaiser window. Rejection is in dB. -static double CalcKaiserBeta(const double rejection) -{ - if(rejection > 50.0) - return 0.1102 * (rejection - 8.7); - if(rejection >= 21.0) - return (0.5842 * pow(rejection - 21.0, 0.4)) + - (0.07886 * (rejection - 21.0)); - return 0.0; -} - -/* Calculates a point on the Kaiser-windowed sinc filter for the given half- - * width, beta, gain, and cutoff. The point is specified in non-normalized - * samples, from 0 to M, where M = (2 l + 1). - * - * w(k) 2 p f_t sinc(2 f_t x) - * - * x -- centered sample index (i - l) - * k -- normalized and centered window index (x / l) - * w(k) -- window function (Kaiser) - * p -- gain compensation factor when sampling - * f_t -- normalized center frequency (or cutoff; 0.5 is nyquist) - */ -static double SincFilter(const int l, const double b, const double gain, const double cutoff, const int i) -{ - return Kaiser(b, (double)(i - l) / l) * 2.0 * gain * cutoff * Sinc(2.0 * cutoff * (i - l)); -} - -/* This is a polyphase sinc-filtered resampler. - * - * Upsample Downsample - * - * p/q = 3/2 p/q = 3/5 - * - * M-+-+-+-> M-+-+-+-> - * -------------------+ ---------------------+ - * p s * f f f f|f| | p s * f f f f f | - * | 0 * 0 0 0|0|0 | | 0 * 0 0 0 0|0| | - * v 0 * 0 0|0|0 0 | v 0 * 0 0 0|0|0 | - * s * f|f|f f f | s * f f|f|f f | - * 0 * |0|0 0 0 0 | 0 * 0|0|0 0 0 | - * --------+=+--------+ 0 * |0|0 0 0 0 | - * d . d .|d|. d . d ----------+=+--------+ - * d . . . .|d|. . . . - * q-> - * q-+-+-+-> - * - * P_f(i,j) = q i mod p + pj - * P_s(i,j) = floor(q i / p) - j - * d[i=0..N-1] = sum_{j=0}^{floor((M - 1) / p)} { - * { f[P_f(i,j)] s[P_s(i,j)], P_f(i,j) < M - * { 0, P_f(i,j) >= M. } - */ - -// Calculate the resampling metrics and build the Kaiser-windowed sinc filter -// that's used to cut frequencies above the destination nyquist. -static void ResamplerSetup(ResamplerT *rs, const uint srcRate, const uint dstRate) -{ - double cutoff, width, beta; - uint gcd, l; - int i; - - gcd = Gcd(srcRate, dstRate); - rs->mP = dstRate / gcd; - rs->mQ = srcRate / gcd; - /* The cutoff is adjusted by half the transition width, so the transition - * ends before the nyquist (0.5). Both are scaled by the downsampling - * factor. - */ - if(rs->mP > rs->mQ) - { - cutoff = 0.475 / rs->mP; - width = 0.05 / rs->mP; - } - else - { - cutoff = 0.475 / rs->mQ; - width = 0.05 / rs->mQ; - } - // A rejection of -180 dB is used for the stop band. Round up when - // calculating the left offset to avoid increasing the transition width. - l = (CalcKaiserOrder(180.0, width)+1) / 2; - beta = CalcKaiserBeta(180.0); - rs->mM = l*2 + 1; - rs->mL = l; - rs->mF = CreateDoubles(rs->mM); - for(i = 0;i < ((int)rs->mM);i++) - rs->mF[i] = SincFilter((int)l, beta, rs->mP, cutoff, i); -} - -// Clean up after the resampler. -static void ResamplerClear(ResamplerT *rs) -{ - free(rs->mF); - rs->mF = NULL; -} - -// Perform the upsample-filter-downsample resampling operation using a -// polyphase filter implementation. -static void ResamplerRun(ResamplerT *rs, const uint inN, const double *in, const uint outN, double *out) -{ - const uint p = rs->mP, q = rs->mQ, m = rs->mM, l = rs->mL; - const double *f = rs->mF; - uint j_f, j_s; - double *work; - uint i; - - if(outN == 0) - return; - - // Handle in-place operation. - if(in == out) - work = CreateDoubles(outN); - else - work = out; - // Resample the input. - for(i = 0;i < outN;i++) - { - double r = 0.0; - // Input starts at l to compensate for the filter delay. This will - // drop any build-up from the first half of the filter. - j_f = (l + (q * i)) % p; - j_s = (l + (q * i)) / p; - while(j_f < m) - { - // Only take input when 0 <= j_s < inN. This single unsigned - // comparison catches both cases. - if(j_s < inN) - r += f[j_f] * in[j_s]; - j_f += p; - j_s--; - } - work[i] = r; - } - // Clean up after in-place operation. - if(work != out) - { - for(i = 0;i < outN;i++) - out[i] = work[i]; - free(work); - } -} - -/************************* - *** File source input *** - *************************/ - -// Read a binary value of the specified byte order and byte size from a file, -// storing it as a 32-bit unsigned integer. -static int ReadBin4(FILE *fp, const char *filename, const ByteOrderT order, const uint bytes, uint32 *out) -{ - uint8 in[4]; - uint32 accum; - uint i; - - if(fread(in, 1, bytes, fp) != bytes) - { - fprintf(stderr, "Error: Bad read from file '%s'.\n", filename); - return 0; - } - accum = 0; - switch(order) - { - case BO_LITTLE: - for(i = 0;i < bytes;i++) - accum = (accum<<8) | in[bytes - i - 1]; - break; - case BO_BIG: - for(i = 0;i < bytes;i++) - accum = (accum<<8) | in[i]; - break; - default: - break; - } - *out = accum; - return 1; -} - -// Read a binary value of the specified byte order from a file, storing it as -// a 64-bit unsigned integer. -static int ReadBin8(FILE *fp, const char *filename, const ByteOrderT order, uint64 *out) -{ - uint8 in [8]; - uint64 accum; - uint i; - - if(fread(in, 1, 8, fp) != 8) - { - fprintf(stderr, "Error: Bad read from file '%s'.\n", filename); - return 0; - } - accum = 0ULL; - switch(order) - { - case BO_LITTLE: - for(i = 0;i < 8;i++) - accum = (accum<<8) | in[8 - i - 1]; - break; - case BO_BIG: - for(i = 0;i < 8;i++) - accum = (accum<<8) | in[i]; - break; - default: - break; - } - *out = accum; - return 1; -} - -/* Read a binary value of the specified type, byte order, and byte size from - * a file, converting it to a double. For integer types, the significant - * bits are used to normalize the result. The sign of bits determines - * whether they are padded toward the MSB (negative) or LSB (positive). - * Floating-point types are not normalized. - */ -static int ReadBinAsDouble(FILE *fp, const char *filename, const ByteOrderT order, const ElementTypeT type, const uint bytes, const int bits, double *out) -{ - union { - uint32 ui; - int32 i; - float f; - } v4; - union { - uint64 ui; - double f; - } v8; - - *out = 0.0; - if(bytes > 4) - { - if(!ReadBin8(fp, filename, order, &v8.ui)) - return 0; - if(type == ET_FP) - *out = v8.f; - } - else - { - if(!ReadBin4(fp, filename, order, bytes, &v4.ui)) - return 0; - if(type == ET_FP) - *out = v4.f; - else - { - if(bits > 0) - v4.ui >>= (8*bytes) - ((uint)bits); - else - v4.ui &= (0xFFFFFFFF >> (32+bits)); - - if(v4.ui&(uint)(1<<(abs(bits)-1))) - v4.ui |= (0xFFFFFFFF << abs (bits)); - *out = v4.i / (double)(1<<(abs(bits)-1)); - } - } - return 1; -} - -/* Read an ascii value of the specified type from a file, converting it to a - * double. For integer types, the significant bits are used to normalize the - * result. The sign of the bits should always be positive. This also skips - * up to one separator character before the element itself. - */ -static int ReadAsciiAsDouble(TokenReaderT *tr, const char *filename, const ElementTypeT type, const uint bits, double *out) -{ - if(TrIsOperator(tr, ",")) - TrReadOperator(tr, ","); - else if(TrIsOperator(tr, ":")) - TrReadOperator(tr, ":"); - else if(TrIsOperator(tr, ";")) - TrReadOperator(tr, ";"); - else if(TrIsOperator(tr, "|")) - TrReadOperator(tr, "|"); - - if(type == ET_FP) - { - if(!TrReadFloat(tr, -HUGE_VAL, HUGE_VAL, out)) - { - fprintf(stderr, "Error: Bad read from file '%s'.\n", filename); - return 0; - } - } - else - { - int v; - if(!TrReadInt(tr, -(1<<(bits-1)), (1<<(bits-1))-1, &v)) - { - fprintf(stderr, "Error: Bad read from file '%s'.\n", filename); - return 0; - } - *out = v / (double)((1<<(bits-1))-1); - } - return 1; -} - -// Read the RIFF/RIFX WAVE format chunk from a file, validating it against -// the source parameters and data set metrics. -static int ReadWaveFormat(FILE *fp, const ByteOrderT order, const uint hrirRate, SourceRefT *src) -{ - uint32 fourCC, chunkSize; - uint32 format, channels, rate, dummy, block, size, bits; - - chunkSize = 0; - do { - if(chunkSize > 0) - fseek (fp, (long) chunkSize, SEEK_CUR); - if(!ReadBin4(fp, src->mPath, BO_LITTLE, 4, &fourCC) || - !ReadBin4(fp, src->mPath, order, 4, &chunkSize)) - return 0; - } while(fourCC != FOURCC_FMT); - if(!ReadBin4(fp, src->mPath, order, 2, &format) || - !ReadBin4(fp, src->mPath, order, 2, &channels) || - !ReadBin4(fp, src->mPath, order, 4, &rate) || - !ReadBin4(fp, src->mPath, order, 4, &dummy) || - !ReadBin4(fp, src->mPath, order, 2, &block)) - return 0; - block /= channels; - if(chunkSize > 14) - { - if(!ReadBin4(fp, src->mPath, order, 2, &size)) - return 0; - size /= 8; - if(block > size) - size = block; - } - else - size = block; - if(format == WAVE_FORMAT_EXTENSIBLE) - { - fseek(fp, 2, SEEK_CUR); - if(!ReadBin4(fp, src->mPath, order, 2, &bits)) - return 0; - if(bits == 0) - bits = 8 * size; - fseek(fp, 4, SEEK_CUR); - if(!ReadBin4(fp, src->mPath, order, 2, &format)) - return 0; - fseek(fp, (long)(chunkSize - 26), SEEK_CUR); - } - else - { - bits = 8 * size; - if(chunkSize > 14) - fseek(fp, (long)(chunkSize - 16), SEEK_CUR); - else - fseek(fp, (long)(chunkSize - 14), SEEK_CUR); - } - if(format != WAVE_FORMAT_PCM && format != WAVE_FORMAT_IEEE_FLOAT) - { - fprintf(stderr, "Error: Unsupported WAVE format in file '%s'.\n", src->mPath); - return 0; - } - if(src->mChannel >= channels) - { - fprintf(stderr, "Error: Missing source channel in WAVE file '%s'.\n", src->mPath); - return 0; - } - if(rate != hrirRate) - { - fprintf(stderr, "Error: Mismatched source sample rate in WAVE file '%s'.\n", src->mPath); - return 0; - } - if(format == WAVE_FORMAT_PCM) - { - if(size < 2 || size > 4) - { - fprintf(stderr, "Error: Unsupported sample size in WAVE file '%s'.\n", src->mPath); - return 0; - } - if(bits < 16 || bits > (8*size)) - { - fprintf (stderr, "Error: Bad significant bits in WAVE file '%s'.\n", src->mPath); - return 0; - } - src->mType = ET_INT; - } - else - { - if(size != 4 && size != 8) - { - fprintf(stderr, "Error: Unsupported sample size in WAVE file '%s'.\n", src->mPath); - return 0; - } - src->mType = ET_FP; - } - src->mSize = size; - src->mBits = (int)bits; - src->mSkip = channels; - return 1; -} - -// Read a RIFF/RIFX WAVE data chunk, converting all elements to doubles. -static int ReadWaveData(FILE *fp, const SourceRefT *src, const ByteOrderT order, const uint n, double *hrir) -{ - int pre, post, skip; - uint i; - - pre = (int)(src->mSize * src->mChannel); - post = (int)(src->mSize * (src->mSkip - src->mChannel - 1)); - skip = 0; - for(i = 0;i < n;i++) - { - skip += pre; - if(skip > 0) - fseek(fp, skip, SEEK_CUR); - if(!ReadBinAsDouble(fp, src->mPath, order, src->mType, src->mSize, src->mBits, &hrir[i])) - return 0; - skip = post; - } - if(skip > 0) - fseek(fp, skip, SEEK_CUR); - return 1; -} - -// Read the RIFF/RIFX WAVE list or data chunk, converting all elements to -// doubles. -static int ReadWaveList(FILE *fp, const SourceRefT *src, const ByteOrderT order, const uint n, double *hrir) -{ - uint32 fourCC, chunkSize, listSize, count; - uint block, skip, offset, i; - double lastSample; - - for(;;) - { - if(!ReadBin4(fp, src->mPath, BO_LITTLE, 4, &fourCC) || - !ReadBin4(fp, src->mPath, order, 4, &chunkSize)) - return 0; - - if(fourCC == FOURCC_DATA) - { - block = src->mSize * src->mSkip; - count = chunkSize / block; - if(count < (src->mOffset + n)) - { - fprintf(stderr, "Error: Bad read from file '%s'.\n", src->mPath); - return 0; - } - fseek(fp, (long)(src->mOffset * block), SEEK_CUR); - if(!ReadWaveData(fp, src, order, n, &hrir[0])) - return 0; - return 1; - } - else if(fourCC == FOURCC_LIST) - { - if(!ReadBin4(fp, src->mPath, BO_LITTLE, 4, &fourCC)) - return 0; - chunkSize -= 4; - if(fourCC == FOURCC_WAVL) - break; - } - if(chunkSize > 0) - fseek(fp, (long)chunkSize, SEEK_CUR); - } - listSize = chunkSize; - block = src->mSize * src->mSkip; - skip = src->mOffset; - offset = 0; - lastSample = 0.0; - while(offset < n && listSize > 8) - { - if(!ReadBin4(fp, src->mPath, BO_LITTLE, 4, &fourCC) || - !ReadBin4(fp, src->mPath, order, 4, &chunkSize)) - return 0; - listSize -= 8 + chunkSize; - if(fourCC == FOURCC_DATA) - { - count = chunkSize / block; - if(count > skip) - { - fseek(fp, (long)(skip * block), SEEK_CUR); - chunkSize -= skip * block; - count -= skip; - skip = 0; - if(count > (n - offset)) - count = n - offset; - if(!ReadWaveData(fp, src, order, count, &hrir[offset])) - return 0; - chunkSize -= count * block; - offset += count; - lastSample = hrir [offset - 1]; - } - else - { - skip -= count; - count = 0; - } - } - else if(fourCC == FOURCC_SLNT) - { - if(!ReadBin4(fp, src->mPath, order, 4, &count)) - return 0; - chunkSize -= 4; - if(count > skip) - { - count -= skip; - skip = 0; - if(count > (n - offset)) - count = n - offset; - for(i = 0; i < count; i ++) - hrir[offset + i] = lastSample; - offset += count; - } - else - { - skip -= count; - count = 0; - } - } - if(chunkSize > 0) - fseek(fp, (long)chunkSize, SEEK_CUR); - } - if(offset < n) - { - fprintf(stderr, "Error: Bad read from file '%s'.\n", src->mPath); - return 0; - } - return 1; -} - -// Load a source HRIR from a RIFF/RIFX WAVE file. -static int LoadWaveSource(FILE *fp, SourceRefT *src, const uint hrirRate, const uint n, double *hrir) -{ - uint32 fourCC, dummy; - ByteOrderT order; - - if(!ReadBin4(fp, src->mPath, BO_LITTLE, 4, &fourCC) || - !ReadBin4(fp, src->mPath, BO_LITTLE, 4, &dummy)) - return 0; - if(fourCC == FOURCC_RIFF) - order = BO_LITTLE; - else if(fourCC == FOURCC_RIFX) - order = BO_BIG; - else - { - fprintf(stderr, "Error: No RIFF/RIFX chunk in file '%s'.\n", src->mPath); - return 0; - } - - if(!ReadBin4(fp, src->mPath, BO_LITTLE, 4, &fourCC)) - return 0; - if(fourCC != FOURCC_WAVE) - { - fprintf(stderr, "Error: Not a RIFF/RIFX WAVE file '%s'.\n", src->mPath); - return 0; - } - if(!ReadWaveFormat(fp, order, hrirRate, src)) - return 0; - if(!ReadWaveList(fp, src, order, n, hrir)) - return 0; - return 1; -} - -// Load a source HRIR from a binary file. -static int LoadBinarySource(FILE *fp, const SourceRefT *src, const ByteOrderT order, const uint n, double *hrir) -{ - uint i; - - fseek(fp, (long)src->mOffset, SEEK_SET); - for(i = 0;i < n;i++) - { - if(!ReadBinAsDouble(fp, src->mPath, order, src->mType, src->mSize, src->mBits, &hrir[i])) - return 0; - if(src->mSkip > 0) - fseek(fp, (long)src->mSkip, SEEK_CUR); - } - return 1; -} - -// Load a source HRIR from an ASCII text file containing a list of elements -// separated by whitespace or common list operators (',', ';', ':', '|'). -static int LoadAsciiSource(FILE *fp, const SourceRefT *src, const uint n, double *hrir) -{ - TokenReaderT tr; - uint i, j; - double dummy; - - TrSetup(fp, NULL, &tr); - for(i = 0;i < src->mOffset;i++) - { - if(!ReadAsciiAsDouble(&tr, src->mPath, src->mType, (uint)src->mBits, &dummy)) - return 0; - } - for(i = 0;i < n;i++) - { - if(!ReadAsciiAsDouble(&tr, src->mPath, src->mType, (uint)src->mBits, &hrir[i])) - return 0; - for(j = 0;j < src->mSkip;j++) - { - if(!ReadAsciiAsDouble(&tr, src->mPath, src->mType, (uint)src->mBits, &dummy)) - return 0; - } - } - return 1; -} - -// Load a source HRIR from a supported file type. -static int LoadSource(SourceRefT *src, const uint hrirRate, const uint n, double *hrir) -{ - int result; - FILE *fp; - - if(src->mFormat == SF_ASCII) - fp = fopen(src->mPath, "r"); - else - fp = fopen(src->mPath, "rb"); - if(fp == NULL) - { - fprintf(stderr, "Error: Could not open source file '%s'.\n", src->mPath); - return 0; - } - if(src->mFormat == SF_WAVE) - result = LoadWaveSource(fp, src, hrirRate, n, hrir); - else if(src->mFormat == SF_BIN_LE) - result = LoadBinarySource(fp, src, BO_LITTLE, n, hrir); - else if(src->mFormat == SF_BIN_BE) - result = LoadBinarySource(fp, src, BO_BIG, n, hrir); - else - result = LoadAsciiSource(fp, src, n, hrir); - fclose(fp); - return result; -} - - -/*************************** - *** File storage output *** - ***************************/ - -// Write an ASCII string to a file. -static int WriteAscii(const char *out, FILE *fp, const char *filename) -{ - size_t len; - - len = strlen(out); - if(fwrite(out, 1, len, fp) != len) - { - fclose(fp); - fprintf(stderr, "Error: Bad write to file '%s'.\n", filename); - return 0; - } - return 1; -} - -// Write a binary value of the given byte order and byte size to a file, -// loading it from a 32-bit unsigned integer. -static int WriteBin4(const ByteOrderT order, const uint bytes, const uint32 in, FILE *fp, const char *filename) -{ - uint8 out[4]; - uint i; - - switch(order) - { - case BO_LITTLE: - for(i = 0;i < bytes;i++) - out[i] = (in>>(i*8)) & 0x000000FF; - break; - case BO_BIG: - for(i = 0;i < bytes;i++) - out[bytes - i - 1] = (in>>(i*8)) & 0x000000FF; - break; - default: - break; - } - if(fwrite(out, 1, bytes, fp) != bytes) - { - fprintf(stderr, "Error: Bad write to file '%s'.\n", filename); - return 0; - } - return 1; -} - -// Store the OpenAL Soft HRTF data set. -static int StoreMhr(const HrirDataT *hData, const char *filename) -{ - uint channels = (hData->mChannelType == CT_STEREO) ? 2 : 1; - uint n = hData->mIrPoints; - FILE *fp; - uint fi, ei, ai, i; - uint dither_seed = 22222; - - if((fp=fopen(filename, "wb")) == NULL) - { - fprintf(stderr, "Error: Could not open MHR file '%s'.\n", filename); - return 0; - } - if(!WriteAscii(MHR_FORMAT, fp, filename)) - return 0; - if(!WriteBin4(BO_LITTLE, 4, (uint32)hData->mIrRate, fp, filename)) - return 0; - if(!WriteBin4(BO_LITTLE, 1, (uint32)hData->mSampleType, fp, filename)) - return 0; - if(!WriteBin4(BO_LITTLE, 1, (uint32)hData->mChannelType, fp, filename)) - return 0; - if(!WriteBin4(BO_LITTLE, 1, (uint32)hData->mIrPoints, fp, filename)) - return 0; - if(!WriteBin4(BO_LITTLE, 1, (uint32)hData->mFdCount, fp, filename)) - return 0; - for(fi = 0;fi < hData->mFdCount;fi++) - { - if(!WriteBin4(BO_LITTLE, 2, (uint32)(1000.0 * hData->mFds[fi].mDistance), fp, filename)) - return 0; - if(!WriteBin4(BO_LITTLE, 1, (uint32)hData->mFds[fi].mEvCount, fp, filename)) - return 0; - for(ei = 0;ei < hData->mFds[fi].mEvCount;ei++) - { - if(!WriteBin4(BO_LITTLE, 1, (uint32)hData->mFds[fi].mEvs[ei].mAzCount, fp, filename)) - return 0; - } - } - - for(fi = 0;fi < hData->mFdCount;fi++) - { - const double scale = (hData->mSampleType == ST_S16) ? 32767.0 : - ((hData->mSampleType == ST_S24) ? 8388607.0 : 0.0); - const int bps = (hData->mSampleType == ST_S16) ? 2 : - ((hData->mSampleType == ST_S24) ? 3 : 0); - - for(ei = 0;ei < hData->mFds[fi].mEvCount;ei++) - { - for(ai = 0;ai < hData->mFds[fi].mEvs[ei].mAzCount;ai++) - { - HrirAzT *azd = &hData->mFds[fi].mEvs[ei].mAzs[ai]; - double out[2 * MAX_TRUNCSIZE]; - - TpdfDither(out, azd->mIrs[0], scale, n, channels, &dither_seed); - if(hData->mChannelType == CT_STEREO) - TpdfDither(out+1, azd->mIrs[1], scale, n, channels, &dither_seed); - for(i = 0;i < (channels * n);i++) - { - int v = (int)Clamp(out[i], -scale-1.0, scale); - if(!WriteBin4(BO_LITTLE, bps, (uint32)v, fp, filename)) - return 0; - } - } - } - } - for(fi = 0;fi < hData->mFdCount;fi++) - { - for(ei = 0;ei < hData->mFds[fi].mEvCount;ei++) - { - for(ai = 0;ai < hData->mFds[fi].mEvs[ei].mAzCount;ai++) - { - HrirAzT *azd = &hData->mFds[fi].mEvs[ei].mAzs[ai]; - int v = (int)fmin(round(hData->mIrRate * azd->mDelays[0]), MAX_HRTD); - - if(!WriteBin4(BO_LITTLE, 1, (uint32)v, fp, filename)) - return 0; - if(hData->mChannelType == CT_STEREO) - { - v = (int)fmin(round(hData->mIrRate * azd->mDelays[1]), MAX_HRTD); - - if(!WriteBin4(BO_LITTLE, 1, (uint32)v, fp, filename)) - return 0; - } - } - } - } - fclose(fp); - return 1; -} - - -/*********************** - *** HRTF processing *** - ***********************/ - -// Calculate the onset time of an HRIR and average it with any existing -// timing for its field, elevation, azimuth, and ear. -static double AverageHrirOnset(const uint rate, const uint n, const double *hrir, const double f, const double onset) -{ - double mag = 0.0; - uint i; - - for(i = 0;i < n;i++) - mag = fmax(fabs(hrir[i]), mag); - mag *= 0.15; - for(i = 0;i < n;i++) - { - if(fabs(hrir[i]) >= mag) - break; - } - return Lerp(onset, (double)i / rate, f); -} - -// Calculate the magnitude response of an HRIR and average it with any -// existing responses for its field, elevation, azimuth, and ear. -static void AverageHrirMagnitude(const uint points, const uint n, const double *hrir, const double f, double *mag) -{ - uint m = 1 + (n / 2), i; - Complex *h = CreateComplexes(n); - double *r = CreateDoubles(n); - - for(i = 0;i < points;i++) - h[i] = MakeComplex(hrir[i], 0.0); - for(;i < n;i++) - h[i] = MakeComplex(0.0, 0.0); - FftForward(n, h); - MagnitudeResponse(n, h, r); - for(i = 0;i < m;i++) - mag[i] = Lerp(mag[i], r[i], f); - free(r); - free(h); -} - -/* Calculate the contribution of each HRIR to the diffuse-field average based - * on the area of its surface patch. All patches are centered at the HRIR - * coordinates on the unit sphere and are measured by solid angle. - */ -static void CalculateDfWeights(const HrirDataT *hData, double *weights) -{ - double sum, evs, ev, upperEv, lowerEv, solidAngle; - uint fi, ei; - - sum = 0.0; - for(fi = 0;fi < hData->mFdCount;fi++) - { - evs = M_PI / 2.0 / (hData->mFds[fi].mEvCount - 1); - for(ei = hData->mFds[fi].mEvStart;ei < hData->mFds[fi].mEvCount;ei++) - { - // For each elevation, calculate the upper and lower limits of - // the patch band. - ev = hData->mFds[fi].mEvs[ei].mElevation; - lowerEv = fmax(-M_PI / 2.0, ev - evs); - upperEv = fmin(M_PI / 2.0, ev + evs); - // Calculate the area of the patch band. - solidAngle = 2.0 * M_PI * (sin(upperEv) - sin(lowerEv)); - // Each weight is the area of one patch. - weights[(fi * MAX_EV_COUNT) + ei] = solidAngle / hData->mFds[fi].mEvs[ei].mAzCount; - // Sum the total surface area covered by the HRIRs of all fields. - sum += solidAngle; - } - } - /* TODO: It may be interesting to experiment with how a volume-based - weighting performs compared to the existing distance-indepenent - surface patches. - */ - for(fi = 0;fi < hData->mFdCount;fi++) - { - // Normalize the weights given the total surface coverage for all - // fields. - for(ei = hData->mFds[fi].mEvStart;ei < hData->mFds[fi].mEvCount;ei++) - weights[(fi * MAX_EV_COUNT) + ei] /= sum; - } -} - -/* Calculate the diffuse-field average from the given magnitude responses of - * the HRIR set. Weighting can be applied to compensate for the varying - * surface area covered by each HRIR. The final average can then be limited - * by the specified magnitude range (in positive dB; 0.0 to skip). - */ -static void CalculateDiffuseFieldAverage(const HrirDataT *hData, const uint channels, const uint m, const int weighted, const double limit, double *dfa) -{ - double *weights = CreateDoubles(hData->mFdCount * MAX_EV_COUNT); - uint count, ti, fi, ei, i, ai; - - if(weighted) - { - // Use coverage weighting to calculate the average. - CalculateDfWeights(hData, weights); - } - else - { - double weight; - - // If coverage weighting is not used, the weights still need to be - // averaged by the number of existing HRIRs. - count = hData->mIrCount; - for(fi = 0;fi < hData->mFdCount;fi++) - { - for(ei = 0;ei < hData->mFds[fi].mEvStart;ei++) - count -= hData->mFds[fi].mEvs[ei].mAzCount; - } - weight = 1.0 / count; - - for(fi = 0;fi < hData->mFdCount;fi++) - { - for(ei = hData->mFds[fi].mEvStart;ei < hData->mFds[fi].mEvCount;ei++) - weights[(fi * MAX_EV_COUNT) + ei] = weight; - } - } - for(ti = 0;ti < channels;ti++) - { - for(i = 0;i < m;i++) - dfa[(ti * m) + i] = 0.0; - for(fi = 0;fi < hData->mFdCount;fi++) - { - for(ei = hData->mFds[fi].mEvStart;ei < hData->mFds[fi].mEvCount;ei++) - { - for(ai = 0;ai < hData->mFds[fi].mEvs[ei].mAzCount;ai++) - { - HrirAzT *azd = &hData->mFds[fi].mEvs[ei].mAzs[ai]; - // Get the weight for this HRIR's contribution. - double weight = weights[(fi * MAX_EV_COUNT) + ei]; - - // Add this HRIR's weighted power average to the total. - for(i = 0;i < m;i++) - dfa[(ti * m) + i] += weight * azd->mIrs[ti][i] * azd->mIrs[ti][i]; - } - } - } - // Finish the average calculation and keep it from being too small. - for(i = 0;i < m;i++) - dfa[(ti * m) + i] = fmax(sqrt(dfa[(ti * m) + i]), EPSILON); - // Apply a limit to the magnitude range of the diffuse-field average - // if desired. - if(limit > 0.0) - LimitMagnitudeResponse(hData->mFftSize, m, limit, &dfa[ti * m], &dfa[ti * m]); - } - free(weights); -} - -// Perform diffuse-field equalization on the magnitude responses of the HRIR -// set using the given average response. -static void DiffuseFieldEqualize(const uint channels, const uint m, const double *dfa, const HrirDataT *hData) -{ - uint ti, fi, ei, ai, i; - - for(fi = 0;fi < hData->mFdCount;fi++) - { - for(ei = hData->mFds[fi].mEvStart;ei < hData->mFds[fi].mEvCount;ei++) - { - for(ai = 0;ai < hData->mFds[fi].mEvs[ei].mAzCount;ai++) - { - HrirAzT *azd = &hData->mFds[fi].mEvs[ei].mAzs[ai]; - - for(ti = 0;ti < channels;ti++) - { - for(i = 0;i < m;i++) - azd->mIrs[ti][i] /= dfa[(ti * m) + i]; - } - } - } - } -} - -// Perform minimum-phase reconstruction using the magnitude responses of the -// HRIR set. -static void ReconstructHrirs(const HrirDataT *hData) -{ - uint channels = (hData->mChannelType == CT_STEREO) ? 2 : 1; - uint n = hData->mFftSize; - uint ti, fi, ei, ai, i; - Complex *h = CreateComplexes(n); - uint total, count, pcdone, lastpc; - - total = hData->mIrCount; - for(fi = 0;fi < hData->mFdCount;fi++) - { - for(ei = 0;ei < hData->mFds[fi].mEvStart;ei++) - total -= hData->mFds[fi].mEvs[ei].mAzCount; - } - total *= channels; - count = pcdone = lastpc = 0; - printf("%3d%% done.", pcdone); - fflush(stdout); - for(fi = 0;fi < hData->mFdCount;fi++) - { - for(ei = hData->mFds[fi].mEvStart;ei < hData->mFds[fi].mEvCount;ei++) - { - for(ai = 0;ai < hData->mFds[fi].mEvs[ei].mAzCount;ai++) - { - HrirAzT *azd = &hData->mFds[fi].mEvs[ei].mAzs[ai]; - - for(ti = 0;ti < channels;ti++) - { - MinimumPhase(n, azd->mIrs[ti], h); - FftInverse(n, h); - for(i = 0;i < hData->mIrPoints;i++) - azd->mIrs[ti][i] = h[i].Real; - pcdone = ++count * 100 / total; - if(pcdone != lastpc) - { - lastpc = pcdone; - printf("\r%3d%% done.", pcdone); - fflush(stdout); - } - } - } - } - } - printf("\n"); - free(h); -} - -// Resamples the HRIRs for use at the given sampling rate. -static void ResampleHrirs(const uint rate, HrirDataT *hData) -{ - uint channels = (hData->mChannelType == CT_STEREO) ? 2 : 1; - uint n = hData->mIrPoints; - uint ti, fi, ei, ai; - ResamplerT rs; - - ResamplerSetup(&rs, hData->mIrRate, rate); - for(fi = 0;fi < hData->mFdCount;fi++) - { - for(ei = hData->mFds[fi].mEvStart;ei < hData->mFds[fi].mEvCount;ei++) - { - for(ai = 0;ai < hData->mFds[fi].mEvs[ei].mAzCount;ai++) - { - HrirAzT *azd = &hData->mFds[fi].mEvs[ei].mAzs[ai]; - - for(ti = 0;ti < channels;ti++) - ResamplerRun(&rs, n, azd->mIrs[ti], n, azd->mIrs[ti]); - } - } - } - hData->mIrRate = rate; - ResamplerClear(&rs); -} - -/* Given field and elevation indices and an azimuth, calculate the indices of - * the two HRIRs that bound the coordinate along with a factor for - * calculating the continuous HRIR using interpolation. - */ -static void CalcAzIndices(const HrirDataT *hData, const uint fi, const uint ei, const double az, uint *a0, uint *a1, double *af) -{ - double f = (2.0*M_PI + az) * hData->mFds[fi].mEvs[ei].mAzCount / (2.0*M_PI); - uint i = (uint)f % hData->mFds[fi].mEvs[ei].mAzCount; - - f -= floor(f); - *a0 = i; - *a1 = (i + 1) % hData->mFds[fi].mEvs[ei].mAzCount; - *af = f; -} - -// Synthesize any missing onset timings at the bottom elevations of each -// field. This just blends between slightly exaggerated known onsets (not -// an accurate model). -static void SynthesizeOnsets(HrirDataT *hData) -{ - uint channels = (hData->mChannelType == CT_STEREO) ? 2 : 1; - uint ti, fi, oi, ai, ei, a0, a1; - double t, of, af; - - for(fi = 0;fi < hData->mFdCount;fi++) - { - if(hData->mFds[fi].mEvStart <= 0) - continue; - oi = hData->mFds[fi].mEvStart; - - for(ti = 0;ti < channels;ti++) - { - t = 0.0; - for(ai = 0;ai < hData->mFds[fi].mEvs[oi].mAzCount;ai++) - t += hData->mFds[fi].mEvs[oi].mAzs[ai].mDelays[ti]; - hData->mFds[fi].mEvs[0].mAzs[0].mDelays[ti] = 1.32e-4 + (t / hData->mFds[fi].mEvs[oi].mAzCount); - for(ei = 1;ei < hData->mFds[fi].mEvStart;ei++) - { - of = (double)ei / hData->mFds[fi].mEvStart; - for(ai = 0;ai < hData->mFds[fi].mEvs[ei].mAzCount;ai++) - { - CalcAzIndices(hData, fi, oi, hData->mFds[fi].mEvs[ei].mAzs[ai].mAzimuth, &a0, &a1, &af); - hData->mFds[fi].mEvs[ei].mAzs[ai].mDelays[ti] = Lerp( - hData->mFds[fi].mEvs[0].mAzs[0].mDelays[ti], - Lerp(hData->mFds[fi].mEvs[oi].mAzs[a0].mDelays[ti], - hData->mFds[fi].mEvs[oi].mAzs[a1].mDelays[ti], af), - of - ); - } - } - } - } -} - -/* Attempt to synthesize any missing HRIRs at the bottom elevations of each - * field. Right now this just blends the lowest elevation HRIRs together and - * applies some attenuation and high frequency damping. It is a simple, if - * inaccurate model. - */ -static void SynthesizeHrirs(HrirDataT *hData) -{ - uint channels = (hData->mChannelType == CT_STEREO) ? 2 : 1; - uint n = hData->mIrPoints; - uint ti, fi, ai, ei, i; - double lp[4], s0, s1; - double of, b; - uint a0, a1; - double af; - - for(fi = 0;fi < hData->mFdCount;fi++) - { - const uint oi = hData->mFds[fi].mEvStart; - if(oi <= 0) continue; - - for(ti = 0;ti < channels;ti++) - { - for(i = 0;i < n;i++) - hData->mFds[fi].mEvs[0].mAzs[0].mIrs[ti][i] = 0.0; - for(ai = 0;ai < hData->mFds[fi].mEvs[oi].mAzCount;ai++) - { - for(i = 0;i < n;i++) - hData->mFds[fi].mEvs[0].mAzs[0].mIrs[ti][i] += hData->mFds[fi].mEvs[oi].mAzs[ai].mIrs[ti][i] / - hData->mFds[fi].mEvs[oi].mAzCount; - } - for(ei = 1;ei < hData->mFds[fi].mEvStart;ei++) - { - of = (double)ei / hData->mFds[fi].mEvStart; - b = (1.0 - of) * (3.5e-6 * hData->mIrRate); - for(ai = 0;ai < hData->mFds[fi].mEvs[ei].mAzCount;ai++) - { - CalcAzIndices(hData, fi, oi, hData->mFds[fi].mEvs[ei].mAzs[ai].mAzimuth, &a0, &a1, &af); - lp[0] = 0.0; - lp[1] = 0.0; - lp[2] = 0.0; - lp[3] = 0.0; - for(i = 0;i < n;i++) - { - s0 = hData->mFds[fi].mEvs[0].mAzs[0].mIrs[ti][i]; - s1 = Lerp(hData->mFds[fi].mEvs[oi].mAzs[a0].mIrs[ti][i], - hData->mFds[fi].mEvs[oi].mAzs[a1].mIrs[ti][i], af); - s0 = Lerp(s0, s1, of); - lp[0] = Lerp(s0, lp[0], b); - lp[1] = Lerp(lp[0], lp[1], b); - lp[2] = Lerp(lp[1], lp[2], b); - lp[3] = Lerp(lp[2], lp[3], b); - hData->mFds[fi].mEvs[ei].mAzs[ai].mIrs[ti][i] = lp[3]; - } - } - } - b = 3.5e-6 * hData->mIrRate; - lp[0] = 0.0; - lp[1] = 0.0; - lp[2] = 0.0; - lp[3] = 0.0; - for(i = 0;i < n;i++) - { - s0 = hData->mFds[fi].mEvs[0].mAzs[0].mIrs[ti][i]; - lp[0] = Lerp(s0, lp[0], b); - lp[1] = Lerp(lp[0], lp[1], b); - lp[2] = Lerp(lp[1], lp[2], b); - lp[3] = Lerp(lp[2], lp[3], b); - hData->mFds[fi].mEvs[0].mAzs[0].mIrs[ti][i] = lp[3]; - } - } - hData->mFds[fi].mEvStart = 0; - } -} - -// The following routines assume a full set of HRIRs for all elevations. - -// Normalize the HRIR set and slightly attenuate the result. -static void NormalizeHrirs(const HrirDataT *hData) -{ - uint channels = (hData->mChannelType == CT_STEREO) ? 2 : 1; - uint n = hData->mIrPoints; - uint ti, fi, ei, ai, i; - double maxLevel = 0.0; - - for(fi = 0;fi < hData->mFdCount;fi++) - { - for(ei = 0;ei < hData->mFds[fi].mEvCount;ei++) - { - for(ai = 0;ai < hData->mFds[fi].mEvs[ei].mAzCount;ai++) - { - HrirAzT *azd = &hData->mFds[fi].mEvs[ei].mAzs[ai]; - - for(ti = 0;ti < channels;ti++) - { - for(i = 0;i < n;i++) - maxLevel = fmax(fabs(azd->mIrs[ti][i]), maxLevel); - } - } - } - } - maxLevel = 1.01 * maxLevel; - for(fi = 0;fi < hData->mFdCount;fi++) - { - for(ei = 0;ei < hData->mFds[fi].mEvCount;ei++) - { - for(ai = 0;ai < hData->mFds[fi].mEvs[ei].mAzCount;ai++) - { - HrirAzT *azd = &hData->mFds[fi].mEvs[ei].mAzs[ai]; - - for(ti = 0;ti < channels;ti++) - { - for(i = 0;i < n;i++) - azd->mIrs[ti][i] /= maxLevel; - } - } - } - } -} - -// Calculate the left-ear time delay using a spherical head model. -static double CalcLTD(const double ev, const double az, const double rad, const double dist) -{ - double azp, dlp, l, al; - - azp = asin(cos(ev) * sin(az)); - dlp = sqrt((dist*dist) + (rad*rad) + (2.0*dist*rad*sin(azp))); - l = sqrt((dist*dist) - (rad*rad)); - al = (0.5 * M_PI) + azp; - if(dlp > l) - dlp = l + (rad * (al - acos(rad / dist))); - return dlp / 343.3; -} - -// Calculate the effective head-related time delays for each minimum-phase -// HRIR. -static void CalculateHrtds(const HeadModelT model, const double radius, HrirDataT *hData) -{ - uint channels = (hData->mChannelType == CT_STEREO) ? 2 : 1; - double minHrtd = INFINITY, maxHrtd = -INFINITY; - uint ti, fi, ei, ai; - double t; - - if(model == HM_DATASET) - { - for(fi = 0;fi < hData->mFdCount;fi++) - { - for(ei = 0;ei < hData->mFds[fi].mEvCount;ei++) - { - for(ai = 0;ai < hData->mFds[fi].mEvs[ei].mAzCount;ai++) - { - HrirAzT *azd = &hData->mFds[fi].mEvs[ei].mAzs[ai]; - - for(ti = 0;ti < channels;ti++) - { - t = azd->mDelays[ti] * radius / hData->mRadius; - azd->mDelays[ti] = t; - maxHrtd = fmax(t, maxHrtd); - minHrtd = fmin(t, minHrtd); - } - } - } - } - } - else - { - for(fi = 0;fi < hData->mFdCount;fi++) - { - for(ei = 0;ei < hData->mFds[fi].mEvCount;ei++) - { - HrirEvT *evd = &hData->mFds[fi].mEvs[ei]; - - for(ai = 0;ai < evd->mAzCount;ai++) - { - HrirAzT *azd = &evd->mAzs[ai]; - - for(ti = 0;ti < channels;ti++) - { - t = CalcLTD(evd->mElevation, azd->mAzimuth, radius, hData->mFds[fi].mDistance); - azd->mDelays[ti] = t; - maxHrtd = fmax(t, maxHrtd); - minHrtd = fmin(t, minHrtd); - } - } - } - } - } - for(fi = 0;fi < hData->mFdCount;fi++) - { - for(ei = 0;ei < hData->mFds[fi].mEvCount;ei++) - { - for(ti = 0;ti < channels;ti++) - { - for(ai = 0;ai < hData->mFds[fi].mEvs[ei].mAzCount;ai++) - hData->mFds[fi].mEvs[ei].mAzs[ai].mDelays[ti] -= minHrtd; - } - } - } -} - -// Clear the initial HRIR data state. -static void ResetHrirData(HrirDataT *hData) -{ - hData->mIrRate = 0; - hData->mSampleType = ST_S24; - hData->mChannelType = CT_NONE; - hData->mIrPoints = 0; - hData->mFftSize = 0; - hData->mIrSize = 0; - hData->mRadius = 0.0; - hData->mIrCount = 0; - hData->mFdCount = 0; - hData->mFds = NULL; -} - -// Allocate and configure dynamic HRIR structures. -static int PrepareHrirData(const uint fdCount, const double distances[MAX_FD_COUNT], const uint evCounts[MAX_FD_COUNT], const uint azCounts[MAX_FD_COUNT * MAX_EV_COUNT], HrirDataT *hData) -{ - uint evTotal = 0, azTotal = 0, fi, ei, ai; - - for(fi = 0;fi < fdCount;fi++) - { - evTotal += evCounts[fi]; - for(ei = 0;ei < evCounts[fi];ei++) - azTotal += azCounts[(fi * MAX_EV_COUNT) + ei]; - } - if(!fdCount || !evTotal || !azTotal) - return 0; - - hData->mFds = calloc(fdCount, sizeof(*hData->mFds)); - if(hData->mFds == NULL) - return 0; - hData->mFds[0].mEvs = calloc(evTotal, sizeof(*hData->mFds[0].mEvs)); - if(hData->mFds[0].mEvs == NULL) - return 0; - hData->mFds[0].mEvs[0].mAzs = calloc(azTotal, sizeof(*hData->mFds[0].mEvs[0].mAzs)); - if(hData->mFds[0].mEvs[0].mAzs == NULL) - return 0; - hData->mIrCount = azTotal; - hData->mFdCount = fdCount; - evTotal = 0; - azTotal = 0; - for(fi = 0;fi < fdCount;fi++) - { - hData->mFds[fi].mDistance = distances[fi]; - hData->mFds[fi].mEvCount = evCounts[fi]; - hData->mFds[fi].mEvStart = 0; - hData->mFds[fi].mEvs = &hData->mFds[0].mEvs[evTotal]; - evTotal += evCounts[fi]; - for(ei = 0;ei < evCounts[fi];ei++) - { - uint azCount = azCounts[(fi * MAX_EV_COUNT) + ei]; - - hData->mFds[fi].mIrCount += azCount; - hData->mFds[fi].mEvs[ei].mElevation = -M_PI / 2.0 + M_PI * ei / (evCounts[fi] - 1); - hData->mFds[fi].mEvs[ei].mIrCount += azCount; - hData->mFds[fi].mEvs[ei].mAzCount = azCount; - hData->mFds[fi].mEvs[ei].mAzs = &hData->mFds[0].mEvs[0].mAzs[azTotal]; - for(ai = 0;ai < azCount;ai++) - { - hData->mFds[fi].mEvs[ei].mAzs[ai].mAzimuth = 2.0 * M_PI * ai / azCount; - hData->mFds[fi].mEvs[ei].mAzs[ai].mIndex = azTotal + ai; - hData->mFds[fi].mEvs[ei].mAzs[ai].mDelays[0] = 0.0; - hData->mFds[fi].mEvs[ei].mAzs[ai].mDelays[1] = 0.0; - hData->mFds[fi].mEvs[ei].mAzs[ai].mIrs[0] = NULL; - hData->mFds[fi].mEvs[ei].mAzs[ai].mIrs[1] = NULL; - } - azTotal += azCount; - } - } - return 1; -} - -// Clean up HRIR data. -static void FreeHrirData(HrirDataT *hData) -{ - if(hData->mFds != NULL) - { - if(hData->mFds[0].mEvs != NULL) - { - if(hData->mFds[0].mEvs[0].mAzs) - { - free(hData->mFds[0].mEvs[0].mAzs[0].mIrs[0]); - free(hData->mFds[0].mEvs[0].mAzs); - } - free(hData->mFds[0].mEvs); - } - free(hData->mFds); - hData->mFds = NULL; - } -} - -// Match the channel type from a given identifier. -static ChannelTypeT MatchChannelType(const char *ident) -{ - if(strcasecmp(ident, "mono") == 0) - return CT_MONO; - if(strcasecmp(ident, "stereo") == 0) - return CT_STEREO; - return CT_NONE; -} - -// Process the data set definition to read and validate the data set metrics. -static int ProcessMetrics(TokenReaderT *tr, const uint fftSize, const uint truncSize, HrirDataT *hData) -{ - int hasRate = 0, hasType = 0, hasPoints = 0, hasRadius = 0; - int hasDistance = 0, hasAzimuths = 0; - char ident[MAX_IDENT_LEN+1]; - uint line, col; - double fpVal; - uint points; - int intVal; - double distances[MAX_FD_COUNT]; - uint fdCount = 0; - uint evCounts[MAX_FD_COUNT]; - uint *azCounts = calloc(MAX_FD_COUNT * MAX_EV_COUNT, sizeof(*azCounts)); - - if(azCounts == NULL) - { - fprintf(stderr, "Error: Out of memory.\n"); - exit(-1); - } - TrIndication(tr, &line, &col); - while(TrIsIdent(tr)) - { - TrIndication(tr, &line, &col); - if(!TrReadIdent(tr, MAX_IDENT_LEN, ident)) - goto error; - if(strcasecmp(ident, "rate") == 0) - { - if(hasRate) - { - TrErrorAt(tr, line, col, "Redefinition of 'rate'.\n"); - goto error; - } - if(!TrReadOperator(tr, "=")) - goto error; - if(!TrReadInt(tr, MIN_RATE, MAX_RATE, &intVal)) - goto error; - hData->mIrRate = (uint)intVal; - hasRate = 1; - } - else if(strcasecmp(ident, "type") == 0) - { - char type[MAX_IDENT_LEN+1]; - - if(hasType) - { - TrErrorAt(tr, line, col, "Redefinition of 'type'.\n"); - goto error; - } - if(!TrReadOperator(tr, "=")) - goto error; - - if(!TrReadIdent(tr, MAX_IDENT_LEN, type)) - goto error; - hData->mChannelType = MatchChannelType(type); - if(hData->mChannelType == CT_NONE) - { - TrErrorAt(tr, line, col, "Expected a channel type.\n"); - goto error; - } - hasType = 1; - } - else if(strcasecmp(ident, "points") == 0) - { - if(hasPoints) - { - TrErrorAt(tr, line, col, "Redefinition of 'points'.\n"); - goto error; - } - if(!TrReadOperator(tr, "=")) - goto error; - TrIndication(tr, &line, &col); - if(!TrReadInt(tr, MIN_POINTS, MAX_POINTS, &intVal)) - goto error; - points = (uint)intVal; - if(fftSize > 0 && points > fftSize) - { - TrErrorAt(tr, line, col, "Value exceeds the overridden FFT size.\n"); - goto error; - } - if(points < truncSize) - { - TrErrorAt(tr, line, col, "Value is below the truncation size.\n"); - goto error; - } - hData->mIrPoints = points; - if(fftSize <= 0) - { - hData->mFftSize = DEFAULT_FFTSIZE; - hData->mIrSize = 1 + (DEFAULT_FFTSIZE / 2); - } - else - { - hData->mFftSize = fftSize; - hData->mIrSize = 1 + (fftSize / 2); - if(points > hData->mIrSize) - hData->mIrSize = points; - } - hasPoints = 1; - } - else if(strcasecmp(ident, "radius") == 0) - { - if(hasRadius) - { - TrErrorAt(tr, line, col, "Redefinition of 'radius'.\n"); - goto error; - } - if(!TrReadOperator(tr, "=")) - goto error; - if(!TrReadFloat(tr, MIN_RADIUS, MAX_RADIUS, &fpVal)) - goto error; - hData->mRadius = fpVal; - hasRadius = 1; - } - else if(strcasecmp(ident, "distance") == 0) - { - uint count = 0; - - if(hasDistance) - { - TrErrorAt(tr, line, col, "Redefinition of 'distance'.\n"); - goto error; - } - if(!TrReadOperator(tr, "=")) - goto error; - - for(;;) - { - if(!TrReadFloat(tr, MIN_DISTANCE, MAX_DISTANCE, &fpVal)) - goto error; - if(count > 0 && fpVal <= distances[count - 1]) - { - TrError(tr, "Distances are not ascending.\n"); - goto error; - } - distances[count++] = fpVal; - if(!TrIsOperator(tr, ",")) - break; - if(count >= MAX_FD_COUNT) - { - TrError(tr, "Exceeded the maximum of %d fields.\n", MAX_FD_COUNT); - goto error; - } - TrReadOperator(tr, ","); - } - if(fdCount != 0 && count != fdCount) - { - TrError(tr, "Did not match the specified number of %d fields.\n", fdCount); - goto error; - } - fdCount = count; - hasDistance = 1; - } - else if(strcasecmp(ident, "azimuths") == 0) - { - uint count = 0; - - if(hasAzimuths) - { - TrErrorAt(tr, line, col, "Redefinition of 'azimuths'.\n"); - goto error; - } - if(!TrReadOperator(tr, "=")) - goto error; - - evCounts[0] = 0; - for(;;) - { - if(!TrReadInt(tr, MIN_AZ_COUNT, MAX_AZ_COUNT, &intVal)) - goto error; - azCounts[(count * MAX_EV_COUNT) + evCounts[count]++] = (uint)intVal; - if(TrIsOperator(tr, ",")) - { - if(evCounts[count] >= MAX_EV_COUNT) - { - TrError(tr, "Exceeded the maximum of %d elevations.\n", MAX_EV_COUNT); - goto error; - } - TrReadOperator(tr, ","); - } - else - { - if(evCounts[count] < MIN_EV_COUNT) - { - TrErrorAt(tr, line, col, "Did not reach the minimum of %d azimuth counts.\n", MIN_EV_COUNT); - goto error; - } - if(azCounts[count * MAX_EV_COUNT] != 1 || azCounts[(count * MAX_EV_COUNT) + evCounts[count] - 1] != 1) - { - TrError(tr, "Poles are not singular for field %d.\n", count - 1); - goto error; - } - count++; - if(TrIsOperator(tr, ";")) - { - if(count >= MAX_FD_COUNT) - { - TrError(tr, "Exceeded the maximum number of %d fields.\n", MAX_FD_COUNT); - goto error; - } - evCounts[count] = 0; - TrReadOperator(tr, ";"); - } - else - { - break; - } - } - } - if(fdCount != 0 && count != fdCount) - { - TrError(tr, "Did not match the specified number of %d fields.\n", fdCount); - goto error; - } - fdCount = count; - hasAzimuths = 1; - } - else - { - TrErrorAt(tr, line, col, "Expected a metric name.\n"); - goto error; - } - TrSkipWhitespace(tr); - } - if(!(hasRate && hasPoints && hasRadius && hasDistance && hasAzimuths)) - { - TrErrorAt(tr, line, col, "Expected a metric name.\n"); - goto error; - } - if(distances[0] < hData->mRadius) - { - TrError(tr, "Distance cannot start below head radius.\n"); - goto error; - } - if(hData->mChannelType == CT_NONE) - hData->mChannelType = CT_MONO; - if(!PrepareHrirData(fdCount, distances, evCounts, azCounts, hData)) - { - fprintf(stderr, "Error: Out of memory.\n"); - exit(-1); - } - free(azCounts); - return 1; - -error: - free(azCounts); - return 0; -} - -// Parse an index triplet from the data set definition. -static int ReadIndexTriplet(TokenReaderT *tr, const HrirDataT *hData, uint *fi, uint *ei, uint *ai) -{ - int intVal; - - if(hData->mFdCount > 1) - { - if(!TrReadInt(tr, 0, (int)hData->mFdCount - 1, &intVal)) - return 0; - *fi = (uint)intVal; - if(!TrReadOperator(tr, ",")) - return 0; - } - else - { - *fi = 0; - } - if(!TrReadInt(tr, 0, (int)hData->mFds[*fi].mEvCount - 1, &intVal)) - return 0; - *ei = (uint)intVal; - if(!TrReadOperator(tr, ",")) - return 0; - if(!TrReadInt(tr, 0, (int)hData->mFds[*fi].mEvs[*ei].mAzCount - 1, &intVal)) - return 0; - *ai = (uint)intVal; - return 1; -} - -// Match the source format from a given identifier. -static SourceFormatT MatchSourceFormat(const char *ident) -{ - if(strcasecmp(ident, "wave") == 0) - return SF_WAVE; - if(strcasecmp(ident, "bin_le") == 0) - return SF_BIN_LE; - if(strcasecmp(ident, "bin_be") == 0) - return SF_BIN_BE; - if(strcasecmp(ident, "ascii") == 0) - return SF_ASCII; - return SF_NONE; -} - -// Match the source element type from a given identifier. -static ElementTypeT MatchElementType(const char *ident) -{ - if(strcasecmp(ident, "int") == 0) - return ET_INT; - if(strcasecmp(ident, "fp") == 0) - return ET_FP; - return ET_NONE; -} - -// Parse and validate a source reference from the data set definition. -static int ReadSourceRef(TokenReaderT *tr, SourceRefT *src) -{ - char ident[MAX_IDENT_LEN+1]; - uint line, col; - int intVal; - - TrIndication(tr, &line, &col); - if(!TrReadIdent(tr, MAX_IDENT_LEN, ident)) - return 0; - src->mFormat = MatchSourceFormat(ident); - if(src->mFormat == SF_NONE) - { - TrErrorAt(tr, line, col, "Expected a source format.\n"); - return 0; - } - if(!TrReadOperator(tr, "(")) - return 0; - if(src->mFormat == SF_WAVE) - { - if(!TrReadInt(tr, 0, MAX_WAVE_CHANNELS, &intVal)) - return 0; - src->mType = ET_NONE; - src->mSize = 0; - src->mBits = 0; - src->mChannel = (uint)intVal; - src->mSkip = 0; - } - else - { - TrIndication(tr, &line, &col); - if(!TrReadIdent(tr, MAX_IDENT_LEN, ident)) - return 0; - src->mType = MatchElementType(ident); - if(src->mType == ET_NONE) - { - TrErrorAt(tr, line, col, "Expected a source element type.\n"); - return 0; - } - if(src->mFormat == SF_BIN_LE || src->mFormat == SF_BIN_BE) - { - if(!TrReadOperator(tr, ",")) - return 0; - if(src->mType == ET_INT) - { - if(!TrReadInt(tr, MIN_BIN_SIZE, MAX_BIN_SIZE, &intVal)) - return 0; - src->mSize = (uint)intVal; - if(!TrIsOperator(tr, ",")) - src->mBits = (int)(8*src->mSize); - else - { - TrReadOperator(tr, ","); - TrIndication(tr, &line, &col); - if(!TrReadInt(tr, -2147483647-1, 2147483647, &intVal)) - return 0; - if(abs(intVal) < MIN_BIN_BITS || (uint)abs(intVal) > (8*src->mSize)) - { - TrErrorAt(tr, line, col, "Expected a value of (+/-) %d to %d.\n", MIN_BIN_BITS, 8*src->mSize); - return 0; - } - src->mBits = intVal; - } - } - else - { - TrIndication(tr, &line, &col); - if(!TrReadInt(tr, -2147483647-1, 2147483647, &intVal)) - return 0; - if(intVal != 4 && intVal != 8) - { - TrErrorAt(tr, line, col, "Expected a value of 4 or 8.\n"); - return 0; - } - src->mSize = (uint)intVal; - src->mBits = 0; - } - } - else if(src->mFormat == SF_ASCII && src->mType == ET_INT) - { - if(!TrReadOperator(tr, ",")) - return 0; - if(!TrReadInt(tr, MIN_ASCII_BITS, MAX_ASCII_BITS, &intVal)) - return 0; - src->mSize = 0; - src->mBits = intVal; - } - else - { - src->mSize = 0; - src->mBits = 0; - } - - if(!TrIsOperator(tr, ";")) - src->mSkip = 0; - else - { - TrReadOperator(tr, ";"); - if(!TrReadInt(tr, 0, 0x7FFFFFFF, &intVal)) - return 0; - src->mSkip = (uint)intVal; - } - } - if(!TrReadOperator(tr, ")")) - return 0; - if(TrIsOperator(tr, "@")) - { - TrReadOperator(tr, "@"); - if(!TrReadInt(tr, 0, 0x7FFFFFFF, &intVal)) - return 0; - src->mOffset = (uint)intVal; - } - else - src->mOffset = 0; - if(!TrReadOperator(tr, ":")) - return 0; - if(!TrReadString(tr, MAX_PATH_LEN, src->mPath)) - return 0; - return 1; -} - -// Match the target ear (index) from a given identifier. -static int MatchTargetEar(const char *ident) -{ - if(strcasecmp(ident, "left") == 0) - return 0; - if(strcasecmp(ident, "right") == 0) - return 1; - return -1; -} - -// Process the list of sources in the data set definition. -static int ProcessSources(const HeadModelT model, TokenReaderT *tr, HrirDataT *hData) -{ - uint channels = (hData->mChannelType == CT_STEREO) ? 2 : 1; - double *hrirs = CreateDoubles(channels * hData->mIrCount * hData->mIrSize); - double *hrir = CreateDoubles(hData->mIrPoints); - uint line, col, fi, ei, ai, ti; - int count; - - printf("Loading sources..."); - fflush(stdout); - count = 0; - while(TrIsOperator(tr, "[")) - { - double factor[2] = { 1.0, 1.0 }; - - TrIndication(tr, &line, &col); - TrReadOperator(tr, "["); - if(!ReadIndexTriplet(tr, hData, &fi, &ei, &ai)) - goto error; - if(!TrReadOperator(tr, "]")) - goto error; - HrirAzT *azd = &hData->mFds[fi].mEvs[ei].mAzs[ai]; - - if(azd->mIrs[0] != NULL) - { - TrErrorAt(tr, line, col, "Redefinition of source.\n"); - goto error; - } - if(!TrReadOperator(tr, "=")) - goto error; - - for(;;) - { - SourceRefT src; - uint ti = 0; - - if(!ReadSourceRef(tr, &src)) - goto error; - - // TODO: Would be nice to display 'x of y files', but that would - // require preparing the source refs first to get a total count - // before loading them. - ++count; - printf("\rLoading sources... %d file%s", count, (count==1)?"":"s"); - fflush(stdout); - - if(!LoadSource(&src, hData->mIrRate, hData->mIrPoints, hrir)) - goto error; - - if(hData->mChannelType == CT_STEREO) - { - char ident[MAX_IDENT_LEN+1]; - - if(!TrReadIdent(tr, MAX_IDENT_LEN, ident)) - goto error; - ti = MatchTargetEar(ident); - if((int)ti < 0) - { - TrErrorAt(tr, line, col, "Expected a target ear.\n"); - goto error; - } - } - azd->mIrs[ti] = &hrirs[hData->mIrSize * (ti * hData->mIrCount + azd->mIndex)]; - if(model == HM_DATASET) - azd->mDelays[ti] = AverageHrirOnset(hData->mIrRate, hData->mIrPoints, hrir, 1.0 / factor[ti], azd->mDelays[ti]); - AverageHrirMagnitude(hData->mIrPoints, hData->mFftSize, hrir, 1.0 / factor[ti], azd->mIrs[ti]); - factor[ti] += 1.0; - if(!TrIsOperator(tr, "+")) - break; - TrReadOperator(tr, "+"); - } - if(hData->mChannelType == CT_STEREO) - { - if(azd->mIrs[0] == NULL) - { - TrErrorAt(tr, line, col, "Missing left ear source reference(s).\n"); - goto error; - } - else if(azd->mIrs[1] == NULL) - { - TrErrorAt(tr, line, col, "Missing right ear source reference(s).\n"); - goto error; - } - } - } - printf("\n"); - for(fi = 0;fi < hData->mFdCount;fi++) - { - for(ei = 0;ei < hData->mFds[fi].mEvCount;ei++) - { - for(ai = 0;ai < hData->mFds[fi].mEvs[ei].mAzCount;ai++) - { - HrirAzT *azd = &hData->mFds[fi].mEvs[ei].mAzs[ai]; - - if(azd->mIrs[0] != NULL) - break; - } - if(ai < hData->mFds[fi].mEvs[ei].mAzCount) - break; - } - if(ei >= hData->mFds[fi].mEvCount) - { - TrError(tr, "Missing source references [ %d, *, * ].\n", fi); - goto error; - } - hData->mFds[fi].mEvStart = ei; - for(;ei < hData->mFds[fi].mEvCount;ei++) - { - for(ai = 0;ai < hData->mFds[fi].mEvs[ei].mAzCount;ai++) - { - HrirAzT *azd = &hData->mFds[fi].mEvs[ei].mAzs[ai]; - - if(azd->mIrs[0] == NULL) - { - TrError(tr, "Missing source reference [ %d, %d, %d ].\n", fi, ei, ai); - goto error; - } - } - } - } - for(ti = 0;ti < channels;ti++) - { - for(fi = 0;fi < hData->mFdCount;fi++) - { - for(ei = 0;ei < hData->mFds[fi].mEvCount;ei++) - { - for(ai = 0;ai < hData->mFds[fi].mEvs[ei].mAzCount;ai++) - { - HrirAzT *azd = &hData->mFds[fi].mEvs[ei].mAzs[ai]; - - azd->mIrs[ti] = &hrirs[hData->mIrSize * (ti * hData->mIrCount + azd->mIndex)]; - } - } - } - } - if(!TrLoad(tr)) - { - free(hrir); - return 1; - } - TrError(tr, "Errant data at end of source list.\n"); - -error: - free(hrir); - return 0; -} - -/* Parse the data set definition and process the source data, storing the - * resulting data set as desired. If the input name is NULL it will read - * from standard input. - */ -static int ProcessDefinition(const char *inName, const uint outRate, const uint fftSize, const int equalize, const int surface, const double limit, const uint truncSize, const HeadModelT model, const double radius, const char *outName) -{ - char rateStr[8+1], expName[MAX_PATH_LEN]; - TokenReaderT tr; - HrirDataT hData; - FILE *fp; - int ret; - - ResetHrirData(&hData); - fprintf(stdout, "Reading HRIR definition from %s...\n", inName?inName:"stdin"); - if(inName != NULL) - { - fp = fopen(inName, "r"); - if(fp == NULL) - { - fprintf(stderr, "Error: Could not open definition file '%s'\n", inName); - return 0; - } - TrSetup(fp, inName, &tr); - } - else - { - fp = stdin; - TrSetup(fp, "", &tr); - } - if(!ProcessMetrics(&tr, fftSize, truncSize, &hData)) - { - if(inName != NULL) - fclose(fp); - return 0; - } - if(!ProcessSources(model, &tr, &hData)) - { - FreeHrirData(&hData); - if(inName != NULL) - fclose(fp); - return 0; - } - if(fp != stdin) - fclose(fp); - if(equalize) - { - uint c = (hData.mChannelType == CT_STEREO) ? 2 : 1; - uint m = 1 + hData.mFftSize / 2; - double *dfa = CreateDoubles(c * m); - - fprintf(stdout, "Calculating diffuse-field average...\n"); - CalculateDiffuseFieldAverage(&hData, c, m, surface, limit, dfa); - fprintf(stdout, "Performing diffuse-field equalization...\n"); - DiffuseFieldEqualize(c, m, dfa, &hData); - free(dfa); - } - fprintf(stdout, "Performing minimum phase reconstruction...\n"); - ReconstructHrirs(&hData); - if(outRate != 0 && outRate != hData.mIrRate) - { - fprintf(stdout, "Resampling HRIRs...\n"); - ResampleHrirs(outRate, &hData); - } - fprintf(stdout, "Truncating minimum-phase HRIRs...\n"); - hData.mIrPoints = truncSize; - fprintf(stdout, "Synthesizing missing elevations...\n"); - if(model == HM_DATASET) - SynthesizeOnsets(&hData); - SynthesizeHrirs(&hData); - fprintf(stdout, "Normalizing final HRIRs...\n"); - NormalizeHrirs(&hData); - fprintf(stdout, "Calculating impulse delays...\n"); - CalculateHrtds(model, (radius > DEFAULT_CUSTOM_RADIUS) ? radius : hData.mRadius, &hData); - snprintf(rateStr, 8, "%u", hData.mIrRate); - StrSubst(outName, "%r", rateStr, MAX_PATH_LEN, expName); - fprintf(stdout, "Creating MHR data set %s...\n", expName); - ret = StoreMhr(&hData, expName); - - FreeHrirData(&hData); - return ret; -} - -static void PrintHelp(const char *argv0, FILE *ofile) -{ - fprintf(ofile, "Usage: %s [ @@ -2201,8 +2201,8 @@ added by the ALC_EXT_DEDICATED extension. 160 20 - 125 - 29 + 129 + 31 @@ -2371,7 +2371,7 @@ added by the ALC_EXT_DEDICATED extension. 0 0 564 - 27 + 29 -- cgit v1.2.3 From 8ca849655f6c292527d0e260718ba0eca4179fb1 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 28 Apr 2019 21:51:47 -0700 Subject: Properly replace sinc4 with cubic in alsoft-config --- utils/alsoft-config/mainwindow.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'utils') diff --git a/utils/alsoft-config/mainwindow.cpp b/utils/alsoft-config/mainwindow.cpp index 920bc5a3..ad0223da 100644 --- a/utils/alsoft-config/mainwindow.cpp +++ b/utils/alsoft-config/mainwindow.cpp @@ -609,11 +609,11 @@ void MainWindow::loadConfig(const QString &fname) QString resampler = settings.value("resampler").toString().trimmed(); ui->resamplerSlider->setValue(2); ui->resamplerLabel->setText(resamplerList[2].name); - /* The "cubic" and "sinc8" resamplers are no longer supported. Use "sinc4" + /* The "sinc4" and "sinc8" resamplers are no longer supported. Use "cubic" * as a fallback. */ - if(resampler == "cubic" || resampler == "sinc8") - resampler = "sinc4"; + if(resampler == "sinc4" || resampler == "sinc8") + resampler = "cubic"; /* The "bsinc" resampler name is an alias for "bsinc12". */ else if(resampler == "bsinc") resampler = "bsinc12"; -- cgit v1.2.3 From c7e388873c075daa58c26d168080b36300372fd0 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 28 Apr 2019 22:21:23 -0700 Subject: Increase the period size slider and don't use steps of 64 --- utils/alsoft-config/mainwindow.cpp | 3 --- utils/alsoft-config/mainwindow.ui | 18 +++++++++--------- 2 files changed, 9 insertions(+), 12 deletions(-) (limited to 'utils') diff --git a/utils/alsoft-config/mainwindow.cpp b/utils/alsoft-config/mainwindow.cpp index ad0223da..a83133b3 100644 --- a/utils/alsoft-config/mainwindow.cpp +++ b/utils/alsoft-config/mainwindow.cpp @@ -1144,10 +1144,7 @@ void MainWindow::updatePeriodSizeEdit(int size) { ui->periodSizeEdit->clear(); if(size >= 64) - { - size = (size+32)&~0x3f; ui->periodSizeEdit->insert(QString::number(size)); - } enableApplyButton(); } diff --git a/utils/alsoft-config/mainwindow.ui b/utils/alsoft-config/mainwindow.ui index 95e9ebe6..158a3316 100644 --- a/utils/alsoft-config/mainwindow.ui +++ b/utils/alsoft-config/mainwindow.ui @@ -283,9 +283,9 @@ mixed and being heard. - 20 + 60 0 - 201 + 161 21 @@ -299,9 +299,9 @@ mixed and being heard. - 80 + 99 20 - 160 + 141 21 @@ -336,7 +336,7 @@ mixed and being heard. - 20 + 40 20 51 21 @@ -365,24 +365,24 @@ frames needed for each mixing update. 60 20 - 160 + 191 21 - 0 + 63 8192 - 64 + 1 1024 - 0 + 63 true -- cgit v1.2.3 From 2eb657f2dfad41e7d0946de4c91f766eb9b846f4 Mon Sep 17 00:00:00 2001 From: ArthurSonzogni Date: Mon, 29 Apr 2019 23:59:36 +0200 Subject: CMAKE: export PUBLIC headers of OpenAL. Remove the cmake function: INCLUDE_DIRECTORIES(..) Replace it by: TARGET_INCLUDE_DIRECTORIES(...) It gives us the opportunity to define whether or not OpenAL dependencies should be exported or not (using PUBLIC or PRIVATE keywoard). [user visible changes] The OpenAL PUBLIC headers are exported. When a target depends on OpenAL, it will have access to its public headers. Some small refactor along the way. --- CMakeLists.txt | 98 +++++++++++++++++++++----------------- utils/alsoft-config/CMakeLists.txt | 2 + 2 files changed, 56 insertions(+), 44 deletions(-) (limited to 'utils') diff --git a/CMakeLists.txt b/CMakeLists.txt index 411ae1ed..fba05186 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -193,9 +193,6 @@ IF(HAVE_LIBLOG) SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} log) ENDIF() -# Add definitions, compiler switches, etc. -INCLUDE_DIRECTORIES("${OpenAL_SOURCE_DIR}/include" "${OpenAL_SOURCE_DIR}/common" "${OpenAL_BINARY_DIR}") - IF(NOT CMAKE_BUILD_TYPE) SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." @@ -639,6 +636,8 @@ IF(NOT HAVE_STDINT_H) ENDIF() +# Common sources used by both the OpenAL implementation library and potentially +# the OpenAL router. SET(COMMON_OBJS common/alcomplex.cpp common/alcomplex.h @@ -1260,15 +1259,8 @@ CONFIGURE_FILE( @ONLY) -# Add a static library with common functions used by multiple targets -ADD_LIBRARY(common STATIC ${COMMON_OBJS}) -TARGET_COMPILE_DEFINITIONS(common PRIVATE ${CPP_DEFS}) -TARGET_COMPILE_OPTIONS(common PRIVATE ${C_FLAGS}) - - UNSET(HAS_ROUTER) -SET(IMPL_TARGET OpenAL) -SET(COMMON_LIB ) +SET(IMPL_TARGET OpenAL) # Either OpenAL or soft_oal. SET(SUBSYS_FLAG ) # Build main library @@ -1279,10 +1271,6 @@ IF(LIBTYPE STREQUAL "STATIC") ENDIF() ADD_LIBRARY(OpenAL STATIC ${COMMON_OBJS} ${OPENAL_OBJS} ${ALC_OBJS}) ELSE() - # Make sure to compile the common code with PIC, since it'll be linked into - # shared libs that needs it. - SET_PROPERTY(TARGET common PROPERTY POSITION_INDEPENDENT_CODE TRUE) - SET(COMMON_LIB common) IF(WIN32) IF(MSVC) @@ -1293,11 +1281,25 @@ ELSE() ENDIF() IF(WIN32 AND ALSOFT_BUILD_ROUTER) - ADD_LIBRARY(OpenAL SHARED router/router.cpp router/router.h router/alc.cpp router/al.cpp) + ADD_LIBRARY(OpenAL SHARED + router/router.cpp + router/router.h + router/alc.cpp + router/al.cpp + ${COMMON_OBJS} + ) TARGET_COMPILE_DEFINITIONS(OpenAL PRIVATE AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES ${CPP_DEFS}) TARGET_COMPILE_OPTIONS(OpenAL PRIVATE ${C_FLAGS}) - TARGET_LINK_LIBRARIES(OpenAL PRIVATE ${COMMON_LIB} ${LINKER_FLAGS}) + TARGET_LINK_LIBRARIES(OpenAL PRIVATE ${LINKER_FLAGS}) + TARGET_INCLUDE_DIRECTORIES(OpenAL + PUBLIC + $ + $ + PRIVATE + ${OpenAL_SOURCE_DIR}/common + ${OpenAL_BINARY_DIR} + ) SET_TARGET_PROPERTIES(OpenAL PROPERTIES PREFIX "") SET_TARGET_PROPERTIES(OpenAL PROPERTIES OUTPUT_NAME ${LIBNAME}) IF(TARGET build_version) @@ -1309,22 +1311,35 @@ ELSE() SET(IMPL_TARGET soft_oal) ENDIF() - ADD_LIBRARY(${IMPL_TARGET} SHARED ${OPENAL_OBJS} ${ALC_OBJS}) + ADD_LIBRARY(${IMPL_TARGET} SHARED ${COMMON_OBJS} ${OPENAL_OBJS} ${ALC_OBJS}) IF(WIN32) SET_TARGET_PROPERTIES(${IMPL_TARGET} PROPERTIES PREFIX "") ENDIF() ENDIF() + +TARGET_LINK_LIBRARIES(${IMPL_TARGET} + PRIVATE ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB}) + +TARGET_INCLUDE_DIRECTORIES(${IMPL_TARGET} + PUBLIC + $ + $ + PRIVATE + ${INC_PATHS} + ${OpenAL_BINARY_DIR} + ${OpenAL_SOURCE_DIR}/Alc + ${OpenAL_SOURCE_DIR}/OpenAL32/Include + ${OpenAL_SOURCE_DIR}/common +) + SET_TARGET_PROPERTIES(${IMPL_TARGET} PROPERTIES OUTPUT_NAME ${LIBNAME} VERSION ${LIB_VERSION} SOVERSION ${LIB_MAJOR_VERSION} ) TARGET_COMPILE_DEFINITIONS(${IMPL_TARGET} PRIVATE AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES ${CPP_DEFS}) -TARGET_INCLUDE_DIRECTORIES(${IMPL_TARGET} - PRIVATE "${OpenAL_SOURCE_DIR}/OpenAL32/Include" "${OpenAL_SOURCE_DIR}/Alc" ${INC_PATHS}) TARGET_COMPILE_OPTIONS(${IMPL_TARGET} PRIVATE ${C_FLAGS}) -TARGET_LINK_LIBRARIES(${IMPL_TARGET} - PRIVATE ${COMMON_LIB} ${LINKER_FLAGS} ${EXTRA_LIBS} ${MATH_LIB}) + IF(TARGET build_version) ADD_DEPENDENCIES(${IMPL_TARGET} build_version) ENDIF() @@ -1497,12 +1512,13 @@ IF(ALSOFT_UTILS) ENDIF() IF(ALSOFT_TESTS) - SET(TEST_COMMON_OBJS examples/common/alhelpers.c) - - ADD_EXECUTABLE(altonegen examples/altonegen.c ${TEST_COMMON_OBJS}) + ADD_EXECUTABLE(altonegen + examples/altonegen.c + examples/common/alhelpers.c + ) TARGET_COMPILE_DEFINITIONS(altonegen PRIVATE ${CPP_DEFS}) TARGET_COMPILE_OPTIONS(altonegen PRIVATE ${C_FLAGS}) - TARGET_LINK_LIBRARIES(altonegen PRIVATE ${LINKER_FLAGS} common OpenAL ${MATH_LIB}) + TARGET_LINK_LIBRARIES(altonegen PRIVATE ${LINKER_FLAGS} OpenAL ${MATH_LIB}) IF(ALSOFT_INSTALL) INSTALL(TARGETS altonegen @@ -1520,12 +1536,13 @@ IF(ALSOFT_EXAMPLES) # Add a static library with common functions used by multiple targets ADD_LIBRARY(ex-common STATIC examples/common/alhelpers.c) TARGET_COMPILE_DEFINITIONS(ex-common PRIVATE ${CPP_DEFS}) - TARGET_COMPILE_OPTIONS(ex-common PRIVATE ${C_FLAGS}) + TARGET_COMPILE_OPTIONS(ex-common PUBLIC ${C_FLAGS}) + TARGET_LINK_LIBRARIES(ex-common PUBLIC OpenAL) ADD_EXECUTABLE(alrecord examples/alrecord.c) TARGET_COMPILE_DEFINITIONS(alrecord PRIVATE ${CPP_DEFS}) TARGET_COMPILE_OPTIONS(alrecord PRIVATE ${C_FLAGS}) - TARGET_LINK_LIBRARIES(alrecord PRIVATE ${LINKER_FLAGS} ex-common common OpenAL) + TARGET_LINK_LIBRARIES(alrecord PRIVATE ${LINKER_FLAGS} ex-common) IF(ALSOFT_INSTALL) INSTALL(TARGETS alrecord @@ -1545,8 +1562,7 @@ IF(ALSOFT_EXAMPLES) PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR}) TARGET_COMPILE_OPTIONS(alplay PRIVATE ${C_FLAGS}) TARGET_LINK_LIBRARIES(alplay - PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common common - OpenAL) + PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common) ADD_EXECUTABLE(alstream examples/alstream.c) TARGET_COMPILE_DEFINITIONS(alstream PRIVATE ${CPP_DEFS}) @@ -1554,8 +1570,7 @@ IF(ALSOFT_EXAMPLES) PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR}) TARGET_COMPILE_OPTIONS(alstream PRIVATE ${C_FLAGS}) TARGET_LINK_LIBRARIES(alstream - PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common common - OpenAL) + PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common) ADD_EXECUTABLE(alreverb examples/alreverb.c) TARGET_COMPILE_DEFINITIONS(alreverb PRIVATE ${CPP_DEFS}) @@ -1563,8 +1578,7 @@ IF(ALSOFT_EXAMPLES) PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR}) TARGET_COMPILE_OPTIONS(alreverb PRIVATE ${C_FLAGS}) TARGET_LINK_LIBRARIES(alreverb - PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common common - OpenAL) + PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common) ADD_EXECUTABLE(almultireverb examples/almultireverb.c) TARGET_COMPILE_DEFINITIONS(almultireverb PRIVATE ${CPP_DEFS}) @@ -1572,8 +1586,8 @@ IF(ALSOFT_EXAMPLES) PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR}) TARGET_COMPILE_OPTIONS(almultireverb PRIVATE ${C_FLAGS}) TARGET_LINK_LIBRARIES(almultireverb - PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common common - OpenAL ${MATH_LIB}) + PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common + ${MATH_LIB}) ADD_EXECUTABLE(allatency examples/allatency.c) TARGET_COMPILE_DEFINITIONS(allatency PRIVATE ${CPP_DEFS}) @@ -1581,8 +1595,7 @@ IF(ALSOFT_EXAMPLES) PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR}) TARGET_COMPILE_OPTIONS(allatency PRIVATE ${C_FLAGS}) TARGET_LINK_LIBRARIES(allatency - PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common common - OpenAL) + PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common) ADD_EXECUTABLE(alloopback examples/alloopback.c) TARGET_COMPILE_DEFINITIONS(alloopback PRIVATE ${CPP_DEFS}) @@ -1590,8 +1603,7 @@ IF(ALSOFT_EXAMPLES) PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR}) TARGET_COMPILE_OPTIONS(alloopback PRIVATE ${C_FLAGS}) TARGET_LINK_LIBRARIES(alloopback - PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common common - OpenAL ${MATH_LIB}) + PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common ${MATH_LIB}) ADD_EXECUTABLE(alhrtf examples/alhrtf.c) TARGET_COMPILE_DEFINITIONS(alhrtf PRIVATE ${CPP_DEFS}) @@ -1599,8 +1611,7 @@ IF(ALSOFT_EXAMPLES) PRIVATE ${SDL2_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR}) TARGET_COMPILE_OPTIONS(alhrtf PRIVATE ${C_FLAGS}) TARGET_LINK_LIBRARIES(alhrtf - PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common common - OpenAL ${MATH_LIB}) + PRIVATE ${LINKER_FLAGS} ${SDL_SOUND_LIBRARIES} ${SDL2_LIBRARY} ex-common ${MATH_LIB}) IF(ALSOFT_INSTALL) INSTALL(TARGETS alplay alstream alreverb almultireverb allatency alloopback alhrtf @@ -1644,8 +1655,7 @@ IF(ALSOFT_EXAMPLES) PRIVATE ${SDL2_INCLUDE_DIR} ${FFMPEG_INCLUDE_DIRS}) TARGET_COMPILE_OPTIONS(alffplay PRIVATE ${C_FLAGS}) TARGET_LINK_LIBRARIES(alffplay - PRIVATE ${LINKER_FLAGS} ${SDL2_LIBRARY} ${FFMPEG_LIBRARIES} ex-common common - OpenAL) + PRIVATE ${LINKER_FLAGS} ${SDL2_LIBRARY} ${FFMPEG_LIBRARIES} ex-common) IF(ALSOFT_INSTALL) INSTALL(TARGETS alffplay diff --git a/utils/alsoft-config/CMakeLists.txt b/utils/alsoft-config/CMakeLists.txt index 67cc44c7..7996ee97 100644 --- a/utils/alsoft-config/CMakeLists.txt +++ b/utils/alsoft-config/CMakeLists.txt @@ -20,6 +20,7 @@ if(Qt5Widgets_FOUND AND NOT ALSOFT_NO_QT5) add_executable(alsoft-config ${alsoft-config_SRCS} ${UIS} ${RSCS} ${TRS} ${MOCS}) target_link_libraries(alsoft-config Qt5::Widgets) + target_include_directories(alsoft-config PRIVATE "${OpenAL_BINARY_DIR}") set_property(TARGET alsoft-config APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS}) set_target_properties(alsoft-config PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${OpenAL_BINARY_DIR}) if(TARGET build_version) @@ -43,6 +44,7 @@ else() add_executable(alsoft-config ${alsoft-config_SRCS} ${UIS} ${RSCS} ${TRS} ${MOCS}) target_link_libraries(alsoft-config ${QT_LIBRARIES}) + target_include_directories(alsoft-config PRIVATE "${OpenAL_BINARY_DIR}") set_property(TARGET alsoft-config APPEND PROPERTY COMPILE_FLAGS ${EXTRA_CFLAGS}) set_target_properties(alsoft-config PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${OpenAL_BINARY_DIR}) if(TARGET build_version) -- cgit v1.2.3 From cef7eebed663e1daf8704eceb09f05ff75609ec5 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 29 Apr 2019 13:07:02 -0700 Subject: Disable NFC by default --- Alc/panning.cpp | 2 +- alsoftrc.sample | 19 ++++++++++--------- utils/alsoft-config/mainwindow.cpp | 4 ++-- 3 files changed, 13 insertions(+), 12 deletions(-) (limited to 'utils') diff --git a/Alc/panning.cpp b/Alc/panning.cpp index cb9a486d..ce822123 100644 --- a/Alc/panning.cpp +++ b/Alc/panning.cpp @@ -235,7 +235,7 @@ void InitNearFieldCtrl(ALCdevice *device, ALfloat ctrl_dist, ALsizei order, cons { /* NFC is only used when AvgSpeakerDist is greater than 0. */ const char *devname{device->DeviceName.c_str()}; - if(!GetConfigValueBool(devname, "decoder", "nfc", 1) || !(ctrl_dist > 0.0f)) + if(!GetConfigValueBool(devname, "decoder", "nfc", 0) || !(ctrl_dist > 0.0f)) return; device->AvgSpeakerDist = minf(ctrl_dist, 10.0f); diff --git a/alsoftrc.sample b/alsoftrc.sample index 9b5dd2f9..95d4ff82 100644 --- a/alsoftrc.sample +++ b/alsoftrc.sample @@ -275,17 +275,18 @@ distance-comp = true # creates a more realistic perception of sound distance. Note that the effect # may be stronger or weaker than intended if the application doesn't use or # specify an appropriate unit scale, or if incorrect speaker distances are set -# in the decoder configuration file. Requires hq-mode to be enabled. -nfc = true +# in the decoder configuration file. +nfc = false ## nfc-ref-delay -# Specifies the reference delay value for ambisonic output. When channels is -# set to one of the ambi* formats, this option enables NFC-HOA output with the -# specified Reference Delay parameter. The specified value can then be shared -# with an appropriate NFC-HOA decoder to reproduce correct near-field effects. -# Keep in mind that despite being designed for higher-order ambisonics, this -# applies to first-order output all the same. When left unset, normal output -# is created with no near-field simulation. +# Specifies the reference delay value for ambisonic output when NFC filters +# are enabled. If channels is set to one of the ambi* formats, this option +# enables NFC-HOA output with the specified Reference Delay parameter. The +# specified value can then be shared with an appropriate NFC-HOA decoder to +# reproduce correct near-field effects. Keep in mind that despite being +# designed for higher-order ambisonics, this also applies to first-order +# output. When left unset, normal output is created with no near-field +# simulation. Requires the nfc option to also be enabled. nfc-ref-delay = ## quad: diff --git a/utils/alsoft-config/mainwindow.cpp b/utils/alsoft-config/mainwindow.cpp index a83133b3..37ea3dd7 100644 --- a/utils/alsoft-config/mainwindow.cpp +++ b/utils/alsoft-config/mainwindow.cpp @@ -697,7 +697,7 @@ void MainWindow::loadConfig(const QString &fname) ui->decoderHQModeCheckBox->setChecked(hqmode); bool distcomp = settings.value("decoder/distance-comp", true).toBool(); ui->decoderDistCompCheckBox->setChecked(distcomp); - bool nfeffects = settings.value("decoder/nfc", true).toBool(); + bool nfeffects = settings.value("decoder/nfc", false).toBool(); ui->decoderNFEffectsCheckBox->setChecked(nfeffects); double refdelay = settings.value("decoder/nfc-ref-delay", 0.0).toDouble(); ui->decoderNFRefDelaySpinBox->setValue(refdelay); @@ -958,7 +958,7 @@ void MainWindow::saveConfig(const QString &fname) const ui->decoderDistCompCheckBox->isChecked() ? QString(/*"true"*/) : QString("false") ); settings.setValue("decoder/nfc", - ui->decoderNFEffectsCheckBox->isChecked() ? QString(/*"true"*/) : QString("false") + ui->decoderNFEffectsCheckBox->isChecked() ? QString("true") : QString(/*"false"*/) ); double refdelay = ui->decoderNFRefDelaySpinBox->value(); settings.setValue("decoder/nfc-ref-delay", -- cgit v1.2.3 From fb52413a6e1ba40643529343e6660ef760f9635d Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 29 Apr 2019 13:44:16 -0700 Subject: Make a number of settings tristate --- utils/alsoft-config/mainwindow.cpp | 110 +++++++++++++++---------------------- utils/alsoft-config/mainwindow.ui | 26 +++++++-- 2 files changed, 63 insertions(+), 73 deletions(-) (limited to 'utils') diff --git a/utils/alsoft-config/mainwindow.cpp b/utils/alsoft-config/mainwindow.cpp index 37ea3dd7..4e2b2464 100644 --- a/utils/alsoft-config/mainwindow.cpp +++ b/utils/alsoft-config/mainwindow.cpp @@ -210,6 +210,26 @@ static QString getNameFromValue(const NameValuePair (&list)[N], const QString &s return QString(); } + +Qt::CheckState getCheckState(const QVariant &var) +{ + if(var.isNull()) + return Qt::PartiallyChecked; + if(var.toBool()) + return Qt::Checked; + return Qt::Unchecked; +} + +QString getCheckValue(const QCheckBox *checkbox) +{ + const Qt::CheckState state{checkbox->checkState()}; + if(state == Qt::Checked) + return QString("true"); + if(state == Qt::Unchecked) + return QString("false"); + return QString(); +} + } MainWindow::MainWindow(QWidget *parent) : @@ -655,19 +675,8 @@ void MainWindow::loadConfig(const QString &fname) updatePeriodCountSlider(); } - if(settings.value("output-limiter").isNull()) - ui->outputLimiterCheckBox->setCheckState(Qt::PartiallyChecked); - else - ui->outputLimiterCheckBox->setCheckState( - settings.value("output-limiter").toBool() ? Qt::Checked : Qt::Unchecked - ); - - if(settings.value("dither").isNull()) - ui->outputDitherCheckBox->setCheckState(Qt::PartiallyChecked); - else - ui->outputDitherCheckBox->setCheckState( - settings.value("dither").toBool() ? Qt::Checked : Qt::Unchecked - ); + ui->outputLimiterCheckBox->setCheckState(getCheckState(settings.value("output-limiter"))); + ui->outputDitherCheckBox->setCheckState(getCheckState(settings.value("dither"))); QString stereopan = settings.value("stereo-encoding").toString(); ui->stereoEncodingComboBox->setCurrentIndex(0); @@ -695,10 +704,8 @@ void MainWindow::loadConfig(const QString &fname) bool hqmode = settings.value("decoder/hq-mode", false).toBool(); ui->decoderHQModeCheckBox->setChecked(hqmode); - bool distcomp = settings.value("decoder/distance-comp", true).toBool(); - ui->decoderDistCompCheckBox->setChecked(distcomp); - bool nfeffects = settings.value("decoder/nfc", false).toBool(); - ui->decoderNFEffectsCheckBox->setChecked(nfeffects); + ui->decoderDistCompCheckBox->setCheckState(getCheckState(settings.value("decoder/distance-comp"))); + ui->decoderNFEffectsCheckBox->setCheckState(getCheckState(settings.value("decoder/nfc"))); double refdelay = settings.value("decoder/nfc-ref-delay", 0.0).toDouble(); ui->decoderNFRefDelaySpinBox->setValue(refdelay); @@ -853,19 +860,19 @@ void MainWindow::loadConfig(const QString &fname) ui->enableDedicatedCheck->setChecked(!excludefx.contains("dedicated", Qt::CaseInsensitive)); ui->enablePitchShifterCheck->setChecked(!excludefx.contains("pshifter", Qt::CaseInsensitive)); - ui->pulseAutospawnCheckBox->setChecked(settings.value("pulse/spawn-server", true).toBool()); - ui->pulseAllowMovesCheckBox->setChecked(settings.value("pulse/allow-moves", false).toBool()); - ui->pulseFixRateCheckBox->setChecked(settings.value("pulse/fix-rate", false).toBool()); - ui->pulseAdjLatencyCheckBox->setChecked(settings.value("pulse/adjust-latency", false).toBool()); + ui->pulseAutospawnCheckBox->setCheckState(getCheckState(settings.value("pulse/spawn-server"))); + ui->pulseAllowMovesCheckBox->setCheckState(getCheckState(settings.value("pulse/allow-moves"))); + ui->pulseFixRateCheckBox->setCheckState(getCheckState(settings.value("pulse/fix-rate"))); + ui->pulseAdjLatencyCheckBox->setCheckState(getCheckState(settings.value("pulse/adjust-latency"))); - ui->jackAutospawnCheckBox->setChecked(settings.value("jack/spawn-server", false).toBool()); + ui->jackAutospawnCheckBox->setCheckState(getCheckState(settings.value("jack/spawn-server"))); ui->jackBufferSizeLine->setText(settings.value("jack/buffer-size", QString()).toString()); updateJackBufferSizeSlider(); ui->alsaDefaultDeviceLine->setText(settings.value("alsa/device", QString()).toString()); ui->alsaDefaultCaptureLine->setText(settings.value("alsa/capture", QString()).toString()); - ui->alsaResamplerCheckBox->setChecked(settings.value("alsa/allow-resampler", false).toBool()); - ui->alsaMmapCheckBox->setChecked(settings.value("alsa/mmap", true).toBool()); + ui->alsaResamplerCheckBox->setCheckState(getCheckState(settings.value("alsa/allow-resampler"))); + ui->alsaMmapCheckBox->setCheckState(getCheckState(settings.value("alsa/mmap"))); ui->ossDefaultDeviceLine->setText(settings.value("oss/device", QString()).toString()); ui->ossDefaultCaptureLine->setText(settings.value("oss/capture", QString()).toString()); @@ -887,7 +894,7 @@ void MainWindow::saveCurrentConfig() ui->closeCancelButton->setText(tr("Close")); mNeedsSave = false; QMessageBox::information(this, tr("Information"), - tr("Applications using OpenAL need to be restarted for changes to take effect.")); + tr("Applications using OpenAL need to be restarted for changes to take effect.")); } void MainWindow::saveConfigAsFile() @@ -935,31 +942,14 @@ void MainWindow::saveConfig(const QString &fname) const settings.setValue("stereo-encoding", getValueFromName(stereoEncList, ui->stereoEncodingComboBox->currentText())); settings.setValue("ambi-format", getValueFromName(ambiFormatList, ui->ambiFormatComboBox->currentText())); - Qt::CheckState limiter = ui->outputLimiterCheckBox->checkState(); - if(limiter == Qt::PartiallyChecked) - settings.setValue("output-limiter", QString()); - else if(limiter == Qt::Checked) - settings.setValue("output-limiter", QString("true")); - else if(limiter == Qt::Unchecked) - settings.setValue("output-limiter", QString("false")); - - Qt::CheckState dither = ui->outputDitherCheckBox->checkState(); - if(dither == Qt::PartiallyChecked) - settings.setValue("dither", QString()); - else if(dither == Qt::Checked) - settings.setValue("dither", QString("true")); - else if(dither == Qt::Unchecked) - settings.setValue("dither", QString("false")); + settings.setValue("output-limiter", getCheckValue(ui->outputLimiterCheckBox)); + settings.setValue("dither", getCheckValue(ui->outputDitherCheckBox)); settings.setValue("decoder/hq-mode", ui->decoderHQModeCheckBox->isChecked() ? QString("true") : QString(/*"false"*/) ); - settings.setValue("decoder/distance-comp", - ui->decoderDistCompCheckBox->isChecked() ? QString(/*"true"*/) : QString("false") - ); - settings.setValue("decoder/nfc", - ui->decoderNFEffectsCheckBox->isChecked() ? QString("true") : QString(/*"false"*/) - ); + settings.setValue("decoder/distance-comp", getCheckValue(ui->decoderDistCompCheckBox)); + settings.setValue("decoder/nfc", getCheckValue(ui->decoderNFEffectsCheckBox)); double refdelay = ui->decoderNFRefDelaySpinBox->value(); settings.setValue("decoder/nfc-ref-delay", (refdelay > 0.0) ? QString::number(refdelay) : QString() @@ -1074,32 +1064,18 @@ void MainWindow::saveConfig(const QString &fname) const strlist.append("pshifter"); settings.setValue("excludefx", strlist.join(QChar(','))); - settings.setValue("pulse/spawn-server", - ui->pulseAutospawnCheckBox->isChecked() ? QString(/*"true"*/) : QString("false") - ); - settings.setValue("pulse/allow-moves", - ui->pulseAllowMovesCheckBox->isChecked() ? QString("true") : QString(/*"false"*/) - ); - settings.setValue("pulse/fix-rate", - ui->pulseFixRateCheckBox->isChecked() ? QString("true") : QString(/*"false"*/) - ); - settings.setValue("pulse/adjust-latency", - ui->pulseAdjLatencyCheckBox->isChecked() ? QString("true") : QString(/*"false"*/) - ); + settings.setValue("pulse/spawn-server", getCheckValue(ui->pulseAutospawnCheckBox)); + settings.setValue("pulse/allow-moves", getCheckValue(ui->pulseAllowMovesCheckBox)); + settings.setValue("pulse/fix-rate", getCheckValue(ui->pulseFixRateCheckBox)); + settings.setValue("pulse/adjust-latency", getCheckValue(ui->pulseAdjLatencyCheckBox)); - settings.setValue("jack/spawn-server", - ui->jackAutospawnCheckBox->isChecked() ? QString("true") : QString(/*"false"*/) - ); + settings.setValue("jack/spawn-server", getCheckValue(ui->jackAutospawnCheckBox)); settings.setValue("jack/buffer-size", ui->jackBufferSizeLine->text()); settings.setValue("alsa/device", ui->alsaDefaultDeviceLine->text()); settings.setValue("alsa/capture", ui->alsaDefaultCaptureLine->text()); - settings.setValue("alsa/allow-resampler", - ui->alsaResamplerCheckBox->isChecked() ? QString("true") : QString(/*"false"*/) - ); - settings.setValue("alsa/mmap", - ui->alsaMmapCheckBox->isChecked() ? QString(/*"true"*/) : QString("false") - ); + settings.setValue("alsa/allow-resampler", getCheckValue(ui->alsaResamplerCheckBox)); + settings.setValue("alsa/mmap", getCheckValue(ui->alsaMmapCheckBox)); settings.setValue("oss/device", ui->ossDefaultDeviceLine->text()); settings.setValue("oss/capture", ui->ossDefaultCaptureLine->text()); diff --git a/utils/alsoft-config/mainwindow.ui b/utils/alsoft-config/mainwindow.ui index 158a3316..46d1b7a8 100644 --- a/utils/alsoft-config/mainwindow.ui +++ b/utils/alsoft-config/mainwindow.ui @@ -655,7 +655,7 @@ configuration file. Distance Compensation: - + true @@ -847,8 +847,7 @@ creates a more realistic perception of sound distance. Note that the effect may be stronger or weaker than intended if the application doesn't use or specify an appropriate unit scale, or if incorrect speaker distances -are set in the decoder configuration file. Requires High -Quality Mode to be enabled. +are set in the decoder configuration file. Qt::RightToLeft @@ -856,7 +855,7 @@ Quality Mode to be enabled. Near-Field Effects: - + true @@ -1282,7 +1281,7 @@ is not already running. AutoSpawn Server - + true @@ -1304,6 +1303,9 @@ to match the new device. Allow Moving Streams + + true + @@ -1321,6 +1323,9 @@ rate to match the PulseAudio device. Fix Sample Rate + + true + @@ -1341,6 +1346,9 @@ drop-outs. Adjust Latency + + true + @@ -1356,6 +1364,9 @@ drop-outs. AutoSpawn Server + + true + @@ -1497,6 +1508,9 @@ resample pass on top of OpenAL's resampler. Allow Resampler + + true + @@ -1515,7 +1529,7 @@ during updates. MMap Buffer - + true -- cgit v1.2.3 From 3edbeefdb73b650d466b76583c8dac664d4d6ee0 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Thu, 4 Jul 2019 22:59:12 -0700 Subject: Add a setting for hrtf-mode to alsoft-config --- utils/alsoft-config/mainwindow.cpp | 37 ++++++++++++++++++++ utils/alsoft-config/mainwindow.h | 1 + utils/alsoft-config/mainwindow.ui | 71 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+) (limited to 'utils') diff --git a/utils/alsoft-config/mainwindow.cpp b/utils/alsoft-config/mainwindow.cpp index 4e2b2464..687f9134 100644 --- a/utils/alsoft-config/mainwindow.cpp +++ b/utils/alsoft-config/mainwindow.cpp @@ -123,6 +123,14 @@ static const struct NameValuePair { { "ACN, N3D", "acn+n3d" }, { "Furse-Malham", "fuma" }, + { "", "" } +}, hrtfModeList[] = { + { "1st Order Ambisonic", "ambi1" }, + { "2nd Order Ambisonic", "ambi2" }, + { "3rd Order Ambisonic", "ambi3" }, + { "Default (Full)", "" }, + { "Full", "full" }, + { "", "" } }; @@ -267,6 +275,9 @@ MainWindow::MainWindow(QWidget *parent) : } ui->resamplerSlider->setRange(0, count-1); + for(count = 0;hrtfModeList[count].name[0];count++) { + } + ui->hrtfqualitySlider->setRange(0, count-1); ui->hrtfStateComboBox->adjustSize(); #if !defined(HAVE_NEON) && !defined(HAVE_SSE) @@ -367,6 +378,8 @@ MainWindow::MainWindow(QWidget *parent) : connect(ui->preferredHrtfComboBox, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(enableApplyButton())); connect(ui->hrtfStateComboBox, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(enableApplyButton())); + connect(ui->hrtfqualitySlider, SIGNAL(valueChanged(int)), this, SLOT(updateHrtfModeLabel(int))); + connect(ui->hrtfAddButton, SIGNAL(clicked()), this, SLOT(addHrtfFile())); connect(ui->hrtfRemoveButton, SIGNAL(clicked()), this, SLOT(removeHrtfFile())); connect(ui->hrtfFileList, SIGNAL(itemSelectionChanged()), this, SLOT(updateHrtfRemoveButton())); @@ -725,6 +738,21 @@ void MainWindow::loadConfig(const QString &fname) ui->enableSSE41CheckBox->setChecked(!disabledCpuExts.contains("sse4.1", Qt::CaseInsensitive)); ui->enableNeonCheckBox->setChecked(!disabledCpuExts.contains("neon", Qt::CaseInsensitive)); + QString hrtfmode = settings.value("hrtf-mode").toString().trimmed(); + ui->hrtfqualitySlider->setValue(3); + ui->hrtfqualityLabel->setText(hrtfModeList[3].name); + /* The "basic" mode name is no longer supported. Use "ambi2" instead. */ + if(hrtfmode == "basic") hrtfmode = "ambi2"; + for(int i = 0;hrtfModeList[i].name[0];i++) + { + if(hrtfmode == hrtfModeList[i].value) + { + ui->hrtfqualitySlider->setValue(i); + ui->hrtfqualityLabel->setText(hrtfModeList[i].name); + break; + } + } + QStringList hrtf_paths = settings.value("hrtf-paths").toStringList(); if(hrtf_paths.size() == 1) hrtf_paths = hrtf_paths[0].split(QChar(',')); @@ -973,6 +1001,8 @@ void MainWindow::saveConfig(const QString &fname) const strlist.append("neon"); settings.setValue("disable-cpu-exts", strlist.join(QChar(','))); + settings.setValue("hrtf-mode", hrtfModeList[ui->hrtfqualitySlider->value()].value); + if(ui->hrtfStateComboBox->currentIndex() == 1) settings.setValue("hrtf", "true"); else if(ui->hrtfStateComboBox->currentIndex() == 2) @@ -1208,6 +1238,13 @@ void MainWindow::updateJackBufferSizeSlider() } +void MainWindow::updateHrtfModeLabel(int num) +{ + ui->hrtfqualityLabel->setText(hrtfModeList[num].name); + enableApplyButton(); +} + + void MainWindow::addHrtfFile() { QString path = QFileDialog::getExistingDirectory(this, tr("Select HRTF Path")); diff --git a/utils/alsoft-config/mainwindow.h b/utils/alsoft-config/mainwindow.h index 8b763845..ca53582b 100644 --- a/utils/alsoft-config/mainwindow.h +++ b/utils/alsoft-config/mainwindow.h @@ -43,6 +43,7 @@ private slots: void updateJackBufferSizeEdit(int size); void updateJackBufferSizeSlider(); + void updateHrtfModeLabel(int num); void addHrtfFile(); void removeHrtfFile(); diff --git a/utils/alsoft-config/mainwindow.ui b/utils/alsoft-config/mainwindow.ui index 46d1b7a8..7ab27c09 100644 --- a/utils/alsoft-config/mainwindow.ui +++ b/utils/alsoft-config/mainwindow.ui @@ -1122,6 +1122,77 @@ application or system to determine if it should be used. The default HRTF to use if the application doesn't request one. + + + + 50 + 90 + 441 + 81 + + + + HRTF Quality + + + + + 20 + 30 + 51 + 21 + + + + Speed + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 340 + 30 + 51 + 21 + + + + Quality + + + + + + 80 + 30 + 251 + 21 + + + + Qt::Horizontal + + + + + + 50 + 50 + 321 + 21 + + + + Default + + + Qt::AlignCenter + + + -- cgit v1.2.3 From fa032368aeb02d88d86f575977f57057796ca51a Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Fri, 5 Jul 2019 12:27:58 -0700 Subject: Rename HRTF Quality title to HRTF Render Method --- utils/alsoft-config/mainwindow.cpp | 16 ++++++++-------- utils/alsoft-config/mainwindow.ui | 6 +++--- 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'utils') diff --git a/utils/alsoft-config/mainwindow.cpp b/utils/alsoft-config/mainwindow.cpp index 687f9134..64178922 100644 --- a/utils/alsoft-config/mainwindow.cpp +++ b/utils/alsoft-config/mainwindow.cpp @@ -277,7 +277,7 @@ MainWindow::MainWindow(QWidget *parent) : for(count = 0;hrtfModeList[count].name[0];count++) { } - ui->hrtfqualitySlider->setRange(0, count-1); + ui->hrtfmodeSlider->setRange(0, count-1); ui->hrtfStateComboBox->adjustSize(); #if !defined(HAVE_NEON) && !defined(HAVE_SSE) @@ -378,7 +378,7 @@ MainWindow::MainWindow(QWidget *parent) : connect(ui->preferredHrtfComboBox, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(enableApplyButton())); connect(ui->hrtfStateComboBox, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(enableApplyButton())); - connect(ui->hrtfqualitySlider, SIGNAL(valueChanged(int)), this, SLOT(updateHrtfModeLabel(int))); + connect(ui->hrtfmodeSlider, SIGNAL(valueChanged(int)), this, SLOT(updateHrtfModeLabel(int))); connect(ui->hrtfAddButton, SIGNAL(clicked()), this, SLOT(addHrtfFile())); connect(ui->hrtfRemoveButton, SIGNAL(clicked()), this, SLOT(removeHrtfFile())); @@ -739,16 +739,16 @@ void MainWindow::loadConfig(const QString &fname) ui->enableNeonCheckBox->setChecked(!disabledCpuExts.contains("neon", Qt::CaseInsensitive)); QString hrtfmode = settings.value("hrtf-mode").toString().trimmed(); - ui->hrtfqualitySlider->setValue(3); - ui->hrtfqualityLabel->setText(hrtfModeList[3].name); + ui->hrtfmodeSlider->setValue(3); + ui->hrtfmodeLabel->setText(hrtfModeList[3].name); /* The "basic" mode name is no longer supported. Use "ambi2" instead. */ if(hrtfmode == "basic") hrtfmode = "ambi2"; for(int i = 0;hrtfModeList[i].name[0];i++) { if(hrtfmode == hrtfModeList[i].value) { - ui->hrtfqualitySlider->setValue(i); - ui->hrtfqualityLabel->setText(hrtfModeList[i].name); + ui->hrtfmodeSlider->setValue(i); + ui->hrtfmodeLabel->setText(hrtfModeList[i].name); break; } } @@ -1001,7 +1001,7 @@ void MainWindow::saveConfig(const QString &fname) const strlist.append("neon"); settings.setValue("disable-cpu-exts", strlist.join(QChar(','))); - settings.setValue("hrtf-mode", hrtfModeList[ui->hrtfqualitySlider->value()].value); + settings.setValue("hrtf-mode", hrtfModeList[ui->hrtfmodeSlider->value()].value); if(ui->hrtfStateComboBox->currentIndex() == 1) settings.setValue("hrtf", "true"); @@ -1240,7 +1240,7 @@ void MainWindow::updateJackBufferSizeSlider() void MainWindow::updateHrtfModeLabel(int num) { - ui->hrtfqualityLabel->setText(hrtfModeList[num].name); + ui->hrtfmodeLabel->setText(hrtfModeList[num].name); enableApplyButton(); } diff --git a/utils/alsoft-config/mainwindow.ui b/utils/alsoft-config/mainwindow.ui index 7ab27c09..54844226 100644 --- a/utils/alsoft-config/mainwindow.ui +++ b/utils/alsoft-config/mainwindow.ui @@ -1132,7 +1132,7 @@ application or system to determine if it should be used. - HRTF Quality + HRTF Render Method @@ -1163,7 +1163,7 @@ application or system to determine if it should be used. Quality - + 80 @@ -1176,7 +1176,7 @@ application or system to determine if it should be used. Qt::Horizontal - + 50 -- cgit v1.2.3 From 363e2fb73a6dea31db4164531016879aa188da84 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sat, 13 Jul 2019 16:51:19 -0700 Subject: MSVC doesn't like parenthesized type initialization --- utils/makemhr/loadsofa.cpp | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'utils') diff --git a/utils/makemhr/loadsofa.cpp b/utils/makemhr/loadsofa.cpp index b6dd66d9..7fb169e2 100644 --- a/utils/makemhr/loadsofa.cpp +++ b/utils/makemhr/loadsofa.cpp @@ -170,9 +170,8 @@ static bool PrepareLayout(const uint m, const float *xyzs, HrirDataT *hData) mysofa_c2s(&aers[i]); } - const uint fdCount{GetUniquelySortedElems(m, aers.data(), 2, - (const double*[3]){ nullptr, nullptr, nullptr }, (const double[3]){ 0.1, 0.1, 0.001 }, - elems.data())}; + const uint fdCount{GetUniquelySortedElems(m, aers.data(), 2, { nullptr, nullptr, nullptr }, + { 0.1, 0.1, 0.001 }, elems.data())}; if(fdCount > MAX_FD_COUNT) { fprintf(stdout, "Incompatible layout (inumerable radii).\n"); @@ -181,7 +180,6 @@ static bool PrepareLayout(const uint m, const float *xyzs, HrirDataT *hData) double distances[MAX_FD_COUNT]{}; uint evCounts[MAX_FD_COUNT]{}; - uint evStarts[MAX_FD_COUNT]{}; auto azCounts = std::vector(MAX_FD_COUNT * MAX_EV_COUNT); for(uint fi{0u};fi < fdCount;fi++) { @@ -201,9 +199,8 @@ static bool PrepareLayout(const uint m, const float *xyzs, HrirDataT *hData) for(uint fi{0u};fi < fdCount;fi++) { const double dist{distances[fi]}; - uint evCount{GetUniquelySortedElems(m, aers.data(), 1, - (const double*[3]){ nullptr, nullptr, &dist }, (const double[3]){ 0.1, 0.1, 0.001 }, - elems.data())}; + uint evCount{GetUniquelySortedElems(m, aers.data(), 1, { nullptr, nullptr, &dist }, + { 0.1, 0.1, 0.001 }, elems.data())}; if(evCount > MAX_EV_COUNT) { @@ -239,14 +236,12 @@ static bool PrepareLayout(const uint m, const float *xyzs, HrirDataT *hData) } evCounts[fi] = evCount; - evStarts[fi] = evStart; for(uint ei{evStart};ei < evCount;ei++) { const double ev{-90.0 + ei*180.0/(evCount - 1)}; - const uint azCount{GetUniquelySortedElems(m, aers.data(), 0, - (const double*[3]){ nullptr, &ev, &dist }, (const double[3]){ 0.1, 0.1, 0.001 }, - elems.data())}; + const uint azCount{GetUniquelySortedElems(m, aers.data(), 0, { nullptr, &ev, &dist }, + { 0.1, 0.1, 0.001 }, elems.data())}; if(azCount > MAX_AZ_COUNT) { -- cgit v1.2.3 From 313549c76d6049a9c36922a6b13724522b8aad58 Mon Sep 17 00:00:00 2001 From: Penguin Date: Sun, 14 Jul 2019 18:03:32 +0900 Subject: Add missing header. --- utils/makemhr/loaddef.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'utils') diff --git a/utils/makemhr/loaddef.cpp b/utils/makemhr/loaddef.cpp index d3962c16..28f2e1b0 100644 --- a/utils/makemhr/loaddef.cpp +++ b/utils/makemhr/loaddef.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include "mysofa.h" -- cgit v1.2.3 From 4027664fc2d73656d7ec223fb3946d501baa433f Mon Sep 17 00:00:00 2001 From: Penguin Date: Sun, 14 Jul 2019 18:03:49 +0900 Subject: Fixed MSVC error. --- utils/sofa-info.cpp | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'utils') diff --git a/utils/sofa-info.cpp b/utils/sofa-info.cpp index e31ca654..c7c7a8f7 100644 --- a/utils/sofa-info.cpp +++ b/utils/sofa-info.cpp @@ -207,9 +207,7 @@ static void PrintCompatibleLayout(const uint m, const float *xyzs) mysofa_c2s(&aers[i]); } - uint fdCount{GetUniquelySortedElems(m, aers.data(), 2, - (const float*[3]){ nullptr, nullptr, nullptr }, (const float[3]){ 0.1f, 0.1f, 0.001f }, - elems.data())}; + uint fdCount{GetUniquelySortedElems(m, aers.data(), 2, { nullptr, nullptr, nullptr }, { 0.1f, 0.1f, 0.001f }, elems.data())}; if(fdCount > (m / 3)) { fprintf(stdout, "Incompatible layout (inumerable radii).\n"); @@ -223,9 +221,7 @@ static void PrintCompatibleLayout(const uint m, const float *xyzs) for(uint fi{0u};fi < fdCount;fi++) { float dist{fds[fi].mDistance}; - uint evCount{GetUniquelySortedElems(m, aers.data(), 1, - (const float*[3]){ nullptr, nullptr, &dist }, (const float[3]){ 0.1f, 0.1f, 0.001f }, - elems.data())}; + uint evCount{GetUniquelySortedElems(m, aers.data(), 1, { nullptr, nullptr, &dist }, { 0.1f, 0.1f, 0.001f }, elems.data())}; if(evCount > (m / 3)) { @@ -268,9 +264,7 @@ static void PrintCompatibleLayout(const uint m, const float *xyzs) for(uint ei{evStart};ei < evCount;ei++) { float ev{-90.0f + ei * 180.0f / (evCount - 1)}; - uint azCount{GetUniquelySortedElems(m, aers.data(), 0, - (const float*[3]){ nullptr, &ev, &dist }, (const float[3]){ 0.1f, 0.1f, 0.001f }, - elems.data())}; + uint azCount{GetUniquelySortedElems(m, aers.data(), 0, { nullptr, &ev, &dist }, { 0.1f, 0.1f, 0.001f }, elems.data())}; if(azCount > (m / 3)) { -- cgit v1.2.3 From b728cf7bd67ef6952bc021b133be654ebdcef357 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 14 Jul 2019 04:05:08 -0700 Subject: Properly include getopt.h --- utils/makemhr/makemhr.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'utils') diff --git a/utils/makemhr/makemhr.cpp b/utils/makemhr/makemhr.cpp index f6e28937..70ddbe5a 100644 --- a/utils/makemhr/makemhr.cpp +++ b/utils/makemhr/makemhr.cpp @@ -77,7 +77,7 @@ #ifdef HAVE_GETOPT #include #else -#include "getopt.h" +#include "../getopt.h" #endif #include -- cgit v1.2.3 From e0a795d9d2c5696d7f7c79d3e219af84c25a7776 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 28 Jul 2019 14:55:02 -0700 Subject: Clean up some more headers --- utils/makemhr/makemhr.cpp | 41 ++++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 23 deletions(-) (limited to 'utils') diff --git a/utils/makemhr/makemhr.cpp b/utils/makemhr/makemhr.cpp index 70ddbe5a..e480277e 100644 --- a/utils/makemhr/makemhr.cpp +++ b/utils/makemhr/makemhr.cpp @@ -59,45 +59,40 @@ * 1999 */ +#define _UNICODE #include "config.h" -#define _UNICODE +#include "makemhr.h" + +#include +#include +#include +#include +#include +#include #include #include -#include -#include #include -#include -#include -#include -#include -#ifdef HAVE_STRINGS_H -#include -#endif +#include +#include +#include +#include +#include +#include +#include + #ifdef HAVE_GETOPT #include #else #include "../getopt.h" #endif -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "mysofa.h" - -#include "makemhr.h" #include "loaddef.h" #include "loadsofa.h" #include "win_main_utf8.h" + namespace { using namespace std::placeholders; -- cgit v1.2.3 From 42602b9ede2d9ea9ead9c8f32d000388f7642670 Mon Sep 17 00:00:00 2001 From: Raulshc <33253777+Raulshc@users.noreply.github.com> Date: Sun, 18 Aug 2019 18:49:52 +0200 Subject: Alsoft-config: Add vocal morpher effect --- alsoftrc.sample | 2 +- utils/alsoft-config/mainwindow.cpp | 4 ++++ utils/alsoft-config/mainwindow.ui | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) (limited to 'utils') diff --git a/alsoftrc.sample b/alsoftrc.sample index 0128008c..f0dde916 100644 --- a/alsoftrc.sample +++ b/alsoftrc.sample @@ -236,7 +236,7 @@ # help for apps that try to use effects which are too CPU intensive for the # system to handle. Available effects are: eaxreverb,reverb,autowah,chorus, # compressor,distortion,echo,equalizer,flanger,modulator,dedicated,pshifter, -# fshifter +# fshifter,vmorpher. #excludefx = ## default-reverb: (global) diff --git a/utils/alsoft-config/mainwindow.cpp b/utils/alsoft-config/mainwindow.cpp index 64178922..ce14596d 100644 --- a/utils/alsoft-config/mainwindow.cpp +++ b/utils/alsoft-config/mainwindow.cpp @@ -416,6 +416,7 @@ MainWindow::MainWindow(QWidget *parent) : connect(ui->enableModulatorCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); connect(ui->enableDedicatedCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); connect(ui->enablePitchShifterCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); + connect(ui->enableVocalMorpherCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); connect(ui->pulseAutospawnCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); connect(ui->pulseAllowMovesCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); @@ -887,6 +888,7 @@ void MainWindow::loadConfig(const QString &fname) ui->enableModulatorCheck->setChecked(!excludefx.contains("modulator", Qt::CaseInsensitive)); ui->enableDedicatedCheck->setChecked(!excludefx.contains("dedicated", Qt::CaseInsensitive)); ui->enablePitchShifterCheck->setChecked(!excludefx.contains("pshifter", Qt::CaseInsensitive)); + ui->enableVocalMorpherCheck->setChecked(!excludefx.contains("vmorpher", Qt::CaseInsensitive)); ui->pulseAutospawnCheckBox->setCheckState(getCheckState(settings.value("pulse/spawn-server"))); ui->pulseAllowMovesCheckBox->setCheckState(getCheckState(settings.value("pulse/allow-moves"))); @@ -1092,6 +1094,8 @@ void MainWindow::saveConfig(const QString &fname) const strlist.append("dedicated"); if(!ui->enablePitchShifterCheck->isChecked()) strlist.append("pshifter"); + if(!ui->enableVocalMorpherCheck->isChecked()) + strlist.append("vmorpher"); settings.setValue("excludefx", strlist.join(QChar(','))); settings.setValue("pulse/spawn-server", getCheckValue(ui->pulseAutospawnCheckBox)); diff --git a/utils/alsoft-config/mainwindow.ui b/utils/alsoft-config/mainwindow.ui index 54844226..1b73536e 100644 --- a/utils/alsoft-config/mainwindow.ui +++ b/utils/alsoft-config/mainwindow.ui @@ -2264,6 +2264,22 @@ added by the ALC_EXT_DEDICATED extension. true + + + + 320 + 210 + 131 + 21 + + + + Vocal morpher + + + true + + -- cgit v1.2.3 From 3223b6a9060d5d5df2d1d79985f47dff20de8412 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 26 Aug 2019 19:13:31 -0700 Subject: Update mainwindow.cpp Use the less-error-prone pointer-to-member syntax for connect calls, and use uniform initialization more often. --- utils/alsoft-config/mainwindow.cpp | 455 ++++++++++++++++++------------------- 1 file changed, 227 insertions(+), 228 deletions(-) (limited to 'utils') diff --git a/utils/alsoft-config/mainwindow.cpp b/utils/alsoft-config/mainwindow.cpp index ce14596d..3b7b428a 100644 --- a/utils/alsoft-config/mainwindow.cpp +++ b/utils/alsoft-config/mainwindow.cpp @@ -170,7 +170,7 @@ static QString getBaseDataPath() return base; } -static QStringList getAllDataPaths(QString append=QString()) +static QStringList getAllDataPaths(const QString &append) { QStringList list; list.append(getBaseDataPath()); @@ -204,7 +204,7 @@ static QString getValueFromName(const NameValuePair (&list)[N], const QString &s if(str == list[i].name) return list[i].value; } - return QString(); + return QString{}; } template @@ -215,7 +215,7 @@ static QString getNameFromValue(const NameValuePair (&list)[N], const QString &s if(str == list[i].value) return list[i].name; } - return QString(); + return QString{}; } @@ -232,10 +232,10 @@ QString getCheckValue(const QCheckBox *checkbox) { const Qt::CheckState state{checkbox->checkState()}; if(state == Qt::Checked) - return QString("true"); + return QString{"true"}; if(state == Qt::Unchecked) - return QString("false"); - return QString(); + return QString{"false"}; + return QString{}; } } @@ -320,129 +320,131 @@ MainWindow::MainWindow(QWidget *parent) : #endif - mPeriodSizeValidator = new QIntValidator(64, 8192, this); + mPeriodSizeValidator = new QIntValidator{64, 8192, this}; ui->periodSizeEdit->setValidator(mPeriodSizeValidator); - mPeriodCountValidator = new QIntValidator(2, 16, this); + mPeriodCountValidator = new QIntValidator{2, 16, this}; ui->periodCountEdit->setValidator(mPeriodCountValidator); - mSourceCountValidator = new QIntValidator(0, 4096, this); + mSourceCountValidator = new QIntValidator{0, 4096, this}; ui->srcCountLineEdit->setValidator(mSourceCountValidator); - mEffectSlotValidator = new QIntValidator(0, 64, this); + mEffectSlotValidator = new QIntValidator{0, 64, this}; ui->effectSlotLineEdit->setValidator(mEffectSlotValidator); - mSourceSendValidator = new QIntValidator(0, 16, this); + mSourceSendValidator = new QIntValidator{0, 16, this}; ui->srcSendLineEdit->setValidator(mSourceSendValidator); - mSampleRateValidator = new QIntValidator(8000, 192000, this); + mSampleRateValidator = new QIntValidator{8000, 192000, this}; ui->sampleRateCombo->lineEdit()->setValidator(mSampleRateValidator); - mJackBufferValidator = new QIntValidator(0, 8192, this); + mJackBufferValidator = new QIntValidator{0, 8192, this}; ui->jackBufferSizeLine->setValidator(mJackBufferValidator); - connect(ui->actionLoad, SIGNAL(triggered()), this, SLOT(loadConfigFromFile())); - connect(ui->actionSave_As, SIGNAL(triggered()), this, SLOT(saveConfigAsFile())); - - connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(showAboutPage())); - - connect(ui->closeCancelButton, SIGNAL(clicked()), this, SLOT(cancelCloseAction())); - connect(ui->applyButton, SIGNAL(clicked()), this, SLOT(saveCurrentConfig())); - - connect(ui->channelConfigCombo, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(enableApplyButton())); - connect(ui->sampleFormatCombo, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(enableApplyButton())); - connect(ui->stereoModeCombo, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(enableApplyButton())); - connect(ui->sampleRateCombo, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(enableApplyButton())); - connect(ui->sampleRateCombo, SIGNAL(editTextChanged(const QString&)), this, SLOT(enableApplyButton())); - - connect(ui->resamplerSlider, SIGNAL(valueChanged(int)), this, SLOT(updateResamplerLabel(int))); - - connect(ui->periodSizeSlider, SIGNAL(valueChanged(int)), this, SLOT(updatePeriodSizeEdit(int))); - connect(ui->periodSizeEdit, SIGNAL(editingFinished()), this, SLOT(updatePeriodSizeSlider())); - connect(ui->periodCountSlider, SIGNAL(valueChanged(int)), this, SLOT(updatePeriodCountEdit(int))); - connect(ui->periodCountEdit, SIGNAL(editingFinished()), this, SLOT(updatePeriodCountSlider())); - - connect(ui->stereoEncodingComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(enableApplyButton())); - connect(ui->ambiFormatComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(enableApplyButton())); - connect(ui->outputLimiterCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); - connect(ui->outputDitherCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); - - connect(ui->decoderHQModeCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); - connect(ui->decoderDistCompCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); - connect(ui->decoderNFEffectsCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); - connect(ui->decoderNFRefDelaySpinBox, SIGNAL(valueChanged(double)), this, SLOT(enableApplyButton())); - connect(ui->decoderQuadLineEdit, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton())); - connect(ui->decoderQuadButton, SIGNAL(clicked()), this, SLOT(selectQuadDecoderFile())); - connect(ui->decoder51LineEdit, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton())); - connect(ui->decoder51Button, SIGNAL(clicked()), this, SLOT(select51DecoderFile())); - connect(ui->decoder61LineEdit, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton())); - connect(ui->decoder61Button, SIGNAL(clicked()), this, SLOT(select61DecoderFile())); - connect(ui->decoder71LineEdit, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton())); - connect(ui->decoder71Button, SIGNAL(clicked()), this, SLOT(select71DecoderFile())); - - connect(ui->preferredHrtfComboBox, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(enableApplyButton())); - connect(ui->hrtfStateComboBox, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(enableApplyButton())); - connect(ui->hrtfmodeSlider, SIGNAL(valueChanged(int)), this, SLOT(updateHrtfModeLabel(int))); - - connect(ui->hrtfAddButton, SIGNAL(clicked()), this, SLOT(addHrtfFile())); - connect(ui->hrtfRemoveButton, SIGNAL(clicked()), this, SLOT(removeHrtfFile())); - connect(ui->hrtfFileList, SIGNAL(itemSelectionChanged()), this, SLOT(updateHrtfRemoveButton())); - connect(ui->defaultHrtfPathsCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); - - connect(ui->srcCountLineEdit, SIGNAL(editingFinished()), this, SLOT(enableApplyButton())); - connect(ui->srcSendLineEdit, SIGNAL(editingFinished()), this, SLOT(enableApplyButton())); - connect(ui->effectSlotLineEdit, SIGNAL(editingFinished()), this, SLOT(enableApplyButton())); - - connect(ui->enableSSECheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); - connect(ui->enableSSE2CheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); - connect(ui->enableSSE3CheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); - connect(ui->enableSSE41CheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); - connect(ui->enableNeonCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); + connect(ui->actionLoad, &QAction::triggered, this, &MainWindow::loadConfigFromFile); + connect(ui->actionSave_As, &QAction::triggered, this, &MainWindow::saveConfigAsFile); + + connect(ui->actionAbout, &QAction::triggered, this, &MainWindow::showAboutPage); + + connect(ui->closeCancelButton, &QPushButton::clicked, this, &MainWindow::cancelCloseAction); + connect(ui->applyButton, &QPushButton::clicked, this, &MainWindow::saveCurrentConfig); + + auto qcb_cicstr = static_cast(&QComboBox::currentIndexChanged); + connect(ui->channelConfigCombo, qcb_cicstr, this, &MainWindow::enableApplyButton); + connect(ui->sampleFormatCombo, qcb_cicstr, this, &MainWindow::enableApplyButton); + connect(ui->stereoModeCombo, qcb_cicstr, this, &MainWindow::enableApplyButton); + connect(ui->sampleRateCombo, qcb_cicstr, this, &MainWindow::enableApplyButton); + connect(ui->sampleRateCombo, &QComboBox::editTextChanged, this, &MainWindow::enableApplyButton); + + connect(ui->resamplerSlider, &QSlider::valueChanged, this, &MainWindow::updateResamplerLabel); + + connect(ui->periodSizeSlider, &QSlider::valueChanged, this, &MainWindow::updatePeriodSizeEdit); + connect(ui->periodSizeEdit, &QLineEdit::editingFinished, this, &MainWindow::updatePeriodSizeSlider); + connect(ui->periodCountSlider, &QSlider::valueChanged, this, &MainWindow::updatePeriodCountEdit); + connect(ui->periodCountEdit, &QLineEdit::editingFinished, this, &MainWindow::updatePeriodCountSlider); + + connect(ui->stereoEncodingComboBox, qcb_cicstr, this, &MainWindow::enableApplyButton); + connect(ui->ambiFormatComboBox, qcb_cicstr, this, &MainWindow::enableApplyButton); + connect(ui->outputLimiterCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton); + connect(ui->outputDitherCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton); + + connect(ui->decoderHQModeCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton); + connect(ui->decoderDistCompCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton); + connect(ui->decoderNFEffectsCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton); + auto qdsb_vcd = static_cast(&QDoubleSpinBox::valueChanged); + connect(ui->decoderNFRefDelaySpinBox, qdsb_vcd, this, &MainWindow::enableApplyButton); + connect(ui->decoderQuadLineEdit, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton); + connect(ui->decoderQuadButton, &QPushButton::clicked, this, &MainWindow::selectQuadDecoderFile); + connect(ui->decoder51LineEdit, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton); + connect(ui->decoder51Button, &QPushButton::clicked, this, &MainWindow::select51DecoderFile); + connect(ui->decoder61LineEdit, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton); + connect(ui->decoder61Button, &QPushButton::clicked, this, &MainWindow::select61DecoderFile); + connect(ui->decoder71LineEdit, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton); + connect(ui->decoder71Button, &QPushButton::clicked, this, &MainWindow::select71DecoderFile); + + connect(ui->preferredHrtfComboBox, qcb_cicstr, this, &MainWindow::enableApplyButton); + connect(ui->hrtfStateComboBox, qcb_cicstr, this, &MainWindow::enableApplyButton); + connect(ui->hrtfmodeSlider, &QSlider::valueChanged, this, &MainWindow::updateHrtfModeLabel); + + connect(ui->hrtfAddButton, &QPushButton::clicked, this, &MainWindow::addHrtfFile); + connect(ui->hrtfRemoveButton, &QPushButton::clicked, this, &MainWindow::removeHrtfFile); + connect(ui->hrtfFileList, &QListWidget::itemSelectionChanged, this, &MainWindow::updateHrtfRemoveButton); + connect(ui->defaultHrtfPathsCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton); + + connect(ui->srcCountLineEdit, &QLineEdit::editingFinished, this, &MainWindow::enableApplyButton); + connect(ui->srcSendLineEdit, &QLineEdit::editingFinished, this, &MainWindow::enableApplyButton); + connect(ui->effectSlotLineEdit, &QLineEdit::editingFinished, this, &MainWindow::enableApplyButton); + + connect(ui->enableSSECheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton); + connect(ui->enableSSE2CheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton); + connect(ui->enableSSE3CheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton); + connect(ui->enableSSE41CheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton); + connect(ui->enableNeonCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton); ui->enabledBackendList->setContextMenuPolicy(Qt::CustomContextMenu); - connect(ui->enabledBackendList, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showEnabledBackendMenu(QPoint))); + connect(ui->enabledBackendList, &QListWidget::customContextMenuRequested, this, &MainWindow::showEnabledBackendMenu); ui->disabledBackendList->setContextMenuPolicy(Qt::CustomContextMenu); - connect(ui->disabledBackendList, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showDisabledBackendMenu(QPoint))); - connect(ui->backendCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); - - connect(ui->defaultReverbComboBox, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(enableApplyButton())); - connect(ui->enableEaxReverbCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); - connect(ui->enableStdReverbCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); - connect(ui->enableAutowahCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); - connect(ui->enableChorusCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); - connect(ui->enableCompressorCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); - connect(ui->enableDistortionCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); - connect(ui->enableEchoCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); - connect(ui->enableEqualizerCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); - connect(ui->enableFlangerCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); - connect(ui->enableFrequencyShifterCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); - connect(ui->enableModulatorCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); - connect(ui->enableDedicatedCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); - connect(ui->enablePitchShifterCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); - connect(ui->enableVocalMorpherCheck, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); - - connect(ui->pulseAutospawnCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); - connect(ui->pulseAllowMovesCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); - connect(ui->pulseFixRateCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); - connect(ui->pulseAdjLatencyCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); - - connect(ui->jackAutospawnCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); - connect(ui->jackBufferSizeSlider, SIGNAL(valueChanged(int)), this, SLOT(updateJackBufferSizeEdit(int))); - connect(ui->jackBufferSizeLine, SIGNAL(editingFinished()), this, SLOT(updateJackBufferSizeSlider())); - - connect(ui->alsaDefaultDeviceLine, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton())); - connect(ui->alsaDefaultCaptureLine, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton())); - connect(ui->alsaResamplerCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); - connect(ui->alsaMmapCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); - - connect(ui->ossDefaultDeviceLine, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton())); - connect(ui->ossPlaybackPushButton, SIGNAL(clicked(bool)), this, SLOT(selectOSSPlayback())); - connect(ui->ossDefaultCaptureLine, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton())); - connect(ui->ossCapturePushButton, SIGNAL(clicked(bool)), this, SLOT(selectOSSCapture())); - - connect(ui->solarisDefaultDeviceLine, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton())); - connect(ui->solarisPlaybackPushButton, SIGNAL(clicked(bool)), this, SLOT(selectSolarisPlayback())); - - connect(ui->waveOutputLine, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton())); - connect(ui->waveOutputButton, SIGNAL(clicked(bool)), this, SLOT(selectWaveOutput())); - connect(ui->waveBFormatCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableApplyButton())); + connect(ui->disabledBackendList, &QListWidget::customContextMenuRequested, this, &MainWindow::showDisabledBackendMenu); + connect(ui->backendCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton); + + connect(ui->defaultReverbComboBox, qcb_cicstr, this, &MainWindow::enableApplyButton); + connect(ui->enableEaxReverbCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton); + connect(ui->enableStdReverbCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton); + connect(ui->enableAutowahCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton); + connect(ui->enableChorusCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton); + connect(ui->enableCompressorCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton); + connect(ui->enableDistortionCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton); + connect(ui->enableEchoCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton); + connect(ui->enableEqualizerCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton); + connect(ui->enableFlangerCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton); + connect(ui->enableFrequencyShifterCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton); + connect(ui->enableModulatorCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton); + connect(ui->enableDedicatedCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton); + connect(ui->enablePitchShifterCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton); + connect(ui->enableVocalMorpherCheck, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton); + + connect(ui->pulseAutospawnCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton); + connect(ui->pulseAllowMovesCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton); + connect(ui->pulseFixRateCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton); + connect(ui->pulseAdjLatencyCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton); + + connect(ui->jackAutospawnCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton); + connect(ui->jackBufferSizeSlider, &QSlider::valueChanged, this, &MainWindow::updateJackBufferSizeEdit); + connect(ui->jackBufferSizeLine, &QLineEdit::editingFinished, this, &MainWindow::updateJackBufferSizeSlider); + + connect(ui->alsaDefaultDeviceLine, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton); + connect(ui->alsaDefaultCaptureLine, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton); + connect(ui->alsaResamplerCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton); + connect(ui->alsaMmapCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton); + + connect(ui->ossDefaultDeviceLine, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton); + connect(ui->ossPlaybackPushButton, &QPushButton::clicked, this, &MainWindow::selectOSSPlayback); + connect(ui->ossDefaultCaptureLine, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton); + connect(ui->ossCapturePushButton, &QPushButton::clicked, this, &MainWindow::selectOSSCapture); + + connect(ui->solarisDefaultDeviceLine, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton); + connect(ui->solarisPlaybackPushButton, &QPushButton::clicked, this, &MainWindow::selectSolarisPlayback); + + connect(ui->waveOutputLine, &QLineEdit::textChanged, this, &MainWindow::enableApplyButton); + connect(ui->waveOutputButton, &QPushButton::clicked, this, &MainWindow::selectWaveOutput); + connect(ui->waveBFormatCheckBox, &QCheckBox::stateChanged, this, &MainWindow::enableApplyButton); ui->backendListWidget->setCurrentRow(0); ui->tabWidget->setCurrentIndex(0); @@ -481,8 +483,7 @@ void MainWindow::closeEvent(QCloseEvent *event) { QMessageBox::StandardButton btn = QMessageBox::warning(this, tr("Apply changes?"), tr("Save changes before quitting?"), - QMessageBox::Save | QMessageBox::No | QMessageBox::Cancel - ); + QMessageBox::Save | QMessageBox::No | QMessageBox::Cancel); if(btn == QMessageBox::Save) saveCurrentConfig(); if(btn == QMessageBox::Cancel) @@ -503,8 +504,7 @@ void MainWindow::showAboutPage() { QMessageBox::information(this, tr("About"), tr("OpenAL Soft Configuration Utility.\nBuilt for OpenAL Soft library version ")+ - (ALSOFT_VERSION "-" ALSOFT_GIT_COMMIT_HASH " (" ALSOFT_GIT_BRANCH " branch).") - ); + (ALSOFT_VERSION "-" ALSOFT_GIT_COMMIT_HASH " (" ALSOFT_GIT_BRANCH " branch).")); } @@ -521,17 +521,17 @@ QStringList MainWindow::collectHrtfs() { if(!fname.endsWith(".mhr", Qt::CaseInsensitive)) continue; - QString fullname = dir.absoluteFilePath(fname); + QString fullname{dir.absoluteFilePath(fname)}; if(processed.contains(fullname)) continue; processed.push_back(fullname); - QString name = fname.left(fname.length()-4); + QString name{fname.left(fname.length()-4)}; if(!ret.contains(name)) ret.push_back(name); else { - size_t i = 2; + size_t i{2}; do { QString s = name+" #"+QString::number(i); if(!ret.contains(s)) @@ -550,25 +550,25 @@ QStringList MainWindow::collectHrtfs() QStringList paths = getAllDataPaths("/openal/hrtf"); foreach(const QString &name, paths) { - QDir dir(name); - QStringList fnames = dir.entryList(QDir::Files | QDir::Readable, QDir::Name); + QDir dir{name}; + QStringList fnames{dir.entryList(QDir::Files | QDir::Readable, QDir::Name)}; foreach(const QString &fname, fnames) { if(!fname.endsWith(".mhr", Qt::CaseInsensitive)) continue; - QString fullname = dir.absoluteFilePath(fname); + QString fullname{dir.absoluteFilePath(fname)}; if(processed.contains(fullname)) continue; processed.push_back(fullname); - QString name = fname.left(fname.length()-4); + QString name{fname.left(fname.length()-4)}; if(!ret.contains(name)) ret.push_back(name); else { - size_t i = 2; + size_t i{2}; do { - QString s = name+" #"+QString::number(i); + QString s{name+" #"+QString::number(i)}; if(!ret.contains(s)) { ret.push_back(s); @@ -598,33 +598,33 @@ void MainWindow::loadConfigFromFile() void MainWindow::loadConfig(const QString &fname) { - QSettings settings(fname, QSettings::IniFormat); + QSettings settings{fname, QSettings::IniFormat}; QString sampletype = settings.value("sample-type").toString(); ui->sampleFormatCombo->setCurrentIndex(0); if(sampletype.isEmpty() == false) { - QString str = getNameFromValue(sampleTypeList, sampletype); + QString str{getNameFromValue(sampleTypeList, sampletype)}; if(!str.isEmpty()) { - int j = ui->sampleFormatCombo->findText(str); + const int j{ui->sampleFormatCombo->findText(str)}; if(j > 0) ui->sampleFormatCombo->setCurrentIndex(j); } } - QString channelconfig = settings.value("channels").toString(); + QString channelconfig{settings.value("channels").toString()}; ui->channelConfigCombo->setCurrentIndex(0); if(channelconfig.isEmpty() == false) { - QString str = getNameFromValue(speakerModeList, channelconfig); + QString str{getNameFromValue(speakerModeList, channelconfig)}; if(!str.isEmpty()) { - int j = ui->channelConfigCombo->findText(str); + const int j{ui->channelConfigCombo->findText(str)}; if(j > 0) ui->channelConfigCombo->setCurrentIndex(j); } } - QString srate = settings.value("frequency").toString(); + QString srate{settings.value("frequency").toString()}; if(srate.isEmpty()) ui->sampleRateCombo->setCurrentIndex(0); else @@ -665,15 +665,15 @@ void MainWindow::loadConfig(const QString &fname) ui->stereoModeCombo->setCurrentIndex(0); if(stereomode.isEmpty() == false) { - QString str = getNameFromValue(stereoModeList, stereomode); + QString str{getNameFromValue(stereoModeList, stereomode)}; if(!str.isEmpty()) { - int j = ui->stereoModeCombo->findText(str); + const int j{ui->stereoModeCombo->findText(str)}; if(j > 0) ui->stereoModeCombo->setCurrentIndex(j); } } - int periodsize = settings.value("period_size").toInt(); + int periodsize{settings.value("period_size").toInt()}; ui->periodSizeEdit->clear(); if(periodsize >= 64) { @@ -681,7 +681,7 @@ void MainWindow::loadConfig(const QString &fname) updatePeriodSizeSlider(); } - int periodcount = settings.value("periods").toInt(); + int periodcount{settings.value("periods").toInt()}; ui->periodCountEdit->clear(); if(periodcount >= 2) { @@ -692,35 +692,35 @@ void MainWindow::loadConfig(const QString &fname) ui->outputLimiterCheckBox->setCheckState(getCheckState(settings.value("output-limiter"))); ui->outputDitherCheckBox->setCheckState(getCheckState(settings.value("dither"))); - QString stereopan = settings.value("stereo-encoding").toString(); + QString stereopan{settings.value("stereo-encoding").toString()}; ui->stereoEncodingComboBox->setCurrentIndex(0); if(stereopan.isEmpty() == false) { - QString str = getNameFromValue(stereoEncList, stereopan); + QString str{getNameFromValue(stereoEncList, stereopan)}; if(!str.isEmpty()) { - int j = ui->stereoEncodingComboBox->findText(str); + const int j{ui->stereoEncodingComboBox->findText(str)}; if(j > 0) ui->stereoEncodingComboBox->setCurrentIndex(j); } } - QString ambiformat = settings.value("ambi-format").toString(); + QString ambiformat{settings.value("ambi-format").toString()}; ui->ambiFormatComboBox->setCurrentIndex(0); if(ambiformat.isEmpty() == false) { - QString str = getNameFromValue(ambiFormatList, ambiformat); + QString str{getNameFromValue(ambiFormatList, ambiformat)}; if(!str.isEmpty()) { - int j = ui->ambiFormatComboBox->findText(str); + const int j{ui->ambiFormatComboBox->findText(str)}; if(j > 0) ui->ambiFormatComboBox->setCurrentIndex(j); } } - bool hqmode = settings.value("decoder/hq-mode", false).toBool(); + bool hqmode{settings.value("decoder/hq-mode", false).toBool()}; ui->decoderHQModeCheckBox->setChecked(hqmode); ui->decoderDistCompCheckBox->setCheckState(getCheckState(settings.value("decoder/distance-comp"))); ui->decoderNFEffectsCheckBox->setCheckState(getCheckState(settings.value("decoder/nfc"))); - double refdelay = settings.value("decoder/nfc-ref-delay", 0.0).toDouble(); + double refdelay{settings.value("decoder/nfc-ref-delay", 0.0).toDouble()}; ui->decoderNFRefDelaySpinBox->setValue(refdelay); ui->decoderQuadLineEdit->setText(settings.value("decoder/quad").toString()); @@ -728,18 +728,18 @@ void MainWindow::loadConfig(const QString &fname) ui->decoder61LineEdit->setText(settings.value("decoder/surround61").toString()); ui->decoder71LineEdit->setText(settings.value("decoder/surround71").toString()); - QStringList disabledCpuExts = settings.value("disable-cpu-exts").toStringList(); + QStringList disabledCpuExts{settings.value("disable-cpu-exts").toStringList()}; if(disabledCpuExts.size() == 1) disabledCpuExts = disabledCpuExts[0].split(QChar(',')); - for(QStringList::iterator iter = disabledCpuExts.begin();iter != disabledCpuExts.end();iter++) - *iter = iter->trimmed(); + for(QString &name : disabledCpuExts) + name = name.trimmed(); ui->enableSSECheckBox->setChecked(!disabledCpuExts.contains("sse", Qt::CaseInsensitive)); ui->enableSSE2CheckBox->setChecked(!disabledCpuExts.contains("sse2", Qt::CaseInsensitive)); ui->enableSSE3CheckBox->setChecked(!disabledCpuExts.contains("sse3", Qt::CaseInsensitive)); ui->enableSSE41CheckBox->setChecked(!disabledCpuExts.contains("sse4.1", Qt::CaseInsensitive)); ui->enableNeonCheckBox->setChecked(!disabledCpuExts.contains("neon", Qt::CaseInsensitive)); - QString hrtfmode = settings.value("hrtf-mode").toString().trimmed(); + QString hrtfmode{settings.value("hrtf-mode").toString().trimmed()}; ui->hrtfmodeSlider->setValue(3); ui->hrtfmodeLabel->setText(hrtfModeList[3].name); /* The "basic" mode name is no longer supported. Use "ambi2" instead. */ @@ -754,11 +754,11 @@ void MainWindow::loadConfig(const QString &fname) } } - QStringList hrtf_paths = settings.value("hrtf-paths").toStringList(); + QStringList hrtf_paths{settings.value("hrtf-paths").toStringList()}; if(hrtf_paths.size() == 1) hrtf_paths = hrtf_paths[0].split(QChar(',')); - for(QStringList::iterator iter = hrtf_paths.begin();iter != hrtf_paths.end();iter++) - *iter = iter->trimmed(); + for(QString &name : hrtf_paths) + name = name.trimmed(); if(!hrtf_paths.empty() && !hrtf_paths.back().isEmpty()) ui->defaultHrtfPathsCheckBox->setCheckState(Qt::Unchecked); else @@ -771,7 +771,7 @@ void MainWindow::loadConfig(const QString &fname) ui->hrtfFileList->addItems(hrtf_paths); updateHrtfRemoveButton(); - QString hrtfstate = settings.value("hrtf").toString().toLower(); + QString hrtfstate{settings.value("hrtf").toString().toLower()}; if(hrtfstate == "true") ui->hrtfStateComboBox->setCurrentIndex(1); else if(hrtfstate == "false") @@ -783,16 +783,16 @@ void MainWindow::loadConfig(const QString &fname) ui->preferredHrtfComboBox->addItem("- Any -"); if(ui->defaultHrtfPathsCheckBox->isChecked()) { - QStringList hrtfs = collectHrtfs(); + QStringList hrtfs{collectHrtfs()}; foreach(const QString &name, hrtfs) ui->preferredHrtfComboBox->addItem(name); } - QString defaulthrtf = settings.value("default-hrtf").toString(); + QString defaulthrtf{settings.value("default-hrtf").toString()}; ui->preferredHrtfComboBox->setCurrentIndex(0); if(defaulthrtf.isEmpty() == false) { - int i = ui->preferredHrtfComboBox->findText(defaulthrtf); + int i{ui->preferredHrtfComboBox->findText(defaulthrtf)}; if(i > 0) ui->preferredHrtfComboBox->setCurrentIndex(i); else @@ -806,23 +806,23 @@ void MainWindow::loadConfig(const QString &fname) ui->enabledBackendList->clear(); ui->disabledBackendList->clear(); - QStringList drivers = settings.value("drivers").toStringList(); + QStringList drivers{settings.value("drivers").toStringList()}; if(drivers.size() == 0) ui->backendCheckBox->setChecked(true); else { if(drivers.size() == 1) drivers = drivers[0].split(QChar(',')); - for(QStringList::iterator iter = drivers.begin();iter != drivers.end();iter++) + for(QString &name : drivers) { - *iter = iter->trimmed(); + name = name.trimmed(); /* Convert "mmdevapi" references to "wasapi" for backwards * compatibility. */ - if(*iter == "-mmdevapi") - *iter = "-wasapi"; - else if(*iter == "mmdevapi") - *iter = "wasapi"; + if(name == "-mmdevapi") + name = "-wasapi"; + else if(name == "mmdevapi") + name = "wasapi"; } bool lastWasEmpty = false; @@ -842,7 +842,7 @@ void MainWindow::loadConfig(const QString &fname) } else if(backend.size() > 1) { - QStringRef backendref = backend.rightRef(backend.size()-1); + QStringRef backendref{backend.rightRef(backend.size()-1)}; for(int j = 0;backendList[j].backend_name[0];j++) { if(backendref == backendList[j].backend_name) @@ -856,7 +856,7 @@ void MainWindow::loadConfig(const QString &fname) ui->backendCheckBox->setChecked(lastWasEmpty); } - QString defaultreverb = settings.value("default-reverb").toString().toLower(); + QString defaultreverb{settings.value("default-reverb").toString().toLower()}; ui->defaultReverbComboBox->setCurrentIndex(0); if(defaultreverb.isEmpty() == false) { @@ -870,11 +870,11 @@ void MainWindow::loadConfig(const QString &fname) } } - QStringList excludefx = settings.value("excludefx").toStringList(); + QStringList excludefx{settings.value("excludefx").toStringList()}; if(excludefx.size() == 1) excludefx = excludefx[0].split(QChar(',')); - for(QStringList::iterator iter = excludefx.begin();iter != excludefx.end();iter++) - *iter = iter->trimmed(); + for(QString &name : excludefx) + name = name.trimmed(); ui->enableEaxReverbCheck->setChecked(!excludefx.contains("eaxreverb", Qt::CaseInsensitive)); ui->enableStdReverbCheck->setChecked(!excludefx.contains("reverb", Qt::CaseInsensitive)); ui->enableAutowahCheck->setChecked(!excludefx.contains("autowah", Qt::CaseInsensitive)); @@ -929,7 +929,7 @@ void MainWindow::saveCurrentConfig() void MainWindow::saveConfigAsFile() { - QString fname = QFileDialog::getOpenFileName(this, tr("Select Files")); + QString fname{QFileDialog::getOpenFileName(this, tr("Select Files"))}; if(fname.isEmpty() == false) { saveConfig(fname); @@ -940,13 +940,13 @@ void MainWindow::saveConfigAsFile() void MainWindow::saveConfig(const QString &fname) const { - QSettings settings(fname, QSettings::IniFormat); + QSettings settings{fname, QSettings::IniFormat}; /* HACK: Compound any stringlist values into a comma-separated string. */ - QStringList allkeys = settings.allKeys(); + QStringList allkeys{settings.allKeys()}; foreach(const QString &key, allkeys) { - QStringList vals = settings.value(key).toStringList(); + QStringList vals{settings.value(key).toStringList()}; if(vals.size() > 1) settings.setValue(key, vals.join(QChar(','))); } @@ -954,9 +954,9 @@ void MainWindow::saveConfig(const QString &fname) const settings.setValue("sample-type", getValueFromName(sampleTypeList, ui->sampleFormatCombo->currentText())); settings.setValue("channels", getValueFromName(speakerModeList, ui->channelConfigCombo->currentText())); - uint rate = ui->sampleRateCombo->currentText().toUInt(); + uint rate{ui->sampleRateCombo->currentText().toUInt()}; if(rate <= 0) - settings.setValue("frequency", QString()); + settings.setValue("frequency", QString{}); else settings.setValue("frequency", rate); @@ -976,13 +976,13 @@ void MainWindow::saveConfig(const QString &fname) const settings.setValue("dither", getCheckValue(ui->outputDitherCheckBox)); settings.setValue("decoder/hq-mode", - ui->decoderHQModeCheckBox->isChecked() ? QString("true") : QString(/*"false"*/) + ui->decoderHQModeCheckBox->isChecked() ? QString{"true"} : QString{/*"false"*/} ); settings.setValue("decoder/distance-comp", getCheckValue(ui->decoderDistCompCheckBox)); settings.setValue("decoder/nfc", getCheckValue(ui->decoderNFEffectsCheckBox)); double refdelay = ui->decoderNFRefDelaySpinBox->value(); settings.setValue("decoder/nfc-ref-delay", - (refdelay > 0.0) ? QString::number(refdelay) : QString() + (refdelay > 0.0) ? QString::number(refdelay) : QString{} ); settings.setValue("decoder/quad", ui->decoderQuadLineEdit->text()); @@ -1010,27 +1010,28 @@ void MainWindow::saveConfig(const QString &fname) const else if(ui->hrtfStateComboBox->currentIndex() == 2) settings.setValue("hrtf", "false"); else - settings.setValue("hrtf", QString()); + settings.setValue("hrtf", QString{}); if(ui->preferredHrtfComboBox->currentIndex() == 0) - settings.setValue("default-hrtf", QString()); + settings.setValue("default-hrtf", QString{}); else { - QString str = ui->preferredHrtfComboBox->currentText(); + QString str{ui->preferredHrtfComboBox->currentText()}; settings.setValue("default-hrtf", str); } strlist.clear(); + strlist.reserve(ui->hrtfFileList->count()); for(int i = 0;i < ui->hrtfFileList->count();i++) strlist.append(ui->hrtfFileList->item(i)->text()); if(!strlist.empty() && ui->defaultHrtfPathsCheckBox->isChecked()) - strlist.append(QString()); - settings.setValue("hrtf-paths", strlist.join(QChar(','))); + strlist.append(QString{}); + settings.setValue("hrtf-paths", strlist.join(QChar{','})); strlist.clear(); for(int i = 0;i < ui->enabledBackendList->count();i++) { - QString label = ui->enabledBackendList->item(i)->text(); + QString label{ui->enabledBackendList->item(i)->text()}; for(int j = 0;backendList[j].backend_name[0];j++) { if(label == backendList[j].full_string) @@ -1042,12 +1043,12 @@ void MainWindow::saveConfig(const QString &fname) const } for(int i = 0;i < ui->disabledBackendList->count();i++) { - QString label = ui->disabledBackendList->item(i)->text(); + QString label{ui->disabledBackendList->item(i)->text()}; for(int j = 0;backendList[j].backend_name[0];j++) { if(label == backendList[j].full_string) { - strlist.append(QChar('-')+QString(backendList[j].backend_name)); + strlist.append(QChar{'-'}+QString{backendList[j].backend_name}); break; } } @@ -1055,15 +1056,15 @@ void MainWindow::saveConfig(const QString &fname) const if(strlist.size() == 0 && !ui->backendCheckBox->isChecked()) strlist.append("-all"); else if(ui->backendCheckBox->isChecked()) - strlist.append(QString()); + strlist.append(QString{}); settings.setValue("drivers", strlist.join(QChar(','))); // TODO: Remove check when we can properly match global values. if(ui->defaultReverbComboBox->currentIndex() == 0) - settings.setValue("default-reverb", QString()); + settings.setValue("default-reverb", QString{}); else { - QString str = ui->defaultReverbComboBox->currentText().toLower(); + QString str{ui->defaultReverbComboBox->currentText().toLower()}; settings.setValue("default-reverb", str); } @@ -1096,7 +1097,7 @@ void MainWindow::saveConfig(const QString &fname) const strlist.append("pshifter"); if(!ui->enableVocalMorpherCheck->isChecked()) strlist.append("vmorpher"); - settings.setValue("excludefx", strlist.join(QChar(','))); + settings.setValue("excludefx", strlist.join(QChar{','})); settings.setValue("pulse/spawn-server", getCheckValue(ui->pulseAutospawnCheckBox)); settings.setValue("pulse/allow-moves", getCheckValue(ui->pulseAllowMovesCheckBox)); @@ -1118,7 +1119,7 @@ void MainWindow::saveConfig(const QString &fname) const settings.setValue("wave/file", ui->waveOutputLine->text()); settings.setValue("wave/bformat", - ui->waveBFormatCheckBox->isChecked() ? QString("true") : QString(/*"false"*/) + ui->waveBFormatCheckBox->isChecked() ? QString{"true"} : QString{/*"false"*/} ); /* Remove empty keys @@ -1127,8 +1128,8 @@ void MainWindow::saveConfig(const QString &fname) const allkeys = settings.allKeys(); foreach(const QString &key, allkeys) { - QString str = settings.value(key).toString(); - if(str == QString()) + QString str{settings.value(key).toString()}; + if(str == QString{}) settings.remove(key); } } @@ -1200,13 +1201,13 @@ void MainWindow::select71DecoderFile() { selectDecoderFile(ui->decoder71LineEdit, "Select 7.1 Surround Decoder");} void MainWindow::selectDecoderFile(QLineEdit *line, const char *caption) { - QString dir = line->text(); + QString dir{line->text()}; if(dir.isEmpty() || QDir::isRelativePath(dir)) { - QStringList paths = getAllDataPaths("/openal/presets"); + QStringList paths{getAllDataPaths("/openal/presets")}; while(!paths.isEmpty()) { - if(QDir(paths.last()).exists()) + if(QDir{paths.last()}.exists()) { dir = paths.last(); break; @@ -1214,9 +1215,8 @@ void MainWindow::selectDecoderFile(QLineEdit *line, const char *caption) paths.removeLast(); } } - QString fname = QFileDialog::getOpenFileName(this, tr(caption), - dir, tr("AmbDec Files (*.ambdec);;All Files (*.*)") - ); + QString fname{QFileDialog::getOpenFileName(this, tr(caption), + dir, tr("AmbDec Files (*.ambdec);;All Files (*.*)"))}; if(!fname.isEmpty()) { line->setText(fname); @@ -1235,8 +1235,8 @@ void MainWindow::updateJackBufferSizeEdit(int size) void MainWindow::updateJackBufferSizeSlider() { - int value = ui->jackBufferSizeLine->text().toInt(); - int pos = static_cast(floor(log2(value) + 0.5)); + int value{ui->jackBufferSizeLine->text().toInt()}; + auto pos = static_cast(floor(log2(value) + 0.5)); ui->jackBufferSizeSlider->setSliderPosition(pos); enableApplyButton(); } @@ -1251,7 +1251,7 @@ void MainWindow::updateHrtfModeLabel(int num) void MainWindow::addHrtfFile() { - QString path = QFileDialog::getExistingDirectory(this, tr("Select HRTF Path")); + QString path{QFileDialog::getExistingDirectory(this, tr("Select HRTF Path"))}; if(path.isEmpty() == false && !getAllDataPaths("/openal/hrtf").contains(path)) { ui->hrtfFileList->addItem(path); @@ -1261,7 +1261,7 @@ void MainWindow::addHrtfFile() void MainWindow::removeHrtfFile() { - QList selected = ui->hrtfFileList->selectedItems(); + QList selected{ui->hrtfFileList->selectedItems()}; if(!selected.isEmpty()) { foreach(QListWidgetItem *item, selected) @@ -1277,37 +1277,37 @@ void MainWindow::updateHrtfRemoveButton() void MainWindow::showEnabledBackendMenu(QPoint pt) { - QMap actionMap; + QHash actionMap; pt = ui->enabledBackendList->mapToGlobal(pt); QMenu ctxmenu; - QAction *removeAction = ctxmenu.addAction(QIcon::fromTheme("list-remove"), "Remove"); + QAction *removeAction{ctxmenu.addAction(QIcon::fromTheme("list-remove"), "Remove")}; if(ui->enabledBackendList->selectedItems().size() == 0) removeAction->setEnabled(false); ctxmenu.addSeparator(); for(size_t i = 0;backendList[i].backend_name[0];i++) { - QString backend = backendList[i].full_string; - QAction *action = ctxmenu.addAction(QString("Add ")+backend); + QString backend{backendList[i].full_string}; + QAction *action{ctxmenu.addAction(QString("Add ")+backend)}; actionMap[action] = backend; if(ui->enabledBackendList->findItems(backend, Qt::MatchFixedString).size() != 0 || ui->disabledBackendList->findItems(backend, Qt::MatchFixedString).size() != 0) action->setEnabled(false); } - QAction *gotAction = ctxmenu.exec(pt); + QAction *gotAction{ctxmenu.exec(pt)}; if(gotAction == removeAction) { - QList selected = ui->enabledBackendList->selectedItems(); + QList selected{ui->enabledBackendList->selectedItems()}; foreach(QListWidgetItem *item, selected) delete item; enableApplyButton(); } else if(gotAction != nullptr) { - QMap::const_iterator iter = actionMap.find(gotAction); - if(iter != actionMap.end()) + auto iter = actionMap.constFind(gotAction); + if(iter != actionMap.cend()) ui->enabledBackendList->addItem(iter.value()); enableApplyButton(); } @@ -1315,37 +1315,37 @@ void MainWindow::showEnabledBackendMenu(QPoint pt) void MainWindow::showDisabledBackendMenu(QPoint pt) { - QMap actionMap; + QHash actionMap; pt = ui->disabledBackendList->mapToGlobal(pt); QMenu ctxmenu; - QAction *removeAction = ctxmenu.addAction(QIcon::fromTheme("list-remove"), "Remove"); + QAction *removeAction{ctxmenu.addAction(QIcon::fromTheme("list-remove"), "Remove")}; if(ui->disabledBackendList->selectedItems().size() == 0) removeAction->setEnabled(false); ctxmenu.addSeparator(); for(size_t i = 0;backendList[i].backend_name[0];i++) { - QString backend = backendList[i].full_string; - QAction *action = ctxmenu.addAction(QString("Add ")+backend); + QString backend{backendList[i].full_string}; + QAction *action{ctxmenu.addAction(QString("Add ")+backend)}; actionMap[action] = backend; if(ui->disabledBackendList->findItems(backend, Qt::MatchFixedString).size() != 0 || ui->enabledBackendList->findItems(backend, Qt::MatchFixedString).size() != 0) action->setEnabled(false); } - QAction *gotAction = ctxmenu.exec(pt); + QAction *gotAction{ctxmenu.exec(pt)}; if(gotAction == removeAction) { - QList selected = ui->disabledBackendList->selectedItems(); + QList selected{ui->disabledBackendList->selectedItems()}; foreach(QListWidgetItem *item, selected) delete item; enableApplyButton(); } else if(gotAction != nullptr) { - QMap::const_iterator iter = actionMap.find(gotAction); - if(iter != actionMap.end()) + auto iter = actionMap.constFind(gotAction); + if(iter != actionMap.cend()) ui->disabledBackendList->addItem(iter.value()); enableApplyButton(); } @@ -1353,9 +1353,9 @@ void MainWindow::showDisabledBackendMenu(QPoint pt) void MainWindow::selectOSSPlayback() { - QString current = ui->ossDefaultDeviceLine->text(); + QString current{ui->ossDefaultDeviceLine->text()}; if(current.isEmpty()) current = ui->ossDefaultDeviceLine->placeholderText(); - QString fname = QFileDialog::getOpenFileName(this, tr("Select Playback Device"), current); + QString fname{QFileDialog::getOpenFileName(this, tr("Select Playback Device"), current)}; if(!fname.isEmpty()) { ui->ossDefaultDeviceLine->setText(fname); @@ -1365,9 +1365,9 @@ void MainWindow::selectOSSPlayback() void MainWindow::selectOSSCapture() { - QString current = ui->ossDefaultCaptureLine->text(); + QString current{ui->ossDefaultCaptureLine->text()}; if(current.isEmpty()) current = ui->ossDefaultCaptureLine->placeholderText(); - QString fname = QFileDialog::getOpenFileName(this, tr("Select Capture Device"), current); + QString fname{QFileDialog::getOpenFileName(this, tr("Select Capture Device"), current)}; if(!fname.isEmpty()) { ui->ossDefaultCaptureLine->setText(fname); @@ -1377,9 +1377,9 @@ void MainWindow::selectOSSCapture() void MainWindow::selectSolarisPlayback() { - QString current = ui->solarisDefaultDeviceLine->text(); + QString current{ui->solarisDefaultDeviceLine->text()}; if(current.isEmpty()) current = ui->solarisDefaultDeviceLine->placeholderText(); - QString fname = QFileDialog::getOpenFileName(this, tr("Select Playback Device"), current); + QString fname{QFileDialog::getOpenFileName(this, tr("Select Playback Device"), current)}; if(!fname.isEmpty()) { ui->solarisDefaultDeviceLine->setText(fname); @@ -1389,9 +1389,8 @@ void MainWindow::selectSolarisPlayback() void MainWindow::selectWaveOutput() { - QString fname = QFileDialog::getSaveFileName(this, tr("Select Wave File Output"), - ui->waveOutputLine->text(), tr("Wave Files (*.wav *.amb);;All Files (*.*)") - ); + QString fname{QFileDialog::getSaveFileName(this, tr("Select Wave File Output"), + ui->waveOutputLine->text(), tr("Wave Files (*.wav *.amb);;All Files (*.*)"))}; if(!fname.isEmpty()) { ui->waveOutputLine->setText(fname); -- cgit v1.2.3 From 5becf4bb73ffc448dbad5ba6dd9377f3c8ab8697 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sat, 31 Aug 2019 21:47:58 -0700 Subject: Don't include version.h in mainwindow.cpp Should help with post-commit compile times --- utils/alsoft-config/CMakeLists.txt | 2 ++ utils/alsoft-config/mainwindow.cpp | 8 ++++---- utils/alsoft-config/verstr.cpp | 10 ++++++++++ utils/alsoft-config/verstr.h | 6 ++++++ 4 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 utils/alsoft-config/verstr.cpp create mode 100644 utils/alsoft-config/verstr.h (limited to 'utils') diff --git a/utils/alsoft-config/CMakeLists.txt b/utils/alsoft-config/CMakeLists.txt index 7996ee97..68b9e9de 100644 --- a/utils/alsoft-config/CMakeLists.txt +++ b/utils/alsoft-config/CMakeLists.txt @@ -8,6 +8,8 @@ set(alsoft-config_SRCS main.cpp mainwindow.cpp mainwindow.h + verstr.cpp + verstr.h ) set(alsoft-config_UIS mainwindow.ui) set(alsoft-config_MOCS mainwindow.h) diff --git a/utils/alsoft-config/mainwindow.cpp b/utils/alsoft-config/mainwindow.cpp index 3b7b428a..c0c0e1e5 100644 --- a/utils/alsoft-config/mainwindow.cpp +++ b/utils/alsoft-config/mainwindow.cpp @@ -1,7 +1,7 @@ #include "config.h" -#include "version.h" +#include "mainwindow.h" #include #include @@ -11,8 +11,8 @@ #include #include #include -#include "mainwindow.h" #include "ui_mainwindow.h" +#include "verstr.h" namespace { @@ -503,8 +503,8 @@ void MainWindow::cancelCloseAction() void MainWindow::showAboutPage() { QMessageBox::information(this, tr("About"), - tr("OpenAL Soft Configuration Utility.\nBuilt for OpenAL Soft library version ")+ - (ALSOFT_VERSION "-" ALSOFT_GIT_COMMIT_HASH " (" ALSOFT_GIT_BRANCH " branch).")); + tr("OpenAL Soft Configuration Utility.\nBuilt for OpenAL Soft library version ") + + tr(GetVersionString())); } diff --git a/utils/alsoft-config/verstr.cpp b/utils/alsoft-config/verstr.cpp new file mode 100644 index 00000000..b2fd0a17 --- /dev/null +++ b/utils/alsoft-config/verstr.cpp @@ -0,0 +1,10 @@ + +#include "verstr.h" + +#include "version.h" + + +const char *GetVersionString() +{ + return ALSOFT_VERSION "-" ALSOFT_GIT_COMMIT_HASH " (" ALSOFT_GIT_BRANCH " branch)."; +} diff --git a/utils/alsoft-config/verstr.h b/utils/alsoft-config/verstr.h new file mode 100644 index 00000000..a97f0895 --- /dev/null +++ b/utils/alsoft-config/verstr.h @@ -0,0 +1,6 @@ +#ifndef VERSTR_H +#define VERSTR_H + +const char *GetVersionString(); + +#endif /* VERSTR_H */ -- cgit v1.2.3 From a15f25b07ad442890bb9a75a7ef7f43cf5ab2ef4 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sat, 31 Aug 2019 22:28:26 -0700 Subject: Return a QString from GetVersionString --- utils/alsoft-config/mainwindow.cpp | 2 +- utils/alsoft-config/verstr.cpp | 4 ++-- utils/alsoft-config/verstr.h | 4 +++- 3 files changed, 6 insertions(+), 4 deletions(-) (limited to 'utils') diff --git a/utils/alsoft-config/mainwindow.cpp b/utils/alsoft-config/mainwindow.cpp index c0c0e1e5..aa0df438 100644 --- a/utils/alsoft-config/mainwindow.cpp +++ b/utils/alsoft-config/mainwindow.cpp @@ -504,7 +504,7 @@ void MainWindow::showAboutPage() { QMessageBox::information(this, tr("About"), tr("OpenAL Soft Configuration Utility.\nBuilt for OpenAL Soft library version ") + - tr(GetVersionString())); + GetVersionString()); } diff --git a/utils/alsoft-config/verstr.cpp b/utils/alsoft-config/verstr.cpp index b2fd0a17..42b1aeac 100644 --- a/utils/alsoft-config/verstr.cpp +++ b/utils/alsoft-config/verstr.cpp @@ -4,7 +4,7 @@ #include "version.h" -const char *GetVersionString() +QString GetVersionString() { - return ALSOFT_VERSION "-" ALSOFT_GIT_COMMIT_HASH " (" ALSOFT_GIT_BRANCH " branch)."; + return QStringLiteral(ALSOFT_VERSION "-" ALSOFT_GIT_COMMIT_HASH " (" ALSOFT_GIT_BRANCH " branch)."); } diff --git a/utils/alsoft-config/verstr.h b/utils/alsoft-config/verstr.h index a97f0895..73e3ecbd 100644 --- a/utils/alsoft-config/verstr.h +++ b/utils/alsoft-config/verstr.h @@ -1,6 +1,8 @@ #ifndef VERSTR_H #define VERSTR_H -const char *GetVersionString(); +#include + +QString GetVersionString(); #endif /* VERSTR_H */ -- cgit v1.2.3 From 19e1cd7430a19cb3592b4bd3e737e2a0e4314a91 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 8 Sep 2019 01:36:19 -0700 Subject: Make hq-mode the default and update ambisonics.txt --- alc/panning.cpp | 7 +++---- alsoftrc.sample | 2 +- docs/ambisonics.txt | 41 ++++++++++++++++---------------------- utils/alsoft-config/mainwindow.cpp | 4 ++-- 4 files changed, 23 insertions(+), 31 deletions(-) (limited to 'utils') diff --git a/alc/panning.cpp b/alc/panning.cpp index 5143b1ea..a33b9387 100644 --- a/alc/panning.cpp +++ b/alc/panning.cpp @@ -509,9 +509,8 @@ void InitCustomPanning(ALCdevice *device, bool hqdec, const AmbDecConf *conf, co auto accum_spkr_dist = std::bind(std::plus{}, _1, std::bind(std::mem_fn(&AmbDecConf::SpeakerConf::Distance), _2)); const ALfloat avg_dist{ - std::accumulate(conf->Speakers.begin(), conf->Speakers.end(), float{0.0f}, - accum_spkr_dist) / static_cast(conf->Speakers.size()) - }; + std::accumulate(conf->Speakers.begin(), conf->Speakers.end(), 0.0f, accum_spkr_dist) / + static_cast(conf->Speakers.size())}; InitNearFieldCtrl(device, avg_dist, order, (conf->ChanMask&AMBI_PERIPHONIC_MASK) ? chans_per_order3d : chans_per_order2d); @@ -717,7 +716,7 @@ void aluInitRenderer(ALCdevice *device, ALint hrtf_id, HrtfRequestMode hrtf_appr InitPanning(device); else { - int hqdec{GetConfigValueBool(devname, "decoder", "hq-mode", 0)}; + int hqdec{GetConfigValueBool(devname, "decoder", "hq-mode", 1)}; InitCustomPanning(device, !!hqdec, pconf, speakermap); } if(device->AmbiDecoder) diff --git a/alsoftrc.sample b/alsoftrc.sample index f0dde916..7cb780a3 100644 --- a/alsoftrc.sample +++ b/alsoftrc.sample @@ -272,7 +272,7 @@ # configuration files for the appropriate speaker configuration you intend to # use (see the quad, surround51, etc options below). Currently, up to third- # order decoding is supported. -#hq-mode = false +#hq-mode = true ## distance-comp: # Enables compensation for the speakers' relative distances to the listener. diff --git a/docs/ambisonics.txt b/docs/ambisonics.txt index 2d94427e..b03e3bed 100644 --- a/docs/ambisonics.txt +++ b/docs/ambisonics.txt @@ -79,30 +79,23 @@ Soft (or any other OpenAL implementation that wishes to) can render using Ambisonics and decode the ambisonic mix for a high level of accuracy over what simple pan-pot could provide. -This is effectively what the high-quality mode option does, when given an -appropriate decoder configuation for the playback channel layout. 3D rendering -and effect mixing is done to an ambisonic buffer, which is later decoded for -output utilizing the benefits available to ambisonic processing. - -The basic, non-high-quality, renderer uses similar principles, however it skips -the frequency-dependent processing (so low frequency sounds are treated the -same as high frequency sounds) and does some creative manipulation of the -involved math to skip the intermediate ambisonic buffer, rendering more -directly to the output while still taking advantage of all the available -speakers to reconstruct the sound wave. This method trades away some playback -quality for less memory and processor usage. - -In addition to providing good support for surround sound playback, Ambisonics -also has benefits with stereo output. 2-channel UHJ is a stereo-compatible -format that encodes some surround sound information using a wide-band 90-degree -phase shift filter. It works by taking a B-Format signal, and deriving a -frontal stereo mix with the rear sounds attenuated and filtered in with it. -Although the result is not as good as 3-channel (2D) B-Format, it has the -distinct advantage of only using 2 channels and being compatible with stereo -output. This means it will sound just fine when played as-is through a normal -stereo device, or it may optionally be fed to a properly configured surround -sound receiver which can extract the encoded information and restore some of -the original surround sound signal. +When given an appropriate decoder configuration for the channel layout, the +ambisonic mix can be decoded utilizing the benefits available to ambisonic +processing, including frequency-dependent processing and near-field effects. +Without a decoder configuration, the ambisonic mix can still be decoded for +good stereo or surround sound output, although without near-field effects as +there's no speaker distance information. + +In addition to surround sound output, Ambisonics also has benefits with stereo +output. 2-channel UHJ is a stereo-compatible format that encodes some surround +sound information using a wide-band 90-degree phase shift filter. This is +generated by taking the ambisonic mix and deriving a front-stereo mix with +with the rear sounds filtered in with it. Although the result is not as good as +3-channel (2D) B-Format, it has the distinct advantage of only using 2 channels +and being compatible with stereo output. This means it will sound just fine +when played as-is through a normal stereo device, or it may optionally be fed +to a properly configured surround sound receiver which can extract the encoded +information and restore some of the original surround sound signal. What Are Its Limitations? diff --git a/utils/alsoft-config/mainwindow.cpp b/utils/alsoft-config/mainwindow.cpp index aa0df438..7e5159cf 100644 --- a/utils/alsoft-config/mainwindow.cpp +++ b/utils/alsoft-config/mainwindow.cpp @@ -716,7 +716,7 @@ void MainWindow::loadConfig(const QString &fname) } } - bool hqmode{settings.value("decoder/hq-mode", false).toBool()}; + bool hqmode{settings.value("decoder/hq-mode", true).toBool()}; ui->decoderHQModeCheckBox->setChecked(hqmode); ui->decoderDistCompCheckBox->setCheckState(getCheckState(settings.value("decoder/distance-comp"))); ui->decoderNFEffectsCheckBox->setCheckState(getCheckState(settings.value("decoder/nfc"))); @@ -976,7 +976,7 @@ void MainWindow::saveConfig(const QString &fname) const settings.setValue("dither", getCheckValue(ui->outputDitherCheckBox)); settings.setValue("decoder/hq-mode", - ui->decoderHQModeCheckBox->isChecked() ? QString{"true"} : QString{/*"false"*/} + ui->decoderHQModeCheckBox->isChecked() ? QString{/*"true"*/} : QString{"false"} ); settings.setValue("decoder/distance-comp", getCheckValue(ui->decoderDistCompCheckBox)); settings.setValue("decoder/nfc", getCheckValue(ui->decoderNFEffectsCheckBox)); -- cgit v1.2.3 From e4b15aeefcc220a46542c4bb2a2cea033e7954f0 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Wed, 11 Sep 2019 04:55:54 -0700 Subject: Fix some implicit casts --- utils/makemhr/loaddef.cpp | 16 +++++++-------- utils/makemhr/makemhr.cpp | 51 +++++++++++++++++++++++------------------------ utils/sofa-info.cpp | 2 +- 3 files changed, 34 insertions(+), 35 deletions(-) (limited to 'utils') diff --git a/utils/makemhr/loaddef.cpp b/utils/makemhr/loaddef.cpp index 28f2e1b0..89893e38 100644 --- a/utils/makemhr/loaddef.cpp +++ b/utils/makemhr/loaddef.cpp @@ -402,7 +402,7 @@ static int TrReadInt(TokenReaderT *tr, const int loBound, const int hiBound, int return 0; } temp[len] = '\0'; - *value = strtol(temp, nullptr, 10); + *value = static_cast(strtol(temp, nullptr, 10)); if(*value < loBound || *value > hiBound) { TrErrorAt(tr, tr->mLine, col, "Expected a value from %d to %d.\n", loBound, hiBound); @@ -1123,9 +1123,9 @@ static int LoadSofaSource(SourceRefT *src, const uint hrirRate, const uint n, do various coordinate systems, listener/source orientations, and direciontal vectors defined in the SOFA file. */ - target[0] = src->mAzimuth; - target[1] = src->mElevation; - target[2] = src->mRadius; + target[0] = static_cast(src->mAzimuth); + target[1] = static_cast(src->mElevation); + target[2] = static_cast(src->mRadius); mysofa_s2c(target); nearest = mysofa_lookup(sofa->lookup, target); @@ -1147,7 +1147,7 @@ static int LoadSofaSource(SourceRefT *src, const uint hrirRate, const uint n, do return 0; } - ExtractSofaHrir(sofa, nearest, src->mChannel, src->mOffset, n, hrir); + ExtractSofaHrir(sofa, static_cast(nearest), src->mChannel, src->mOffset, n, hrir); return 1; } @@ -1834,13 +1834,13 @@ static int ProcessSources(TokenReaderT *tr, HrirDataT *hData) continue; double ef{(90.0 + aer[1]) * (hData->mFds[fi].mEvCount - 1) / 180.0}; - ei = (int)std::round(ef); + ei = (uint)std::round(ef); ef = (ef - ei) * 180.0f / (hData->mFds[fi].mEvCount - 1); if(std::abs(ef) >= 0.1) continue; double af{aer[0] * hData->mFds[fi].mEvs[ei].mAzCount / 360.0f}; - ai = (int)std::round(af); + ai = (uint)std::round(af); af = (af - ai) * 360.0f / hData->mFds[fi].mEvs[ei].mAzCount; ai = ai % hData->mFds[fi].mEvs[ei].mAzCount; if(std::abs(af) >= 0.1) @@ -1913,7 +1913,7 @@ static int ProcessSources(TokenReaderT *tr, HrirDataT *hData) if(!TrReadIdent(tr, MAX_IDENT_LEN, ident)) return 0; - ti = MatchTargetEar(ident); + ti = static_cast(MatchTargetEar(ident)); if(static_cast(ti) < 0) { TrErrorAt(tr, line, col, "Expected a target ear.\n"); diff --git a/utils/makemhr/makemhr.cpp b/utils/makemhr/makemhr.cpp index e480277e..5930e582 100644 --- a/utils/makemhr/makemhr.cpp +++ b/utils/makemhr/makemhr.cpp @@ -220,15 +220,16 @@ static inline uint dither_rng(uint *seed) // Performs a triangular probability density function dither. The input samples // should be normalized (-1 to +1). static void TpdfDither(double *RESTRICT out, const double *RESTRICT in, const double scale, - const int count, const int step, uint *seed) + const uint count, const uint step, uint *seed) { static constexpr double PRNG_SCALE = 1.0 / std::numeric_limits::max(); - for(int i{0};i < count;i++) + for(uint i{0};i < count;i++) { uint prn0{dither_rng(seed)}; uint prn1{dither_rng(seed)}; - out[i*step] = std::round(in[i]*scale + (prn0*PRNG_SCALE - prn1*PRNG_SCALE)); + *out = std::round(*(in++)*scale + (prn0*PRNG_SCALE - prn1*PRNG_SCALE)); + out += step; } } @@ -254,18 +255,18 @@ static void FftArrange(const uint n, complex_d *inout) } // Performs the summation. -static void FftSummation(const int n, const double s, complex_d *cplx) +static void FftSummation(const uint n, const double s, complex_d *cplx) { double pi; - int m, m2; - int i, k, mk; + uint m, m2; + uint i, k, mk; pi = s * M_PI; for(m = 1, m2 = 2;m < n; m <<= 1, m2 <<= 1) { // v = Complex (-2.0 * sin (0.5 * pi / m) * sin (0.5 * pi / m), -sin (pi / m)) - double sm = sin(0.5 * pi / m); - auto v = complex_d{-2.0*sm*sm, -sin(pi / m)}; + double sm = std::sin(0.5 * pi / m); + auto v = complex_d{-2.0*sm*sm, -std::sin(pi / m)}; auto w = complex_d{1.0, 0.0}; for(i = 0;i < m;i++) { @@ -511,7 +512,7 @@ static double CalcKaiserBeta(const double rejection) * p -- gain compensation factor when sampling * f_t -- normalized center frequency (or cutoff; 0.5 is nyquist) */ -static double SincFilter(const int l, const double b, const double gain, const double cutoff, const int i) +static double SincFilter(const uint l, const double b, const double gain, const double cutoff, const uint i) { return Kaiser(b, static_cast(i - l) / l) * 2.0 * gain * cutoff * Sinc(2.0 * cutoff * (i - l)); } @@ -546,17 +547,15 @@ static double SincFilter(const int l, const double b, const double gain, const d // that's used to cut frequencies above the destination nyquist. void ResamplerSetup(ResamplerT *rs, const uint srcRate, const uint dstRate) { - double cutoff, width, beta; - uint gcd, l; - int i; - - gcd = Gcd(srcRate, dstRate); + const uint gcd{Gcd(srcRate, dstRate)}; rs->mP = dstRate / gcd; rs->mQ = srcRate / gcd; + /* The cutoff is adjusted by half the transition width, so the transition * ends before the nyquist (0.5). Both are scaled by the downsampling * factor. */ + double cutoff, width; if(rs->mP > rs->mQ) { cutoff = 0.475 / rs->mP; @@ -569,13 +568,13 @@ void ResamplerSetup(ResamplerT *rs, const uint srcRate, const uint dstRate) } // A rejection of -180 dB is used for the stop band. Round up when // calculating the left offset to avoid increasing the transition width. - l = (CalcKaiserOrder(180.0, width)+1) / 2; - beta = CalcKaiserBeta(180.0); + const uint l{(CalcKaiserOrder(180.0, width)+1) / 2}; + const double beta{CalcKaiserBeta(180.0)}; rs->mM = l*2 + 1; rs->mL = l; rs->mF.resize(rs->mM); - for(i = 0;i < (static_cast(rs->mM));i++) - rs->mF[i] = SincFilter(static_cast(l), beta, rs->mP, cutoff, i); + for(uint i{0};i < rs->mM;i++) + rs->mF[i] = SincFilter(l, beta, rs->mP, cutoff, i); } // Perform the upsample-filter-downsample resampling operation using a @@ -709,8 +708,8 @@ static int StoreMhr(const HrirDataT *hData, const char *filename) { const double scale = (hData->mSampleType == ST_S16) ? 32767.0 : ((hData->mSampleType == ST_S24) ? 8388607.0 : 0.0); - const int bps = (hData->mSampleType == ST_S16) ? 2 : - ((hData->mSampleType == ST_S24) ? 3 : 0); + const uint bps = (hData->mSampleType == ST_S16) ? 2 : + ((hData->mSampleType == ST_S24) ? 3 : 0); for(ei = 0;ei < hData->mFds[fi].mEvCount;ei++) { @@ -960,8 +959,8 @@ struct HrirReconstructor { std::vector mIrs; std::atomic mCurrent; std::atomic mDone; - size_t mFftSize; - size_t mIrPoints; + uint mFftSize; + uint mIrPoints; void Worker() { @@ -987,7 +986,7 @@ struct HrirReconstructor { */ MinimumPhase(mFftSize, mIrs[idx], h.data()); FftInverse(mFftSize, h.data()); - for(size_t i{0u};i < mIrPoints;++i) + for(uint i{0u};i < mIrPoints;++i) mIrs[idx][i] = h[i].real(); /* Increment the number of IRs done. */ @@ -1684,7 +1683,7 @@ int main(int argc, char *argv[]) switch(opt) { case 'r': - outRate = strtoul(optarg, &end, 10); + outRate = static_cast(strtoul(optarg, &end, 10)); if(end[0] != '\0' || outRate < MIN_RATE || outRate > MAX_RATE) { fprintf(stderr, "\nError: Got unexpected value \"%s\" for option -%c, expected between %u to %u.\n", optarg, opt, MIN_RATE, MAX_RATE); @@ -1697,7 +1696,7 @@ int main(int argc, char *argv[]) break; case 'f': - fftSize = strtoul(optarg, &end, 10); + fftSize = static_cast(strtoul(optarg, &end, 10)); if(end[0] != '\0' || (fftSize&(fftSize-1)) || fftSize < MIN_FFTSIZE || fftSize > MAX_FFTSIZE) { fprintf(stderr, "\nError: Got unexpected value \"%s\" for option -%c, expected a power-of-two between %u to %u.\n", optarg, opt, MIN_FFTSIZE, MAX_FFTSIZE); @@ -1744,7 +1743,7 @@ int main(int argc, char *argv[]) break; case 'w': - truncSize = strtoul(optarg, &end, 10); + truncSize = static_cast(strtoul(optarg, &end, 10)); if(end[0] != '\0' || truncSize < MIN_TRUNCSIZE || truncSize > MAX_TRUNCSIZE || (truncSize%MOD_TRUNCSIZE)) { fprintf(stderr, "\nError: Got unexpected value \"%s\" for option -%c, expected multiple of %u between %u to %u.\n", optarg, opt, MOD_TRUNCSIZE, MIN_TRUNCSIZE, MAX_TRUNCSIZE); diff --git a/utils/sofa-info.cpp b/utils/sofa-info.cpp index c7c7a8f7..83e3d065 100644 --- a/utils/sofa-info.cpp +++ b/utils/sofa-info.cpp @@ -84,7 +84,7 @@ static void PrintSofaArray(const char *prefix, struct MYSOFA_ARRAY *array) * of other axes as necessary. The epsilons are used to constrain the * equality of unique elements. */ -static uint GetUniquelySortedElems(const uint m, const float *triplets, const int axis, +static uint GetUniquelySortedElems(const uint m, const float *triplets, const uint axis, const float *const (&filters)[3], const float (&epsilons)[3], float *elems) { -- cgit v1.2.3 From be0442c6207cc10fca079a803bbdd8985959b657 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Wed, 11 Sep 2019 06:47:56 -0700 Subject: Avoid C-style casts in C++ --- CMakeLists.txt | 2 +- al/state.cpp | 16 ++++++++-------- alc/alc.cpp | 18 ++++++++---------- alc/backends/sdl2.cpp | 2 +- alc/backends/sndio.cpp | 2 +- alc/backends/wasapi.cpp | 9 ++++++--- alc/backends/winmm.cpp | 8 +++++--- alc/helpers.cpp | 2 +- utils/makemhr/loaddef.cpp | 12 ++++++------ utils/makemhr/loadsofa.cpp | 2 +- utils/sofa-info.cpp | 2 +- 11 files changed, 39 insertions(+), 36 deletions(-) (limited to 'utils') diff --git a/CMakeLists.txt b/CMakeLists.txt index 7626c1ef..c37a2d18 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -220,7 +220,7 @@ IF(MSVC) ENDFOREACH(flag_var) ENDIF() ELSE() - SET(C_FLAGS ${C_FLAGS} -Winline -Wall) + SET(C_FLAGS ${C_FLAGS} -Winline -Wall -Wold-style-cast) CHECK_C_COMPILER_FLAG(-Wextra HAVE_W_EXTRA) IF(HAVE_W_EXTRA) SET(C_FLAGS ${C_FLAGS} -Wextra) diff --git a/al/state.cpp b/al/state.cpp index 64cbae6e..cc5d8bac 100644 --- a/al/state.cpp +++ b/al/state.cpp @@ -371,36 +371,36 @@ START_API_FUNC switch(pname) { case AL_DOPPLER_FACTOR: - value = (ALint64SOFT)context->mDopplerFactor; + value = static_cast(context->mDopplerFactor); break; case AL_DOPPLER_VELOCITY: - value = (ALint64SOFT)context->mDopplerVelocity; + value = static_cast(context->mDopplerVelocity); break; case AL_DISTANCE_MODEL: - value = (ALint64SOFT)context->mDistanceModel; + value = static_cast(context->mDistanceModel); break; case AL_SPEED_OF_SOUND: - value = (ALint64SOFT)context->mSpeedOfSound; + value = static_cast(context->mSpeedOfSound); break; case AL_DEFERRED_UPDATES_SOFT: if(context->mDeferUpdates.load(std::memory_order_acquire)) - value = (ALint64SOFT)AL_TRUE; + value = AL_TRUE; break; case AL_GAIN_LIMIT_SOFT: - value = (ALint64SOFT)(GAIN_MIX_MAX/context->mGainBoost); + value = static_cast(GAIN_MIX_MAX/context->mGainBoost); break; case AL_NUM_RESAMPLERS_SOFT: - value = (ALint64SOFT)(ResamplerMax + 1); + value = static_cast(ResamplerMax + 1); break; case AL_DEFAULT_RESAMPLER_SOFT: - value = (ALint64SOFT)ResamplerDefault; + value = static_cast(ResamplerDefault); break; default: diff --git a/alc/alc.cpp b/alc/alc.cpp index 5f52ca26..10ab3b94 100644 --- a/alc/alc.cpp +++ b/alc/alc.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -214,7 +215,7 @@ BackendFactory *CaptureFactory{}; /************************************************ * Functions, enums, and errors ************************************************/ -#define DECL(x) { #x, (ALCvoid*)(x) } +#define DECL(x) { #x, reinterpret_cast(x) } const struct { const ALCchar *funcName; ALCvoid *address; @@ -1228,14 +1229,11 @@ BOOL APIENTRY DllMain(HINSTANCE module, DWORD reason, LPVOID /*reserved*/) { switch(reason) { - case DLL_PROCESS_ATTACH: - /* Pin the DLL so we won't get unloaded until the process terminates */ - GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_PIN | GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, - (WCHAR*)module, &module); - break; - - case DLL_PROCESS_DETACH: - break; + case DLL_PROCESS_ATTACH: + /* Pin the DLL so we won't get unloaded until the process terminates */ + GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_PIN | GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, + reinterpret_cast(module), &module); + break; } return TRUE; } @@ -2087,7 +2085,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) TRACE("Output limiter enabled, %.4fdB limit\n", thrshld_dB); } - TRACE("Fixed device latency: %ldns\n", (long)device->FixedLatency.count()); + TRACE("Fixed device latency: %" PRId64 "ns\n", int64_t{device->FixedLatency.count()}); /* Need to delay returning failure until replacement Send arrays have been * allocated with the appropriate size. diff --git a/alc/backends/sdl2.cpp b/alc/backends/sdl2.cpp index 29d27c05..4b3b5e63 100644 --- a/alc/backends/sdl2.cpp +++ b/alc/backends/sdl2.cpp @@ -133,7 +133,7 @@ ALCenum Sdl2Backend::open(const ALCchar *name) mDevice->FmtChans = DevFmtStereo; else { - ERR("Got unhandled SDL channel count: %d\n", (int)have.channels); + ERR("Got unhandled SDL channel count: %d\n", int{have.channels}); return ALC_INVALID_VALUE; } switch(have.format) diff --git a/alc/backends/sndio.cpp b/alc/backends/sndio.cpp index 587f67bb..c7a86670 100644 --- a/alc/backends/sndio.cpp +++ b/alc/backends/sndio.cpp @@ -396,7 +396,7 @@ ALCenum SndioCapture::open(const ALCchar *name) (mDevice->FmtType == DevFmtUShort && par.bits == 16 && par.sig == 0) || (mDevice->FmtType == DevFmtInt && par.bits == 32 && par.sig != 0) || (mDevice->FmtType == DevFmtUInt && par.bits == 32 && par.sig == 0)) || - mDevice->channelsFromFmt() != (ALsizei)par.rchan || + mDevice->channelsFromFmt() != static_cast(par.rchan) || mDevice->Frequency != par.rate) { ERR("Failed to set format %s %s %uhz, got %c%u %u-channel %uhz instead\n", diff --git a/alc/backends/wasapi.cpp b/alc/backends/wasapi.cpp index ec1ee936..55c95146 100644 --- a/alc/backends/wasapi.cpp +++ b/alc/backends/wasapi.cpp @@ -81,6 +81,9 @@ DEFINE_PROPERTYKEY(PKEY_AudioEndpoint_GUID, 0x1da5d803, 0xd492, 0x4edd, 0x8c, 0x namespace { +inline constexpr REFERENCE_TIME operator "" _reftime(unsigned long long int n) noexcept +{ return static_cast(n); } + #define MONO SPEAKER_FRONT_CENTER #define STEREO (SPEAKER_FRONT_LEFT|SPEAKER_FRONT_RIGHT) #define QUAD (SPEAKER_FRONT_LEFT|SPEAKER_FRONT_RIGHT|SPEAKER_BACK_LEFT|SPEAKER_BACK_RIGHT) @@ -90,7 +93,7 @@ namespace { #define X7DOT1 (SPEAKER_FRONT_LEFT|SPEAKER_FRONT_RIGHT|SPEAKER_FRONT_CENTER|SPEAKER_LOW_FREQUENCY|SPEAKER_BACK_LEFT|SPEAKER_BACK_RIGHT|SPEAKER_SIDE_LEFT|SPEAKER_SIDE_RIGHT) #define X7DOT1_WIDE (SPEAKER_FRONT_LEFT|SPEAKER_FRONT_RIGHT|SPEAKER_FRONT_CENTER|SPEAKER_LOW_FREQUENCY|SPEAKER_BACK_LEFT|SPEAKER_BACK_RIGHT|SPEAKER_FRONT_LEFT_OF_CENTER|SPEAKER_FRONT_RIGHT_OF_CENTER) -#define REFTIME_PER_SEC ((REFERENCE_TIME)10000000) +#define REFTIME_PER_SEC 10000000_reftime #define DEVNAME_HEAD "OpenAL Soft on " @@ -1051,7 +1054,7 @@ HRESULT WasapiPlayback::resetProxy() /* Find the nearest multiple of the period size to the update size */ if(min_per < per_time) min_per *= maxi64((per_time + min_per/2) / min_per, 1); - min_len = (UINT32)ScaleCeil(min_per, mDevice->Frequency, REFTIME_PER_SEC); + min_len = static_cast(ScaleCeil(min_per, mDevice->Frequency, REFTIME_PER_SEC)); min_len = minu(min_len, buffer_len/2); mDevice->UpdateSize = min_len; @@ -1680,7 +1683,7 @@ void WasapiCapture::stopProxy() ALCuint WasapiCapture::availableSamples() -{ return (ALCuint)mRing->readSpace(); } +{ return static_cast(mRing->readSpace()); } ALCenum WasapiCapture::captureSamples(void *buffer, ALCuint samples) { diff --git a/alc/backends/winmm.cpp b/alc/backends/winmm.cpp index b6787a24..76e6fe3b 100644 --- a/alc/backends/winmm.cpp +++ b/alc/backends/winmm.cpp @@ -245,7 +245,8 @@ retry_open: mFormat.nAvgBytesPerSec = mFormat.nSamplesPerSec * mFormat.nBlockAlign; mFormat.cbSize = 0; - MMRESULT res{waveOutOpen(&mOutHdl, DeviceID, &mFormat, (DWORD_PTR)&WinMMPlayback::waveOutProcC, + MMRESULT res{waveOutOpen(&mOutHdl, DeviceID, &mFormat, + reinterpret_cast(&WinMMPlayback::waveOutProcC), reinterpret_cast(this), CALLBACK_FUNCTION)}; if(res != MMSYSERR_NOERROR) { @@ -506,7 +507,8 @@ ALCenum WinMMCapture::open(const ALCchar *name) mFormat.nAvgBytesPerSec = mFormat.nSamplesPerSec * mFormat.nBlockAlign; mFormat.cbSize = 0; - MMRESULT res{waveInOpen(&mInHdl, DeviceID, &mFormat, (DWORD_PTR)&WinMMCapture::waveInProcC, + MMRESULT res{waveInOpen(&mInHdl, DeviceID, &mFormat, + reinterpret_cast(&WinMMCapture::waveInProcC), reinterpret_cast(this), CALLBACK_FUNCTION)}; if(res != MMSYSERR_NOERROR) { @@ -590,7 +592,7 @@ ALCenum WinMMCapture::captureSamples(void *buffer, ALCuint samples) } ALCuint WinMMCapture::availableSamples() -{ return (ALCuint)mRing->readSpace(); } +{ return static_cast(mRing->readSpace()); } } // namespace diff --git a/alc/helpers.cpp b/alc/helpers.cpp index ba95c0f8..84787637 100644 --- a/alc/helpers.cpp +++ b/alc/helpers.cpp @@ -255,7 +255,7 @@ auto filebuf::underflow() -> int_type { // Read in the next chunk of data, and set the pointers on success DWORD got{}; - if(ReadFile(mFile, mBuffer.data(), (DWORD)mBuffer.size(), &got, nullptr)) + if(ReadFile(mFile, mBuffer.data(), static_cast(mBuffer.size()), &got, nullptr)) setg(mBuffer.data(), mBuffer.data(), mBuffer.data()+got); } if(gptr() == egptr()) diff --git a/utils/makemhr/loaddef.cpp b/utils/makemhr/loaddef.cpp index 89893e38..5f6d76d8 100644 --- a/utils/makemhr/loaddef.cpp +++ b/utils/makemhr/loaddef.cpp @@ -1047,7 +1047,7 @@ static int LoadWaveSource(FILE *fp, SourceRefT *src, const uint hrirRate, const // Load a Spatially Oriented Format for Accoustics (SOFA) file. static MYSOFA_EASY* LoadSofaFile(SourceRefT *src, const uint hrirRate, const uint n) { - struct MYSOFA_EASY *sofa{mysofa_cache_lookup(src->mPath, (float)hrirRate)}; + struct MYSOFA_EASY *sofa{mysofa_cache_lookup(src->mPath, static_cast(hrirRate))}; if(sofa) return sofa; sofa = static_cast(calloc(1, sizeof(*sofa))); @@ -1096,7 +1096,7 @@ static MYSOFA_EASY* LoadSofaFile(SourceRefT *src, const uint hrirRate, const uin fprintf(stderr, "\nError: Out of memory.\n"); return nullptr; } - return mysofa_cache_store(sofa, src->mPath, (float)hrirRate); + return mysofa_cache_store(sofa, src->mPath, static_cast(hrirRate)); } // Copies the HRIR data from a particular SOFA measurement. @@ -1532,7 +1532,7 @@ static int ReadSourceRef(TokenReaderT *tr, SourceRefT *src) src->mType = ET_NONE; src->mSize = 0; src->mBits = 0; - src->mChannel = (uint)intVal; + src->mChannel = static_cast(intVal); src->mSkip = 0; } else if(src->mFormat == SF_WAVE) @@ -1666,7 +1666,7 @@ static int ReadSofaRef(TokenReaderT *tr, SourceRefT *src) TrReadOperator(tr, "@"); if(!TrReadInt(tr, 0, 0x7FFFFFFF, &intVal)) return 0; - src->mOffset = (uint)intVal; + src->mOffset = static_cast(intVal); } else src->mOffset = 0; @@ -1834,13 +1834,13 @@ static int ProcessSources(TokenReaderT *tr, HrirDataT *hData) continue; double ef{(90.0 + aer[1]) * (hData->mFds[fi].mEvCount - 1) / 180.0}; - ei = (uint)std::round(ef); + ei = static_cast(std::round(ef)); ef = (ef - ei) * 180.0f / (hData->mFds[fi].mEvCount - 1); if(std::abs(ef) >= 0.1) continue; double af{aer[0] * hData->mFds[fi].mEvs[ei].mAzCount / 360.0f}; - ai = (uint)std::round(af); + ai = static_cast(std::round(af)); af = (af - ai) * 360.0f / hData->mFds[fi].mEvs[ei].mAzCount; ai = ai % hData->mFds[fi].mEvs[ei].mAzCount; if(std::abs(af) >= 0.1) diff --git a/utils/makemhr/loadsofa.cpp b/utils/makemhr/loadsofa.cpp index 7fb169e2..e82376aa 100644 --- a/utils/makemhr/loadsofa.cpp +++ b/utils/makemhr/loadsofa.cpp @@ -221,7 +221,7 @@ static bool PrepareLayout(const uint m, const float *xyzs, HrirDataT *hData) float ev{90.0f + elems[ei]}; float eif{std::round(ev / step)}; - if(std::fabs(eif - (uint)eif) < (0.1f / step)) + if(std::fabs(eif - static_cast(eif)) < (0.1f / step)) { evStart = static_cast(eif); break; diff --git a/utils/sofa-info.cpp b/utils/sofa-info.cpp index 83e3d065..e9f2257c 100644 --- a/utils/sofa-info.cpp +++ b/utils/sofa-info.cpp @@ -242,7 +242,7 @@ static void PrintCompatibleLayout(const uint m, const float *xyzs) float ev{90.0f + elems[ei]}; float eif{std::round(ev / step)}; - if(std::fabs(eif - (uint)eif) < (0.1f / step)) + if(std::fabs(eif - static_cast(eif)) < (0.1f / step)) { evStart = static_cast(eif); break; -- cgit v1.2.3 From 4c76f32ddac5145231609b1cb4f28028abed814b Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Thu, 12 Sep 2019 03:14:01 -0700 Subject: Avoid implicit conversions with the examples and utils --- examples/alffplay.cpp | 86 +++++++++++++++++++++++---------------------- examples/alhrtf.c | 13 ++++--- examples/allatency.c | 4 +-- examples/alloopback.c | 2 +- examples/almultireverb.c | 18 +++++----- examples/alplay.c | 4 +-- examples/alrecord.c | 24 ++++++------- examples/alreverb.c | 8 ++--- examples/alstream.c | 17 +++++---- examples/altonegen.c | 8 ++--- examples/common/alhelpers.c | 4 +-- utils/makemhr/loadsofa.cpp | 2 +- utils/openal-info.c | 2 +- 13 files changed, 99 insertions(+), 93 deletions(-) (limited to 'utils') diff --git a/examples/alffplay.cpp b/examples/alffplay.cpp index cdb228e1..655ffc96 100644 --- a/examples/alffplay.cpp +++ b/examples/alffplay.cpp @@ -213,7 +213,7 @@ class PacketQueue { void pop() { AVPacket *pkt = &mPackets.front(); - mTotalSize -= pkt->size; + mTotalSize -= static_cast(pkt->size); av_packet_unref(pkt); mPackets.pop_front(); } @@ -267,7 +267,7 @@ public: return true; } - mTotalSize += mPackets.back().size; + mTotalSize += static_cast(mPackets.back().size); } mCondVar.notify_one(); return true; @@ -299,7 +299,7 @@ struct AudioState { SwrContextPtr mSwresCtx; /* Conversion format, for what gets fed to OpenAL */ - int mDstChanLayout{0}; + uint64_t mDstChanLayout{0}; AVSampleFormat mDstSampleFmt{AV_SAMPLE_FMT_NONE}; /* Storage of converted samples */ @@ -310,14 +310,14 @@ struct AudioState { /* OpenAL format */ ALenum mFormat{AL_NONE}; - ALsizei mFrameSize{0}; + ALuint mFrameSize{0}; std::mutex mSrcMutex; std::condition_variable mSrcCond; std::atomic_flag mConnected; ALuint mSource{0}; std::vector mBuffers; - ALsizei mBufferIdx{0}; + ALuint mBufferIdx{0}; AudioState(MovieState &movie) : mMovie(movie) { mConnected.test_and_set(std::memory_order_relaxed); } @@ -326,7 +326,7 @@ struct AudioState { if(mSource) alDeleteSources(1, &mSource); if(!mBuffers.empty()) - alDeleteBuffers(mBuffers.size(), mBuffers.data()); + alDeleteBuffers(static_cast(mBuffers.size()), mBuffers.data()); av_freep(&mSamples); } @@ -348,7 +348,7 @@ struct AudioState { int getSync(); int decodeFrame(); - bool readAudio(uint8_t *samples, int length); + bool readAudio(uint8_t *samples, unsigned int length); int handler(); }; @@ -441,7 +441,7 @@ struct MovieState { nanoseconds getDuration(); - int streamComponentOpen(int stream_index); + int streamComponentOpen(unsigned int stream_index); int parse_handler(); }; @@ -618,17 +618,17 @@ int AudioState::decodeFrame() * multiple of the template type size. */ template -static void sample_dup(uint8_t *out, const uint8_t *in, int count, int frame_size) +static void sample_dup(uint8_t *out, const uint8_t *in, unsigned int count, size_t frame_size) { - const T *sample = reinterpret_cast(in); - T *dst = reinterpret_cast(out); + auto *sample = reinterpret_cast(in); + auto *dst = reinterpret_cast(out); if(frame_size == sizeof(T)) std::fill_n(dst, count, *sample); else { /* NOTE: frame_size is a multiple of sizeof(T). */ - int type_mult = frame_size / sizeof(T); - int i = 0; + size_t type_mult{frame_size / sizeof(T)}; + size_t i{0}; std::generate_n(dst, count*type_mult, [sample,type_mult,&i]() -> T { @@ -641,10 +641,10 @@ static void sample_dup(uint8_t *out, const uint8_t *in, int count, int frame_siz } -bool AudioState::readAudio(uint8_t *samples, int length) +bool AudioState::readAudio(uint8_t *samples, unsigned int length) { - int sample_skip = getSync(); - int audio_size = 0; + int sample_skip{getSync()}; + unsigned int audio_size{0}; /* Read the next chunk of data, refill the buffer, and queue it * on the source */ @@ -669,16 +669,17 @@ bool AudioState::readAudio(uint8_t *samples, int length) continue; } - int rem = length - audio_size; + unsigned int rem{length - audio_size}; if(mSamplesPos >= 0) { - int len = mSamplesLen - mSamplesPos; + const auto len = static_cast(mSamplesLen - mSamplesPos); if(rem > len) rem = len; - memcpy(samples, mSamples + mSamplesPos*mFrameSize, rem*mFrameSize); + std::copy_n(mSamples + static_cast(mSamplesPos)*mFrameSize, + rem*mFrameSize, samples); } else { - rem = std::min(rem, -mSamplesPos); + rem = std::min(rem, static_cast(-mSamplesPos)); /* Add samples by copying the first sample */ if((mFrameSize&7) == 0) @@ -692,7 +693,7 @@ bool AudioState::readAudio(uint8_t *samples, int length) } mSamplesPos += rem; - mCurrentPts += nanoseconds(seconds(rem)) / mCodecCtx->sample_rate; + mCurrentPts += nanoseconds{seconds{rem}} / mCodecCtx->sample_rate; samples += rem*mFrameSize; audio_size += rem; } @@ -701,10 +702,10 @@ bool AudioState::readAudio(uint8_t *samples, int length) if(audio_size < length) { - int rem = length - audio_size; + const unsigned int rem{length - audio_size}; std::fill_n(samples, rem*mFrameSize, (mDstSampleFmt == AV_SAMPLE_FMT_U8) ? 0x80 : 0x00); - mCurrentPts += nanoseconds(seconds(rem)) / mCodecCtx->sample_rate; + mCurrentPts += nanoseconds{seconds{rem}} / mCodecCtx->sample_rate; audio_size += rem; } return true; @@ -928,8 +929,8 @@ int AudioState::handler() } } void *samples{nullptr}; - ALsizei buffer_len = std::chrono::duration_cast>( - mCodecCtx->sample_rate * AudioBufferTime).count() * mFrameSize; + ALsizei buffer_len = static_cast(std::chrono::duration_cast( + mCodecCtx->sample_rate * AudioBufferTime).count() * mFrameSize); mSamples = nullptr; mSamplesMax = 0; @@ -968,9 +969,9 @@ int AudioState::handler() } else mSwresCtx.reset(swr_alloc_set_opts(nullptr, - mDstChanLayout, mDstSampleFmt, mCodecCtx->sample_rate, - mCodecCtx->channel_layout ? mCodecCtx->channel_layout : - static_cast(av_get_default_channel_layout(mCodecCtx->channels)), + static_cast(mDstChanLayout), mDstSampleFmt, mCodecCtx->sample_rate, + mCodecCtx->channel_layout ? static_cast(mCodecCtx->channel_layout) : + av_get_default_channel_layout(mCodecCtx->channels), mCodecCtx->sample_fmt, mCodecCtx->sample_rate, 0, nullptr)); if(!mSwresCtx || swr_init(mSwresCtx.get()) != 0) @@ -980,7 +981,7 @@ int AudioState::handler() } mBuffers.assign(AudioBufferTotalTime / AudioBufferTime, 0); - alGenBuffers(mBuffers.size(), mBuffers.data()); + alGenBuffers(static_cast(mBuffers.size()), mBuffers.data()); alGenSources(1, &mSource); if(EnableDirectOut) @@ -1003,12 +1004,12 @@ int AudioState::handler() if(alGetError() != AL_NO_ERROR) { fprintf(stderr, "Failed to use mapped buffers\n"); - samples = av_malloc(buffer_len); + samples = av_malloc(static_cast(buffer_len)); } } else #endif - samples = av_malloc(buffer_len); + samples = av_malloc(static_cast(buffer_len)); /* Prefill the codec buffer. */ do { @@ -1053,14 +1054,15 @@ int AudioState::handler() { auto ptr = static_cast(alMapBufferSOFT(bufid, 0, buffer_len, AL_MAP_WRITE_BIT_SOFT)); - bool got_audio{readAudio(ptr, buffer_len)}; + bool got_audio{readAudio(ptr, static_cast(buffer_len))}; alUnmapBufferSOFT(bufid); if(!got_audio) break; } else #endif { - if(!readAudio(static_cast(samples), buffer_len)) + auto ptr = static_cast(samples); + if(!readAudio(ptr, static_cast(buffer_len))) break; alBufferData(bufid, mFormat, samples, buffer_len, mCodecCtx->sample_rate); } @@ -1138,27 +1140,27 @@ void VideoState::display(SDL_Window *screen, SDL_Renderer *renderer) if(!mImage) return; - float aspect_ratio; + double aspect_ratio; int win_w, win_h; int w, h, x, y; if(mCodecCtx->sample_aspect_ratio.num == 0) - aspect_ratio = 0.0f; + aspect_ratio = 0.0; else { aspect_ratio = av_q2d(mCodecCtx->sample_aspect_ratio) * mCodecCtx->width / mCodecCtx->height; } - if(aspect_ratio <= 0.0f) - aspect_ratio = static_cast(mCodecCtx->width) / static_cast(mCodecCtx->height); + if(aspect_ratio <= 0.0) + aspect_ratio = static_cast(mCodecCtx->width) / mCodecCtx->height; SDL_GetWindowSize(screen, &win_w, &win_h); h = win_h; - w = (static_cast(rint(h * aspect_ratio)) + 3) & ~3; + w = (static_cast(std::rint(h * aspect_ratio)) + 3) & ~3; if(w > win_w) { w = win_w; - h = (static_cast(rint(w / aspect_ratio)) + 3) & ~3; + h = (static_cast(std::rint(w / aspect_ratio)) + 3) & ~3; } x = (win_w - w) / 2; y = (win_h - h) / 2; @@ -1460,9 +1462,9 @@ nanoseconds MovieState::getMasterClock() nanoseconds MovieState::getDuration() { return std::chrono::duration>(mFormatCtx->duration); } -int MovieState::streamComponentOpen(int stream_index) +int MovieState::streamComponentOpen(unsigned int stream_index) { - if(stream_index < 0 || static_cast(stream_index) >= mFormatCtx->nb_streams) + if(stream_index >= mFormatCtx->nb_streams) return -1; /* Get a pointer to the codec context for the stream, and open the @@ -1499,7 +1501,7 @@ int MovieState::streamComponentOpen(int stream_index) return -1; } - return stream_index; + return static_cast(stream_index); } int MovieState::parse_handler() diff --git a/examples/alhrtf.c b/examples/alhrtf.c index 96cf0255..f09f3e99 100644 --- a/examples/alhrtf.c +++ b/examples/alhrtf.c @@ -112,7 +112,7 @@ static ALuint LoadSound(const char *filename) * close the file. */ buffer = 0; alGenBuffers(1, &buffer); - alBufferData(buffer, format, sample->buffer, slen, sample->actual.rate); + alBufferData(buffer, format, sample->buffer, (ALsizei)slen, (ALsizei)sample->actual.rate); Sound_FreeSample(sample); /* Check if an error occured, and clean up if so. */ @@ -132,6 +132,7 @@ static ALuint LoadSound(const char *filename) int main(int argc, char **argv) { ALCdevice *device; + ALCcontext *context; ALboolean has_angle_ext; ALuint source, buffer; const char *soundname; @@ -153,7 +154,8 @@ int main(int argc, char **argv) if(InitAL(&argv, &argc) != 0) return 1; - device = alcGetContextsDevice(alcGetCurrentContext()); + context = alcGetCurrentContext(); + device = alcGetContextsDevice(context); if(!alcIsExtensionPresent(device, "ALC_SOFT_HRTF")) { fprintf(stderr, "Error: ALC_SOFT_HRTF not supported\n"); @@ -171,7 +173,7 @@ int main(int argc, char **argv) * stereo sources. */ has_angle_ext = alIsExtensionPresent("AL_EXT_STEREO_ANGLES"); - printf("AL_EXT_STEREO_ANGLES%s found\n", has_angle_ext?"":" not"); + printf("AL_EXT_STEREO_ANGLES %sfound\n", has_angle_ext?"":"not "); /* Check for user-preferred HRTF */ if(strcmp(argv[0], "-hrtf") == 0) @@ -255,7 +257,7 @@ int main(int argc, char **argv) alGenSources(1, &source); alSourcei(source, AL_SOURCE_RELATIVE, AL_TRUE); alSource3f(source, AL_POSITION, 0.0f, 0.0f, -1.0f); - alSourcei(source, AL_BUFFER, buffer); + alSourcei(source, AL_BUFFER, (ALint)buffer); assert(alGetError()==AL_NO_ERROR && "Failed to setup sound source"); /* Play the sound until it finishes. */ @@ -264,6 +266,8 @@ int main(int argc, char **argv) do { al_nssleep(10000000); + alcSuspendContext(context); + /* Rotate the source around the listener by about 1/4 cycle per second, * and keep it within -pi...+pi. */ @@ -282,6 +286,7 @@ int main(int argc, char **argv) ALfloat angles[2] = { (ALfloat)(M_PI/6.0 - angle), (ALfloat)(-M_PI/6.0 - angle) }; alSourcefv(source, AL_STEREO_ANGLES, angles); } + alcProcessContext(context); alGetSourcei(source, AL_SOURCE_STATE, &state); } while(alGetError() == AL_NO_ERROR && state == AL_PLAYING); diff --git a/examples/allatency.c b/examples/allatency.c index 2bc76289..ad700cc1 100644 --- a/examples/allatency.c +++ b/examples/allatency.c @@ -115,7 +115,7 @@ static ALuint LoadSound(const char *filename) * close the file. */ buffer = 0; alGenBuffers(1, &buffer); - alBufferData(buffer, format, sample->buffer, slen, sample->actual.rate); + alBufferData(buffer, format, sample->buffer, (ALsizei)slen, (ALsizei)sample->actual.rate); Sound_FreeSample(sample); /* Check if an error occured, and clean up if so. */ @@ -188,7 +188,7 @@ int main(int argc, char **argv) /* Create the source to play the sound with. */ source = 0; alGenSources(1, &source); - alSourcei(source, AL_BUFFER, buffer); + alSourcei(source, AL_BUFFER, (ALint)buffer); assert(alGetError()==AL_NO_ERROR && "Failed to setup sound source"); /* Play the sound until it finishes. */ diff --git a/examples/alloopback.c b/examples/alloopback.c index 313b89d5..426a2af9 100644 --- a/examples/alloopback.c +++ b/examples/alloopback.c @@ -249,7 +249,7 @@ int main(int argc, char *argv[]) /* Create the source to play the sound with. */ source = 0; alGenSources(1, &source); - alSourcei(source, AL_BUFFER, buffer); + alSourcei(source, AL_BUFFER, (ALint)buffer); assert(alGetError()==AL_NO_ERROR && "Failed to setup sound source"); /* Play the sound until it finishes. */ diff --git a/examples/almultireverb.c b/examples/almultireverb.c index efd3bf16..b967a050 100644 --- a/examples/almultireverb.c +++ b/examples/almultireverb.c @@ -211,7 +211,7 @@ static ALuint LoadSound(const char *filename) * close the file. */ buffer = 0; alGenBuffers(1, &buffer); - alBufferData(buffer, format, sample->buffer, slen, sample->actual.rate); + alBufferData(buffer, format, sample->buffer, (ALsizei)slen, (ALsizei)sample->actual.rate); Sound_FreeSample(sample); /* Check if an error occured, and clean up if so. */ @@ -443,8 +443,8 @@ static void UpdateListenerAndEffects(float timediff, const ALuint slots[2], cons } /* Finally, update the effect slots with the updated effect parameters. */ - alAuxiliaryEffectSloti(slots[0], AL_EFFECTSLOT_EFFECT, effects[0]); - alAuxiliaryEffectSloti(slots[1], AL_EFFECTSLOT_EFFECT, effects[1]); + alAuxiliaryEffectSloti(slots[0], AL_EFFECTSLOT_EFFECT, (ALint)effects[0]); + alAuxiliaryEffectSloti(slots[1], AL_EFFECTSLOT_EFFECT, (ALint)effects[1]); } @@ -598,8 +598,8 @@ int main(int argc, char **argv) * effect properties. Modifying or deleting the effect object afterward * won't directly affect the effect slot until they're reapplied like this. */ - alAuxiliaryEffectSloti(slots[0], AL_EFFECTSLOT_EFFECT, effects[0]); - alAuxiliaryEffectSloti(slots[1], AL_EFFECTSLOT_EFFECT, effects[1]); + alAuxiliaryEffectSloti(slots[0], AL_EFFECTSLOT_EFFECT, (ALint)effects[0]); + alAuxiliaryEffectSloti(slots[1], AL_EFFECTSLOT_EFFECT, (ALint)effects[1]); assert(alGetError()==AL_NO_ERROR && "Failed to set effect slot"); /* For the purposes of this example, prepare a filter that optionally @@ -621,8 +621,8 @@ int main(int argc, char **argv) alGenSources(1, &source); alSourcei(source, AL_LOOPING, AL_TRUE); alSource3f(source, AL_POSITION, -5.0f, 0.0f, -2.0f); - alSourcei(source, AL_DIRECT_FILTER, direct_filter); - alSourcei(source, AL_BUFFER, buffer); + alSourcei(source, AL_DIRECT_FILTER, (ALint)direct_filter); + alSourcei(source, AL_BUFFER, (ALint)buffer); /* Connect the source to the effect slots. Here, we connect source send 0 * to Zone 0's slot, and send 1 to Zone 1's slot. Filters can be specified @@ -631,8 +631,8 @@ int main(int argc, char **argv) * can only see a zone through a window or thin wall may be attenuated for * that zone. */ - alSource3i(source, AL_AUXILIARY_SEND_FILTER, slots[0], 0, AL_FILTER_NULL); - alSource3i(source, AL_AUXILIARY_SEND_FILTER, slots[1], 1, AL_FILTER_NULL); + alSource3i(source, AL_AUXILIARY_SEND_FILTER, (ALint)slots[0], 0, AL_FILTER_NULL); + alSource3i(source, AL_AUXILIARY_SEND_FILTER, (ALint)slots[1], 1, AL_FILTER_NULL); assert(alGetError()==AL_NO_ERROR && "Failed to setup sound source"); /* Get the current time as the base for timing in the main loop. */ diff --git a/examples/alplay.c b/examples/alplay.c index 4ff8fb7f..09ad96b4 100644 --- a/examples/alplay.c +++ b/examples/alplay.c @@ -101,7 +101,7 @@ static ALuint LoadSound(const char *filename) * close the file. */ buffer = 0; alGenBuffers(1, &buffer); - alBufferData(buffer, format, sample->buffer, slen, sample->actual.rate); + alBufferData(buffer, format, sample->buffer, (ALsizei)slen, (ALsizei)sample->actual.rate); Sound_FreeSample(sample); /* Check if an error occured, and clean up if so. */ @@ -151,7 +151,7 @@ int main(int argc, char **argv) /* Create the source to play the sound with. */ source = 0; alGenSources(1, &source); - alSourcei(source, AL_BUFFER, buffer); + alSourcei(source, AL_BUFFER, (ALint)buffer); assert(alGetError()==AL_NO_ERROR && "Failed to setup sound source"); /* Play the sound until it finishes. */ diff --git a/examples/alrecord.c b/examples/alrecord.c index d65414c9..627f8540 100644 --- a/examples/alrecord.c +++ b/examples/alrecord.c @@ -73,9 +73,9 @@ typedef struct Recorder { ALuint mDataSize; float mRecTime; - int mChannels; - int mBits; - int mSampleRate; + ALuint mChannels; + ALuint mBits; + ALuint mSampleRate; ALuint mFrameSize; ALbyte *mBuffer; ALsizei mBufferSize; @@ -139,7 +139,7 @@ int main(int argc, char **argv) return 1; } - recorder.mChannels = strtol(argv[1], &end, 0); + recorder.mChannels = (ALuint)strtoul(argv[1], &end, 0); if((recorder.mChannels != 1 && recorder.mChannels != 2) || (end && *end != '\0')) { fprintf(stderr, "Invalid channels: %s\n", argv[1]); @@ -156,7 +156,7 @@ int main(int argc, char **argv) return 1; } - recorder.mBits = strtol(argv[1], &end, 0); + recorder.mBits = (ALuint)strtoul(argv[1], &end, 0); if((recorder.mBits != 8 && recorder.mBits != 16 && recorder.mBits != 32) || (end && *end != '\0')) { @@ -174,7 +174,7 @@ int main(int argc, char **argv) return 1; } - recorder.mSampleRate = strtol(argv[1], &end, 0); + recorder.mSampleRate = (ALuint)strtoul(argv[1], &end, 0); if(!(recorder.mSampleRate >= 8000 && recorder.mSampleRate <= 96000) || (end && *end != '\0')) { fprintf(stderr, "Invalid sample rate: %s\n", argv[1]); @@ -285,15 +285,15 @@ int main(int argc, char **argv) // 16-bit val, format type id (1 = integer PCM, 3 = float PCM) fwrite16le((recorder.mBits == 32) ? 0x0003 : 0x0001, recorder.mFile); // 16-bit val, channel count - fwrite16le(recorder.mChannels, recorder.mFile); + fwrite16le((ALushort)recorder.mChannels, recorder.mFile); // 32-bit val, frequency fwrite32le(recorder.mSampleRate, recorder.mFile); // 32-bit val, bytes per second fwrite32le(recorder.mSampleRate * recorder.mFrameSize, recorder.mFile); // 16-bit val, frame size - fwrite16le(recorder.mFrameSize, recorder.mFile); + fwrite16le((ALushort)recorder.mFrameSize, recorder.mFile); // 16-bit val, bits per sample - fwrite16le(recorder.mBits, recorder.mFile); + fwrite16le((ALushort)recorder.mBits, recorder.mFile); // 16-bit val, extra byte count fwrite16le(0, recorder.mFile); @@ -331,7 +331,7 @@ int main(int argc, char **argv) } if(count > recorder.mBufferSize) { - ALbyte *data = calloc(recorder.mFrameSize, count); + ALbyte *data = calloc(recorder.mFrameSize, (ALuint)count); free(recorder.mBuffer); recorder.mBuffer = data; recorder.mBufferSize = count; @@ -365,7 +365,7 @@ int main(int argc, char **argv) } } #endif - recorder.mDataSize += (ALuint)fwrite(recorder.mBuffer, recorder.mFrameSize, count, + recorder.mDataSize += (ALuint)fwrite(recorder.mBuffer, recorder.mFrameSize, (ALuint)count, recorder.mFile); } alcCaptureStop(recorder.mDevice); @@ -385,7 +385,7 @@ int main(int argc, char **argv) { fwrite32le(recorder.mDataSize*recorder.mFrameSize, recorder.mFile); if(fseek(recorder.mFile, 4, SEEK_SET) == 0) - fwrite32le(total_size - 8, recorder.mFile); + fwrite32le((ALuint)total_size - 8, recorder.mFile); } fclose(recorder.mFile); diff --git a/examples/alreverb.c b/examples/alreverb.c index e1d3c207..68f0269f 100644 --- a/examples/alreverb.c +++ b/examples/alreverb.c @@ -209,7 +209,7 @@ static ALuint LoadSound(const char *filename) * close the file. */ buffer = 0; alGenBuffers(1, &buffer); - alBufferData(buffer, format, sample->buffer, slen, sample->actual.rate); + alBufferData(buffer, format, sample->buffer, (ALsizei)slen, (ALsizei)sample->actual.rate); Sound_FreeSample(sample); /* Check if an error occured, and clean up if so. */ @@ -309,18 +309,18 @@ int main(int argc, char **argv) * effectively copies the effect properties. You can modify or delete the * effect object afterward without affecting the effect slot. */ - alAuxiliaryEffectSloti(slot, AL_EFFECTSLOT_EFFECT, effect); + alAuxiliaryEffectSloti(slot, AL_EFFECTSLOT_EFFECT, (ALint)effect); assert(alGetError()==AL_NO_ERROR && "Failed to set effect slot"); /* Create the source to play the sound with. */ source = 0; alGenSources(1, &source); - alSourcei(source, AL_BUFFER, buffer); + alSourcei(source, AL_BUFFER, (ALint)buffer); /* Connect the source to the effect slot. This tells the source to use the * effect slot 'slot', on send #0 with the AL_FILTER_NULL filter object. */ - alSource3i(source, AL_AUXILIARY_SEND_FILTER, slot, 0, AL_FILTER_NULL); + alSource3i(source, AL_AUXILIARY_SEND_FILTER, (ALint)slot, 0, AL_FILTER_NULL); assert(alGetError()==AL_NO_ERROR && "Failed to setup sound source"); /* Play the sound until it finishes. */ diff --git a/examples/alstream.c b/examples/alstream.c index cb447355..56505ddb 100644 --- a/examples/alstream.c +++ b/examples/alstream.c @@ -160,10 +160,10 @@ static int OpenPlayerFile(StreamPlayer *player, const char *filename) fprintf(stderr, "Unsupported channel count: %d\n", player->sample->actual.channels); goto error; } - player->srate = player->sample->actual.rate; + player->srate = (ALsizei)player->sample->actual.rate; frame_size = player->sample->actual.channels * - SDL_AUDIO_BITSIZE(player->sample->actual.format) / 8; + SDL_AUDIO_BITSIZE(player->sample->actual.format) / 8; /* Set the buffer size, given the desired millisecond length. */ Sound_SetBufferSize(player->sample, (Uint32)((Uint64)player->srate*BUFFER_TIME_MS/1000) * @@ -191,7 +191,7 @@ static void ClosePlayerFile(StreamPlayer *player) /* Prebuffers some audio from the file, and starts playing the source */ static int StartPlayer(StreamPlayer *player) { - size_t i; + ALsizei i; /* Rewind the source position and clear the buffer queue */ alSourceRewind(player->source); @@ -204,8 +204,8 @@ static int StartPlayer(StreamPlayer *player) Uint32 slen = Sound_Decode(player->sample); if(slen == 0) break; - alBufferData(player->buffers[i], player->format, - player->sample->buffer, slen, player->srate); + alBufferData(player->buffers[i], player->format, player->sample->buffer, (ALsizei)slen, + player->srate); } if(alGetError() != AL_NO_ERROR) { @@ -255,8 +255,8 @@ static int UpdatePlayer(StreamPlayer *player) slen = Sound_Decode(player->sample); if(slen > 0) { - alBufferData(bufid, player->format, player->sample->buffer, slen, - player->srate); + alBufferData(bufid, player->format, player->sample->buffer, (ALsizei)slen, + player->srate); alSourceQueueBuffers(player->source, 1, &bufid); } if(alGetError() != AL_NO_ERROR) @@ -323,8 +323,7 @@ int main(int argc, char **argv) else namepart = argv[i]; - printf("Playing: %s (%s, %dhz)\n", namepart, FormatName(player->format), - player->srate); + printf("Playing: %s (%s, %dhz)\n", namepart, FormatName(player->format), player->srate); fflush(stdout); if(!StartPlayer(player)) diff --git a/examples/altonegen.c b/examples/altonegen.c index 628e695d..aacc3496 100644 --- a/examples/altonegen.c +++ b/examples/altonegen.c @@ -91,7 +91,7 @@ static void ApplySin(ALfloat *data, ALdouble g, ALuint srate, ALuint freq) static ALuint CreateWave(enum WaveType type, ALuint freq, ALuint srate) { ALuint seed = 22222; - ALint data_size; + ALuint data_size; ALfloat *data; ALuint buffer; ALenum err; @@ -142,7 +142,7 @@ static ALuint CreateWave(enum WaveType type, ALuint freq, ALuint srate) /* Buffer the audio data into a new buffer object. */ buffer = 0; alGenBuffers(1, &buffer); - alBufferData(buffer, AL_FORMAT_MONO_FLOAT32, data, data_size, srate); + alBufferData(buffer, AL_FORMAT_MONO_FLOAT32, data, (ALsizei)data_size, (ALsizei)srate); free(data); /* Check if an error occured, and clean up if so. */ @@ -257,7 +257,7 @@ int main(int argc, char *argv[]) srate = dev_rate; /* Load the sound into a buffer. */ - buffer = CreateWave(wavetype, tone_freq, srate); + buffer = CreateWave(wavetype, (ALuint)tone_freq, (ALuint)srate); if(!buffer) { CloseAL(); @@ -271,7 +271,7 @@ int main(int argc, char *argv[]) /* Create the source to play the sound with. */ source = 0; alGenSources(1, &source); - alSourcei(source, AL_BUFFER, buffer); + alSourcei(source, AL_BUFFER, (ALint)buffer); assert(alGetError()==AL_NO_ERROR && "Failed to setup sound source"); /* Play the sound for a while. */ diff --git a/examples/common/alhelpers.c b/examples/common/alhelpers.c index b387fd2d..730d2e13 100644 --- a/examples/common/alhelpers.c +++ b/examples/common/alhelpers.c @@ -159,12 +159,12 @@ int altime_get(void) struct timespec ts; int ret = clock_gettime(CLOCK_REALTIME, &ts); if(ret != 0) return 0; - cur_time = ts.tv_sec*1000 + ts.tv_nsec/1000000; + cur_time = (int)(ts.tv_sec*1000 + ts.tv_nsec/1000000); #else /* _POSIX_TIMERS > 0 */ struct timeval tv; int ret = gettimeofday(&tv, NULL); if(ret != 0) return 0; - cur_time = tv.tv_sec*1000 + tv.tv_usec/1000; + cur_time = (int)(tv.tv_sec*1000 + tv.tv_usec/1000); #endif if(!start_time) diff --git a/utils/makemhr/loadsofa.cpp b/utils/makemhr/loadsofa.cpp index e82376aa..02911e12 100644 --- a/utils/makemhr/loadsofa.cpp +++ b/utils/makemhr/loadsofa.cpp @@ -50,7 +50,7 @@ static const char *SofaErrorStr(int err) * of other axes as necessary. The epsilons are used to constrain the * equality of unique elements. */ -static uint GetUniquelySortedElems(const uint m, const float *triplets, const int axis, +static uint GetUniquelySortedElems(const uint m, const float *triplets, const uint axis, const double *const (&filters)[3], const double (&epsilons)[3], float *elems) { uint count{0u}; diff --git a/utils/openal-info.c b/utils/openal-info.c index 12dc6311..cc628b6e 100644 --- a/utils/openal-info.c +++ b/utils/openal-info.c @@ -124,7 +124,7 @@ static void printList(const char *list, char separator) next = strchr(list, separator); if(next) { - len = next-list; + len = (size_t)(next-list); do { next++; } while(*next == separator); -- cgit v1.2.3 From 807d3b64cac2793ce678acb3fc4d4191b2252875 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sat, 14 Sep 2019 18:27:57 -0700 Subject: Enable and fix more warnings --- CMakeLists.txt | 7 ++----- al/event.cpp | 18 +++++------------- al/source.cpp | 30 ++++++++++++++++-------------- alc/alc.cpp | 8 ++++---- alc/alconfig.cpp | 12 ++++++------ alc/backends/base.h | 2 ++ alc/backends/pulseaudio.cpp | 2 +- alc/filters/biquad.cpp | 28 ++++++++++++++-------------- alc/filters/biquad.h | 32 +++++++++++++++----------------- alc/filters/splitter.cpp | 44 ++++++++++++++++++++++---------------------- alc/filters/splitter.h | 10 +++++----- alc/hrtf.cpp | 8 ++++---- alc/hrtf.h | 2 +- alc/mixvoice.cpp | 29 +++++++++++++++-------------- utils/makemhr/loaddef.cpp | 9 ++++----- utils/makemhr/loadsofa.cpp | 10 +++------- utils/sofa-info.cpp | 10 +++------- 17 files changed, 122 insertions(+), 139 deletions(-) (limited to 'utils') diff --git a/CMakeLists.txt b/CMakeLists.txt index 3ec17ce5..44d829d6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -220,11 +220,8 @@ IF(MSVC) ENDFOREACH(flag_var) ENDIF() ELSE() - SET(C_FLAGS ${C_FLAGS} -Winline -Wall $<$:-Wold-style-cast> -Wconversion) - CHECK_C_COMPILER_FLAG(-Wextra HAVE_W_EXTRA) - IF(HAVE_W_EXTRA) - SET(C_FLAGS ${C_FLAGS} -Wextra) - ENDIF() + SET(C_FLAGS ${C_FLAGS} -Winline -Wall -Wextra -Wshadow -Wconversion -Wcast-align + $<$:-Wold-style-cast -Wnon-virtual-dtor -Woverloaded-virtual>) IF(ALSOFT_WERROR) SET(C_FLAGS ${C_FLAGS} -Werror) diff --git a/al/event.cpp b/al/event.cpp index 2832ace7..0da48cbf 100644 --- a/al/event.cpp +++ b/al/event.cpp @@ -44,21 +44,13 @@ static int EventThread(ALCcontext *context) std::lock_guard _{context->mEventCbLock}; do { - auto &evt = *reinterpret_cast(evt_data.buf); + auto *evt_ptr = reinterpret_cast(evt_data.buf); evt_data.buf += sizeof(AsyncEvent); evt_data.len -= 1; - /* This automatically destructs the event object and advances the - * ringbuffer's read offset at the end of scope. - */ - const struct EventAutoDestructor { - AsyncEvent &evt_; - RingBuffer *ring_; - ~EventAutoDestructor() - { - al::destroy_at(std::addressof(evt_)); - ring_->readAdvance(1); - } - } _{evt, ring}; + + AsyncEvent evt{*evt_ptr}; + al::destroy_at(evt_ptr); + ring->readAdvance(1); quitnow = evt.EnumType == EventType_KillThread; if UNLIKELY(quitnow) break; diff --git a/al/source.cpp b/al/source.cpp index 733758f7..f8d5fbcd 100644 --- a/al/source.cpp +++ b/al/source.cpp @@ -1199,7 +1199,7 @@ bool SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a std::unique_ptr temp{oldlist}; oldlist = temp->mNext.load(std::memory_order_relaxed); - if(ALbuffer *buffer{temp->mBuffer}) + if((buffer=temp->mBuffer) != nullptr) DecrementRef(buffer->ref); } return true; @@ -1215,7 +1215,6 @@ bool SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a if(IsPlayingOrPaused(Source)) { - ALCdevice *device{Context->mDevice.get()}; BackendLockGuard _{*device->Backend}; if(ALvoice *voice{GetSourceVoice(Source, Context)}) { @@ -1347,8 +1346,8 @@ bool SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a { /* Add refcount on the new slot, and release the previous slot */ if(slot) IncrementRef(slot->ref); - if(auto *slot = Source->Send[static_cast(values[1])].Slot) - DecrementRef(slot->ref); + if(auto *oldslot = Source->Send[static_cast(values[1])].Slot) + DecrementRef(oldslot->ref); Source->Send[static_cast(values[1])].Slot = slot; /* We must force an update if the auxiliary slot changed on an @@ -1361,8 +1360,8 @@ bool SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a else { if(slot) IncrementRef(slot->ref); - if(auto *slot = Source->Send[static_cast(values[1])].Slot) - DecrementRef(slot->ref); + if(auto *oldslot = Source->Send[static_cast(values[1])].Slot) + DecrementRef(oldslot->ref); Source->Send[static_cast(values[1])].Slot = slot; UpdateSourceProps(Source, Context); } @@ -1730,7 +1729,6 @@ bool GetSourcedv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a bool GetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const al::span values) { - ALbufferlistitem *BufferList; ALdouble dvals[MaxValues]; bool err; @@ -1748,9 +1746,13 @@ bool GetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a case AL_BUFFER: CHECKSIZE(values, 1); - BufferList = (Source->SourceType == AL_STATIC) ? Source->queue : nullptr; - values[0] = (BufferList && BufferList->mBuffer) ? - static_cast(BufferList->mBuffer->id) : 0; + { + ALbufferlistitem *BufferList{nullptr}; + if(Source->SourceType == AL_STATIC) BufferList = Source->queue; + ALbuffer *buffer{nullptr}; + if(BufferList) buffer = BufferList->mBuffer; + values[0] = buffer ? static_cast(buffer->id) : 0; + } return true; case AL_SOURCE_STATE: @@ -1760,9 +1762,7 @@ bool GetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a case AL_BUFFERS_QUEUED: CHECKSIZE(values, 1); - if(!(BufferList=Source->queue)) - values[0] = 0; - else + if(ALbufferlistitem *BufferList{Source->queue}) { ALsizei count{0}; do { @@ -1771,6 +1771,8 @@ bool GetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, const a } while(BufferList != nullptr); values[0] = count; } + else + values[0] = 0; return true; case AL_BUFFERS_PROCESSED: @@ -3135,7 +3137,7 @@ START_API_FUNC { std::unique_ptr head{BufferListStart}; BufferListStart = head->mNext.load(std::memory_order_relaxed); - if(ALbuffer *buffer{head->mBuffer}) DecrementRef(buffer->ref); + if((buffer=head->mBuffer) != nullptr) DecrementRef(buffer->ref); } return; } diff --git a/alc/alc.cpp b/alc/alc.cpp index 8e9d3963..fa88cba8 100644 --- a/alc/alc.cpp +++ b/alc/alc.cpp @@ -3731,11 +3731,11 @@ START_API_FUNC al::vector orphanctxs; for(ALCcontext *ctx : *dev->mContexts.load()) { - auto iter = std::lower_bound(ContextList.begin(), ContextList.end(), ctx); - if(iter != ContextList.end() && *iter == ctx) + auto ctxiter = std::lower_bound(ContextList.begin(), ContextList.end(), ctx); + if(ctxiter != ContextList.end() && *ctxiter == ctx) { - orphanctxs.emplace_back(std::move(*iter)); - ContextList.erase(iter); + orphanctxs.emplace_back(std::move(*ctxiter)); + ContextList.erase(ctxiter); } } listlock.unlock(); diff --git a/alc/alconfig.cpp b/alc/alconfig.cpp index 8ca81bc8..666c2c2d 100644 --- a/alc/alconfig.cpp +++ b/alc/alconfig.cpp @@ -359,7 +359,7 @@ void ReadALConfig() else fname += "alsoft.conf"; TRACE("Loading config %s...\n", fname.c_str()); - al::ifstream f{fname}; + f = al::ifstream{fname}; if(f.is_open()) LoadConfigFromFile(f); } @@ -376,7 +376,7 @@ void ReadALConfig() if((configURL=CFBundleCopyResourceURL(mainBundle, CFSTR(".alsoftrc"), CFSTR(""), nullptr)) && CFURLGetFileSystemRepresentation(configURL, true, fileName, sizeof(fileName))) { - al::ifstream f{reinterpret_cast(fileName)}; + f = al::ifstream{reinterpret_cast(fileName)}; if(f.is_open()) LoadConfigFromFile(f); } @@ -390,7 +390,7 @@ void ReadALConfig() else fname += ".alsoftrc"; TRACE("Loading config %s...\n", fname.c_str()); - al::ifstream f{fname}; + f = al::ifstream{fname}; if(f.is_open()) LoadConfigFromFile(f); } @@ -414,7 +414,7 @@ void ReadALConfig() if(!fname.empty()) { TRACE("Loading config %s...\n", fname.c_str()); - al::ifstream f{fname}; + f = al::ifstream{fname}; if(f.is_open()) LoadConfigFromFile(f); } @@ -426,7 +426,7 @@ void ReadALConfig() else ppath += "alsoft.conf"; TRACE("Loading config %s...\n", ppath.c_str()); - al::ifstream f{ppath}; + f = al::ifstream{ppath}; if(f.is_open()) LoadConfigFromFile(f); } @@ -434,7 +434,7 @@ void ReadALConfig() if(auto confname = al::getenv("ALSOFT_CONF")) { TRACE("Loading config %s...\n", confname->c_str()); - al::ifstream f{*confname}; + f = al::ifstream{*confname}; if(f.is_open()) LoadConfigFromFile(f); } diff --git a/alc/backends/base.h b/alc/backends/base.h index 5e294fe8..e88734dc 100644 --- a/alc/backends/base.h +++ b/alc/backends/base.h @@ -68,6 +68,8 @@ enum class DevProbe { struct BackendFactory { + virtual ~BackendFactory() = default; + virtual bool init() = 0; virtual bool querySupport(BackendType type) = 0; diff --git a/alc/backends/pulseaudio.cpp b/alc/backends/pulseaudio.cpp index 9c54c07b..23d4e71a 100644 --- a/alc/backends/pulseaudio.cpp +++ b/alc/backends/pulseaudio.cpp @@ -484,7 +484,7 @@ pa_stream *pulse_connect_stream(const char *device_name, std::unique_lock::setParams(BiquadType type, Real gain, Real f0norm, Rea break; } - a1 = a[1] / a[0]; - a2 = a[2] / a[0]; - b0 = b[0] / a[0]; - b1 = b[1] / a[0]; - b2 = b[2] / a[0]; + mA1 = a[1] / a[0]; + mA2 = a[2] / a[0]; + mB0 = b[0] / a[0]; + mB1 = b[1] / a[0]; + mB2 = b[2] / a[0]; } template @@ -93,13 +93,13 @@ void BiquadFilterR::process(Real *dst, const Real *src, const size_t numsa { ASSUME(numsamples > 0); - const Real b0{this->b0}; - const Real b1{this->b1}; - const Real b2{this->b2}; - const Real a1{this->a1}; - const Real a2{this->a2}; - Real z1{this->z1}; - Real z2{this->z2}; + const Real b0{mB0}; + const Real b1{mB1}; + const Real b2{mB2}; + const Real a1{mA1}; + const Real a2{mA2}; + Real z1{mZ1}; + Real z2{mZ2}; /* Processing loop is Transposed Direct Form II. This requires less storage * compared to Direct Form I (only two delay components, instead of a four- @@ -118,8 +118,8 @@ void BiquadFilterR::process(Real *dst, const Real *src, const size_t numsa }; std::transform(src, src+numsamples, dst, proc_sample); - this->z1 = z1; - this->z2 = z2; + mZ1 = z1; + mZ2 = z2; } template class BiquadFilterR; diff --git a/alc/filters/biquad.h b/alc/filters/biquad.h index 9de86f2f..9af954ae 100644 --- a/alc/filters/biquad.h +++ b/alc/filters/biquad.h @@ -38,14 +38,14 @@ enum class BiquadType { template class BiquadFilterR { /* Last two delayed components for direct form II. */ - Real z1{0.0f}, z2{0.0f}; + Real mZ1{0.0f}, mZ2{0.0f}; /* Transfer function coefficients "b" (numerator) */ - Real b0{1.0f}, b1{0.0f}, b2{0.0f}; + Real mB0{1.0f}, mB1{0.0f}, mB2{0.0f}; /* Transfer function coefficients "a" (denominator; a0 is pre-applied). */ - Real a1{0.0f}, a2{0.0f}; + Real mA1{0.0f}, mA2{0.0f}; public: - void clear() noexcept { z1 = z2 = 0.0f; } + void clear() noexcept { mZ1 = mZ2 = 0.0f; } /** * Sets the filter state for the specified filter type and its parameters. @@ -65,26 +65,24 @@ public: void copyParamsFrom(const BiquadFilterR &other) { - b0 = other.b0; - b1 = other.b1; - b2 = other.b2; - a1 = other.a1; - a2 = other.a2; + mB0 = other.mB0; + mB1 = other.mB1; + mB2 = other.mB2; + mA1 = other.mA1; + mA2 = other.mA2; } void process(Real *dst, const Real *src, const size_t numsamples); /* Rather hacky. It's just here to support "manual" processing. */ - std::pair getComponents() const noexcept - { return {z1, z2}; } - void setComponents(Real z1_, Real z2_) noexcept - { z1 = z1_; z2 = z2_; } - Real processOne(const Real in, Real &z1_, Real &z2_) const noexcept + std::pair getComponents() const noexcept { return {mZ1, mZ2}; } + void setComponents(Real z1, Real z2) noexcept { mZ1 = z1; mZ2 = z2; } + Real processOne(const Real in, Real &z1, Real &z2) const noexcept { - Real out{in*b0 + z1_}; - z1_ = in*b1 - out*a1 + z2_; - z2_ = in*b2 - out*a2; + Real out{in*mB0 + z1}; + z1 = in*mB1 - out*mA1 + z2; + z2 = in*mB2 - out*mA2; return out; } diff --git a/alc/filters/splitter.cpp b/alc/filters/splitter.cpp index 66806ea9..c6218e70 100644 --- a/alc/filters/splitter.cpp +++ b/alc/filters/splitter.cpp @@ -17,13 +17,13 @@ void BandSplitterR::init(Real f0norm) const Real w{f0norm * al::MathDefs::Tau()}; const Real cw{std::cos(w)}; if(cw > std::numeric_limits::epsilon()) - coeff = (std::sin(w) - 1.0f) / cw; + mCoeff = (std::sin(w) - 1.0f) / cw; else - coeff = cw * -0.5f; + mCoeff = cw * -0.5f; - lp_z1 = 0.0f; - lp_z2 = 0.0f; - ap_z1 = 0.0f; + mLpZ1 = 0.0f; + mLpZ2 = 0.0f; + mApZ1 = 0.0f; } template @@ -31,11 +31,11 @@ void BandSplitterR::process(Real *hpout, Real *lpout, const Real *input, c { ASSUME(count > 0); - const Real ap_coeff{this->coeff}; - const Real lp_coeff{this->coeff*0.5f + 0.5f}; - Real lp_z1{this->lp_z1}; - Real lp_z2{this->lp_z2}; - Real ap_z1{this->ap_z1}; + const Real ap_coeff{mCoeff}; + const Real lp_coeff{mCoeff*0.5f + 0.5f}; + Real lp_z1{mLpZ1}; + Real lp_z2{mLpZ2}; + Real ap_z1{mApZ1}; auto proc_sample = [ap_coeff,lp_coeff,&lp_z1,&lp_z2,&ap_z1,&lpout](const Real in) noexcept -> Real { /* Low-pass sample processing. */ @@ -57,9 +57,9 @@ void BandSplitterR::process(Real *hpout, Real *lpout, const Real *input, c return ap_y - lp_y; }; std::transform(input, input+count, hpout, proc_sample); - this->lp_z1 = lp_z1; - this->lp_z2 = lp_z2; - this->ap_z1 = ap_z1; + mLpZ1 = lp_z1; + mLpZ2 = lp_z2; + mApZ1 = ap_z1; } template @@ -67,11 +67,11 @@ void BandSplitterR::applyHfScale(Real *samples, const Real hfscale, const { ASSUME(count > 0); - const Real ap_coeff{this->coeff}; - const Real lp_coeff{this->coeff*0.5f + 0.5f}; - Real lp_z1{this->lp_z1}; - Real lp_z2{this->lp_z2}; - Real ap_z1{this->ap_z1}; + const Real ap_coeff{mCoeff}; + const Real lp_coeff{mCoeff*0.5f + 0.5f}; + Real lp_z1{mLpZ1}; + Real lp_z2{mLpZ2}; + Real ap_z1{mApZ1}; auto proc_sample = [hfscale,ap_coeff,lp_coeff,&lp_z1,&lp_z2,&ap_z1](const Real in) noexcept -> Real { /* Low-pass sample processing. */ @@ -91,9 +91,9 @@ void BandSplitterR::applyHfScale(Real *samples, const Real hfscale, const return (ap_y-lp_y)*hfscale + lp_y; }; std::transform(samples, samples+count, samples, proc_sample); - this->lp_z1 = lp_z1; - this->lp_z2 = lp_z2; - this->ap_z1 = ap_z1; + mLpZ1 = lp_z1; + mLpZ2 = lp_z2; + mApZ1 = ap_z1; } template @@ -101,7 +101,7 @@ void BandSplitterR::applyAllpass(Real *samples, const size_t count) const { ASSUME(count > 0); - const Real coeff{this->coeff}; + const Real coeff{mCoeff}; Real z1{0.0f}; auto proc_sample = [coeff,&z1](const Real in) noexcept -> Real { diff --git a/alc/filters/splitter.h b/alc/filters/splitter.h index b024f0c3..5117a244 100644 --- a/alc/filters/splitter.h +++ b/alc/filters/splitter.h @@ -7,10 +7,10 @@ /* Band splitter. Splits a signal into two phase-matching frequency bands. */ template class BandSplitterR { - Real coeff{0.0f}; - Real lp_z1{0.0f}; - Real lp_z2{0.0f}; - Real ap_z1{0.0f}; + Real mCoeff{0.0f}; + Real mLpZ1{0.0f}; + Real mLpZ2{0.0f}; + Real mApZ1{0.0f}; public: BandSplitterR() = default; @@ -18,7 +18,7 @@ public: BandSplitterR(Real f0norm) { init(f0norm); } void init(Real f0norm); - void clear() noexcept { lp_z1 = lp_z2 = ap_z1 = 0.0f; } + void clear() noexcept { mLpZ1 = mLpZ2 = mApZ1 = 0.0f; } void process(Real *hpout, Real *lpout, const Real *input, const size_t count); void applyHfScale(Real *samples, const Real hfscale, const size_t count); diff --git a/alc/hrtf.cpp b/alc/hrtf.cpp index e20bf0a9..3d2f36ea 100644 --- a/alc/hrtf.cpp +++ b/alc/hrtf.cpp @@ -475,7 +475,7 @@ std::unique_ptr CreateHrtfStore(ALuint rate, ALushort irSize, const A ERR("Out of memory allocating storage for %s.\n", filename); else { - InitRef(Hrtf->ref, 1u); + InitRef(Hrtf->mRef, 1u); Hrtf->sampleRate = rate; Hrtf->irSize = irSize; Hrtf->fdCount = fdCount; @@ -1362,13 +1362,13 @@ HrtfEntry *GetLoadedHrtf(HrtfHandle *handle) void HrtfEntry::IncRef() { - auto ref = IncrementRef(this->ref); + auto ref = IncrementRef(mRef); TRACE("HrtfEntry %p increasing refcount to %u\n", this, ref); } void HrtfEntry::DecRef() { - auto ref = DecrementRef(this->ref); + auto ref = DecrementRef(mRef); TRACE("HrtfEntry %p decreasing refcount to %u\n", this, ref); if(ref == 0) { @@ -1378,7 +1378,7 @@ void HrtfEntry::DecRef() auto delete_unused = [](HrtfHandlePtr &handle) -> void { HrtfEntry *entry{handle->entry.get()}; - if(entry && ReadRef(entry->ref) == 0) + if(entry && ReadRef(entry->mRef) == 0) { TRACE("Unloading unused HRTF %s\n", handle->filename.data()); handle->entry = nullptr; diff --git a/alc/hrtf.h b/alc/hrtf.h index 92b3fd96..20b3409d 100644 --- a/alc/hrtf.h +++ b/alc/hrtf.h @@ -26,7 +26,7 @@ struct HrtfHandle; struct HrtfEntry { - RefCount ref; + RefCount mRef; ALuint sampleRate; ALuint irSize; diff --git a/alc/mixvoice.cpp b/alc/mixvoice.cpp index d7a32f35..2b5972f3 100644 --- a/alc/mixvoice.cpp +++ b/alc/mixvoice.cpp @@ -405,24 +405,24 @@ ALfloat *LoadBufferStatic(ALbufferlistitem *BufferListItem, ALbufferlistitem *&B BufferLoopItem = nullptr; /* Load what's left to play from the buffer */ - const size_t DataSize{minz(SrcBuffer.size(), Buffer->SampleLen-DataPosInt)}; + const size_t DataRem{minz(SrcBuffer.size(), Buffer->SampleLen-DataPosInt)}; const al::byte *Data{Buffer->mData.data()}; Data += (DataPosInt*NumChannels + chan)*SampleSize; - LoadSamples(SrcBuffer.data(), Data, NumChannels, Buffer->mFmtType, DataSize); - SrcBuffer = SrcBuffer.subspan(DataSize); + LoadSamples(SrcBuffer.data(), Data, NumChannels, Buffer->mFmtType, DataRem); + SrcBuffer = SrcBuffer.subspan(DataRem); } else { /* Load what's left of this loop iteration */ - const size_t DataSize{minz(SrcBuffer.size(), LoopEnd-DataPosInt)}; + const size_t DataRem{minz(SrcBuffer.size(), LoopEnd-DataPosInt)}; const al::byte *Data{Buffer->mData.data()}; Data += (DataPosInt*NumChannels + chan)*SampleSize; - LoadSamples(SrcBuffer.data(), Data, NumChannels, Buffer->mFmtType, DataSize); - SrcBuffer = SrcBuffer.subspan(DataSize); + LoadSamples(SrcBuffer.data(), Data, NumChannels, Buffer->mFmtType, DataRem); + SrcBuffer = SrcBuffer.subspan(DataRem); /* Load any repeats of the loop we can to fill the buffer. */ const auto LoopSize = static_cast(LoopEnd - LoopStart); @@ -430,8 +430,7 @@ ALfloat *LoadBufferStatic(ALbufferlistitem *BufferListItem, ALbufferlistitem *&B { const size_t DataSize{minz(SrcBuffer.size(), LoopSize)}; - const al::byte *Data{Buffer->mData.data()}; - Data += (LoopStart*NumChannels + chan)*SampleSize; + Data = Buffer->mData.data() + (LoopStart*NumChannels + chan)*SampleSize; LoadSamples(SrcBuffer.data(), Data, NumChannels, Buffer->mFmtType, DataSize); SrcBuffer = SrcBuffer.subspan(DataSize); @@ -510,12 +509,14 @@ void ALvoice::mix(State vstate, ALCcontext *Context, const ALuint SamplesToDo) for(ALuint chan{0};chan < NumChannels;chan++) { ChannelData &chandata = mChans[chan]; - DirectParams &parms = chandata.mDryParams; - if(!(mFlags&VOICE_HAS_HRTF)) - std::copy(std::begin(parms.Gains.Target), std::end(parms.Gains.Target), - std::begin(parms.Gains.Current)); - else - parms.Hrtf.Old = parms.Hrtf.Target; + { + DirectParams &parms = chandata.mDryParams; + if(!(mFlags&VOICE_HAS_HRTF)) + std::copy(std::begin(parms.Gains.Target), std::end(parms.Gains.Target), + std::begin(parms.Gains.Current)); + else + parms.Hrtf.Old = parms.Hrtf.Target; + } for(ALuint send{0};send < NumSends;++send) { if(mSend[send].Buffer.empty()) diff --git a/utils/makemhr/loaddef.cpp b/utils/makemhr/loaddef.cpp index 5f6d76d8..aaefd62c 100644 --- a/utils/makemhr/loaddef.cpp +++ b/utils/makemhr/loaddef.cpp @@ -1737,7 +1737,7 @@ static int ProcessSources(TokenReaderT *tr, HrirDataT *hData) hData->mHrirsBase.resize(channels * hData->mIrCount * hData->mIrSize); double *hrirs = hData->mHrirsBase.data(); std::vector hrir(hData->mIrPoints); - uint line, col, fi, ei, ai, ti; + uint line, col, fi, ei, ai; int count; printf("Loading sources..."); @@ -1827,8 +1827,7 @@ static int ProcessSources(TokenReaderT *tr, HrirDataT *hData) for(fi = 0;fi < hData->mFdCount;fi++) { double delta = aer[2] - hData->mFds[fi].mDistance; - if(std::abs(delta) < 0.001) - break; + if(std::abs(delta) < 0.001) break; } if(fi >= hData->mFdCount) continue; @@ -1892,7 +1891,6 @@ static int ProcessSources(TokenReaderT *tr, HrirDataT *hData) for(;;) { SourceRefT src; - uint ti = 0; if(!ReadSourceRef(tr, &src)) return 0; @@ -1907,6 +1905,7 @@ static int ProcessSources(TokenReaderT *tr, HrirDataT *hData) if(!LoadSource(&src, hData->mIrRate, hData->mIrPoints, hrir.data())) return 0; + uint ti{0}; if(hData->mChannelType == CT_STEREO) { char ident[MAX_IDENT_LEN+1]; @@ -1976,7 +1975,7 @@ static int ProcessSources(TokenReaderT *tr, HrirDataT *hData) } } } - for(ti = 0;ti < channels;ti++) + for(uint ti{0};ti < channels;ti++) { for(fi = 0;fi < hData->mFdCount;fi++) { diff --git a/utils/makemhr/loadsofa.cpp b/utils/makemhr/loadsofa.cpp index 02911e12..219eb558 100644 --- a/utils/makemhr/loadsofa.cpp +++ b/utils/makemhr/loadsofa.cpp @@ -101,7 +101,6 @@ static float GetUniformStepSize(const double epsilon, const uint m, const float { auto steps = std::vector(m, 0.0f); auto counts = std::vector(m, 0u); - float step{0.0f}; uint count{0u}; for(uint stride{1u};stride < m/2;stride++) @@ -140,15 +139,12 @@ static float GetUniformStepSize(const double epsilon, const uint m, const float count = 1; if(counts[0] > m/2) - { - step = steps[0]; - return step; - } + return steps[0]; } if(counts[0] > 5) - step = steps[0]; - return step; + return steps[0]; + return 0.0f; } /* Attempts to produce a compatible layout. Most data sets tend to be diff --git a/utils/sofa-info.cpp b/utils/sofa-info.cpp index e9f2257c..87531b37 100644 --- a/utils/sofa-info.cpp +++ b/utils/sofa-info.cpp @@ -136,7 +136,6 @@ static float GetUniformStepSize(const float epsilon, const uint m, const float * { std::vector steps(m, 0.0f); std::vector counts(m, 0u); - float step{0.0f}; uint count{0u}; for(uint stride{1u};stride < m/2;stride++) @@ -175,15 +174,12 @@ static float GetUniformStepSize(const float epsilon, const uint m, const float * count = 1; if(counts[0] > m/2) - { - step = steps[0]; - return step; - } + return steps[0]; } if(counts[0] > 5) - step = steps[0]; - return step; + return steps[0]; + return 0.0f; } /* Attempts to produce a compatible layout. Most data sets tend to be -- cgit v1.2.3 From 4b8f78a8d633e3f39e2b708184c051465fcfef7d Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sat, 14 Sep 2019 19:42:54 -0700 Subject: Fix a few more GCC warnings --- alc/backends/coreaudio.cpp | 3 ++- alc/backends/opensl.cpp | 6 +++--- alc/backends/wasapi.cpp | 2 ++ alc/mixer/mixer_c.cpp | 2 +- common/alcomplex.cpp | 2 +- examples/almultireverb.c | 4 ++-- utils/openal-info.c | 2 +- 7 files changed, 12 insertions(+), 9 deletions(-) (limited to 'utils') diff --git a/alc/backends/coreaudio.cpp b/alc/backends/coreaudio.cpp index 99b06b7a..3ae9800c 100644 --- a/alc/backends/coreaudio.cpp +++ b/alc/backends/coreaudio.cpp @@ -374,7 +374,8 @@ OSStatus CoreAudioCapture::RecordProc(AudioUnitRenderActionFlags*, audiobuf.list.mNumberBuffers = 2; audiobuf.list.mBuffers[0].mNumberChannels = mFormat.mChannelsPerFrame; audiobuf.list.mBuffers[0].mData = rec_vec.first.buf; - audiobuf.list.mBuffers[0].mDataByteSize = rec_vec.first.len * mFormat.mBytesPerFrame; + audiobuf.list.mBuffers[0].mDataByteSize = static_cast(rec_vec.first.len) * + mFormat.mBytesPerFrame; audiobuf.list.mBuffers[1].mNumberChannels = mFormat.mChannelsPerFrame; audiobuf.list.mBuffers[1].mData = rec_vec.second.buf; audiobuf.list.mBuffers[1].mDataByteSize = remaining * mFormat.mBytesPerFrame; diff --git a/alc/backends/opensl.cpp b/alc/backends/opensl.cpp index 06d5cd40..3a2f455e 100644 --- a/alc/backends/opensl.cpp +++ b/alc/backends/opensl.cpp @@ -681,11 +681,11 @@ ALCenum OpenSLCapture::open(const ALCchar* name) { mFrameSize = mDevice->frameSizeFromFmt(); /* Ensure the total length is at least 100ms */ - ALsizei length{maxi(mDevice->BufferSize, mDevice->Frequency/10)}; + ALuint length{maxu(mDevice->BufferSize, mDevice->Frequency/10)}; /* Ensure the per-chunk length is at least 10ms, and no more than 50ms. */ - ALsizei update_len{clampi(mDevice->BufferSize/3, mDevice->Frequency/100, + ALuint update_len{clampu(mDevice->BufferSize/3, mDevice->Frequency/100, mDevice->Frequency/100*5)}; - ALsizei num_updates{(length+update_len-1) / update_len}; + ALuint num_updates{(length+update_len-1) / update_len}; try { mRing = CreateRingBuffer(num_updates, update_len*mFrameSize, false); diff --git a/alc/backends/wasapi.cpp b/alc/backends/wasapi.cpp index b762da76..0d04d5a7 100644 --- a/alc/backends/wasapi.cpp +++ b/alc/backends/wasapi.cpp @@ -429,6 +429,8 @@ constexpr char MessageStr[static_cast(MsgType::Count)][20]{ /* Proxy interface used by the message handler. */ struct WasapiProxy { + virtual ~WasapiProxy() = default; + virtual HRESULT openProxy() = 0; virtual void closeProxy() = 0; diff --git a/alc/mixer/mixer_c.cpp b/alc/mixer/mixer_c.cpp index 74315dd5..7beab1a9 100644 --- a/alc/mixer/mixer_c.cpp +++ b/alc/mixer/mixer_c.cpp @@ -30,7 +30,7 @@ inline ALfloat do_bsinc(const InterpState &istate, const ALfloat *RESTRICT vals, (1.0f/(1<(istate.bsinc.m)*pi*4}; + const ALfloat *fil{istate.bsinc.filter + istate.bsinc.m*static_cast(pi*4)}; const ALfloat *scd{fil + istate.bsinc.m}; const ALfloat *phd{scd + istate.bsinc.m}; const ALfloat *spd{phd + istate.bsinc.m}; diff --git a/common/alcomplex.cpp b/common/alcomplex.cpp index f77ec203..e5cbe8a0 100644 --- a/common/alcomplex.cpp +++ b/common/alcomplex.cpp @@ -35,7 +35,7 @@ void complex_fft(const al::span> buffer, const double sign) for(size_t i{1u};i < fftsize;i<<=1, step<<=1) { const size_t step2{step >> 1}; - double arg{al::MathDefs::Pi() / step2}; + double arg{al::MathDefs::Pi() / static_cast(step2)}; std::complex w{std::cos(arg), std::sin(arg)*sign}; std::complex u{1.0, 0.0}; diff --git a/examples/almultireverb.c b/examples/almultireverb.c index b967a050..4e3e188f 100644 --- a/examples/almultireverb.c +++ b/examples/almultireverb.c @@ -653,12 +653,12 @@ int main(int argc, char **argv) * Convert the difference to seconds. */ curtime = altime_get(); - timediff = (ALfloat)(curtime - basetime) / 1000.0f; + timediff = (float)(curtime - basetime) / 1000.0f; /* Avoid negative time deltas, in case of non-monotonic clocks. */ if(timediff < 0.0f) timediff = 0.0f; - else while(timediff >= 4.0f*((loops&1)+1)) + else while(timediff >= 4.0f*(float)((loops&1)+1)) { /* For this example, each transition occurs over 4 seconds, and * there's 2 transitions per cycle. diff --git a/utils/openal-info.c b/utils/openal-info.c index cc628b6e..76cdf37d 100644 --- a/utils/openal-info.c +++ b/utils/openal-info.c @@ -53,7 +53,7 @@ static WCHAR *FromUTF8(const char *str) if((len=MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0)) > 0) { - out = calloc(sizeof(WCHAR), len); + out = calloc(sizeof(WCHAR), (unsigned int)(len)); MultiByteToWideChar(CP_UTF8, 0, str, -1, out, len); } return out; -- cgit v1.2.3 From 6d93b2ba81958eb277da4361924e89bc7048da41 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 16 Sep 2019 14:55:52 -0700 Subject: Use our case-insensitive compare functions in makemhr --- CMakeLists.txt | 2 +- utils/makemhr/loaddef.cpp | 39 ++++++++++++++++++++------------------- utils/makemhr/makemhr.cpp | 3 ++- 3 files changed, 23 insertions(+), 21 deletions(-) (limited to 'utils') diff --git a/CMakeLists.txt b/CMakeLists.txt index bcd03cca..32cb017e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1470,7 +1470,7 @@ IF(ALSOFT_UTILS) target_include_directories(makemhr PRIVATE ${OpenAL_SOURCE_DIR}/common ${OpenAL_BINARY_DIR}) target_compile_options(makemhr PRIVATE ${C_FLAGS}) - target_link_libraries(makemhr PRIVATE ${LINKER_FLAGS} MySOFA::MySOFA) + target_link_libraries(makemhr PRIVATE common ${LINKER_FLAGS} MySOFA::MySOFA) set(UTIL_TARGETS ${UTIL_TARGETS} makemhr) set(SOFAINFO_SRCS utils/sofa-info.cpp) diff --git a/utils/makemhr/loaddef.cpp b/utils/makemhr/loaddef.cpp index aaefd62c..bc62b725 100644 --- a/utils/makemhr/loaddef.cpp +++ b/utils/makemhr/loaddef.cpp @@ -21,6 +21,8 @@ * Or visit: http://www.gnu.org/licenses/old-licenses/gpl-2.0.html */ +#include "loaddef.h" + #include #include #include @@ -28,8 +30,7 @@ #include "mysofa.h" -#include "loaddef.h" - +#include "alstring.h" // Constants for accessing the token reader's ring buffer. #define TR_RING_BITS (16) @@ -1197,9 +1198,9 @@ static int LoadSource(SourceRefT *src, const uint hrirRate, const uint n, double // Match the channel type from a given identifier. static ChannelTypeT MatchChannelType(const char *ident) { - if(strcasecmp(ident, "mono") == 0) + if(al::strcasecmp(ident, "mono") == 0) return CT_MONO; - if(strcasecmp(ident, "stereo") == 0) + if(al::strcasecmp(ident, "stereo") == 0) return CT_STEREO; return CT_NONE; } @@ -1226,7 +1227,7 @@ static int ProcessMetrics(TokenReaderT *tr, const uint fftSize, const uint trunc TrIndication(tr, &line, &col); if(!TrReadIdent(tr, MAX_IDENT_LEN, ident)) return 0; - if(strcasecmp(ident, "rate") == 0) + if(al::strcasecmp(ident, "rate") == 0) { if(hasRate) { @@ -1240,7 +1241,7 @@ static int ProcessMetrics(TokenReaderT *tr, const uint fftSize, const uint trunc hData->mIrRate = static_cast(intVal); hasRate = 1; } - else if(strcasecmp(ident, "type") == 0) + else if(al::strcasecmp(ident, "type") == 0) { char type[MAX_IDENT_LEN+1]; @@ -1267,7 +1268,7 @@ static int ProcessMetrics(TokenReaderT *tr, const uint fftSize, const uint trunc } hasType = 1; } - else if(strcasecmp(ident, "points") == 0) + else if(al::strcasecmp(ident, "points") == 0) { if(hasPoints) { @@ -1297,7 +1298,7 @@ static int ProcessMetrics(TokenReaderT *tr, const uint fftSize, const uint trunc hData->mIrSize = points; hasPoints = 1; } - else if(strcasecmp(ident, "radius") == 0) + else if(al::strcasecmp(ident, "radius") == 0) { if(hasRadius) { @@ -1311,7 +1312,7 @@ static int ProcessMetrics(TokenReaderT *tr, const uint fftSize, const uint trunc hData->mRadius = fpVal; hasRadius = 1; } - else if(strcasecmp(ident, "distance") == 0) + else if(al::strcasecmp(ident, "distance") == 0) { uint count = 0; @@ -1350,7 +1351,7 @@ static int ProcessMetrics(TokenReaderT *tr, const uint fftSize, const uint trunc fdCount = count; hasDistance = 1; } - else if(strcasecmp(ident, "azimuths") == 0) + else if(al::strcasecmp(ident, "azimuths") == 0) { uint count = 0; @@ -1468,15 +1469,15 @@ static int ReadIndexTriplet(TokenReaderT *tr, const HrirDataT *hData, uint *fi, // Match the source format from a given identifier. static SourceFormatT MatchSourceFormat(const char *ident) { - if(strcasecmp(ident, "ascii") == 0) + if(al::strcasecmp(ident, "ascii") == 0) return SF_ASCII; - if(strcasecmp(ident, "bin_le") == 0) + if(al::strcasecmp(ident, "bin_le") == 0) return SF_BIN_LE; - if(strcasecmp(ident, "bin_be") == 0) + if(al::strcasecmp(ident, "bin_be") == 0) return SF_BIN_BE; - if(strcasecmp(ident, "wave") == 0) + if(al::strcasecmp(ident, "wave") == 0) return SF_WAVE; - if(strcasecmp(ident, "sofa") == 0) + if(al::strcasecmp(ident, "sofa") == 0) return SF_SOFA; return SF_NONE; } @@ -1484,9 +1485,9 @@ static SourceFormatT MatchSourceFormat(const char *ident) // Match the source element type from a given identifier. static ElementTypeT MatchElementType(const char *ident) { - if(strcasecmp(ident, "int") == 0) + if(al::strcasecmp(ident, "int") == 0) return ET_INT; - if(strcasecmp(ident, "fp") == 0) + if(al::strcasecmp(ident, "fp") == 0) return ET_FP; return ET_NONE; } @@ -1680,9 +1681,9 @@ static int ReadSofaRef(TokenReaderT *tr, SourceRefT *src) // Match the target ear (index) from a given identifier. static int MatchTargetEar(const char *ident) { - if(strcasecmp(ident, "left") == 0) + if(al::strcasecmp(ident, "left") == 0) return 0; - if(strcasecmp(ident, "right") == 0) + if(al::strcasecmp(ident, "right") == 0) return 1; return -1; } diff --git a/utils/makemhr/makemhr.cpp b/utils/makemhr/makemhr.cpp index 5930e582..8071ac18 100644 --- a/utils/makemhr/makemhr.cpp +++ b/utils/makemhr/makemhr.cpp @@ -87,6 +87,7 @@ #include "../getopt.h" #endif +#include "alstring.h" #include "loaddef.h" #include "loadsofa.h" @@ -178,7 +179,7 @@ static int StrSubst(const char *in, const char *pat, const char *rep, const size { if(patLen <= inLen-si) { - if(strncasecmp(&in[si], pat, patLen) == 0) + if(al::strncasecmp(&in[si], pat, patLen) == 0) { if(repLen > maxLen-di) { -- cgit v1.2.3 From 66565ca7a3cd63e242eedb0141341eb9450f0d4a Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Wed, 18 Sep 2019 10:09:04 -0700 Subject: Enable and fix some more warnings --- CMakeLists.txt | 1 + al/auxeffectslot.cpp | 3 +- al/error.cpp | 3 +- alc/alc.cpp | 33 ++++++++++++---------- alc/hrtf.cpp | 4 +-- common/threads.cpp | 2 +- examples/alhrtf.c | 6 ++-- examples/allatency.c | 26 ++++++++--------- examples/alloopback.c | 8 +++--- examples/almultireverb.c | 72 ++++++++++++++++++++++++------------------------ examples/alreverb.c | 48 ++++++++++++++++---------------- utils/openal-info.c | 4 +-- 12 files changed, 108 insertions(+), 102 deletions(-) (limited to 'utils') diff --git a/CMakeLists.txt b/CMakeLists.txt index 3ef1ca6b..4f6cf010 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -222,6 +222,7 @@ IF(MSVC) ENDIF() ELSE() SET(C_FLAGS ${C_FLAGS} -Winline -Wunused -Wall -Wextra -Wshadow -Wconversion -Wcast-align + -Wpedantic -Wno-zero-length-array $<$:-Wold-style-cast -Wnon-virtual-dtor -Woverloaded-virtual>) IF(ALSOFT_WERROR) diff --git a/al/auxeffectslot.cpp b/al/auxeffectslot.cpp index df35c533..3c312c66 100644 --- a/al/auxeffectslot.cpp +++ b/al/auxeffectslot.cpp @@ -709,7 +709,8 @@ ALeffectslot::~ALeffectslot() if(props) { if(props->State) props->State->release(); - TRACE("Freed unapplied AuxiliaryEffectSlot update %p\n", props); + TRACE("Freed unapplied AuxiliaryEffectSlot update %p\n", + decltype(std::declval()){props}); delete props; } diff --git a/al/error.cpp b/al/error.cpp index f3e2dbb3..b667d14f 100644 --- a/al/error.cpp +++ b/al/error.cpp @@ -67,7 +67,8 @@ void ALCcontext::setError(ALenum errorCode, const char *msg, ...) else msg = ""; msglen = static_cast(strlen(msg)); - WARN("Error generated on context %p, code 0x%04x, \"%s\"\n", this, errorCode, msg); + WARN("Error generated on context %p, code 0x%04x, \"%s\"\n", + decltype(std::declval()){this}, errorCode, msg); if(TrapALError) { #ifdef _WIN32 diff --git a/alc/alc.cpp b/alc/alc.cpp index 8a0a3468..0652f858 100644 --- a/alc/alc.cpp +++ b/alc/alc.cpp @@ -845,8 +845,8 @@ std::atomic LastNullDeviceError{ALC_NO_ERROR}; void ReleaseThreadCtx(ALCcontext *context) { const bool result{context->releaseIfNoDelete()}; - ERR("Context %p current for thread being destroyed%s!\n", context, - result ? "" : ", leak detected"); + ERR("Context %p current for thread being destroyed%s!\n", + decltype(std::declval()){context}, result ? "" : ", leak detected"); } class ThreadCtx { @@ -1567,7 +1567,8 @@ void ALCcontext::processUpdates() */ static void alcSetError(ALCdevice *device, ALCenum errorCode) { - WARN("Error generated on device %p, code 0x%04x\n", device, errorCode); + WARN("Error generated on device %p, code 0x%04x\n", decltype(std::declval()){device}, + errorCode); if(TrapALCError) { #ifdef _WIN32 @@ -2256,7 +2257,7 @@ ALCdevice::ALCdevice(DeviceType type) : Type{type}, mContexts{&EmptyContextArray */ ALCdevice::~ALCdevice() { - TRACE("Freeing device %p\n", this); + TRACE("Freeing device %p\n", decltype(std::declval()){this}); Backend = nullptr; @@ -2311,15 +2312,15 @@ ALCcontext::ALCcontext(al::intrusive_ptr device) : mDevice{std::move( ALCcontext::~ALCcontext() { - TRACE("Freeing context %p\n", this); + TRACE("Freeing context %p\n", decltype(std::declval()){this}); + size_t count{0}; ALcontextProps *cprops{mUpdate.exchange(nullptr, std::memory_order_relaxed)}; if(cprops) { - TRACE("Freed unapplied context update %p\n", cprops); + ++count; delete cprops; } - size_t count{0}; cprops = mFreeContextProps.exchange(nullptr, std::memory_order_acquire); while(cprops) { @@ -2376,13 +2377,13 @@ ALCcontext::~ALCcontext() mVoices.clear(); + count = 0; ALlistenerProps *lprops{mListener.Params.Update.exchange(nullptr, std::memory_order_relaxed)}; if(lprops) { - TRACE("Freed unapplied listener update %p\n", lprops); + ++count; delete lprops; } - count = 0; lprops = mFreeListenerProps.exchange(nullptr, std::memory_order_acquire); while(lprops) { @@ -2462,7 +2463,7 @@ bool ALCcontext::deinit() { if(LocalContext.get() == this) { - WARN("%p released while current on thread\n", this); + WARN("%p released while current on thread\n", decltype(std::declval()){this}); LocalContext.set(nullptr); release(); } @@ -3356,7 +3357,7 @@ START_API_FUNC ERR("Failed to initialize the default effect\n"); } - TRACE("Created context %p\n", context.get()); + TRACE("Created context %p\n", decltype(std::declval()){context.get()}); return context.get(); } END_API_FUNC @@ -3700,7 +3701,8 @@ START_API_FUNC DeviceList.emplace(iter, device); } - TRACE("Created device %p, \"%s\"\n", device.get(), device->DeviceName.c_str()); + TRACE("Created device %p, \"%s\"\n", decltype(std::declval()){device.get()}, + device->DeviceName.c_str()); return device.get(); } END_API_FUNC @@ -3746,7 +3748,7 @@ START_API_FUNC for(ContextRef &context : orphanctxs) { - WARN("Releasing orphaned context %p\n", context.get()); + WARN("Releasing orphaned context %p\n", decltype(std::declval()){context.get()}); context->deinit(); } orphanctxs.clear(); @@ -3829,7 +3831,8 @@ START_API_FUNC DeviceList.emplace(iter, device); } - TRACE("Created device %p, \"%s\"\n", device.get(), device->DeviceName.c_str()); + TRACE("Created capture device %p, \"%s\"\n", decltype(std::declval()){device.get()}, + device->DeviceName.c_str()); return device.get(); } END_API_FUNC @@ -4011,7 +4014,7 @@ START_API_FUNC DeviceList.emplace(iter, device); } - TRACE("Created device %p\n", device.get()); + TRACE("Created loopback device %p\n", decltype(std::declval()){device.get()}); return device.get(); } END_API_FUNC diff --git a/alc/hrtf.cpp b/alc/hrtf.cpp index 7110478d..b925c5dd 100644 --- a/alc/hrtf.cpp +++ b/alc/hrtf.cpp @@ -1363,13 +1363,13 @@ HrtfEntry *GetLoadedHrtf(HrtfHandle *handle) void HrtfEntry::IncRef() { auto ref = IncrementRef(mRef); - TRACE("HrtfEntry %p increasing refcount to %u\n", this, ref); + TRACE("HrtfEntry %p increasing refcount to %u\n", decltype(std::declval()){this}, ref); } void HrtfEntry::DecRef() { auto ref = DecrementRef(mRef); - TRACE("HrtfEntry %p decreasing refcount to %u\n", this, ref); + TRACE("HrtfEntry %p decreasing refcount to %u\n", decltype(std::declval()){this}, ref); if(ref == 0) { std::lock_guard _{LoadedHrtfLock}; diff --git a/common/threads.cpp b/common/threads.cpp index fe34f5b0..ff01de42 100644 --- a/common/threads.cpp +++ b/common/threads.cpp @@ -43,7 +43,7 @@ void althrd_setname(const char *name) #pragma pack(pop) info.dwType = 0x1000; info.szName = name; - info.dwThreadID = -1; + info.dwThreadID = ~DWORD{0}; info.dwFlags = 0; __try { diff --git a/examples/alhrtf.c b/examples/alhrtf.c index f09f3e99..2be28a91 100644 --- a/examples/alhrtf.c +++ b/examples/alhrtf.c @@ -164,9 +164,9 @@ int main(int argc, char **argv) } /* Define a macro to help load the function pointers. */ -#define LOAD_PROC(d, x) ((x) = alcGetProcAddress((d), #x)) - LOAD_PROC(device, alcGetStringiSOFT); - LOAD_PROC(device, alcResetDeviceSOFT); +#define LOAD_PROC(d, T, x) ((x) = (T)alcGetProcAddress((d), #x)) + LOAD_PROC(device, LPALCGETSTRINGISOFT, alcGetStringiSOFT); + LOAD_PROC(device, LPALCRESETDEVICESOFT, alcResetDeviceSOFT); #undef LOAD_PROC /* Check for the AL_EXT_STEREO_ANGLES extension to be able to also rotate diff --git a/examples/allatency.c b/examples/allatency.c index ad700cc1..a61fb820 100644 --- a/examples/allatency.c +++ b/examples/allatency.c @@ -158,19 +158,19 @@ int main(int argc, char **argv) } /* Define a macro to help load the function pointers. */ -#define LOAD_PROC(x) ((x) = alGetProcAddress(#x)) - LOAD_PROC(alSourcedSOFT); - LOAD_PROC(alSource3dSOFT); - LOAD_PROC(alSourcedvSOFT); - LOAD_PROC(alGetSourcedSOFT); - LOAD_PROC(alGetSource3dSOFT); - LOAD_PROC(alGetSourcedvSOFT); - LOAD_PROC(alSourcei64SOFT); - LOAD_PROC(alSource3i64SOFT); - LOAD_PROC(alSourcei64vSOFT); - LOAD_PROC(alGetSourcei64SOFT); - LOAD_PROC(alGetSource3i64SOFT); - LOAD_PROC(alGetSourcei64vSOFT); +#define LOAD_PROC(T, x) ((x) = (T)alGetProcAddress(#x)) + LOAD_PROC(LPALSOURCEDSOFT, alSourcedSOFT); + LOAD_PROC(LPALSOURCE3DSOFT, alSource3dSOFT); + LOAD_PROC(LPALSOURCEDVSOFT, alSourcedvSOFT); + LOAD_PROC(LPALGETSOURCEDSOFT, alGetSourcedSOFT); + LOAD_PROC(LPALGETSOURCE3DSOFT, alGetSource3dSOFT); + LOAD_PROC(LPALGETSOURCEDVSOFT, alGetSourcedvSOFT); + LOAD_PROC(LPALSOURCEI64SOFT, alSourcei64SOFT); + LOAD_PROC(LPALSOURCE3I64SOFT, alSource3i64SOFT); + LOAD_PROC(LPALSOURCEI64VSOFT, alSourcei64vSOFT); + LOAD_PROC(LPALGETSOURCEI64SOFT, alGetSourcei64SOFT); + LOAD_PROC(LPALGETSOURCE3I64SOFT, alGetSource3i64SOFT); + LOAD_PROC(LPALGETSOURCEI64VSOFT, alGetSourcei64vSOFT); #undef LOAD_PROC /* Initialize SDL_sound. */ diff --git a/examples/alloopback.c b/examples/alloopback.c index 426a2af9..844efa74 100644 --- a/examples/alloopback.c +++ b/examples/alloopback.c @@ -149,10 +149,10 @@ int main(int argc, char *argv[]) } /* Define a macro to help load the function pointers. */ -#define LOAD_PROC(x) ((x) = alcGetProcAddress(NULL, #x)) - LOAD_PROC(alcLoopbackOpenDeviceSOFT); - LOAD_PROC(alcIsRenderFormatSupportedSOFT); - LOAD_PROC(alcRenderSamplesSOFT); +#define LOAD_PROC(T, x) ((x) = (T)alcGetProcAddress(NULL, #x)) + LOAD_PROC(LPALCLOOPBACKOPENDEVICESOFT, alcLoopbackOpenDeviceSOFT); + LOAD_PROC(LPALCISRENDERFORMATSUPPORTEDSOFT, alcIsRenderFormatSupportedSOFT); + LOAD_PROC(LPALCRENDERSAMPLESSOFT, alcRenderSamplesSOFT); #undef LOAD_PROC if(SDL_Init(SDL_INIT_AUDIO) == -1) diff --git a/examples/almultireverb.c b/examples/almultireverb.c index 4e3e188f..a90b3368 100644 --- a/examples/almultireverb.c +++ b/examples/almultireverb.c @@ -523,42 +523,42 @@ int main(int argc, char **argv) } /* Define a macro to help load the function pointers. */ -#define LOAD_PROC(x) ((x) = alGetProcAddress(#x)) - LOAD_PROC(alGenFilters); - LOAD_PROC(alDeleteFilters); - LOAD_PROC(alIsFilter); - LOAD_PROC(alFilteri); - LOAD_PROC(alFilteriv); - LOAD_PROC(alFilterf); - LOAD_PROC(alFilterfv); - LOAD_PROC(alGetFilteri); - LOAD_PROC(alGetFilteriv); - LOAD_PROC(alGetFilterf); - LOAD_PROC(alGetFilterfv); - - LOAD_PROC(alGenEffects); - LOAD_PROC(alDeleteEffects); - LOAD_PROC(alIsEffect); - LOAD_PROC(alEffecti); - LOAD_PROC(alEffectiv); - LOAD_PROC(alEffectf); - LOAD_PROC(alEffectfv); - LOAD_PROC(alGetEffecti); - LOAD_PROC(alGetEffectiv); - LOAD_PROC(alGetEffectf); - LOAD_PROC(alGetEffectfv); - - LOAD_PROC(alGenAuxiliaryEffectSlots); - LOAD_PROC(alDeleteAuxiliaryEffectSlots); - LOAD_PROC(alIsAuxiliaryEffectSlot); - LOAD_PROC(alAuxiliaryEffectSloti); - LOAD_PROC(alAuxiliaryEffectSlotiv); - LOAD_PROC(alAuxiliaryEffectSlotf); - LOAD_PROC(alAuxiliaryEffectSlotfv); - LOAD_PROC(alGetAuxiliaryEffectSloti); - LOAD_PROC(alGetAuxiliaryEffectSlotiv); - LOAD_PROC(alGetAuxiliaryEffectSlotf); - LOAD_PROC(alGetAuxiliaryEffectSlotfv); +#define LOAD_PROC(T, x) ((x) = (T)alGetProcAddress(#x)) + LOAD_PROC(LPALGENFILTERS, alGenFilters); + LOAD_PROC(LPALDELETEFILTERS, alDeleteFilters); + LOAD_PROC(LPALISFILTER, alIsFilter); + LOAD_PROC(LPALFILTERI, alFilteri); + LOAD_PROC(LPALFILTERIV, alFilteriv); + LOAD_PROC(LPALFILTERF, alFilterf); + LOAD_PROC(LPALFILTERFV, alFilterfv); + LOAD_PROC(LPALGETFILTERI, alGetFilteri); + LOAD_PROC(LPALGETFILTERIV, alGetFilteriv); + LOAD_PROC(LPALGETFILTERF, alGetFilterf); + LOAD_PROC(LPALGETFILTERFV, alGetFilterfv); + + LOAD_PROC(LPALGENEFFECTS, alGenEffects); + LOAD_PROC(LPALDELETEEFFECTS, alDeleteEffects); + LOAD_PROC(LPALISEFFECT, alIsEffect); + LOAD_PROC(LPALEFFECTI, alEffecti); + LOAD_PROC(LPALEFFECTIV, alEffectiv); + LOAD_PROC(LPALEFFECTF, alEffectf); + LOAD_PROC(LPALEFFECTFV, alEffectfv); + LOAD_PROC(LPALGETEFFECTI, alGetEffecti); + LOAD_PROC(LPALGETEFFECTIV, alGetEffectiv); + LOAD_PROC(LPALGETEFFECTF, alGetEffectf); + LOAD_PROC(LPALGETEFFECTFV, alGetEffectfv); + + LOAD_PROC(LPALGENAUXILIARYEFFECTSLOTS, alGenAuxiliaryEffectSlots); + LOAD_PROC(LPALDELETEAUXILIARYEFFECTSLOTS, alDeleteAuxiliaryEffectSlots); + LOAD_PROC(LPALISAUXILIARYEFFECTSLOT, alIsAuxiliaryEffectSlot); + LOAD_PROC(LPALAUXILIARYEFFECTSLOTI, alAuxiliaryEffectSloti); + LOAD_PROC(LPALAUXILIARYEFFECTSLOTIV, alAuxiliaryEffectSlotiv); + LOAD_PROC(LPALAUXILIARYEFFECTSLOTF, alAuxiliaryEffectSlotf); + LOAD_PROC(LPALAUXILIARYEFFECTSLOTFV, alAuxiliaryEffectSlotfv); + LOAD_PROC(LPALGETAUXILIARYEFFECTSLOTI, alGetAuxiliaryEffectSloti); + LOAD_PROC(LPALGETAUXILIARYEFFECTSLOTIV, alGetAuxiliaryEffectSlotiv); + LOAD_PROC(LPALGETAUXILIARYEFFECTSLOTF, alGetAuxiliaryEffectSlotf); + LOAD_PROC(LPALGETAUXILIARYEFFECTSLOTFV, alGetAuxiliaryEffectSlotfv); #undef LOAD_PROC /* Initialize SDL_sound. */ diff --git a/examples/alreverb.c b/examples/alreverb.c index 68f0269f..d789dffe 100644 --- a/examples/alreverb.c +++ b/examples/alreverb.c @@ -252,30 +252,30 @@ int main(int argc, char **argv) } /* Define a macro to help load the function pointers. */ -#define LOAD_PROC(x) ((x) = alGetProcAddress(#x)) - LOAD_PROC(alGenEffects); - LOAD_PROC(alDeleteEffects); - LOAD_PROC(alIsEffect); - LOAD_PROC(alEffecti); - LOAD_PROC(alEffectiv); - LOAD_PROC(alEffectf); - LOAD_PROC(alEffectfv); - LOAD_PROC(alGetEffecti); - LOAD_PROC(alGetEffectiv); - LOAD_PROC(alGetEffectf); - LOAD_PROC(alGetEffectfv); - - LOAD_PROC(alGenAuxiliaryEffectSlots); - LOAD_PROC(alDeleteAuxiliaryEffectSlots); - LOAD_PROC(alIsAuxiliaryEffectSlot); - LOAD_PROC(alAuxiliaryEffectSloti); - LOAD_PROC(alAuxiliaryEffectSlotiv); - LOAD_PROC(alAuxiliaryEffectSlotf); - LOAD_PROC(alAuxiliaryEffectSlotfv); - LOAD_PROC(alGetAuxiliaryEffectSloti); - LOAD_PROC(alGetAuxiliaryEffectSlotiv); - LOAD_PROC(alGetAuxiliaryEffectSlotf); - LOAD_PROC(alGetAuxiliaryEffectSlotfv); +#define LOAD_PROC(T, x) ((x) = (T)alGetProcAddress(#x)) + LOAD_PROC(LPALGENEFFECTS, alGenEffects); + LOAD_PROC(LPALDELETEEFFECTS, alDeleteEffects); + LOAD_PROC(LPALISEFFECT, alIsEffect); + LOAD_PROC(LPALEFFECTI, alEffecti); + LOAD_PROC(LPALEFFECTIV, alEffectiv); + LOAD_PROC(LPALEFFECTF, alEffectf); + LOAD_PROC(LPALEFFECTFV, alEffectfv); + LOAD_PROC(LPALGETEFFECTI, alGetEffecti); + LOAD_PROC(LPALGETEFFECTIV, alGetEffectiv); + LOAD_PROC(LPALGETEFFECTF, alGetEffectf); + LOAD_PROC(LPALGETEFFECTFV, alGetEffectfv); + + LOAD_PROC(LPALGENAUXILIARYEFFECTSLOTS, alGenAuxiliaryEffectSlots); + LOAD_PROC(LPALDELETEAUXILIARYEFFECTSLOTS, alDeleteAuxiliaryEffectSlots); + LOAD_PROC(LPALISAUXILIARYEFFECTSLOT, alIsAuxiliaryEffectSlot); + LOAD_PROC(LPALAUXILIARYEFFECTSLOTI, alAuxiliaryEffectSloti); + LOAD_PROC(LPALAUXILIARYEFFECTSLOTIV, alAuxiliaryEffectSlotiv); + LOAD_PROC(LPALAUXILIARYEFFECTSLOTF, alAuxiliaryEffectSlotf); + LOAD_PROC(LPALAUXILIARYEFFECTSLOTFV, alAuxiliaryEffectSlotfv); + LOAD_PROC(LPALGETAUXILIARYEFFECTSLOTI, alGetAuxiliaryEffectSloti); + LOAD_PROC(LPALGETAUXILIARYEFFECTSLOTIV, alGetAuxiliaryEffectSlotiv); + LOAD_PROC(LPALGETAUXILIARYEFFECTSLOTF, alGetAuxiliaryEffectSlotf); + LOAD_PROC(LPALGETAUXILIARYEFFECTSLOTFV, alGetAuxiliaryEffectSlotfv); #undef LOAD_PROC /* Initialize SDL_sound. */ diff --git a/utils/openal-info.c b/utils/openal-info.c index 76cdf37d..cdce77e0 100644 --- a/utils/openal-info.c +++ b/utils/openal-info.c @@ -223,7 +223,7 @@ static void printHRTFInfo(ALCdevice *device) return; } - alcGetStringiSOFT = alcGetProcAddress(device, "alcGetStringiSOFT"); + alcGetStringiSOFT = (LPALCGETSTRINGISOFT)alcGetProcAddress(device, "alcGetStringiSOFT"); alcGetIntegerv(device, ALC_NUM_HRTF_SPECIFIERS_SOFT, 1, &num_hrtfs); if(!num_hrtfs) @@ -263,7 +263,7 @@ static void printResamplerInfo(void) return; } - alGetStringiSOFT = alGetProcAddress("alGetStringiSOFT"); + alGetStringiSOFT = (LPALGETSTRINGISOFT)alGetProcAddress("alGetStringiSOFT"); num_resamplers = alGetInteger(AL_NUM_RESAMPLERS_SOFT); def_resampler = alGetInteger(AL_DEFAULT_RESAMPLER_SOFT); -- cgit v1.2.3 From 34a0fad6cd2513f640c58dcff16817d00cf00456 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 23 Sep 2019 17:38:43 -0700 Subject: Use a unique_ptr to auto-free MYSOFA_HRTF --- utils/sofa-info.cpp | 79 ++++++++++++++++++++++------------------------------- 1 file changed, 32 insertions(+), 47 deletions(-) (limited to 'utils') diff --git a/utils/sofa-info.cpp b/utils/sofa-info.cpp index 87531b37..32bef938 100644 --- a/utils/sofa-info.cpp +++ b/utils/sofa-info.cpp @@ -22,17 +22,23 @@ */ #include -#include #include +#include #include #include #include "win_main_utf8.h" + using uint = unsigned int; +struct MySofaDeleter { + void operator()(MYSOFA_HRTF *sofa) { mysofa_free(sofa); } +}; +using MySofaHrtfPtr = std::unique_ptr; + // Per-field measurement info. struct HrirFdT { float mDistance{0.0f}; @@ -45,20 +51,13 @@ static const char *SofaErrorStr(int err) { switch(err) { - case MYSOFA_OK: - return "OK"; - case MYSOFA_INVALID_FORMAT: - return "Invalid format"; - case MYSOFA_UNSUPPORTED_FORMAT: - return "Unsupported format"; - case MYSOFA_INTERNAL_ERROR: - return "Internal error"; - case MYSOFA_NO_MEMORY: - return "Out of memory"; - case MYSOFA_READ_ERROR: - return "Read error"; + case MYSOFA_OK: return "OK"; + case MYSOFA_INVALID_FORMAT: return "Invalid format"; + case MYSOFA_UNSUPPORTED_FORMAT: return "Unsupported format"; + case MYSOFA_INTERNAL_ERROR: return "Internal error"; + case MYSOFA_NO_MEMORY: return "Out of memory"; + case MYSOFA_READ_ERROR: return "Read error"; } - return "Unknown"; } @@ -237,10 +236,11 @@ static void PrintCompatibleLayout(const uint m, const float *xyzs) { float ev{90.0f + elems[ei]}; float eif{std::round(ev / step)}; + const uint ev_start{static_cast(eif)}; - if(std::fabs(eif - static_cast(eif)) < (0.1f / step)) + if(std::fabs(eif - static_cast(ev_start)) < (0.1f/step)) { - evStart = static_cast(eif); + evStart = ev_start; break; } } @@ -259,7 +259,7 @@ static void PrintCompatibleLayout(const uint m, const float *xyzs) for(uint ei{evStart};ei < evCount;ei++) { - float ev{-90.0f + ei * 180.0f / (evCount - 1)}; + float ev{-90.0f + static_cast(ei)*180.0f/static_cast(evCount - 1)}; uint azCount{GetUniquelySortedElems(m, aers.data(), 0, { nullptr, &ev, &dist }, { 0.1f, 0.1f, 0.001f }, elems.data())}; if(azCount > (m / 3)) @@ -312,48 +312,33 @@ static void PrintCompatibleLayout(const uint m, const float *xyzs) // Load and inspect the given SOFA file. static void SofaInfo(const char *filename) { - struct MYSOFA_EASY sofa; - - sofa.lookup = nullptr; - sofa.neighborhood = nullptr; - int err; - sofa.hrtf = mysofa_load(filename, &err); - - if(!sofa.hrtf) + MySofaHrtfPtr sofa{mysofa_load(filename, &err)}; + if(!sofa) { - mysofa_close(&sofa); fprintf(stdout, "Error: Could not load source file '%s'.\n", filename); return; } - err = mysofa_check(sofa.hrtf); + /* NOTE: Some valid SOFA files are failing this check. */ + err = mysofa_check(sofa.get()); if(err != MYSOFA_OK) -/* NOTE: Some valid SOFA files are failing this check. - { - mysofa_close(&sofa); - fprintf(stdout, "Error: Malformed source file '%s' (%s).\n", filename, SofaErrorStr(err)); - - return; - } -*/ - fprintf(stdout, "Warning: Supposedly malformed source file '%s' (%s).\n", filename, SofaErrorStr(err)); - - mysofa_tocartesian(sofa.hrtf); + fprintf(stdout, "Warning: Supposedly malformed source file '%s' (%s).\n", filename, + SofaErrorStr(err)); - PrintSofaAttributes("Info", sofa.hrtf->attributes); + mysofa_tocartesian(sofa.get()); - fprintf(stdout, "Measurements: %u\n", sofa.hrtf->M); - fprintf(stdout, "Receivers: %u\n", sofa.hrtf->R); - fprintf(stdout, "Emitters: %u\n", sofa.hrtf->E); - fprintf(stdout, "Samples: %u\n", sofa.hrtf->N); + PrintSofaAttributes("Info", sofa->attributes); - PrintSofaArray("SampleRate", &sofa.hrtf->DataSamplingRate); - PrintSofaArray("DataDelay", &sofa.hrtf->DataDelay); + fprintf(stdout, "Measurements: %u\n", sofa->M); + fprintf(stdout, "Receivers: %u\n", sofa->R); + fprintf(stdout, "Emitters: %u\n", sofa->E); + fprintf(stdout, "Samples: %u\n", sofa->N); - PrintCompatibleLayout(sofa.hrtf->M, sofa.hrtf->SourcePosition.values); + PrintSofaArray("SampleRate", &sofa->DataSamplingRate); + PrintSofaArray("DataDelay", &sofa->DataDelay); - mysofa_free(sofa.hrtf); + PrintCompatibleLayout(sofa->M, sofa->SourcePosition.values); } int main(int argc, char *argv[]) -- cgit v1.2.3 From e01b32f8e02730b9e4474bbfcdbf2b88fc6c16f5 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 23 Sep 2019 18:37:36 -0700 Subject: Use istream for makemhr input --- utils/makemhr/loaddef.cpp | 255 +++++++++++++++++++++++---------------------- utils/makemhr/loaddef.h | 7 +- utils/makemhr/loadsofa.cpp | 41 ++++---- utils/makemhr/makemhr.cpp | 87 ++++++++-------- 4 files changed, 198 insertions(+), 192 deletions(-) (limited to 'utils') diff --git a/utils/makemhr/loaddef.cpp b/utils/makemhr/loaddef.cpp index bc62b725..619f5104 100644 --- a/utils/makemhr/loaddef.cpp +++ b/utils/makemhr/loaddef.cpp @@ -23,14 +23,23 @@ #include "loaddef.h" +#include +#include +#include #include #include +#include +#include +#include #include -#include - -#include "mysofa.h" +#include +#include +#include "alfstream.h" #include "alstring.h" +#include "makemhr.h" + +#include "mysofa.h" // Constants for accessing the token reader's ring buffer. #define TR_RING_BITS (16) @@ -42,13 +51,16 @@ // Token reader state for parsing the data set definition. struct TokenReaderT { - FILE *mFile; - const char *mName; - uint mLine; - uint mColumn; - char mRing[TR_RING_SIZE]; - size_t mIn; - size_t mOut; + std::istream &mIStream; + const char *mName{}; + uint mLine{}; + uint mColumn{}; + char mRing[TR_RING_SIZE]{}; + std::streamsize mIn{}; + std::streamsize mOut{}; + + TokenReaderT(std::istream &istream) noexcept : mIStream{istream} { } + TokenReaderT(const TokenReaderT&) = default; }; @@ -140,7 +152,8 @@ struct SourceRefT { // Setup the reader on the given file. The filename can be NULL if no error // output is desired. -static void TrSetup(FILE *fp, const char *startbytes, size_t startbytecount, const char *filename, TokenReaderT *tr) +static void TrSetup(const char *startbytes, std::streamsize startbytecount, const char *filename, + TokenReaderT *tr) { const char *name = nullptr; @@ -161,7 +174,6 @@ static void TrSetup(FILE *fp, const char *startbytes, size_t startbytecount, con } } - tr->mFile = fp; tr->mName = name; tr->mLine = 1; tr->mColumn = 1; @@ -170,7 +182,7 @@ static void TrSetup(FILE *fp, const char *startbytes, size_t startbytecount, con if(startbytecount > 0) { - memcpy(tr->mRing, startbytes, startbytecount); + std::copy_n(startbytes, startbytecount, std::begin(tr->mRing)); tr->mIn += startbytecount; } } @@ -179,22 +191,27 @@ static void TrSetup(FILE *fp, const char *startbytes, size_t startbytecount, con // is text to process. static int TrLoad(TokenReaderT *tr) { - size_t toLoad, in, count; + std::istream &istream = tr->mIStream; - toLoad = TR_RING_SIZE - (tr->mIn - tr->mOut); - if(toLoad >= TR_LOAD_SIZE && !feof(tr->mFile)) + std::streamsize toLoad{TR_RING_SIZE - static_cast(tr->mIn - tr->mOut)}; + if(toLoad >= TR_LOAD_SIZE && istream.good()) { // Load TR_LOAD_SIZE (or less if at the end of the file) per read. toLoad = TR_LOAD_SIZE; - in = tr->mIn&TR_RING_MASK; - count = TR_RING_SIZE - in; + std::streamsize in{tr->mIn&TR_RING_MASK}; + std::streamsize count{TR_RING_SIZE - in}; if(count < toLoad) { - tr->mIn += fread(&tr->mRing[in], 1, count, tr->mFile); - tr->mIn += fread(&tr->mRing[0], 1, toLoad-count, tr->mFile); + istream.read(&tr->mRing[in], count); + tr->mIn += istream.gcount(); + istream.read(&tr->mRing[0], toLoad-count); + tr->mIn += istream.gcount(); } else - tr->mIn += fread(&tr->mRing[in], 1, toLoad, tr->mFile); + { + istream.read(&tr->mRing[in], toLoad); + tr->mIn += istream.gcount(); + } if(tr->mOut >= TR_RING_SIZE) { @@ -303,7 +320,8 @@ static int TrIsIdent(TokenReaderT *tr) // errors and will not proceed to the next token. static int TrIsOperator(TokenReaderT *tr, const char *op) { - size_t out, len; + std::streamsize out; + size_t len; char ch; if(!TrSkipWhitespace(tr)) @@ -598,26 +616,24 @@ static int TrReadOperator(TokenReaderT *tr, const char *op) // Read a binary value of the specified byte order and byte size from a file, // storing it as a 32-bit unsigned integer. -static int ReadBin4(FILE *fp, const char *filename, const ByteOrderT order, const uint bytes, uint32_t *out) +static int ReadBin4(std::istream &istream, const char *filename, const ByteOrderT order, const uint bytes, uint32_t *out) { uint8_t in[4]; - uint32_t accum; - uint i; - - if(fread(in, 1, bytes, fp) != bytes) + istream.read(reinterpret_cast(in), static_cast(bytes)); + if(istream.gcount() != bytes) { fprintf(stderr, "\nError: Bad read from file '%s'.\n", filename); return 0; } - accum = 0; + uint32_t accum{0}; switch(order) { case BO_LITTLE: - for(i = 0;i < bytes;i++) + for(uint i = 0;i < bytes;i++) accum = (accum<<8) | in[bytes - i - 1]; break; case BO_BIG: - for(i = 0;i < bytes;i++) + for(uint i = 0;i < bytes;i++) accum = (accum<<8) | in[i]; break; default: @@ -629,18 +645,19 @@ static int ReadBin4(FILE *fp, const char *filename, const ByteOrderT order, cons // Read a binary value of the specified byte order from a file, storing it as // a 64-bit unsigned integer. -static int ReadBin8(FILE *fp, const char *filename, const ByteOrderT order, uint64_t *out) +static int ReadBin8(std::istream &istream, const char *filename, const ByteOrderT order, uint64_t *out) { uint8_t in[8]; uint64_t accum; uint i; - if(fread(in, 1, 8, fp) != 8) + istream.read(reinterpret_cast(in), 8); + if(istream.gcount() != 8) { fprintf(stderr, "\nError: Bad read from file '%s'.\n", filename); return 0; } - accum = 0ULL; + accum = 0; switch(order) { case BO_LITTLE: @@ -664,7 +681,8 @@ static int ReadBin8(FILE *fp, const char *filename, const ByteOrderT order, uint * whether they are padded toward the MSB (negative) or LSB (positive). * Floating-point types are not normalized. */ -static int ReadBinAsDouble(FILE *fp, const char *filename, const ByteOrderT order, const ElementTypeT type, const uint bytes, const int bits, double *out) +static int ReadBinAsDouble(std::istream &istream, const char *filename, const ByteOrderT order, + const ElementTypeT type, const uint bytes, const int bits, double *out) { union { uint32_t ui; @@ -679,14 +697,14 @@ static int ReadBinAsDouble(FILE *fp, const char *filename, const ByteOrderT orde *out = 0.0; if(bytes > 4) { - if(!ReadBin8(fp, filename, order, &v8.ui)) + if(!ReadBin8(istream, filename, order, &v8.ui)) return 0; if(type == ET_FP) *out = v8.f; } else { - if(!ReadBin4(fp, filename, order, bytes, &v4.ui)) + if(!ReadBin4(istream, filename, order, bytes, &v4.ui)) return 0; if(type == ET_FP) *out = v4.f; @@ -745,7 +763,8 @@ static int ReadAsciiAsDouble(TokenReaderT *tr, const char *filename, const Eleme // Read the RIFF/RIFX WAVE format chunk from a file, validating it against // the source parameters and data set metrics. -static int ReadWaveFormat(FILE *fp, const ByteOrderT order, const uint hrirRate, SourceRefT *src) +static int ReadWaveFormat(std::istream &istream, const ByteOrderT order, const uint hrirRate, + SourceRefT *src) { uint32_t fourCC, chunkSize; uint32_t format, channels, rate, dummy, block, size, bits; @@ -753,21 +772,21 @@ static int ReadWaveFormat(FILE *fp, const ByteOrderT order, const uint hrirRate, chunkSize = 0; do { if(chunkSize > 0) - fseek(fp, static_cast(chunkSize), SEEK_CUR); - if(!ReadBin4(fp, src->mPath, BO_LITTLE, 4, &fourCC) || - !ReadBin4(fp, src->mPath, order, 4, &chunkSize)) + istream.seekg(static_cast(chunkSize), std::ios::cur); + if(!ReadBin4(istream, src->mPath, BO_LITTLE, 4, &fourCC) + || !ReadBin4(istream, src->mPath, order, 4, &chunkSize)) return 0; } while(fourCC != FOURCC_FMT); - if(!ReadBin4(fp, src->mPath, order, 2, &format) || - !ReadBin4(fp, src->mPath, order, 2, &channels) || - !ReadBin4(fp, src->mPath, order, 4, &rate) || - !ReadBin4(fp, src->mPath, order, 4, &dummy) || - !ReadBin4(fp, src->mPath, order, 2, &block)) + if(!ReadBin4(istream, src->mPath, order, 2, &format) + || !ReadBin4(istream, src->mPath, order, 2, &channels) + || !ReadBin4(istream, src->mPath, order, 4, &rate) + || !ReadBin4(istream, src->mPath, order, 4, &dummy) + || !ReadBin4(istream, src->mPath, order, 2, &block)) return 0; block /= channels; if(chunkSize > 14) { - if(!ReadBin4(fp, src->mPath, order, 2, &size)) + if(!ReadBin4(istream, src->mPath, order, 2, &size)) return 0; size /= 8; if(block > size) @@ -777,23 +796,23 @@ static int ReadWaveFormat(FILE *fp, const ByteOrderT order, const uint hrirRate, size = block; if(format == WAVE_FORMAT_EXTENSIBLE) { - fseek(fp, 2, SEEK_CUR); - if(!ReadBin4(fp, src->mPath, order, 2, &bits)) + istream.seekg(2, std::ios::cur); + if(!ReadBin4(istream, src->mPath, order, 2, &bits)) return 0; if(bits == 0) bits = 8 * size; - fseek(fp, 4, SEEK_CUR); - if(!ReadBin4(fp, src->mPath, order, 2, &format)) + istream.seekg(4, std::ios::cur); + if(!ReadBin4(istream, src->mPath, order, 2, &format)) return 0; - fseek(fp, static_cast(chunkSize - 26), SEEK_CUR); + istream.seekg(static_cast(chunkSize - 26), std::ios::cur); } else { bits = 8 * size; if(chunkSize > 14) - fseek(fp, static_cast(chunkSize - 16), SEEK_CUR); + istream.seekg(static_cast(chunkSize - 16), std::ios::cur); else - fseek(fp, static_cast(chunkSize - 14), SEEK_CUR); + istream.seekg(static_cast(chunkSize - 14), std::ios::cur); } if(format != WAVE_FORMAT_PCM && format != WAVE_FORMAT_IEEE_FLOAT) { @@ -840,7 +859,8 @@ static int ReadWaveFormat(FILE *fp, const ByteOrderT order, const uint hrirRate, } // Read a RIFF/RIFX WAVE data chunk, converting all elements to doubles. -static int ReadWaveData(FILE *fp, const SourceRefT *src, const ByteOrderT order, const uint n, double *hrir) +static int ReadWaveData(std::istream &istream, const SourceRefT *src, const ByteOrderT order, + const uint n, double *hrir) { int pre, post, skip; uint i; @@ -852,19 +872,20 @@ static int ReadWaveData(FILE *fp, const SourceRefT *src, const ByteOrderT order, { skip += pre; if(skip > 0) - fseek(fp, skip, SEEK_CUR); - if(!ReadBinAsDouble(fp, src->mPath, order, src->mType, src->mSize, src->mBits, &hrir[i])) + istream.seekg(skip, std::ios::cur); + if(!ReadBinAsDouble(istream, src->mPath, order, src->mType, src->mSize, src->mBits, &hrir[i])) return 0; skip = post; } if(skip > 0) - fseek(fp, skip, SEEK_CUR); + istream.seekg(skip, std::ios::cur); return 1; } // Read the RIFF/RIFX WAVE list or data chunk, converting all elements to // doubles. -static int ReadWaveList(FILE *fp, const SourceRefT *src, const ByteOrderT order, const uint n, double *hrir) +static int ReadWaveList(std::istream &istream, const SourceRefT *src, const ByteOrderT order, + const uint n, double *hrir) { uint32_t fourCC, chunkSize, listSize, count; uint block, skip, offset, i; @@ -872,8 +893,8 @@ static int ReadWaveList(FILE *fp, const SourceRefT *src, const ByteOrderT order, for(;;) { - if(!ReadBin4(fp, src->mPath, BO_LITTLE, 4, &fourCC) || - !ReadBin4(fp, src->mPath, order, 4, &chunkSize)) + if(!ReadBin4(istream, src->mPath, BO_LITTLE, 4, &fourCC) + || !ReadBin4(istream, src->mPath, order, 4, &chunkSize)) return 0; if(fourCC == FOURCC_DATA) @@ -885,21 +906,21 @@ static int ReadWaveList(FILE *fp, const SourceRefT *src, const ByteOrderT order, fprintf(stderr, "\nError: Bad read from file '%s'.\n", src->mPath); return 0; } - fseek(fp, static_cast(src->mOffset * block), SEEK_CUR); - if(!ReadWaveData(fp, src, order, n, &hrir[0])) + istream.seekg(static_cast(src->mOffset * block), std::ios::cur); + if(!ReadWaveData(istream, src, order, n, &hrir[0])) return 0; return 1; } else if(fourCC == FOURCC_LIST) { - if(!ReadBin4(fp, src->mPath, BO_LITTLE, 4, &fourCC)) + if(!ReadBin4(istream, src->mPath, BO_LITTLE, 4, &fourCC)) return 0; chunkSize -= 4; if(fourCC == FOURCC_WAVL) break; } if(chunkSize > 0) - fseek(fp, static_cast(chunkSize), SEEK_CUR); + istream.seekg(static_cast(chunkSize), std::ios::cur); } listSize = chunkSize; block = src->mSize * src->mSkip; @@ -908,8 +929,8 @@ static int ReadWaveList(FILE *fp, const SourceRefT *src, const ByteOrderT order, lastSample = 0.0; while(offset < n && listSize > 8) { - if(!ReadBin4(fp, src->mPath, BO_LITTLE, 4, &fourCC) || - !ReadBin4(fp, src->mPath, order, 4, &chunkSize)) + if(!ReadBin4(istream, src->mPath, BO_LITTLE, 4, &fourCC) + || !ReadBin4(istream, src->mPath, order, 4, &chunkSize)) return 0; listSize -= 8 + chunkSize; if(fourCC == FOURCC_DATA) @@ -917,13 +938,13 @@ static int ReadWaveList(FILE *fp, const SourceRefT *src, const ByteOrderT order, count = chunkSize / block; if(count > skip) { - fseek(fp, static_cast(skip * block), SEEK_CUR); + istream.seekg(static_cast(skip * block), std::ios::cur); chunkSize -= skip * block; count -= skip; skip = 0; if(count > (n - offset)) count = n - offset; - if(!ReadWaveData(fp, src, order, count, &hrir[offset])) + if(!ReadWaveData(istream, src, order, count, &hrir[offset])) return 0; chunkSize -= count * block; offset += count; @@ -937,7 +958,7 @@ static int ReadWaveList(FILE *fp, const SourceRefT *src, const ByteOrderT order, } else if(fourCC == FOURCC_SLNT) { - if(!ReadBin4(fp, src->mPath, order, 4, &count)) + if(!ReadBin4(istream, src->mPath, order, 4, &count)) return 0; chunkSize -= 4; if(count > skip) @@ -957,7 +978,7 @@ static int ReadWaveList(FILE *fp, const SourceRefT *src, const ByteOrderT order, } } if(chunkSize > 0) - fseek(fp, static_cast(chunkSize), SEEK_CUR); + istream.seekg(static_cast(chunkSize), std::ios::cur); } if(offset < n) { @@ -969,13 +990,14 @@ static int ReadWaveList(FILE *fp, const SourceRefT *src, const ByteOrderT order, // Load a source HRIR from an ASCII text file containing a list of elements // separated by whitespace or common list operators (',', ';', ':', '|'). -static int LoadAsciiSource(FILE *fp, const SourceRefT *src, const uint n, double *hrir) +static int LoadAsciiSource(std::istream &istream, const SourceRefT *src, + const uint n, double *hrir) { - TokenReaderT tr; + TokenReaderT tr{istream}; uint i, j; double dummy; - TrSetup(fp, nullptr, 0, nullptr, &tr); + TrSetup(nullptr, 0, nullptr, &tr); for(i = 0;i < src->mOffset;i++) { if(!ReadAsciiAsDouble(&tr, src->mPath, src->mType, static_cast(src->mBits), &dummy)) @@ -995,29 +1017,29 @@ static int LoadAsciiSource(FILE *fp, const SourceRefT *src, const uint n, double } // Load a source HRIR from a binary file. -static int LoadBinarySource(FILE *fp, const SourceRefT *src, const ByteOrderT order, const uint n, double *hrir) +static int LoadBinarySource(std::istream &istream, const SourceRefT *src, const ByteOrderT order, + const uint n, double *hrir) { - uint i; - - fseek(fp, static_cast(src->mOffset), SEEK_SET); - for(i = 0;i < n;i++) + istream.seekg(static_cast(src->mOffset), std::ios::beg); + for(uint i{0};i < n;i++) { - if(!ReadBinAsDouble(fp, src->mPath, order, src->mType, src->mSize, src->mBits, &hrir[i])) + if(!ReadBinAsDouble(istream, src->mPath, order, src->mType, src->mSize, src->mBits, &hrir[i])) return 0; if(src->mSkip > 0) - fseek(fp, static_cast(src->mSkip), SEEK_CUR); + istream.seekg(static_cast(src->mSkip), std::ios::cur); } return 1; } // Load a source HRIR from a RIFF/RIFX WAVE file. -static int LoadWaveSource(FILE *fp, SourceRefT *src, const uint hrirRate, const uint n, double *hrir) +static int LoadWaveSource(std::istream &istream, SourceRefT *src, const uint hrirRate, + const uint n, double *hrir) { uint32_t fourCC, dummy; ByteOrderT order; - if(!ReadBin4(fp, src->mPath, BO_LITTLE, 4, &fourCC) || - !ReadBin4(fp, src->mPath, BO_LITTLE, 4, &dummy)) + if(!ReadBin4(istream, src->mPath, BO_LITTLE, 4, &fourCC) + || !ReadBin4(istream, src->mPath, BO_LITTLE, 4, &dummy)) return 0; if(fourCC == FOURCC_RIFF) order = BO_LITTLE; @@ -1029,16 +1051,16 @@ static int LoadWaveSource(FILE *fp, SourceRefT *src, const uint hrirRate, const return 0; } - if(!ReadBin4(fp, src->mPath, BO_LITTLE, 4, &fourCC)) + if(!ReadBin4(istream, src->mPath, BO_LITTLE, 4, &fourCC)) return 0; if(fourCC != FOURCC_WAVE) { fprintf(stderr, "\nError: Not a RIFF/RIFX WAVE file '%s'.\n", src->mPath); return 0; } - if(!ReadWaveFormat(fp, order, hrirRate, src)) + if(!ReadWaveFormat(istream, order, hrirRate, src)) return 0; - if(!ReadWaveList(fp, src, order, n, hrir)) + if(!ReadWaveList(istream, src, order, n, hrir)) return 0; return 1; } @@ -1068,14 +1090,9 @@ static MYSOFA_EASY* LoadSofaFile(SourceRefT *src, const uint hrirRate, const uin fprintf(stderr, "\nError: Could not load source file '%s'.\n", src->mPath); return nullptr; } + /* NOTE: Some valid SOFA files are failing this check. */ err = mysofa_check(sofa->hrtf); if(err != MYSOFA_OK) -/* NOTE: Some valid SOFA files are failing this check. - { - mysofa_close(sofa); - fprintf(stderr, "\nError: Malformed source file '%s'.\n", src->mPath); - return nullptr; - }*/ fprintf(stderr, "\nWarning: Supposedly malformed source file '%s'.\n", src->mPath); if((src->mOffset + n) > sofa->hrtf->N) { @@ -1156,41 +1173,40 @@ static int LoadSofaSource(SourceRefT *src, const uint hrirRate, const uint n, do // Load a source HRIR from a supported file type. static int LoadSource(SourceRefT *src, const uint hrirRate, const uint n, double *hrir) { - FILE *fp{nullptr}; + std::unique_ptr istream; if(src->mFormat != SF_SOFA) { if(src->mFormat == SF_ASCII) - fp = fopen(src->mPath, "r"); + istream.reset(new al::ifstream{src->mPath}); else - fp = fopen(src->mPath, "rb"); - if(fp == nullptr) + istream.reset(new al::ifstream{src->mPath, std::ios::binary}); + if(!istream->good()) { fprintf(stderr, "\nError: Could not open source file '%s'.\n", src->mPath); return 0; } } - int result; + int result{0}; switch(src->mFormat) { case SF_ASCII: - result = LoadAsciiSource(fp, src, n, hrir); + result = LoadAsciiSource(*istream, src, n, hrir); break; case SF_BIN_LE: - result = LoadBinarySource(fp, src, BO_LITTLE, n, hrir); + result = LoadBinarySource(*istream, src, BO_LITTLE, n, hrir); break; case SF_BIN_BE: - result = LoadBinarySource(fp, src, BO_BIG, n, hrir); + result = LoadBinarySource(*istream, src, BO_BIG, n, hrir); break; case SF_WAVE: - result = LoadWaveSource(fp, src, hrirRate, n, hrir); + result = LoadWaveSource(*istream, src, hrirRate, n, hrir); break; case SF_SOFA: result = LoadSofaSource(src, hrirRate, n, hrir); break; - default: - result = 0; + case SF_NONE: + break; } - if(fp) fclose(fp); return result; } @@ -1833,21 +1849,20 @@ static int ProcessSources(TokenReaderT *tr, HrirDataT *hData) if(fi >= hData->mFdCount) continue; - double ef{(90.0 + aer[1]) * (hData->mFds[fi].mEvCount - 1) / 180.0}; + double ef{(90.0 + aer[1]) / 180.0 * (hData->mFds[fi].mEvCount - 1)}; ei = static_cast(std::round(ef)); - ef = (ef - ei) * 180.0f / (hData->mFds[fi].mEvCount - 1); + ef = (ef - ei) * 180.0 / (hData->mFds[fi].mEvCount - 1); if(std::abs(ef) >= 0.1) continue; - double af{aer[0] * hData->mFds[fi].mEvs[ei].mAzCount / 360.0f}; + double af{aer[0] / 360.0 * hData->mFds[fi].mEvs[ei].mAzCount}; ai = static_cast(std::round(af)); - af = (af - ai) * 360.0f / hData->mFds[fi].mEvs[ei].mAzCount; + af = (af - ai) * 360.0 / hData->mFds[fi].mEvs[ei].mAzCount; ai = ai % hData->mFds[fi].mEvs[ei].mAzCount; if(std::abs(af) >= 0.1) continue; HrirAzT *azd = &hData->mFds[fi].mEvs[ei].mAzs[ai]; - if(azd->mIrs[0] != nullptr) { TrErrorAt(tr, line, col, "Redefinition of source [ %d, %d, %d ].\n", fi, ei, ai); @@ -2003,24 +2018,16 @@ static int ProcessSources(TokenReaderT *tr, HrirDataT *hData) } -bool LoadDefInput(FILE *fp, const char *startbytes, size_t startbytecount, const char *filename, - const uint fftSize, const uint truncSize, const ChannelModeT chanMode, HrirDataT *hData) +bool LoadDefInput(std::istream &istream, const char *startbytes, std::streamsize startbytecount, + const char *filename, const uint fftSize, const uint truncSize, const ChannelModeT chanMode, + HrirDataT *hData) { - TokenReaderT tr; + TokenReaderT tr{istream}; - TrSetup(fp, startbytes, startbytecount, filename, &tr); - if(!ProcessMetrics(&tr, fftSize, truncSize, chanMode, hData)) - { - if(fp != stdin) - fclose(fp); - return false; - } - if(!ProcessSources(&tr, hData)) - { - if(fp != stdin) - fclose(fp); + TrSetup(startbytes, startbytecount, filename, &tr); + if(!ProcessMetrics(&tr, fftSize, truncSize, chanMode, hData) + || !ProcessSources(&tr, hData)) return false; - } return true; } diff --git a/utils/makemhr/loaddef.h b/utils/makemhr/loaddef.h index 05862228..34fbb832 100644 --- a/utils/makemhr/loaddef.h +++ b/utils/makemhr/loaddef.h @@ -1,12 +1,13 @@ #ifndef LOADDEF_H #define LOADDEF_H -#include +#include #include "makemhr.h" -bool LoadDefInput(FILE *fp, const char *startbytes, size_t startbytecount, const char *filename, - const uint fftSize, const uint truncSize, const ChannelModeT chanMode, HrirDataT *hData); +bool LoadDefInput(std::istream &istream, const char *startbytes, std::streamsize startbytecount, + const char *filename, const uint fftSize, const uint truncSize, const ChannelModeT chanMode, + HrirDataT *hData); #endif /* LOADDEF_H */ diff --git a/utils/makemhr/loadsofa.cpp b/utils/makemhr/loadsofa.cpp index 219eb558..e0c08349 100644 --- a/utils/makemhr/loadsofa.cpp +++ b/utils/makemhr/loadsofa.cpp @@ -21,13 +21,20 @@ * Or visit: http://www.gnu.org/licenses/old-licenses/gpl-2.0.html */ +#include "loadsofa.h" + +#include +#include +#include +#include #include #include -#include +#include +#include -#include "mysofa.h" +#include "makemhr.h" -#include "loadsofa.h" +#include "mysofa.h" static const char *SofaErrorStr(int err) @@ -216,10 +223,11 @@ static bool PrepareLayout(const uint m, const float *xyzs, HrirDataT *hData) { float ev{90.0f + elems[ei]}; float eif{std::round(ev / step)}; + const uint ei_start{static_cast(eif)}; - if(std::fabs(eif - static_cast(eif)) < (0.1f / step)) + if(std::fabs(eif - static_cast(ei_start)) < (0.1f/step)) { - evStart = static_cast(eif); + evStart = ei_start; break; } } @@ -428,8 +436,8 @@ static double CalcHrirOnset(const uint rate, const uint n, std::vector & } double mag{std::accumulate(upsampled.cbegin(), upsampled.cend(), double{0.0}, - [](const double mag, const double sample) -> double - { return std::max(mag, std::abs(sample)); })}; + [](const double magnitude, const double sample) -> double + { return std::max(magnitude, std::abs(sample)); })}; mag *= 0.15; auto iter = std::find_if(upsampled.cbegin(), upsampled.cend(), @@ -487,14 +495,14 @@ static bool LoadResponses(MYSOFA_HRTF *sofaHrtf, HrirDataT *hData) if(field == hData->mFds.cend()) continue; - double ef{(90.0+aer[1]) * (field->mEvCount-1) / 180.0}; + double ef{(90.0+aer[1]) / 180.0 * (field->mEvCount-1)}; auto ei = static_cast(std::round(ef)); - ef = (ef-ei) * 180.0f / (field->mEvCount-1); + ef = (ef-ei) * 180.0 / (field->mEvCount-1); if(std::abs(ef) >= 0.1) continue; - double af{aer[0] * field->mEvs[ei].mAzCount / 360.0f}; + double af{aer[0] / 360.0 * field->mEvs[ei].mAzCount}; auto ai = static_cast(std::round(af)); - af = (af-ai) * 360.0f / field->mEvs[ei].mAzCount; + af = (af-ai) * 360.0 / field->mEvs[ei].mAzCount; ai %= field->mEvs[ei].mAzCount; if(std::abs(af) >= 0.1) continue; @@ -541,14 +549,9 @@ bool LoadSofaFile(const char *filename, const uint fftSize, const uint truncSize return false; } + /* NOTE: Some valid SOFA files are failing this check. */ err = mysofa_check(sofaHrtf.get()); if(err != MYSOFA_OK) -/* NOTE: Some valid SOFA files are failing this check. - { - fprintf(stdout, "Error: Malformed source file '%s' (%s).\n", filename, SofaErrorStr(err)); - return false; - } -*/ fprintf(stderr, "Warning: Supposedly malformed source file '%s' (%s).\n", filename, SofaErrorStr(err)); @@ -589,8 +592,8 @@ bool LoadSofaFile(const char *filename, const uint fftSize, const uint truncSize /* Assume a default head radius of 9cm. */ hData->mRadius = 0.09; - if(!PrepareSampleRate(sofaHrtf.get(), hData) || !PrepareDelay(sofaHrtf.get(), hData) || - !CheckIrData(sofaHrtf.get())) + if(!PrepareSampleRate(sofaHrtf.get(), hData) || !PrepareDelay(sofaHrtf.get(), hData) + || !CheckIrData(sofaHrtf.get())) return false; if(!PrepareLayout(sofaHrtf->M, sofaHrtf->SourcePosition.values, hData)) return false; diff --git a/utils/makemhr/makemhr.cpp b/utils/makemhr/makemhr.cpp index 8071ac18..3659d40b 100644 --- a/utils/makemhr/makemhr.cpp +++ b/utils/makemhr/makemhr.cpp @@ -74,6 +74,7 @@ #include #include #include +#include #include #include #include @@ -87,6 +88,7 @@ #include "../getopt.h" #endif +#include "alfstream.h" #include "alstring.h" #include "loaddef.h" #include "loadsofa.h" @@ -1321,32 +1323,32 @@ static void NormalizeHrirs(HrirDataT *hData) /* Find the maximum amplitude and RMS out of all the IRs. */ struct LevelPair { double amp, rms; }; - auto proc0_field = [channels,irSize](const LevelPair levels, const HrirFdT &field) -> LevelPair + auto proc0_field = [channels,irSize](const LevelPair levels0, const HrirFdT &field) -> LevelPair { - auto proc_elev = [channels,irSize](const LevelPair levels, const HrirEvT &elev) -> LevelPair + auto proc_elev = [channels,irSize](const LevelPair levels1, const HrirEvT &elev) -> LevelPair { - auto proc_azi = [channels,irSize](const LevelPair levels, const HrirAzT &azi) -> LevelPair + auto proc_azi = [channels,irSize](const LevelPair levels2, const HrirAzT &azi) -> LevelPair { - auto proc_channel = [irSize](const LevelPair levels, const double *ir) -> LevelPair + auto proc_channel = [irSize](const LevelPair levels3, const double *ir) -> LevelPair { /* Calculate the peak amplitude and RMS of this IR. */ auto current = std::accumulate(ir, ir+irSize, LevelPair{0.0, 0.0}, - [](const LevelPair current, const double impulse) -> LevelPair + [](const LevelPair cur, const double impulse) -> LevelPair { - return LevelPair{std::max(std::abs(impulse), current.amp), - current.rms + impulse*impulse}; + return {std::max(std::abs(impulse), cur.amp), + cur.rms + impulse*impulse}; }); current.rms = std::sqrt(current.rms / irSize); /* Accumulate levels by taking the maximum amplitude and RMS. */ - return LevelPair{std::max(current.amp, levels.amp), - std::max(current.rms, levels.rms)}; + return LevelPair{std::max(current.amp, levels3.amp), + std::max(current.rms, levels3.rms)}; }; - return std::accumulate(azi.mIrs, azi.mIrs+channels, levels, proc_channel); + return std::accumulate(azi.mIrs, azi.mIrs+channels, levels2, proc_channel); }; - return std::accumulate(elev.mAzs, elev.mAzs+elev.mAzCount, levels, proc_azi); + return std::accumulate(elev.mAzs, elev.mAzs+elev.mAzCount, levels1, proc_azi); }; - return std::accumulate(field.mEvs, field.mEvs+field.mEvCount, levels, proc_elev); + return std::accumulate(field.mEvs, field.mEvs+field.mEvCount, levels0, proc_elev); }; const auto maxlev = std::accumulate(hData->mFds.begin(), hData->mFds.begin()+hData->mFdCount, LevelPair{0.0, 0.0}, proc0_field); @@ -1528,64 +1530,59 @@ int PrepareHrirData(const uint fdCount, const double (&distances)[MAX_FD_COUNT], * resulting data set as desired. If the input name is NULL it will read * from standard input. */ -static int ProcessDefinition(const char *inName, const uint outRate, const ChannelModeT chanMode, const uint fftSize, const int equalize, const int surface, const double limit, const uint truncSize, const HeadModelT model, const double radius, const char *outName) +static int ProcessDefinition(const char *inName, const uint outRate, const ChannelModeT chanMode, + const uint fftSize, const int equalize, const int surface, const double limit, + const uint truncSize, const HeadModelT model, const double radius, const char *outName) { char rateStr[8+1], expName[MAX_PATH_LEN]; - char startbytes[4]{}; - size_t startbytecount{0u}; HrirDataT hData; - FILE *fp; - int ret; if(!inName) { inName = "stdin"; - fp = stdin; + fprintf(stdout, "Reading HRIR definition from %s...\n", inName); + if(!LoadDefInput(std::cin, nullptr, 0, inName, fftSize, truncSize, chanMode, &hData)) + return 0; } else { - fp = fopen(inName, "r"); - if(fp == nullptr) + std::unique_ptr input{new al::ifstream{inName}}; + if(!input->is_open()) { fprintf(stderr, "Error: Could not open input file '%s'\n", inName); return 0; } - startbytecount = fread(startbytes, 1, sizeof(startbytes), fp); - if(startbytecount != sizeof(startbytes)) + char startbytes[4]{}; + input->read(startbytes, sizeof(startbytes)); + std::streamsize startbytecount{input->gcount()}; + if(startbytecount != sizeof(startbytes) || !input->good()) { - fclose(fp); fprintf(stderr, "Error: Could not read input file '%s'\n", inName); return 0; } - if(startbytes[0] == '\x89' && startbytes[1] == 'H' && startbytes[2] == 'D' && - startbytes[3] == 'F') + if(startbytes[0] == '\x89' && startbytes[1] == 'H' && startbytes[2] == 'D' + && startbytes[3] == 'F') { - fclose(fp); - fp = nullptr; - + input = nullptr; fprintf(stdout, "Reading HRTF data from %s...\n", inName); if(!LoadSofaFile(inName, fftSize, truncSize, chanMode, &hData)) return 0; } - } - if(fp != nullptr) - { - fprintf(stdout, "Reading HRIR definition from %s...\n", inName); - const bool success{LoadDefInput(fp, startbytes, startbytecount, inName, fftSize, truncSize, - chanMode, &hData)}; - if(fp != stdin) - fclose(fp); - if(!success) - return 0; + else + { + fprintf(stdout, "Reading HRIR definition from %s...\n", inName); + if(!LoadDefInput(*input, startbytes, startbytecount, inName, fftSize, truncSize, chanMode, &hData)) + return 0; + } } if(equalize) { - uint c = (hData.mChannelType == CT_STEREO) ? 2 : 1; - uint m = 1 + hData.mFftSize / 2; - std::vector dfa(c * m); + uint c{(hData.mChannelType == CT_STEREO) ? 2u : 1u}; + uint m{hData.mFftSize/2u + 1u}; + auto dfa = std::vector(c * m); if(hData.mFdCount > 1) { @@ -1614,12 +1611,10 @@ static int ProcessDefinition(const char *inName, const uint outRate, const Chann NormalizeHrirs(&hData); fprintf(stdout, "Calculating impulse delays...\n"); CalculateHrtds(model, (radius > DEFAULT_CUSTOM_RADIUS) ? radius : hData.mRadius, &hData); - snprintf(rateStr, 8, "%u", hData.mIrRate); - StrSubst(outName, "%r", rateStr, MAX_PATH_LEN, expName); + snprintf(rateStr, sizeof(rateStr), "%u", hData.mIrRate); + StrSubst(outName, "%r", rateStr, sizeof(expName), expName); fprintf(stdout, "Creating MHR data set %s...\n", expName); - ret = StoreMhr(&hData, expName); - - return ret; + return StoreMhr(&hData, expName); } static void PrintHelp(const char *argv0, FILE *ofile) -- cgit v1.2.3 From 882b4acae80f41547a9e16b7def02a972842c857 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sat, 28 Sep 2019 01:58:29 -0700 Subject: Add "fast" variants for the bsinc resamplers This simply omits the scale factor from the filter, similar to how up-sampling does. The consequence of this is less smooth transitions when ramping the pitch while down-sampling, but otherwise behaves fine. --- al/state.cpp | 7 +++++-- alc/alu.cpp | 8 ++++---- alc/alu.h | 2 ++ alc/converter.cpp | 4 ++-- alc/mixvoice.cpp | 7 ++++++- alsoftrc.sample | 6 +++++- utils/alsoft-config/mainwindow.cpp | 2 ++ 7 files changed, 26 insertions(+), 10 deletions(-) (limited to 'utils') diff --git a/al/state.cpp b/al/state.cpp index 8f456ed3..d426f022 100644 --- a/al/state.cpp +++ b/al/state.cpp @@ -63,7 +63,9 @@ constexpr ALchar alErrOutOfMemory[] = "Out of Memory"; constexpr ALchar alPointResampler[] = "Nearest"; constexpr ALchar alLinearResampler[] = "Linear"; constexpr ALchar alCubicResampler[] = "Cubic"; +constexpr ALchar alFastBSinc12Resampler[] = "11th order Sinc (fast)"; constexpr ALchar alBSinc12Resampler[] = "11th order Sinc"; +constexpr ALchar alFastBSinc24Resampler[] = "23rd order Sinc (fast)"; constexpr ALchar alBSinc24Resampler[] = "23rd order Sinc"; } // namespace @@ -798,8 +800,9 @@ START_API_FUNC { const char *ResamplerNames[] = { alPointResampler, alLinearResampler, - alCubicResampler, alBSinc12Resampler, - alBSinc24Resampler, + alCubicResampler, alFastBSinc12Resampler, + alBSinc12Resampler, alFastBSinc24Resampler, + alBSinc24Resampler }; static_assert(al::size(ResamplerNames) == static_cast(Resampler::Max)+1, "Incorrect ResamplerNames list"); diff --git a/alc/alu.cpp b/alc/alu.cpp index 86d2789e..5df1c3a2 100644 --- a/alc/alu.cpp +++ b/alc/alu.cpp @@ -947,9 +947,9 @@ void CalcNonAttnSourceParams(ALvoice *voice, const ALvoicePropsBase *props, cons voice->mStep = MAX_PITCH<mStep = maxu(fastf2u(Pitch * FRACTIONONE), 1); - if(props->mResampler == Resampler::BSinc24) + if(props->mResampler == Resampler::BSinc24 || props->mResampler == Resampler::FastBSinc24) BsincPrepare(voice->mStep, &voice->mResampleState.bsinc, &bsinc24); - else if(props->mResampler == Resampler::BSinc12) + else if(props->mResampler == Resampler::BSinc12 || props->mResampler == Resampler::FastBSinc12) BsincPrepare(voice->mStep, &voice->mResampleState.bsinc, &bsinc12); voice->mResampler = SelectResampler(props->mResampler, voice->mStep); @@ -1277,9 +1277,9 @@ void CalcAttnSourceParams(ALvoice *voice, const ALvoicePropsBase *props, const A voice->mStep = MAX_PITCH<mStep = maxu(fastf2u(Pitch * FRACTIONONE), 1); - if(props->mResampler == Resampler::BSinc24) + if(props->mResampler == Resampler::BSinc24 || props->mResampler == Resampler::FastBSinc24) BsincPrepare(voice->mStep, &voice->mResampleState.bsinc, &bsinc24); - else if(props->mResampler == Resampler::BSinc12) + else if(props->mResampler == Resampler::BSinc12 || props->mResampler == Resampler::FastBSinc12) BsincPrepare(voice->mStep, &voice->mResampleState.bsinc, &bsinc12); voice->mResampler = SelectResampler(props->mResampler, voice->mStep); diff --git a/alc/alu.h b/alc/alu.h index e9858ddb..e2b25556 100644 --- a/alc/alu.h +++ b/alc/alu.h @@ -46,7 +46,9 @@ enum class Resampler { Point, Linear, Cubic, + FastBSinc12, BSinc12, + FastBSinc24, BSinc24, Max = BSinc24 diff --git a/alc/converter.cpp b/alc/converter.cpp index b0efb839..aff1c353 100644 --- a/alc/converter.cpp +++ b/alc/converter.cpp @@ -167,9 +167,9 @@ SampleConverterPtr CreateSampleConverter(DevFmtType srcType, DevFmtType dstType, converter->mResample = Resample_; else { - if(resampler == Resampler::BSinc24) + if(resampler == Resampler::BSinc24 || resampler == Resampler::FastBSinc24) BsincPrepare(converter->mIncrement, &converter->mState.bsinc, &bsinc24); - else if(resampler == Resampler::BSinc12) + else if(resampler == Resampler::BSinc12 || resampler == Resampler::FastBSinc12) BsincPrepare(converter->mIncrement, &converter->mState.bsinc, &bsinc12); converter->mResample = SelectResampler(resampler, converter->mIncrement); } diff --git a/alc/mixvoice.cpp b/alc/mixvoice.cpp index 58a08ce3..e9e0d8df 100644 --- a/alc/mixvoice.cpp +++ b/alc/mixvoice.cpp @@ -161,6 +161,9 @@ ResamplerFunc SelectResampler(Resampler resampler, ALuint increment) case Resampler::BSinc24: if(increment <= FRACTIONONE) { + /* fall-through */ + case Resampler::FastBSinc12: + case Resampler::FastBSinc24: #ifdef HAVE_NEON if((CPUCapFlags&CPU_CAP_NEON)) return Resample_; @@ -191,7 +194,7 @@ void aluInitMixer() if(auto resopt = ConfigValueStr(nullptr, nullptr, "resampler")) { struct ResamplerEntry { - const char name[12]; + const char name[16]; const Resampler resampler; }; constexpr ResamplerEntry ResamplerList[]{ @@ -199,7 +202,9 @@ void aluInitMixer() { "point", Resampler::Point }, { "cubic", Resampler::Cubic }, { "bsinc12", Resampler::BSinc12 }, + { "fast_bsinc12", Resampler::FastBSinc12 }, { "bsinc24", Resampler::BSinc24 }, + { "fast_bsinc24", Resampler::FastBSinc24 }, }; const char *str{resopt->c_str()}; diff --git a/alsoftrc.sample b/alsoftrc.sample index 7cb780a3..de3ab6f3 100644 --- a/alsoftrc.sample +++ b/alsoftrc.sample @@ -161,14 +161,18 @@ #cf_level = 0 ## resampler: (global) -# Selects the resampler used when mixing sources. Valid values are: +# Selects the default resampler used when mixing sources. Valid values are: # point - nearest sample, no interpolation # linear - extrapolates samples using a linear slope between samples # cubic - extrapolates samples using a Catmull-Rom spline # bsinc12 - extrapolates samples using a band-limited Sinc filter (varying # between 12 and 24 points, with anti-aliasing) +# fast_bsinc12 - same as bsinc12, except without interpolation between down- +# sampling scales # bsinc24 - extrapolates samples using a band-limited Sinc filter (varying # between 24 and 48 points, with anti-aliasing) +# fast_bsinc24 - same as bsinc24, except without interpolation between down- +# sampling scales #resampler = linear ## rt-prio: (global) diff --git a/utils/alsoft-config/mainwindow.cpp b/utils/alsoft-config/mainwindow.cpp index 7e5159cf..f4f5fd45 100644 --- a/utils/alsoft-config/mainwindow.cpp +++ b/utils/alsoft-config/mainwindow.cpp @@ -101,7 +101,9 @@ static const struct NameValuePair { { "Linear", "linear" }, { "Default (Linear)", "" }, { "Cubic Spline", "cubic" }, + { "11th order Sinc (fast)", "fast_bsinc12" }, { "11th order Sinc", "bsinc12" }, + { "23rd order Sinc (fast)", "fast_bsinc24" }, { "23rd order Sinc", "bsinc24" }, { "", "" } -- cgit v1.2.3 From fcde56e1fc2e16b2ac461fdc2e97a89adb82c6c6 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 21 Oct 2019 11:30:39 -0700 Subject: Increase the max elevation and azimuth count for HRTFs --- alc/hrtf.cpp | 4 ++-- utils/makemhr/makemhr.h | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'utils') diff --git a/alc/hrtf.cpp b/alc/hrtf.cpp index b23f9d6f..7643ce44 100644 --- a/alc/hrtf.cpp +++ b/alc/hrtf.cpp @@ -88,10 +88,10 @@ using HrtfHandlePtr = std::unique_ptr; #define MAX_FD_DISTANCE (2.5f) #define MIN_EV_COUNT (5) -#define MAX_EV_COUNT (128) +#define MAX_EV_COUNT (181) #define MIN_AZ_COUNT (1) -#define MAX_AZ_COUNT (128) +#define MAX_AZ_COUNT (360) #define MAX_HRIR_DELAY (HRTF_HISTORY_LENGTH-1) diff --git a/utils/makemhr/makemhr.h b/utils/makemhr/makemhr.h index 24520bd2..5125b43c 100644 --- a/utils/makemhr/makemhr.h +++ b/utils/makemhr/makemhr.h @@ -11,13 +11,13 @@ // The limit to the number of 'distances' listed in the data set definition. #define MAX_FD_COUNT (16) -// The limits to the number of 'azimuths' listed in the data set definition. +// The limits to the number of 'elevations' listed in the data set definition. #define MIN_EV_COUNT (5) -#define MAX_EV_COUNT (128) +#define MAX_EV_COUNT (181) // The limits for each of the 'azimuths' listed in the data set definition. #define MIN_AZ_COUNT (1) -#define MAX_AZ_COUNT (128) +#define MAX_AZ_COUNT (360) // The limits for the 'distance' from source to listener for each field in // the definition file. -- cgit v1.2.3 From a8a3acb6f66da6b630e6d71b77cdbc2b23a4f552 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Tue, 22 Oct 2019 15:22:37 -0700 Subject: More consistently use doubles in makemhr and loadsofa --- utils/makemhr/loadsofa.cpp | 69 +++++++++++++++++++++++--------------------- utils/sofa-info.cpp | 71 +++++++++++++++++++++++++--------------------- 2 files changed, 75 insertions(+), 65 deletions(-) (limited to 'utils') diff --git a/utils/makemhr/loadsofa.cpp b/utils/makemhr/loadsofa.cpp index e0c08349..49d16556 100644 --- a/utils/makemhr/loadsofa.cpp +++ b/utils/makemhr/loadsofa.cpp @@ -24,6 +24,7 @@ #include "loadsofa.h" #include +#include #include #include #include @@ -37,6 +38,8 @@ #include "mysofa.h" +using double3 = std::array; + static const char *SofaErrorStr(int err) { switch(err) @@ -57,18 +60,18 @@ static const char *SofaErrorStr(int err) * of other axes as necessary. The epsilons are used to constrain the * equality of unique elements. */ -static uint GetUniquelySortedElems(const uint m, const float *triplets, const uint axis, - const double *const (&filters)[3], const double (&epsilons)[3], float *elems) +static uint GetUniquelySortedElems(const uint m, const double3 *aers, const uint axis, + const double *const (&filters)[3], const double (&epsilons)[3], double *elems) { uint count{0u}; - for(uint i{0u};i < 3*m;i += 3) + for(uint i{0u};i < m;++i) { - const float elem{triplets[i + axis]}; + const double elem{aers[i][axis]}; uint j; for(j = 0;j < 3;j++) { - if(filters[j] && std::fabs(triplets[i + j] - *filters[j]) > epsilons[j]) + if(filters[j] && std::fabs(aers[i][j] - *filters[j]) > epsilons[j]) break; } if(j < 3) @@ -76,7 +79,7 @@ static uint GetUniquelySortedElems(const uint m, const float *triplets, const ui for(j = 0;j < count;j++) { - const float delta{elem - elems[j]}; + const double delta{elem - elems[j]}; if(delta > epsilons[axis]) continue; @@ -104,9 +107,9 @@ static uint GetUniquelySortedElems(const uint m, const float *triplets, const ui * half, but in degenerate cases this can fall to a minimum of 5 (the lower * limit on elevations necessary to build a layout). */ -static float GetUniformStepSize(const double epsilon, const uint m, const float *elems) +static double GetUniformStepSize(const double epsilon, const uint m, const double *elems) { - auto steps = std::vector(m, 0.0f); + auto steps = std::vector(m, 0.0); auto counts = std::vector(m, 0u); uint count{0u}; @@ -114,7 +117,7 @@ static float GetUniformStepSize(const double epsilon, const uint m, const float { for(uint i{0u};i < m-stride;i++) { - const float step{elems[i + stride] - elems[i]}; + const double step{elems[i + stride] - elems[i]}; uint j; for(j = 0;j < count;j++) @@ -151,7 +154,7 @@ static float GetUniformStepSize(const double epsilon, const uint m, const float if(counts[0] > 5) return steps[0]; - return 0.0f; + return 0.0; } /* Attempts to produce a compatible layout. Most data sets tend to be @@ -162,15 +165,16 @@ static float GetUniformStepSize(const double epsilon, const uint m, const float */ static bool PrepareLayout(const uint m, const float *xyzs, HrirDataT *hData) { - std::vector aers(3*m, 0.0f); - std::vector elems(m, 0.0f); + auto aers = std::vector(m, double3{}); + auto elems = std::vector(m, 0.0); - for(uint i{0u};i < 3*m;i += 3) + for(uint i{0u};i < m;++i) { - aers[i] = xyzs[i]; - aers[i + 1] = xyzs[i + 1]; - aers[i + 2] = xyzs[i + 2]; - mysofa_c2s(&aers[i]); + float aer[3]{xyzs[i*3], xyzs[i*3 + 1], xyzs[i*3 + 2]}; + mysofa_c2s(&aer[0]); + aers[i][0] = aer[0]; + aers[i][1] = aer[1]; + aers[i][2] = aer[2]; } const uint fdCount{GetUniquelySortedElems(m, aers.data(), 2, { nullptr, nullptr, nullptr }, @@ -183,7 +187,7 @@ static bool PrepareLayout(const uint m, const float *xyzs, HrirDataT *hData) double distances[MAX_FD_COUNT]{}; uint evCounts[MAX_FD_COUNT]{}; - auto azCounts = std::vector(MAX_FD_COUNT * MAX_EV_COUNT); + auto azCounts = std::vector(MAX_FD_COUNT*MAX_EV_COUNT, 0u); for(uint fi{0u};fi < fdCount;fi++) { distances[fi] = elems[fi]; @@ -211,8 +215,8 @@ static bool PrepareLayout(const uint m, const float *xyzs, HrirDataT *hData) return false; } - float step{GetUniformStepSize(0.1, evCount, elems.data())}; - if(step <= 0.0f) + double step{GetUniformStepSize(0.1, evCount, elems.data())}; + if(step <= 0.0) { fprintf(stderr, "Incompatible layout (non-uniform elevations).\n"); return false; @@ -221,18 +225,18 @@ static bool PrepareLayout(const uint m, const float *xyzs, HrirDataT *hData) uint evStart{0u}; for(uint ei{0u};ei < evCount;ei++) { - float ev{90.0f + elems[ei]}; - float eif{std::round(ev / step)}; + double ev{90.0 + elems[ei]}; + double eif{std::round(ev / step)}; const uint ei_start{static_cast(eif)}; - if(std::fabs(eif - static_cast(ei_start)) < (0.1f/step)) + if(std::fabs(eif - static_cast(ei_start)) < (0.1/step)) { evStart = ei_start; break; } } - evCount = static_cast(std::round(180.0f / step)) + 1; + evCount = static_cast(std::round(180.0 / step)) + 1; if(evCount < 5) { fprintf(stderr, "Incompatible layout (too few uniform elevations).\n"); @@ -247,22 +251,23 @@ static bool PrepareLayout(const uint m, const float *xyzs, HrirDataT *hData) const uint azCount{GetUniquelySortedElems(m, aers.data(), 0, { nullptr, &ev, &dist }, { 0.1, 0.1, 0.001 }, elems.data())}; - if(azCount > MAX_AZ_COUNT) - { - fprintf(stderr, "Incompatible layout (innumerable azimuths).\n"); - return false; - } - if(ei > 0 && ei < (evCount - 1)) { step = GetUniformStepSize(0.1, azCount, elems.data()); - if(step <= 0.0f) + if(step <= 0.0) { fprintf(stderr, "Incompatible layout (non-uniform azimuths).\n"); return false; } - azCounts[fi*MAX_EV_COUNT + ei] = static_cast(std::round(360.0f / step)); + azCounts[fi*MAX_EV_COUNT + ei] = static_cast(std::round(360.0 / step)); + if(azCounts[fi*MAX_EV_COUNT + ei] > MAX_AZ_COUNT) + { + fprintf(stderr, + "Incompatible layout (too many azimuths on elev=%f, rad=%f, %u > %u).\n", + ev, dist, azCounts[fi*MAX_EV_COUNT + ei], MAX_AZ_COUNT); + return false; + } } else if(azCount != 1) { diff --git a/utils/sofa-info.cpp b/utils/sofa-info.cpp index 32bef938..a0ed9ff4 100644 --- a/utils/sofa-info.cpp +++ b/utils/sofa-info.cpp @@ -23,6 +23,7 @@ #include +#include #include #include #include @@ -33,6 +34,7 @@ using uint = unsigned int; +using double3 = std::array; struct MySofaDeleter { void operator()(MYSOFA_HRTF *sofa) { mysofa_free(sofa); } @@ -41,7 +43,7 @@ using MySofaHrtfPtr = std::unique_ptr; // Per-field measurement info. struct HrirFdT { - float mDistance{0.0f}; + double mDistance{0.0}; uint mEvCount{0u}; uint mEvStart{0u}; std::vector mAzCounts; @@ -83,19 +85,18 @@ static void PrintSofaArray(const char *prefix, struct MYSOFA_ARRAY *array) * of other axes as necessary. The epsilons are used to constrain the * equality of unique elements. */ -static uint GetUniquelySortedElems(const uint m, const float *triplets, const uint axis, - const float *const (&filters)[3], const float (&epsilons)[3], - float *elems) +static uint GetUniquelySortedElems(const uint m, const double3 *aers, const uint axis, + const double *const (&filters)[3], const double (&epsilons)[3], double *elems) { uint count{0u}; - for(uint i{0u};i < 3*m;i += 3) + for(uint i{0u};i < m;++i) { - float elem = triplets[i + axis]; + const double elem{aers[i][axis]}; uint j; for(j = 0;j < 3;j++) { - if(filters[j] && std::fabs(triplets[i + j] - *filters[j]) > epsilons[j]) + if(filters[j] && std::fabs(aers[i][j] - *filters[j]) > epsilons[j]) break; } if(j < 3) @@ -103,7 +104,7 @@ static uint GetUniquelySortedElems(const uint m, const float *triplets, const ui for(j = 0;j < count;j++) { - const float delta{elem - elems[j]}; + const double delta{elem - elems[j]}; if(delta > epsilons[axis]) continue; @@ -131,17 +132,17 @@ static uint GetUniquelySortedElems(const uint m, const float *triplets, const ui * half, but in degenerate cases this can fall to a minimum of 5 (the lower * limit on elevations necessary to build a layout). */ -static float GetUniformStepSize(const float epsilon, const uint m, const float *elems) +static double GetUniformStepSize(const double epsilon, const uint m, const double *elems) { - std::vector steps(m, 0.0f); - std::vector counts(m, 0u); + auto steps = std::vector(m, 0.0); + auto counts = std::vector(m, 0u); uint count{0u}; for(uint stride{1u};stride < m/2;stride++) { for(uint i{0u};i < m-stride;i++) { - const float step{elems[i + stride] - elems[i]}; + const double step{elems[i + stride] - elems[i]}; uint j; for(j = 0;j < count;j++) @@ -178,7 +179,7 @@ static float GetUniformStepSize(const float epsilon, const uint m, const float * if(counts[0] > 5) return steps[0]; - return 0.0f; + return 0.0; } /* Attempts to produce a compatible layout. Most data sets tend to be @@ -189,20 +190,22 @@ static float GetUniformStepSize(const float epsilon, const uint m, const float * */ static void PrintCompatibleLayout(const uint m, const float *xyzs) { - std::vector aers(3*m, 0.0f); - std::vector elems(m, 0.0f); + auto aers = std::vector(m, double3{}); + auto elems = std::vector(m, {}); fprintf(stdout, "\n"); - for(uint i{0u};i < 3*m;i += 3) + for(uint i{0u};i < m;++i) { - aers[i] = xyzs[i]; - aers[i + 1] = xyzs[i + 1]; - aers[i + 2] = xyzs[i + 2]; - mysofa_c2s(&aers[i]); + float aer[3]{xyzs[i*3], xyzs[i*3 + 1], xyzs[i*3 + 2]}; + mysofa_c2s(&aer[0]); + aers[i][0] = aer[0]; + aers[i][1] = aer[1]; + aers[i][2] = aer[2]; } - uint fdCount{GetUniquelySortedElems(m, aers.data(), 2, { nullptr, nullptr, nullptr }, { 0.1f, 0.1f, 0.001f }, elems.data())}; + uint fdCount{GetUniquelySortedElems(m, aers.data(), 2, { nullptr, nullptr, nullptr }, + { 0.1, 0.1, 0.001 }, elems.data())}; if(fdCount > (m / 3)) { fprintf(stdout, "Incompatible layout (inumerable radii).\n"); @@ -215,8 +218,9 @@ static void PrintCompatibleLayout(const uint m, const float *xyzs) for(uint fi{0u};fi < fdCount;fi++) { - float dist{fds[fi].mDistance}; - uint evCount{GetUniquelySortedElems(m, aers.data(), 1, { nullptr, nullptr, &dist }, { 0.1f, 0.1f, 0.001f }, elems.data())}; + const double dist{fds[fi].mDistance}; + uint evCount{GetUniquelySortedElems(m, aers.data(), 1, { nullptr, nullptr, &dist }, + { 0.1, 0.1, 0.001 }, elems.data())}; if(evCount > (m / 3)) { @@ -224,8 +228,8 @@ static void PrintCompatibleLayout(const uint m, const float *xyzs) return; } - float step{GetUniformStepSize(0.1f, evCount, elems.data())}; - if(step <= 0.0f) + double step{GetUniformStepSize(0.1, evCount, elems.data())}; + if(step <= 0.0) { fprintf(stdout, "Incompatible layout (non-uniform elevations).\n"); return; @@ -234,18 +238,18 @@ static void PrintCompatibleLayout(const uint m, const float *xyzs) uint evStart{0u}; for(uint ei{0u};ei < evCount;ei++) { - float ev{90.0f + elems[ei]}; - float eif{std::round(ev / step)}; + double ev{90.0 + elems[ei]}; + double eif{std::round(ev / step)}; const uint ev_start{static_cast(eif)}; - if(std::fabs(eif - static_cast(ev_start)) < (0.1f/step)) + if(std::fabs(eif - static_cast(ev_start)) < (0.1/step)) { evStart = ev_start; break; } } - evCount = static_cast(std::round(180.0f / step)) + 1; + evCount = static_cast(std::round(180.0 / step)) + 1; if(evCount < 5) { fprintf(stdout, "Incompatible layout (too few uniform elevations).\n"); @@ -259,8 +263,9 @@ static void PrintCompatibleLayout(const uint m, const float *xyzs) for(uint ei{evStart};ei < evCount;ei++) { - float ev{-90.0f + static_cast(ei)*180.0f/static_cast(evCount - 1)}; - uint azCount{GetUniquelySortedElems(m, aers.data(), 0, { nullptr, &ev, &dist }, { 0.1f, 0.1f, 0.001f }, elems.data())}; + double ev{-90.0 + static_cast(ei)*180.0/static_cast(evCount - 1)}; + uint azCount{GetUniquelySortedElems(m, aers.data(), 0, { nullptr, &ev, &dist }, + { 0.1, 0.1, 0.001 }, elems.data())}; if(azCount > (m / 3)) { @@ -270,8 +275,8 @@ static void PrintCompatibleLayout(const uint m, const float *xyzs) if(ei > 0 && ei < (evCount - 1)) { - step = GetUniformStepSize(0.1f, azCount, elems.data()); - if(step <= 0.0f) + step = GetUniformStepSize(0.1, azCount, elems.data()); + if(step <= 0.0) { fprintf(stdout, "Incompatible layout (non-uniform azimuths).\n"); return; -- cgit v1.2.3 From 4733fc6f1e2ba1bcdaca9d7c1941b2abbf150b67 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Tue, 22 Oct 2019 15:23:17 -0700 Subject: Fix azimuth limit --- alc/hrtf.cpp | 2 +- utils/makemhr/makemhr.cpp | 8 +++++--- utils/makemhr/makemhr.h | 5 ++++- 3 files changed, 10 insertions(+), 5 deletions(-) (limited to 'utils') diff --git a/alc/hrtf.cpp b/alc/hrtf.cpp index 7643ce44..bfce69f5 100644 --- a/alc/hrtf.cpp +++ b/alc/hrtf.cpp @@ -91,7 +91,7 @@ using HrtfHandlePtr = std::unique_ptr; #define MAX_EV_COUNT (181) #define MIN_AZ_COUNT (1) -#define MAX_AZ_COUNT (360) +#define MAX_AZ_COUNT (255) #define MAX_HRIR_DELAY (HRTF_HISTORY_LENGTH-1) diff --git a/utils/makemhr/makemhr.cpp b/utils/makemhr/makemhr.cpp index 3659d40b..1e28ca4b 100644 --- a/utils/makemhr/makemhr.cpp +++ b/utils/makemhr/makemhr.cpp @@ -1462,10 +1462,12 @@ static void CalculateHrtds(const HeadModelT model, const double radius, HrirData for(ei = 0;ei < hData->mFds[fi].mEvCount;ei++) { - for(ti = 0;ti < channels;ti++) + for(ai = 0;ai < hData->mFds[fi].mEvs[ei].mAzCount;ai++) { - for(ai = 0;ai < hData->mFds[fi].mEvs[ei].mAzCount;ai++) - hData->mFds[fi].mEvs[ei].mAzs[ai].mDelays[ti] -= minHrtd; + HrirAzT *azd = &hData->mFds[fi].mEvs[ei].mAzs[ai]; + + for(ti = 0;ti < channels;ti++) + azd->mDelays[ti] -= minHrtd; } } } diff --git a/utils/makemhr/makemhr.h b/utils/makemhr/makemhr.h index 5125b43c..ba19efbe 100644 --- a/utils/makemhr/makemhr.h +++ b/utils/makemhr/makemhr.h @@ -9,15 +9,18 @@ #define MAX_PATH_LEN (256) // The limit to the number of 'distances' listed in the data set definition. +// Must be less than 256 #define MAX_FD_COUNT (16) // The limits to the number of 'elevations' listed in the data set definition. +// Must be less than 256. #define MIN_EV_COUNT (5) #define MAX_EV_COUNT (181) // The limits for each of the 'azimuths' listed in the data set definition. +// Must be less than 256. #define MIN_AZ_COUNT (1) -#define MAX_AZ_COUNT (360) +#define MAX_AZ_COUNT (255) // The limits for the 'distance' from source to listener for each field in // the definition file. -- cgit v1.2.3 From 0dfdebdf6d2a27a7af666a64aab976c3ef2102b0 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Tue, 22 Oct 2019 16:30:07 -0700 Subject: Limit the number of azimuths and elevations used in SOFA files --- utils/makemhr/loadsofa.cpp | 10 +++++++++- utils/sofa-info.cpp | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) (limited to 'utils') diff --git a/utils/makemhr/loadsofa.cpp b/utils/makemhr/loadsofa.cpp index 49d16556..c91613c8 100644 --- a/utils/makemhr/loadsofa.cpp +++ b/utils/makemhr/loadsofa.cpp @@ -149,9 +149,17 @@ static double GetUniformStepSize(const double epsilon, const uint m, const doubl count = 1; if(counts[0] > m/2) - return steps[0]; + break; } + if(counts[0] > 255) + { + uint i{2u}; + while(counts[0]/i > 255 && (counts[0]%i) != 0) + ++i; + counts[0] /= i; + steps[0] *= i; + } if(counts[0] > 5) return steps[0]; return 0.0; diff --git a/utils/sofa-info.cpp b/utils/sofa-info.cpp index a0ed9ff4..bc5b709a 100644 --- a/utils/sofa-info.cpp +++ b/utils/sofa-info.cpp @@ -174,9 +174,17 @@ static double GetUniformStepSize(const double epsilon, const uint m, const doubl count = 1; if(counts[0] > m/2) - return steps[0]; + break; } + if(counts[0] > 255) + { + uint i{2u}; + while(counts[0]/i > 255 && (counts[0]%i) != 0) + ++i; + counts[0] /= i; + steps[0] *= i; + } if(counts[0] > 5) return steps[0]; return 0.0; -- cgit v1.2.3 From 205ff0080edfecb03ddcd24933722851d9fd8206 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 27 Oct 2019 18:02:25 -0700 Subject: Adjust padding in alsoft-config and remove an invalid signal --- utils/alsoft-config/mainwindow.ui | 131 ++++++++++++++++---------------------- 1 file changed, 55 insertions(+), 76 deletions(-) (limited to 'utils') diff --git a/utils/alsoft-config/mainwindow.ui b/utils/alsoft-config/mainwindow.ui index 1b73536e..0506304e 100644 --- a/utils/alsoft-config/mainwindow.ui +++ b/utils/alsoft-config/mainwindow.ui @@ -7,7 +7,7 @@ 0 0 564 - 460 + 469 @@ -21,8 +21,7 @@ - - + .. @@ -31,7 +30,7 @@ 470 405 81 - 21 + 31 @@ -39,8 +38,7 @@ - - + .. @@ -64,8 +62,8 @@ 110 50 - 78 - 21 + 76 + 31 @@ -82,7 +80,7 @@ float and converted to the output sample type as needed. 0 50 101 - 21 + 31 @@ -98,7 +96,7 @@ float and converted to the output sample type as needed. 0 20 101 - 21 + 31 @@ -113,8 +111,8 @@ float and converted to the output sample type as needed. 110 20 - 78 - 21 + 76 + 31 @@ -131,7 +129,7 @@ to stereo output. 380 20 - 95 + 96 31 @@ -194,7 +192,7 @@ to stereo output. 290 20 81 - 21 + 31 @@ -210,7 +208,7 @@ to stereo output. 290 50 81 - 21 + 31 @@ -225,8 +223,8 @@ to stereo output. 380 50 - 78 - 21 + 101 + 31 @@ -256,7 +254,7 @@ otherwise be suitable for speakers. 20 30 511 - 91 + 81 @@ -432,9 +430,9 @@ frames needed for each mixing update. 130 - 130 - 131 - 21 + 120 + 111 + 31 @@ -451,9 +449,9 @@ receiver. 20 - 130 + 120 101 - 21 + 31 @@ -466,23 +464,26 @@ receiver. - 270 - 130 - 111 - 21 + 260 + 120 + 121 + 31 Ambisonic Format: + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + 390 - 130 + 120 131 - 21 + 31 @@ -533,7 +534,7 @@ quantization with low-level whitenoise. 60 - 80 + 90 421 81 @@ -611,7 +612,7 @@ quantization with low-level whitenoise. - 10 + 30 20 181 21 @@ -635,7 +636,7 @@ appropriate speaker configuration you intend to use. - 10 + 30 50 181 21 @@ -834,7 +835,7 @@ configuration file. - 10 + 30 80 181 21 @@ -884,7 +885,7 @@ normal output is created with no near-field simulation. 20 0 - 151 + 171 21 @@ -898,9 +899,9 @@ normal output is created with no near-field simulation. - 180 + 200 0 - 91 + 81 21 @@ -998,8 +999,7 @@ normal output is created with no near-field simulation. - - + .. false @@ -1039,8 +1039,7 @@ listed above. - - + .. @@ -1048,10 +1047,10 @@ listed above. - 40 - 50 + 50 + 60 71 - 21 + 31 @@ -1065,9 +1064,9 @@ listed above. 130 - 50 + 60 161 - 21 + 31 @@ -1096,10 +1095,10 @@ application or system to determine if it should be used. - 20 + 30 20 91 - 21 + 31 @@ -1115,7 +1114,7 @@ application or system to determine if it should be used. 130 20 161 - 21 + 31 @@ -1126,7 +1125,7 @@ application or system to determine if it should be used. 50 - 90 + 100 441 81 @@ -2287,7 +2286,7 @@ added by the ALC_EXT_DEDICATED extension. 10 20 141 - 21 + 31 @@ -2302,7 +2301,7 @@ added by the ALC_EXT_DEDICATED extension. 160 20 - 129 + 131 31 @@ -2453,7 +2452,7 @@ added by the ALC_EXT_DEDICATED extension. 370 405 91 - 21 + 31 @@ -2461,8 +2460,7 @@ added by the ALC_EXT_DEDICATED extension. - - + .. @@ -2496,8 +2494,7 @@ added by the ALC_EXT_DEDICATED extension. - - + .. &Quit @@ -2506,8 +2503,7 @@ added by the ALC_EXT_DEDICATED extension. - - + .. Save &As... @@ -2519,8 +2515,7 @@ added by the ALC_EXT_DEDICATED extension. - - + .. &Load... @@ -2538,22 +2533,6 @@ added by the ALC_EXT_DEDICATED extension. - - actionQuit - activated() - MainWindow - close() - - - -1 - -1 - - - 267 - 181 - - - backendListWidget currentRowChanged(int) -- cgit v1.2.3 From 74cbba511d6b71634d07d44a822c826400fe967d Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sat, 9 Nov 2019 12:51:51 -0800 Subject: Limit HRTF ambisonic decoding to second-order The generated third-order matrix has incorrect first-order coefficients, indicating a wonky decoder. The generated second-order matrix looks more stable. --- alc/panning.cpp | 61 +++++++++++++++++--------------------- utils/alsoft-config/mainwindow.cpp | 12 ++++---- 2 files changed, 35 insertions(+), 38 deletions(-) (limited to 'utils') diff --git a/alc/panning.cpp b/alc/panning.cpp index 832fc202..1288197d 100644 --- a/alc/panning.cpp +++ b/alc/panning.cpp @@ -551,39 +551,37 @@ void InitHrtfPanning(ALCdevice *device) { Deg2Rad(-35.264390f), Deg2Rad( 135.000000f) }, }; static const float AmbiMatrix[][MAX_AMBI_CHANNELS]{ - { 3.84615387e-02f, 0.00000000e+00f, 0.00000000e+00f, 8.33950391e-02f, 0.00000000e+00f, 0.00000000e+00f, -4.96903997e-02f, 0.00000000e+00f, 8.60662966e-02f, 0.00000000e+00f, 0.00000000e+00f, 0.00000000e+00f, 0.00000000e+00f, -7.49473409e-02f, 0.00000000e+00f, 9.67566016e-02f }, - { 3.84615387e-02f, 0.00000000e+00f, 0.00000000e+00f, -8.33950391e-02f, 0.00000000e+00f, 0.00000000e+00f, -4.96903997e-02f, 0.00000000e+00f, 8.60662966e-02f, 0.00000000e+00f, 0.00000000e+00f, 0.00000000e+00f, 0.00000000e+00f, 7.49473409e-02f, 0.00000000e+00f, -9.67566016e-02f }, - { 3.84615387e-02f, 8.33950391e-02f, 0.00000000e+00f, 0.00000000e+00f, 0.00000000e+00f, 0.00000000e+00f, -4.96903997e-02f, 0.00000000e+00f, -8.60662966e-02f, -9.67566016e-02f, 0.00000000e+00f, -7.49473409e-02f, 0.00000000e+00f, 0.00000000e+00f, 0.00000000e+00f, 0.00000000e+00f }, - { 3.84615387e-02f, -8.33950391e-02f, 0.00000000e+00f, 0.00000000e+00f, 0.00000000e+00f, 0.00000000e+00f, -4.96903997e-02f, 0.00000000e+00f, -8.60662966e-02f, 9.67566016e-02f, 0.00000000e+00f, 7.49473409e-02f, 0.00000000e+00f, 0.00000000e+00f, 0.00000000e+00f, 0.00000000e+00f }, - { 3.84615379e-02f, 0.00000000e+00f, 8.33950384e-02f, 0.00000000e+00f, 0.00000000e+00f, 0.00000000e+00f, 9.93807988e-02f, 0.00000000e+00f, 0.00000000e+00f, 0.00000000e+00f, 0.00000000e+00f, 0.00000000e+00f, 1.22388497e-01f, 0.00000000e+00f, 0.00000000e+00f, 0.00000000e+00f }, - { 3.84615379e-02f, 0.00000000e+00f, -8.33950384e-02f, 0.00000000e+00f, 0.00000000e+00f, 0.00000000e+00f, 9.93807988e-02f, 0.00000000e+00f, 0.00000000e+00f, 0.00000000e+00f, 0.00000000e+00f, 0.00000000e+00f, -1.22388497e-01f, 0.00000000e+00f, 0.00000000e+00f, 0.00000000e+00f }, - { 3.84615383e-02f, 4.53609209e-02f, 4.53609209e-02f, 0.00000000e+00f, 0.00000000e+00f, 6.83467647e-02f, 2.48451995e-02f, 0.00000000e+00f, -4.30331483e-02f, -3.21963528e-02f, 0.00000000e+00f, 6.23479680e-02f, -1.27267260e-02f, 0.00000000e+00f, -6.90065559e-02f, 0.00000000e+00f }, - { 3.84615383e-02f, 4.53609209e-02f, -4.53609209e-02f, 0.00000000e+00f, 0.00000000e+00f, -6.83467647e-02f, 2.48451995e-02f, 0.00000000e+00f, -4.30331483e-02f, -3.21963528e-02f, 0.00000000e+00f, 6.23479680e-02f, 1.27267260e-02f, 0.00000000e+00f, 6.90065559e-02f, 0.00000000e+00f }, - { 3.84615383e-02f, -4.53609209e-02f, 4.53609209e-02f, 0.00000000e+00f, 0.00000000e+00f, -6.83467647e-02f, 2.48451995e-02f, 0.00000000e+00f, -4.30331483e-02f, 3.21963528e-02f, 0.00000000e+00f, -6.23479680e-02f, -1.27267260e-02f, 0.00000000e+00f, -6.90065559e-02f, 0.00000000e+00f }, - { 3.84615383e-02f, -4.53609209e-02f, -4.53609209e-02f, 0.00000000e+00f, 0.00000000e+00f, 6.83467647e-02f, 2.48451995e-02f, 0.00000000e+00f, -4.30331483e-02f, 3.21963528e-02f, 0.00000000e+00f, -6.23479680e-02f, 1.27267260e-02f, 0.00000000e+00f, 6.90065559e-02f, 0.00000000e+00f }, - { 3.84615383e-02f, 0.00000000e+00f, 4.53609209e-02f, 4.53609209e-02f, 0.00000000e+00f, 0.00000000e+00f, 2.48451995e-02f, 6.83467647e-02f, 4.30331483e-02f, 0.00000000e+00f, 0.00000000e+00f, 0.00000000e+00f, -1.27267260e-02f, 6.23479680e-02f, 6.90065559e-02f, 3.21963528e-02f }, - { 3.84615383e-02f, 0.00000000e+00f, -4.53609209e-02f, 4.53609209e-02f, 0.00000000e+00f, 0.00000000e+00f, 2.48451995e-02f, -6.83467647e-02f, 4.30331483e-02f, 0.00000000e+00f, 0.00000000e+00f, 0.00000000e+00f, 1.27267260e-02f, 6.23479680e-02f, -6.90065559e-02f, 3.21963528e-02f }, - { 3.84615383e-02f, 0.00000000e+00f, 4.53609209e-02f, -4.53609209e-02f, 0.00000000e+00f, 0.00000000e+00f, 2.48451995e-02f, -6.83467647e-02f, 4.30331483e-02f, 0.00000000e+00f, 0.00000000e+00f, 0.00000000e+00f, -1.27267260e-02f, -6.23479680e-02f, 6.90065559e-02f, -3.21963528e-02f }, - { 3.84615383e-02f, 0.00000000e+00f, -4.53609209e-02f, -4.53609209e-02f, 0.00000000e+00f, 0.00000000e+00f, 2.48451995e-02f, 6.83467647e-02f, 4.30331483e-02f, 0.00000000e+00f, 0.00000000e+00f, 0.00000000e+00f, 1.27267260e-02f, -6.23479680e-02f, -6.90065559e-02f, -3.21963528e-02f }, - { 3.84615387e-02f, 4.53609217e-02f, 0.00000000e+00f, 4.53609217e-02f, 6.83467654e-02f, 0.00000000e+00f, -4.96903997e-02f, 0.00000000e+00f, 0.00000000e+00f, 5.23190735e-02f, 0.00000000e+00f, -4.67609766e-02f, 0.00000000e+00f, -4.67609766e-02f, 0.00000000e+00f, -5.23190735e-02f }, - { 3.84615387e-02f, -4.53609217e-02f, 0.00000000e+00f, 4.53609217e-02f, -6.83467654e-02f, 0.00000000e+00f, -4.96903997e-02f, 0.00000000e+00f, 0.00000000e+00f, -5.23190735e-02f, 0.00000000e+00f, 4.67609766e-02f, 0.00000000e+00f, -4.67609766e-02f, 0.00000000e+00f, -5.23190735e-02f }, - { 3.84615387e-02f, 4.53609217e-02f, 0.00000000e+00f, -4.53609217e-02f, -6.83467654e-02f, 0.00000000e+00f, -4.96903997e-02f, 0.00000000e+00f, 0.00000000e+00f, 5.23190735e-02f, 0.00000000e+00f, -4.67609766e-02f, 0.00000000e+00f, 4.67609766e-02f, 0.00000000e+00f, 5.23190735e-02f }, - { 3.84615387e-02f, -4.53609217e-02f, 0.00000000e+00f, -4.53609217e-02f, 6.83467654e-02f, 0.00000000e+00f, -4.96903997e-02f, 0.00000000e+00f, 0.00000000e+00f, -5.23190735e-02f, 0.00000000e+00f, 4.67609766e-02f, 0.00000000e+00f, 4.67609766e-02f, 0.00000000e+00f, 5.23190735e-02f }, - { 3.84615385e-02f, 3.33333332e-02f, 3.33333335e-02f, 3.33333332e-02f, 4.55645099e-02f, 4.55645100e-02f, 0.00000000e+00f, 4.55645100e-02f, 0.00000000e+00f, 2.95742381e-02f, 6.33865691e-02f, 2.29081068e-02f, -3.74087810e-02f, 2.29081068e-02f, 0.00000000e+00f, -2.95742381e-02f }, - { 3.84615385e-02f, 3.33333332e-02f, -3.33333335e-02f, 3.33333332e-02f, 4.55645099e-02f, -4.55645100e-02f, 0.00000000e+00f, -4.55645100e-02f, 0.00000000e+00f, 2.95742381e-02f, -6.33865691e-02f, 2.29081068e-02f, 3.74087810e-02f, 2.29081068e-02f, 0.00000000e+00f, -2.95742381e-02f }, - { 3.84615385e-02f, -3.33333332e-02f, 3.33333335e-02f, 3.33333332e-02f, -4.55645099e-02f, -4.55645100e-02f, 0.00000000e+00f, 4.55645100e-02f, 0.00000000e+00f, -2.95742381e-02f, -6.33865691e-02f, -2.29081068e-02f, -3.74087810e-02f, 2.29081068e-02f, 0.00000000e+00f, -2.95742381e-02f }, - { 3.84615385e-02f, -3.33333332e-02f, -3.33333335e-02f, 3.33333332e-02f, -4.55645099e-02f, 4.55645100e-02f, 0.00000000e+00f, -4.55645100e-02f, 0.00000000e+00f, -2.95742381e-02f, 6.33865691e-02f, -2.29081068e-02f, 3.74087810e-02f, 2.29081068e-02f, 0.00000000e+00f, -2.95742381e-02f }, - { 3.84615385e-02f, 3.33333332e-02f, 3.33333335e-02f, -3.33333332e-02f, -4.55645099e-02f, 4.55645100e-02f, 0.00000000e+00f, -4.55645100e-02f, 0.00000000e+00f, 2.95742381e-02f, -6.33865691e-02f, 2.29081068e-02f, -3.74087810e-02f, -2.29081068e-02f, 0.00000000e+00f, 2.95742381e-02f }, - { 3.84615385e-02f, 3.33333332e-02f, -3.33333335e-02f, -3.33333332e-02f, -4.55645099e-02f, -4.55645100e-02f, 0.00000000e+00f, 4.55645100e-02f, 0.00000000e+00f, 2.95742381e-02f, 6.33865691e-02f, 2.29081068e-02f, 3.74087810e-02f, -2.29081068e-02f, 0.00000000e+00f, 2.95742381e-02f }, - { 3.84615385e-02f, -3.33333332e-02f, 3.33333335e-02f, -3.33333332e-02f, 4.55645099e-02f, -4.55645100e-02f, 0.00000000e+00f, -4.55645100e-02f, 0.00000000e+00f, -2.95742381e-02f, 6.33865691e-02f, -2.29081068e-02f, -3.74087810e-02f, -2.29081068e-02f, 0.00000000e+00f, 2.95742381e-02f }, - { 3.84615385e-02f, -3.33333332e-02f, -3.33333335e-02f, -3.33333332e-02f, 4.55645099e-02f, 4.55645100e-02f, 0.00000000e+00f, 4.55645100e-02f, 0.00000000e+00f, -2.95742381e-02f, -6.33865691e-02f, -2.29081068e-02f, 3.74087810e-02f, -2.29081068e-02f, 0.00000000e+00f, 2.95742381e-02f }, + { 3.84615387e-02f, 0.00000000e+00f, 0.00000000e+00f, 6.66173389e-02f, 0.00000000e+00f, 0.00000000e+00f, -4.96903997e-02f, 0.00000000e+00f, 8.60662966e-02f }, + { 3.84615387e-02f, 0.00000000e+00f, 0.00000000e+00f, -6.66173389e-02f, 0.00000000e+00f, 0.00000000e+00f, -4.96903997e-02f, 0.00000000e+00f, 8.60662966e-02f }, + { 3.84615387e-02f, 6.66173389e-02f, 0.00000000e+00f, 0.00000000e+00f, 0.00000000e+00f, 0.00000000e+00f, -4.96903997e-02f, 0.00000000e+00f, -8.60662966e-02f }, + { 3.84615387e-02f, -6.66173389e-02f, 0.00000000e+00f, 0.00000000e+00f, 0.00000000e+00f, 0.00000000e+00f, -4.96903997e-02f, 0.00000000e+00f, -8.60662966e-02f }, + { 3.84615379e-02f, 0.00000000e+00f, 6.66173384e-02f, 0.00000000e+00f, 0.00000000e+00f, 0.00000000e+00f, 9.93807988e-02f, 0.00000000e+00f, 0.00000000e+00f }, + { 3.84615379e-02f, 0.00000000e+00f, -6.66173384e-02f, 0.00000000e+00f, 0.00000000e+00f, 0.00000000e+00f, 9.93807988e-02f, 0.00000000e+00f, 0.00000000e+00f }, + { 3.84615383e-02f, 4.71055721e-02f, 4.71055717e-02f, 0.00000000e+00f, 0.00000000e+00f, 6.83467647e-02f, 2.48451995e-02f, 0.00000000e+00f, -4.30331483e-02f }, + { 3.84615383e-02f, 4.71055721e-02f, -4.71055717e-02f, 0.00000000e+00f, 0.00000000e+00f, -6.83467647e-02f, 2.48451995e-02f, 0.00000000e+00f, -4.30331483e-02f }, + { 3.84615383e-02f, -4.71055721e-02f, 4.71055717e-02f, 0.00000000e+00f, 0.00000000e+00f, -6.83467647e-02f, 2.48451995e-02f, 0.00000000e+00f, -4.30331483e-02f }, + { 3.84615383e-02f, -4.71055721e-02f, -4.71055717e-02f, 0.00000000e+00f, 0.00000000e+00f, 6.83467647e-02f, 2.48451995e-02f, 0.00000000e+00f, -4.30331483e-02f }, + { 3.84615383e-02f, 0.00000000e+00f, 4.71055717e-02f, 4.71055721e-02f, 0.00000000e+00f, 0.00000000e+00f, 2.48451995e-02f, 6.83467647e-02f, 4.30331483e-02f }, + { 3.84615383e-02f, 0.00000000e+00f, -4.71055717e-02f, 4.71055721e-02f, 0.00000000e+00f, 0.00000000e+00f, 2.48451995e-02f, -6.83467647e-02f, 4.30331483e-02f }, + { 3.84615383e-02f, 0.00000000e+00f, 4.71055717e-02f, -4.71055721e-02f, 0.00000000e+00f, 0.00000000e+00f, 2.48451995e-02f, -6.83467647e-02f, 4.30331483e-02f }, + { 3.84615383e-02f, 0.00000000e+00f, -4.71055717e-02f, -4.71055721e-02f, 0.00000000e+00f, 0.00000000e+00f, 2.48451995e-02f, 6.83467647e-02f, 4.30331483e-02f }, + { 3.84615387e-02f, 4.71055721e-02f, 0.00000000e+00f, 4.71055721e-02f, 6.83467654e-02f, 0.00000000e+00f, -4.96903997e-02f, 0.00000000e+00f, 0.00000000e+00f }, + { 3.84615387e-02f, -4.71055721e-02f, 0.00000000e+00f, 4.71055721e-02f, -6.83467654e-02f, 0.00000000e+00f, -4.96903997e-02f, 0.00000000e+00f, 0.00000000e+00f }, + { 3.84615387e-02f, 4.71055721e-02f, 0.00000000e+00f, -4.71055721e-02f, -6.83467654e-02f, 0.00000000e+00f, -4.96903997e-02f, 0.00000000e+00f, 0.00000000e+00f }, + { 3.84615387e-02f, -4.71055721e-02f, 0.00000000e+00f, -4.71055721e-02f, 6.83467654e-02f, 0.00000000e+00f, -4.96903997e-02f, 0.00000000e+00f, 0.00000000e+00f }, + { 3.84615385e-02f, 3.84615384e-02f, 3.84615386e-02f, 3.84615384e-02f, 4.55645099e-02f, 4.55645100e-02f, 0.00000000e+00f, 4.55645100e-02f, 0.00000000e+00f }, + { 3.84615385e-02f, 3.84615384e-02f, -3.84615386e-02f, 3.84615384e-02f, 4.55645099e-02f, -4.55645100e-02f, 0.00000000e+00f, -4.55645100e-02f, 0.00000000e+00f }, + { 3.84615385e-02f, -3.84615384e-02f, 3.84615386e-02f, 3.84615384e-02f, -4.55645099e-02f, -4.55645100e-02f, 0.00000000e+00f, 4.55645100e-02f, 0.00000000e+00f }, + { 3.84615385e-02f, -3.84615384e-02f, -3.84615386e-02f, 3.84615384e-02f, -4.55645099e-02f, 4.55645100e-02f, 0.00000000e+00f, -4.55645100e-02f, 0.00000000e+00f }, + { 3.84615385e-02f, 3.84615384e-02f, 3.84615386e-02f, -3.84615384e-02f, -4.55645099e-02f, 4.55645100e-02f, 0.00000000e+00f, -4.55645100e-02f, 0.00000000e+00f }, + { 3.84615385e-02f, 3.84615384e-02f, -3.84615386e-02f, -3.84615384e-02f, -4.55645099e-02f, -4.55645100e-02f, 0.00000000e+00f, 4.55645100e-02f, 0.00000000e+00f }, + { 3.84615385e-02f, -3.84615384e-02f, 3.84615386e-02f, -3.84615384e-02f, 4.55645099e-02f, -4.55645100e-02f, 0.00000000e+00f, -4.55645100e-02f, 0.00000000e+00f }, + { 3.84615385e-02f, -3.84615384e-02f, -3.84615386e-02f, -3.84615384e-02f, 4.55645099e-02f, 4.55645100e-02f, 0.00000000e+00f, 4.55645100e-02f, 0.00000000e+00f }, }; static const float AmbiOrderHFGain1O[MAX_AMBI_ORDER+1]{ 3.60555128e+00f, 2.08166600e+00f }, AmbiOrderHFGain2O[MAX_AMBI_ORDER+1]{ 2.68741925e+00f, 2.08166600e+00f, 1.07496770e+00f - }, AmbiOrderHFGain3O[MAX_AMBI_ORDER+1]{ - 2.12652604e+00f, 1.83122879e+00f, 1.30214339e+00f, 6.48052398e-01f }; static const ALuint ChansPerOrder[MAX_AMBI_ORDER+1]{ 1, 3, 5, 7 }; const float *AmbiOrderHFGain{AmbiOrderHFGain1O}; @@ -606,11 +604,10 @@ void InitHrtfPanning(ALCdevice *device) { "full", HrtfRender, 1 }, { "ambi1", NormalRender, 1 }, { "ambi2", NormalRender, 2 }, - { "ambi3", NormalRender, 3 }, }; const char *mode{modeopt->c_str()}; - if(al::strcasecmp(mode, "basic") == 0) + if(al::strcasecmp(mode, "basic") == 0 || al::strcasecmp(mode, "ambi3") == 0) { ERR("HRTF mode \"%s\" deprecated, substituting \"%s\"\n", mode, "ambi2"); mode = "ambi2"; @@ -635,9 +632,7 @@ void InitHrtfPanning(ALCdevice *device) (device->mRenderMode == HrtfRender) ? "+ Full " : "", device->HrtfName.c_str()); - if(ambi_order >= 3) - AmbiOrderHFGain = AmbiOrderHFGain3O; - else if(ambi_order == 2) + if(ambi_order >= 2) AmbiOrderHFGain = AmbiOrderHFGain2O; else if(ambi_order == 1) AmbiOrderHFGain = AmbiOrderHFGain1O; diff --git a/utils/alsoft-config/mainwindow.cpp b/utils/alsoft-config/mainwindow.cpp index f4f5fd45..7b1d8a91 100644 --- a/utils/alsoft-config/mainwindow.cpp +++ b/utils/alsoft-config/mainwindow.cpp @@ -129,7 +129,6 @@ static const struct NameValuePair { }, hrtfModeList[] = { { "1st Order Ambisonic", "ambi1" }, { "2nd Order Ambisonic", "ambi2" }, - { "3rd Order Ambisonic", "ambi3" }, { "Default (Full)", "" }, { "Full", "full" }, @@ -742,10 +741,13 @@ void MainWindow::loadConfig(const QString &fname) ui->enableNeonCheckBox->setChecked(!disabledCpuExts.contains("neon", Qt::CaseInsensitive)); QString hrtfmode{settings.value("hrtf-mode").toString().trimmed()}; - ui->hrtfmodeSlider->setValue(3); - ui->hrtfmodeLabel->setText(hrtfModeList[3].name); - /* The "basic" mode name is no longer supported. Use "ambi2" instead. */ - if(hrtfmode == "basic") hrtfmode = "ambi2"; + ui->hrtfmodeSlider->setValue(2); + ui->hrtfmodeLabel->setText(hrtfModeList[2].name); + /* The "basic" mode name is no longer supported, and "ambi3" is temporarily + * disabled. Use "ambi2" instead. + */ + if(hrtfmode == "basic" || hrtfmode == "ambi3") + hrtfmode = "ambi2"; for(int i = 0;hrtfModeList[i].name[0];i++) { if(hrtfmode == hrtfModeList[i].value) -- cgit v1.2.3 From f2eab3e919aa06b72ad467118db3269fe2571bbb Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Wed, 20 Nov 2019 14:22:04 -0800 Subject: Properly get the AppData path on Windows in alsoft-config --- utils/alsoft-config/mainwindow.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'utils') diff --git a/utils/alsoft-config/mainwindow.cpp b/utils/alsoft-config/mainwindow.cpp index 7b1d8a91..fed9de59 100644 --- a/utils/alsoft-config/mainwindow.cpp +++ b/utils/alsoft-config/mainwindow.cpp @@ -14,6 +14,11 @@ #include "ui_mainwindow.h" #include "verstr.h" +#ifdef _WIN32 +#include +#include +#endif + namespace { static const struct { @@ -139,7 +144,14 @@ static QString getDefaultConfigName() { #ifdef Q_OS_WIN32 static const char fname[] = "alsoft.ini"; - QByteArray base = qgetenv("AppData"); + auto get_appdata_path = []() noexcept -> QString + { + WCHAR buffer[MAX_PATH]; + if(SHGetSpecialFolderPathW(nullptr, buffer, CSIDL_APPDATA, FALSE) != FALSE) + return QString::fromWCharArray(buffer); + return QString(); + }; + QString base = get_appdata_path(); #else static const char fname[] = "alsoft.conf"; QByteArray base = qgetenv("XDG_CONFIG_HOME"); @@ -158,7 +170,14 @@ static QString getDefaultConfigName() static QString getBaseDataPath() { #ifdef Q_OS_WIN32 - QByteArray base = qgetenv("AppData"); + auto get_appdata_path = []() noexcept -> QString + { + WCHAR buffer[MAX_PATH]; + if(SHGetSpecialFolderPathW(nullptr, buffer, CSIDL_APPDATA, FALSE) != FALSE) + return QString::fromWCharArray(buffer); + return QString(); + }; + QString base = get_appdata_path(); #else QByteArray base = qgetenv("XDG_DATA_HOME"); if(base.isEmpty()) -- cgit v1.2.3