diff options
-rw-r--r-- | Alc/ALc.c | 7 | ||||
-rw-r--r-- | Alc/bformatdec.c | 22 | ||||
-rw-r--r-- | Alc/bformatdec.h | 4 | ||||
-rw-r--r-- | Alc/panning.c | 24 |
4 files changed, 25 insertions, 32 deletions
@@ -2469,11 +2469,8 @@ static ALCvoid FreeDevice(ALCdevice *device) al_free(device->Uhj_Encoder); device->Uhj_Encoder = NULL; - bformatdec_free(device->AmbiDecoder); - device->AmbiDecoder = NULL; - - ambiup_free(device->AmbiUp); - device->AmbiUp = NULL; + bformatdec_free(&device->AmbiDecoder); + ambiup_free(&device->AmbiUp); al_free(device->Stablizer); device->Stablizer = NULL; diff --git a/Alc/bformatdec.c b/Alc/bformatdec.c index 4dbca6a3..5a3726e1 100644 --- a/Alc/bformatdec.c +++ b/Alc/bformatdec.c @@ -217,17 +217,17 @@ BFormatDec *bformatdec_alloc() return al_calloc(16, sizeof(BFormatDec)); } -void bformatdec_free(BFormatDec *dec) +void bformatdec_free(BFormatDec **dec) { if(dec) { - al_free(dec->Samples); - dec->Samples = NULL; - dec->SamplesHF = NULL; - dec->SamplesLF = NULL; + al_free((*dec)->Samples); + (*dec)->Samples = NULL; + (*dec)->SamplesHF = NULL; + (*dec)->SamplesLF = NULL; - memset(dec, 0, sizeof(*dec)); - al_free(dec); + al_free(*dec); + *dec = NULL; } } @@ -507,9 +507,13 @@ AmbiUpsampler *ambiup_alloc() return al_calloc(16, sizeof(AmbiUpsampler)); } -void ambiup_free(struct AmbiUpsampler *ambiup) +void ambiup_free(struct AmbiUpsampler **ambiup) { - al_free(ambiup); + if(ambiup) + { + al_free(*ambiup); + *ambiup = NULL; + } } void ambiup_reset(struct AmbiUpsampler *ambiup, const ALCdevice *device) diff --git a/Alc/bformatdec.h b/Alc/bformatdec.h index c897ac3a..c997c0b9 100644 --- a/Alc/bformatdec.h +++ b/Alc/bformatdec.h @@ -27,7 +27,7 @@ struct AmbiUpsampler; struct BFormatDec *bformatdec_alloc(); -void bformatdec_free(struct BFormatDec *dec); +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. */ @@ -41,7 +41,7 @@ void bformatdec_upSample(struct BFormatDec *dec, ALfloat (*restrict OutBuffer)[B * with bformatdec. */ struct AmbiUpsampler *ambiup_alloc(); -void ambiup_free(struct AmbiUpsampler *ambiup); +void ambiup_free(struct AmbiUpsampler **ambiup); void ambiup_reset(struct AmbiUpsampler *ambiup, const ALCdevice *device); void ambiup_process(struct AmbiUpsampler *ambiup, ALfloat (*restrict OutBuffer)[BUFFERSIZE], ALsizei OutChannels, const ALfloat (*restrict InSamples)[BUFFERSIZE], ALsizei SamplesToDo); diff --git a/Alc/panning.c b/Alc/panning.c index e368c946..b90652a3 100644 --- a/Alc/panning.c +++ b/Alc/panning.c @@ -1086,25 +1086,20 @@ void aluInitRenderer(ALCdevice *device, ALint hrtf_id, enum HrtfRequestMode hrtf if(pconf && GetConfigValueBool(devname, "decoder", "hq-mode", 0)) { - ambiup_free(device->AmbiUp); - device->AmbiUp = NULL; + ambiup_free(&device->AmbiUp); if(!device->AmbiDecoder) device->AmbiDecoder = bformatdec_alloc(); } else { - bformatdec_free(device->AmbiDecoder); - device->AmbiDecoder = NULL; - if(device->FmtChans == DevFmtAmbi3D && device->AmbiOrder > 1) + bformatdec_free(&device->AmbiDecoder); + if(device->FmtChans != DevFmtAmbi3D || device->AmbiOrder < 2) + ambiup_free(&device->AmbiUp); + else { if(!device->AmbiUp) device->AmbiUp = ambiup_alloc(); } - else - { - ambiup_free(device->AmbiUp); - device->AmbiUp = NULL; - } } if(!pconf) @@ -1155,8 +1150,7 @@ void aluInitRenderer(ALCdevice *device, ALint hrtf_id, enum HrtfRequestMode hrtf return; } - bformatdec_free(device->AmbiDecoder); - device->AmbiDecoder = NULL; + bformatdec_free(&device->AmbiDecoder); headphones = device->IsHeadphones; if(device->Type != Loopback) @@ -1248,8 +1242,7 @@ void aluInitRenderer(ALCdevice *device, ALint hrtf_id, enum HrtfRequestMode hrtf /* Don't bother with HOA when using full HRTF rendering. Nothing * needs it, and it eases the CPU/memory load. */ - ambiup_free(device->AmbiUp); - device->AmbiUp = NULL; + ambiup_free(&device->AmbiUp); } else { @@ -1274,8 +1267,7 @@ no_hrtf: device->Render_Mode = StereoPair; - ambiup_free(device->AmbiUp); - device->AmbiUp = NULL; + ambiup_free(&device->AmbiUp); bs2blevel = ((headphones && hrtf_appreq != Hrtf_Disable) || (hrtf_appreq == Hrtf_Enable)) ? 5 : 0; |