2011-05-01 20:59:44 +00:00
|
|
|
/**
|
|
|
|
* OpenAL cross platform audio library
|
|
|
|
* Copyright (C) 2011 by Chris Robinson
|
|
|
|
* 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
|
2014-08-18 12:11:03 +00:00
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2011-05-01 20:59:44 +00:00
|
|
|
* Or go to http://www.gnu.org/copyleft/lgpl.html
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2011-09-18 17:09:32 +00:00
|
|
|
#include <stdlib.h>
|
2011-09-18 18:10:32 +00:00
|
|
|
#include <ctype.h>
|
2011-09-18 17:09:32 +00:00
|
|
|
|
2011-05-01 20:59:44 +00:00
|
|
|
#include "AL/al.h"
|
|
|
|
#include "AL/alc.h"
|
|
|
|
#include "alMain.h"
|
2011-06-03 08:06:00 +00:00
|
|
|
#include "alSource.h"
|
2012-09-11 08:59:42 +00:00
|
|
|
#include "alu.h"
|
2016-08-21 10:05:42 +00:00
|
|
|
#include "bformatdec.h"
|
2014-02-24 05:11:01 +00:00
|
|
|
#include "hrtf.h"
|
2011-05-01 20:59:44 +00:00
|
|
|
|
2015-10-06 11:01:53 +00:00
|
|
|
#include "compat.h"
|
2016-07-07 17:31:43 +00:00
|
|
|
#include "almalloc.h"
|
2015-10-06 11:01:53 +00:00
|
|
|
|
2012-09-12 10:45:26 +00:00
|
|
|
|
2012-09-11 08:59:42 +00:00
|
|
|
/* Current data set limits defined by the makehrtf utility. */
|
|
|
|
#define MIN_IR_SIZE (8)
|
|
|
|
#define MAX_IR_SIZE (128)
|
|
|
|
#define MOD_IR_SIZE (8)
|
2011-07-16 07:22:01 +00:00
|
|
|
|
2012-09-11 08:59:42 +00:00
|
|
|
#define MIN_EV_COUNT (5)
|
|
|
|
#define MAX_EV_COUNT (128)
|
2011-07-16 07:22:01 +00:00
|
|
|
|
2012-09-11 08:59:42 +00:00
|
|
|
#define MIN_AZ_COUNT (1)
|
|
|
|
#define MAX_AZ_COUNT (128)
|
2011-05-01 20:59:44 +00:00
|
|
|
|
2012-09-12 14:25:05 +00:00
|
|
|
static const ALchar magicMarker00[8] = "MinPHR00";
|
|
|
|
static const ALchar magicMarker01[8] = "MinPHR01";
|
2012-09-11 08:59:42 +00:00
|
|
|
|
2014-11-23 18:49:54 +00:00
|
|
|
/* First value for pass-through coefficients (remaining are 0), used for omni-
|
|
|
|
* directional sounds. */
|
|
|
|
static const ALfloat PassthruCoeff = 32767.0f * 0.707106781187f/*sqrt(0.5)*/;
|
|
|
|
|
2012-09-11 08:59:42 +00:00
|
|
|
static struct Hrtf *LoadedHrtfs = NULL;
|
2011-09-18 17:09:32 +00:00
|
|
|
|
2016-10-09 07:37:47 +00:00
|
|
|
|
|
|
|
/* Calculate the elevation index given the polar elevation in radians. This
|
|
|
|
* will return an index between 0 and (evcount - 1). Assumes the FPU is in
|
|
|
|
* round-to-zero mode.
|
2012-09-11 08:59:42 +00:00
|
|
|
*/
|
2017-01-16 15:45:07 +00:00
|
|
|
static ALsizei CalcEvIndex(ALsizei evcount, ALfloat ev)
|
2011-05-01 20:59:44 +00:00
|
|
|
{
|
2014-07-16 20:26:47 +00:00
|
|
|
ev = (F_PI_2 + ev) * (evcount-1) / F_PI;
|
2017-01-16 15:45:07 +00:00
|
|
|
return mini(fastf2i(ev + 0.5f), evcount-1);
|
2011-06-03 08:06:00 +00:00
|
|
|
}
|
|
|
|
|
2016-10-09 07:37:47 +00:00
|
|
|
/* Calculate the azimuth index given the polar azimuth in radians. This will
|
|
|
|
* return an index between 0 and (azcount - 1). Assumes the FPU is in round-to-
|
|
|
|
* zero mode.
|
2012-09-11 08:59:42 +00:00
|
|
|
*/
|
2017-01-16 15:45:07 +00:00
|
|
|
static ALsizei CalcAzIndex(ALsizei azcount, ALfloat az)
|
2011-06-03 08:06:00 +00:00
|
|
|
{
|
2015-09-13 15:46:48 +00:00
|
|
|
az = (F_TAU + az) * azcount / F_TAU;
|
2017-01-16 15:45:07 +00:00
|
|
|
return fastf2i(az + 0.5f) % azcount;
|
2011-05-01 20:59:44 +00:00
|
|
|
}
|
|
|
|
|
2016-10-09 07:37:47 +00:00
|
|
|
/* Calculates static HRIR coefficients and delays for the given polar elevation
|
2017-03-12 02:04:06 +00:00
|
|
|
* and azimuth in radians. The coefficients are normalized.
|
2012-09-11 08:59:42 +00:00
|
|
|
*/
|
2017-03-12 02:04:06 +00:00
|
|
|
void GetHrtfCoeffs(const struct Hrtf *Hrtf, ALfloat elevation, ALfloat azimuth, ALfloat spread, ALfloat (*coeffs)[2], ALsizei *delays)
|
2011-05-01 20:59:44 +00:00
|
|
|
{
|
2017-01-16 15:45:07 +00:00
|
|
|
ALsizei evidx, azidx, lidx, ridx;
|
|
|
|
ALsizei azcount, evoffset;
|
2016-04-25 04:42:59 +00:00
|
|
|
ALfloat dirfact;
|
2017-01-16 15:45:07 +00:00
|
|
|
ALsizei i;
|
2011-06-03 08:06:00 +00:00
|
|
|
|
2016-04-25 04:42:59 +00:00
|
|
|
dirfact = 1.0f - (spread / F_TAU);
|
|
|
|
|
2016-10-09 07:37:47 +00:00
|
|
|
/* Claculate elevation index. */
|
|
|
|
evidx = CalcEvIndex(Hrtf->evCount, elevation);
|
|
|
|
azcount = Hrtf->azCount[evidx];
|
|
|
|
evoffset = Hrtf->evOffset[evidx];
|
2011-06-03 08:06:00 +00:00
|
|
|
|
2016-10-09 07:37:47 +00:00
|
|
|
/* Calculate azimuth index. */
|
|
|
|
azidx = CalcAzIndex(Hrtf->azCount[evidx], azimuth);
|
2011-07-04 14:14:45 +00:00
|
|
|
|
2016-10-09 07:37:47 +00:00
|
|
|
/* Calculate the HRIR indices for left and right channels. */
|
|
|
|
lidx = evoffset + azidx;
|
|
|
|
ridx = evoffset + ((azcount-azidx) % azcount);
|
2012-08-11 09:16:34 +00:00
|
|
|
|
2016-10-09 07:37:47 +00:00
|
|
|
/* Calculate the HRIR delays. */
|
2017-03-12 02:04:06 +00:00
|
|
|
delays[0] = fastf2i(Hrtf->delays[lidx]*dirfact + 0.5f);
|
|
|
|
delays[1] = fastf2i(Hrtf->delays[ridx]*dirfact + 0.5f);
|
2012-09-11 08:59:42 +00:00
|
|
|
|
|
|
|
/* Calculate the sample offsets for the HRIR indices. */
|
2016-10-09 07:37:47 +00:00
|
|
|
lidx *= Hrtf->irSize;
|
|
|
|
ridx *= Hrtf->irSize;
|
|
|
|
|
2017-03-12 02:04:06 +00:00
|
|
|
/* Calculate the normalized and attenuated HRIR coefficients. */
|
|
|
|
i = 0;
|
|
|
|
coeffs[i][0] = lerp(PassthruCoeff, Hrtf->coeffs[lidx+i], dirfact) * (1.0f/32767.0f);
|
|
|
|
coeffs[i][1] = lerp(PassthruCoeff, Hrtf->coeffs[ridx+i], dirfact) * (1.0f/32767.0f);
|
|
|
|
for(i = 1;i < Hrtf->irSize;i++)
|
2011-07-04 14:14:45 +00:00
|
|
|
{
|
2017-03-12 02:04:06 +00:00
|
|
|
coeffs[i][0] = Hrtf->coeffs[lidx+i]*(1.0f/32767.0f) * dirfact;
|
|
|
|
coeffs[i][1] = Hrtf->coeffs[ridx+i]*(1.0f/32767.0f) * dirfact;
|
2014-11-23 18:49:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-09 23:59:29 +00:00
|
|
|
|
2017-03-11 14:20:04 +00:00
|
|
|
ALsizei BuildBFormatHrtf(const struct Hrtf *Hrtf, DirectHrtfState *state, ALsizei NumChannels, const ALfloat (*restrict AmbiPoints)[2], const ALfloat (*restrict AmbiMatrix)[2][MAX_AMBI_COEFFS], ALsizei AmbiCount)
|
Decode directly from B-Format to HRTF instead of a cube
Last time this attempted to average the HRIRs according to their contribution
to a given B-Format channel as if they were loudspeakers, as well as averaging
the HRIR delays. The latter part resulted in the loss of the ITD (inter-aural
time delay), a key component of HRTF.
This time, the HRIRs are averaged similar to above, except instead of averaging
the delays, they're applied to the resulting coefficients (for example, a delay
of 8 would apply the HRIR starting at the 8th sample of the target HRIR). This
does roughly double the IR length, as the largest delay is about 35 samples
while the filter is normally 32 samples. However, this is still smaller the
original data set IR (which was 256 samples), it also only needs to be applied
to 4 channels for first-order ambisonics, rather than the 8-channel cube. So
it's doing twice as much work per sample, but only working on half the number
of samples.
Additionally, since the resulting HRIRs no longer rely on an extra delay line,
a more efficient HRTF mixing function can be made that doesn't use one. Such a
function can also avoid the per-sample stepping parameters the original uses.
2016-08-12 06:20:35 +00:00
|
|
|
{
|
2017-01-15 21:57:22 +00:00
|
|
|
/* Set this to 2 for dual-band HRTF processing. May require a higher quality
|
2016-08-31 05:33:33 +00:00
|
|
|
* band-splitter, or better calculation of the new IR length to deal with the
|
|
|
|
* tail generated by the filter.
|
|
|
|
*/
|
2016-09-26 18:18:26 +00:00
|
|
|
#define NUM_BANDS 2
|
2016-08-21 10:05:42 +00:00
|
|
|
BandSplitter splitter;
|
2017-01-19 03:16:24 +00:00
|
|
|
ALsizei lidx[HRTF_AMBI_MAX_CHANNELS], ridx[HRTF_AMBI_MAX_CHANNELS];
|
2017-01-16 15:45:07 +00:00
|
|
|
ALsizei min_delay = HRTF_HISTORY_LENGTH;
|
2017-01-16 17:04:58 +00:00
|
|
|
ALfloat temps[3][HRIR_LENGTH];
|
2017-01-16 15:45:07 +00:00
|
|
|
ALsizei max_length = 0;
|
|
|
|
ALsizei i, j, c, b;
|
Decode directly from B-Format to HRTF instead of a cube
Last time this attempted to average the HRIRs according to their contribution
to a given B-Format channel as if they were loudspeakers, as well as averaging
the HRIR delays. The latter part resulted in the loss of the ITD (inter-aural
time delay), a key component of HRTF.
This time, the HRIRs are averaged similar to above, except instead of averaging
the delays, they're applied to the resulting coefficients (for example, a delay
of 8 would apply the HRIR starting at the 8th sample of the target HRIR). This
does roughly double the IR length, as the largest delay is about 35 samples
while the filter is normally 32 samples. However, this is still smaller the
original data set IR (which was 256 samples), it also only needs to be applied
to 4 channels for first-order ambisonics, rather than the 8-channel cube. So
it's doing twice as much work per sample, but only working on half the number
of samples.
Additionally, since the resulting HRIRs no longer rely on an extra delay line,
a more efficient HRTF mixing function can be made that doesn't use one. Such a
function can also avoid the per-sample stepping parameters the original uses.
2016-08-12 06:20:35 +00:00
|
|
|
|
2017-01-19 03:16:24 +00:00
|
|
|
for(c = 0;c < AmbiCount;c++)
|
Decode directly from B-Format to HRTF instead of a cube
Last time this attempted to average the HRIRs according to their contribution
to a given B-Format channel as if they were loudspeakers, as well as averaging
the HRIR delays. The latter part resulted in the loss of the ITD (inter-aural
time delay), a key component of HRTF.
This time, the HRIRs are averaged similar to above, except instead of averaging
the delays, they're applied to the resulting coefficients (for example, a delay
of 8 would apply the HRIR starting at the 8th sample of the target HRIR). This
does roughly double the IR length, as the largest delay is about 35 samples
while the filter is normally 32 samples. However, this is still smaller the
original data set IR (which was 256 samples), it also only needs to be applied
to 4 channels for first-order ambisonics, rather than the 8-channel cube. So
it's doing twice as much work per sample, but only working on half the number
of samples.
Additionally, since the resulting HRIRs no longer rely on an extra delay line,
a more efficient HRTF mixing function can be made that doesn't use one. Such a
function can also avoid the per-sample stepping parameters the original uses.
2016-08-12 06:20:35 +00:00
|
|
|
{
|
2016-08-19 06:33:08 +00:00
|
|
|
ALuint evidx, azidx;
|
2016-08-17 12:34:09 +00:00
|
|
|
ALuint evoffset;
|
|
|
|
ALuint azcount;
|
Decode directly from B-Format to HRTF instead of a cube
Last time this attempted to average the HRIRs according to their contribution
to a given B-Format channel as if they were loudspeakers, as well as averaging
the HRIR delays. The latter part resulted in the loss of the ITD (inter-aural
time delay), a key component of HRTF.
This time, the HRIRs are averaged similar to above, except instead of averaging
the delays, they're applied to the resulting coefficients (for example, a delay
of 8 would apply the HRIR starting at the 8th sample of the target HRIR). This
does roughly double the IR length, as the largest delay is about 35 samples
while the filter is normally 32 samples. However, this is still smaller the
original data set IR (which was 256 samples), it also only needs to be applied
to 4 channels for first-order ambisonics, rather than the 8-channel cube. So
it's doing twice as much work per sample, but only working on half the number
of samples.
Additionally, since the resulting HRIRs no longer rely on an extra delay line,
a more efficient HRTF mixing function can be made that doesn't use one. Such a
function can also avoid the per-sample stepping parameters the original uses.
2016-08-12 06:20:35 +00:00
|
|
|
|
2016-08-17 12:34:09 +00:00
|
|
|
/* Calculate elevation index. */
|
2017-01-19 03:16:24 +00:00
|
|
|
evidx = (ALsizei)floorf((F_PI_2 + AmbiPoints[c][0]) *
|
2017-01-16 15:45:07 +00:00
|
|
|
(Hrtf->evCount-1)/F_PI + 0.5f);
|
|
|
|
evidx = mini(evidx, Hrtf->evCount-1);
|
2016-08-17 12:34:09 +00:00
|
|
|
|
2016-08-19 06:33:08 +00:00
|
|
|
azcount = Hrtf->azCount[evidx];
|
|
|
|
evoffset = Hrtf->evOffset[evidx];
|
2016-08-17 12:34:09 +00:00
|
|
|
|
|
|
|
/* Calculate azimuth index for this elevation. */
|
2017-01-19 03:16:24 +00:00
|
|
|
azidx = (ALsizei)floorf((F_TAU+AmbiPoints[c][1]) *
|
2017-01-16 15:45:07 +00:00
|
|
|
azcount/F_TAU + 0.5f) % azcount;
|
2016-08-17 12:34:09 +00:00
|
|
|
|
|
|
|
/* Calculate indices for left and right channels. */
|
2016-08-19 06:33:08 +00:00
|
|
|
lidx[c] = evoffset + azidx;
|
|
|
|
ridx[c] = evoffset + ((azcount-azidx) % azcount);
|
2016-08-17 12:34:09 +00:00
|
|
|
|
2017-01-16 15:45:07 +00:00
|
|
|
min_delay = mini(min_delay, mini(Hrtf->delays[lidx[c]], Hrtf->delays[ridx[c]]));
|
Decode directly from B-Format to HRTF instead of a cube
Last time this attempted to average the HRIRs according to their contribution
to a given B-Format channel as if they were loudspeakers, as well as averaging
the HRIR delays. The latter part resulted in the loss of the ITD (inter-aural
time delay), a key component of HRTF.
This time, the HRIRs are averaged similar to above, except instead of averaging
the delays, they're applied to the resulting coefficients (for example, a delay
of 8 would apply the HRIR starting at the 8th sample of the target HRIR). This
does roughly double the IR length, as the largest delay is about 35 samples
while the filter is normally 32 samples. However, this is still smaller the
original data set IR (which was 256 samples), it also only needs to be applied
to 4 channels for first-order ambisonics, rather than the 8-channel cube. So
it's doing twice as much work per sample, but only working on half the number
of samples.
Additionally, since the resulting HRIRs no longer rely on an extra delay line,
a more efficient HRTF mixing function can be made that doesn't use one. Such a
function can also avoid the per-sample stepping parameters the original uses.
2016-08-12 06:20:35 +00:00
|
|
|
}
|
|
|
|
|
2016-08-21 10:05:42 +00:00
|
|
|
memset(temps, 0, sizeof(temps));
|
|
|
|
bandsplit_init(&splitter, 400.0f / (ALfloat)Hrtf->sampleRate);
|
2017-01-19 03:16:24 +00:00
|
|
|
for(c = 0;c < AmbiCount;c++)
|
Decode directly from B-Format to HRTF instead of a cube
Last time this attempted to average the HRIRs according to their contribution
to a given B-Format channel as if they were loudspeakers, as well as averaging
the HRIR delays. The latter part resulted in the loss of the ITD (inter-aural
time delay), a key component of HRTF.
This time, the HRIRs are averaged similar to above, except instead of averaging
the delays, they're applied to the resulting coefficients (for example, a delay
of 8 would apply the HRIR starting at the 8th sample of the target HRIR). This
does roughly double the IR length, as the largest delay is about 35 samples
while the filter is normally 32 samples. However, this is still smaller the
original data set IR (which was 256 samples), it also only needs to be applied
to 4 channels for first-order ambisonics, rather than the 8-channel cube. So
it's doing twice as much work per sample, but only working on half the number
of samples.
Additionally, since the resulting HRIRs no longer rely on an extra delay line,
a more efficient HRTF mixing function can be made that doesn't use one. Such a
function can also avoid the per-sample stepping parameters the original uses.
2016-08-12 06:20:35 +00:00
|
|
|
{
|
2016-08-17 12:34:09 +00:00
|
|
|
const ALshort *fir;
|
2017-01-16 15:45:07 +00:00
|
|
|
ALsizei delay;
|
2016-08-17 12:34:09 +00:00
|
|
|
|
2016-08-31 05:33:33 +00:00
|
|
|
/* Convert the left FIR from shorts to float */
|
2016-08-17 12:34:09 +00:00
|
|
|
fir = &Hrtf->coeffs[lidx[c] * Hrtf->irSize];
|
2016-08-31 05:33:33 +00:00
|
|
|
if(NUM_BANDS == 1)
|
|
|
|
{
|
|
|
|
for(i = 0;i < Hrtf->irSize;i++)
|
|
|
|
temps[0][i] = fir[i] / 32767.0f;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Band-split left HRIR into low and high frequency responses. */
|
|
|
|
bandsplit_clear(&splitter);
|
|
|
|
for(i = 0;i < Hrtf->irSize;i++)
|
|
|
|
temps[2][i] = fir[i] / 32767.0f;
|
|
|
|
bandsplit_process(&splitter, temps[0], temps[1], temps[2], HRIR_LENGTH);
|
|
|
|
}
|
2016-08-21 10:05:42 +00:00
|
|
|
|
|
|
|
/* Add to the left output coefficients with the specified delay. */
|
2016-08-17 12:34:09 +00:00
|
|
|
delay = Hrtf->delays[lidx[c]] - min_delay;
|
|
|
|
for(i = 0;i < NumChannels;++i)
|
Decode directly from B-Format to HRTF instead of a cube
Last time this attempted to average the HRIRs according to their contribution
to a given B-Format channel as if they were loudspeakers, as well as averaging
the HRIR delays. The latter part resulted in the loss of the ITD (inter-aural
time delay), a key component of HRTF.
This time, the HRIRs are averaged similar to above, except instead of averaging
the delays, they're applied to the resulting coefficients (for example, a delay
of 8 would apply the HRIR starting at the 8th sample of the target HRIR). This
does roughly double the IR length, as the largest delay is about 35 samples
while the filter is normally 32 samples. However, this is still smaller the
original data set IR (which was 256 samples), it also only needs to be applied
to 4 channels for first-order ambisonics, rather than the 8-channel cube. So
it's doing twice as much work per sample, but only working on half the number
of samples.
Additionally, since the resulting HRIRs no longer rely on an extra delay line,
a more efficient HRTF mixing function can be made that doesn't use one. Such a
function can also avoid the per-sample stepping parameters the original uses.
2016-08-12 06:20:35 +00:00
|
|
|
{
|
2016-08-31 05:33:33 +00:00
|
|
|
for(b = 0;b < NUM_BANDS;b++)
|
2016-08-21 10:05:42 +00:00
|
|
|
{
|
2017-01-16 15:45:07 +00:00
|
|
|
ALsizei k = 0;
|
2016-08-21 10:05:42 +00:00
|
|
|
for(j = delay;j < HRIR_LENGTH;++j)
|
2017-03-11 14:20:04 +00:00
|
|
|
state->Chan[i].Coeffs[j][0] += temps[b][k++] * AmbiMatrix[c][b][i];
|
2016-08-21 10:05:42 +00:00
|
|
|
}
|
Decode directly from B-Format to HRTF instead of a cube
Last time this attempted to average the HRIRs according to their contribution
to a given B-Format channel as if they were loudspeakers, as well as averaging
the HRIR delays. The latter part resulted in the loss of the ITD (inter-aural
time delay), a key component of HRTF.
This time, the HRIRs are averaged similar to above, except instead of averaging
the delays, they're applied to the resulting coefficients (for example, a delay
of 8 would apply the HRIR starting at the 8th sample of the target HRIR). This
does roughly double the IR length, as the largest delay is about 35 samples
while the filter is normally 32 samples. However, this is still smaller the
original data set IR (which was 256 samples), it also only needs to be applied
to 4 channels for first-order ambisonics, rather than the 8-channel cube. So
it's doing twice as much work per sample, but only working on half the number
of samples.
Additionally, since the resulting HRIRs no longer rely on an extra delay line,
a more efficient HRTF mixing function can be made that doesn't use one. Such a
function can also avoid the per-sample stepping parameters the original uses.
2016-08-12 06:20:35 +00:00
|
|
|
}
|
2017-01-16 15:45:07 +00:00
|
|
|
max_length = maxi(max_length, mini(delay + Hrtf->irSize, HRIR_LENGTH));
|
2016-08-17 12:34:09 +00:00
|
|
|
|
2016-08-31 05:33:33 +00:00
|
|
|
/* Convert the right FIR from shorts to float */
|
2016-08-17 12:34:09 +00:00
|
|
|
fir = &Hrtf->coeffs[ridx[c] * Hrtf->irSize];
|
2016-08-31 05:33:33 +00:00
|
|
|
if(NUM_BANDS == 1)
|
|
|
|
{
|
|
|
|
for(i = 0;i < Hrtf->irSize;i++)
|
|
|
|
temps[0][i] = fir[i] / 32767.0f;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Band-split right HRIR into low and high frequency responses. */
|
|
|
|
bandsplit_clear(&splitter);
|
|
|
|
for(i = 0;i < Hrtf->irSize;i++)
|
|
|
|
temps[2][i] = fir[i] / 32767.0f;
|
|
|
|
bandsplit_process(&splitter, temps[0], temps[1], temps[2], HRIR_LENGTH);
|
|
|
|
}
|
2016-08-21 10:05:42 +00:00
|
|
|
|
|
|
|
/* Add to the right output coefficients with the specified delay. */
|
2016-08-17 12:34:09 +00:00
|
|
|
delay = Hrtf->delays[ridx[c]] - min_delay;
|
|
|
|
for(i = 0;i < NumChannels;++i)
|
|
|
|
{
|
2016-08-31 05:33:33 +00:00
|
|
|
for(b = 0;b < NUM_BANDS;b++)
|
2016-08-21 10:05:42 +00:00
|
|
|
{
|
|
|
|
ALuint k = 0;
|
|
|
|
for(j = delay;j < HRIR_LENGTH;++j)
|
2017-03-11 14:20:04 +00:00
|
|
|
state->Chan[i].Coeffs[j][1] += temps[b][k++] * AmbiMatrix[c][b][i];
|
2016-08-21 10:05:42 +00:00
|
|
|
}
|
2016-08-17 12:34:09 +00:00
|
|
|
}
|
2017-01-16 15:45:07 +00:00
|
|
|
max_length = maxi(max_length, mini(delay + Hrtf->irSize, HRIR_LENGTH));
|
Decode directly from B-Format to HRTF instead of a cube
Last time this attempted to average the HRIRs according to their contribution
to a given B-Format channel as if they were loudspeakers, as well as averaging
the HRIR delays. The latter part resulted in the loss of the ITD (inter-aural
time delay), a key component of HRTF.
This time, the HRIRs are averaged similar to above, except instead of averaging
the delays, they're applied to the resulting coefficients (for example, a delay
of 8 would apply the HRIR starting at the 8th sample of the target HRIR). This
does roughly double the IR length, as the largest delay is about 35 samples
while the filter is normally 32 samples. However, this is still smaller the
original data set IR (which was 256 samples), it also only needs to be applied
to 4 channels for first-order ambisonics, rather than the 8-channel cube. So
it's doing twice as much work per sample, but only working on half the number
of samples.
Additionally, since the resulting HRIRs no longer rely on an extra delay line,
a more efficient HRTF mixing function can be made that doesn't use one. Such a
function can also avoid the per-sample stepping parameters the original uses.
2016-08-12 06:20:35 +00:00
|
|
|
}
|
2017-01-16 15:45:07 +00:00
|
|
|
TRACE("Skipped min delay: %d, new combined length: %d\n", min_delay, max_length);
|
2016-08-17 12:34:09 +00:00
|
|
|
|
Decode directly from B-Format to HRTF instead of a cube
Last time this attempted to average the HRIRs according to their contribution
to a given B-Format channel as if they were loudspeakers, as well as averaging
the HRIR delays. The latter part resulted in the loss of the ITD (inter-aural
time delay), a key component of HRTF.
This time, the HRIRs are averaged similar to above, except instead of averaging
the delays, they're applied to the resulting coefficients (for example, a delay
of 8 would apply the HRIR starting at the 8th sample of the target HRIR). This
does roughly double the IR length, as the largest delay is about 35 samples
while the filter is normally 32 samples. However, this is still smaller the
original data set IR (which was 256 samples), it also only needs to be applied
to 4 channels for first-order ambisonics, rather than the 8-channel cube. So
it's doing twice as much work per sample, but only working on half the number
of samples.
Additionally, since the resulting HRIRs no longer rely on an extra delay line,
a more efficient HRTF mixing function can be made that doesn't use one. Such a
function can also avoid the per-sample stepping parameters the original uses.
2016-08-12 06:20:35 +00:00
|
|
|
return max_length;
|
2017-01-19 03:16:24 +00:00
|
|
|
#undef NUM_BANDS
|
Decode directly from B-Format to HRTF instead of a cube
Last time this attempted to average the HRIRs according to their contribution
to a given B-Format channel as if they were loudspeakers, as well as averaging
the HRIR delays. The latter part resulted in the loss of the ITD (inter-aural
time delay), a key component of HRTF.
This time, the HRIRs are averaged similar to above, except instead of averaging
the delays, they're applied to the resulting coefficients (for example, a delay
of 8 would apply the HRIR starting at the 8th sample of the target HRIR). This
does roughly double the IR length, as the largest delay is about 35 samples
while the filter is normally 32 samples. However, this is still smaller the
original data set IR (which was 256 samples), it also only needs to be applied
to 4 channels for first-order ambisonics, rather than the 8-channel cube. So
it's doing twice as much work per sample, but only working on half the number
of samples.
Additionally, since the resulting HRIRs no longer rely on an extra delay line,
a more efficient HRTF mixing function can be made that doesn't use one. Such a
function can also avoid the per-sample stepping parameters the original uses.
2016-08-12 06:20:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-31 15:16:49 +00:00
|
|
|
static struct Hrtf *LoadHrtf00(const ALubyte *data, size_t datalen, const_al_string filename)
|
2012-09-12 14:25:05 +00:00
|
|
|
{
|
2014-11-22 12:20:17 +00:00
|
|
|
const ALubyte maxDelay = HRTF_HISTORY_LENGTH-1;
|
2012-09-12 14:25:05 +00:00
|
|
|
struct Hrtf *Hrtf = NULL;
|
|
|
|
ALboolean failed = AL_FALSE;
|
|
|
|
ALuint rate = 0, irCount = 0;
|
2012-10-07 15:19:09 +00:00
|
|
|
ALushort irSize = 0;
|
|
|
|
ALubyte evCount = 0;
|
2012-09-12 14:25:05 +00:00
|
|
|
ALubyte *azCount = NULL;
|
|
|
|
ALushort *evOffset = NULL;
|
|
|
|
ALshort *coeffs = NULL;
|
2016-08-31 15:16:49 +00:00
|
|
|
const ALubyte *delays = NULL;
|
2012-09-12 14:25:05 +00:00
|
|
|
ALuint i, j;
|
|
|
|
|
2016-08-31 15:16:49 +00:00
|
|
|
if(datalen < 9)
|
|
|
|
{
|
|
|
|
ERR("Unexpected end of %s data (req %d, rem "SZFMT")\n",
|
|
|
|
al_string_get_cstr(filename), 9, datalen);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
rate = *(data++);
|
|
|
|
rate |= *(data++)<<8;
|
|
|
|
rate |= *(data++)<<16;
|
|
|
|
rate |= *(data++)<<24;
|
|
|
|
datalen -= 4;
|
2012-09-12 14:25:05 +00:00
|
|
|
|
2016-08-31 15:16:49 +00:00
|
|
|
irCount = *(data++);
|
|
|
|
irCount |= *(data++)<<8;
|
|
|
|
datalen -= 2;
|
2012-09-12 14:25:05 +00:00
|
|
|
|
2016-08-31 15:16:49 +00:00
|
|
|
irSize = *(data++);
|
|
|
|
irSize |= *(data++)<<8;
|
|
|
|
datalen -= 2;
|
2012-09-12 14:25:05 +00:00
|
|
|
|
2016-08-31 15:16:49 +00:00
|
|
|
evCount = *(data++);
|
|
|
|
datalen -= 1;
|
2012-09-12 14:25:05 +00:00
|
|
|
|
|
|
|
if(irSize < MIN_IR_SIZE || irSize > MAX_IR_SIZE || (irSize%MOD_IR_SIZE))
|
|
|
|
{
|
|
|
|
ERR("Unsupported HRIR size: irSize=%d (%d to %d by %d)\n",
|
|
|
|
irSize, MIN_IR_SIZE, MAX_IR_SIZE, MOD_IR_SIZE);
|
|
|
|
failed = AL_TRUE;
|
|
|
|
}
|
|
|
|
if(evCount < MIN_EV_COUNT || evCount > MAX_EV_COUNT)
|
|
|
|
{
|
|
|
|
ERR("Unsupported elevation count: evCount=%d (%d to %d)\n",
|
|
|
|
evCount, MIN_EV_COUNT, MAX_EV_COUNT);
|
|
|
|
failed = AL_TRUE;
|
|
|
|
}
|
|
|
|
if(failed)
|
|
|
|
return NULL;
|
|
|
|
|
2016-08-31 15:16:49 +00:00
|
|
|
if(datalen < evCount*2)
|
|
|
|
{
|
|
|
|
ERR("Unexpected end of %s data (req %d, rem "SZFMT")\n",
|
|
|
|
al_string_get_cstr(filename), evCount*2, datalen);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-09-12 14:25:05 +00:00
|
|
|
azCount = malloc(sizeof(azCount[0])*evCount);
|
|
|
|
evOffset = malloc(sizeof(evOffset[0])*evCount);
|
|
|
|
if(azCount == NULL || evOffset == NULL)
|
|
|
|
{
|
|
|
|
ERR("Out of memory.\n");
|
|
|
|
failed = AL_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!failed)
|
|
|
|
{
|
2016-08-31 15:16:49 +00:00
|
|
|
evOffset[0] = *(data++);
|
|
|
|
evOffset[0] |= *(data++)<<8;
|
|
|
|
datalen -= 2;
|
2012-09-12 14:25:05 +00:00
|
|
|
for(i = 1;i < evCount;i++)
|
|
|
|
{
|
2016-08-31 15:16:49 +00:00
|
|
|
evOffset[i] = *(data++);
|
|
|
|
evOffset[i] |= *(data++)<<8;
|
|
|
|
datalen -= 2;
|
2012-09-12 14:25:05 +00:00
|
|
|
if(evOffset[i] <= evOffset[i-1])
|
|
|
|
{
|
|
|
|
ERR("Invalid evOffset: evOffset[%d]=%d (last=%d)\n",
|
|
|
|
i, evOffset[i], evOffset[i-1]);
|
|
|
|
failed = AL_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
azCount[i-1] = evOffset[i] - evOffset[i-1];
|
|
|
|
if(azCount[i-1] < MIN_AZ_COUNT || azCount[i-1] > MAX_AZ_COUNT)
|
|
|
|
{
|
|
|
|
ERR("Unsupported azimuth count: azCount[%d]=%d (%d to %d)\n",
|
|
|
|
i-1, azCount[i-1], MIN_AZ_COUNT, MAX_AZ_COUNT);
|
|
|
|
failed = AL_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(irCount <= evOffset[i-1])
|
|
|
|
{
|
|
|
|
ERR("Invalid evOffset: evOffset[%d]=%d (irCount=%d)\n",
|
|
|
|
i-1, evOffset[i-1], irCount);
|
|
|
|
failed = AL_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
azCount[i-1] = irCount - evOffset[i-1];
|
|
|
|
if(azCount[i-1] < MIN_AZ_COUNT || azCount[i-1] > MAX_AZ_COUNT)
|
|
|
|
{
|
|
|
|
ERR("Unsupported azimuth count: azCount[%d]=%d (%d to %d)\n",
|
|
|
|
i-1, azCount[i-1], MIN_AZ_COUNT, MAX_AZ_COUNT);
|
|
|
|
failed = AL_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!failed)
|
|
|
|
{
|
|
|
|
coeffs = malloc(sizeof(coeffs[0])*irSize*irCount);
|
2016-08-31 15:16:49 +00:00
|
|
|
if(coeffs == NULL)
|
2012-09-12 14:25:05 +00:00
|
|
|
{
|
|
|
|
ERR("Out of memory.\n");
|
|
|
|
failed = AL_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-31 15:16:49 +00:00
|
|
|
if(!failed)
|
|
|
|
{
|
|
|
|
size_t reqsize = 2*irSize*irCount + irCount;
|
|
|
|
if(datalen < reqsize)
|
|
|
|
{
|
|
|
|
ERR("Unexpected end of %s data (req "SZFMT", rem "SZFMT")\n",
|
|
|
|
al_string_get_cstr(filename), reqsize, datalen);
|
|
|
|
failed = AL_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-12 14:25:05 +00:00
|
|
|
if(!failed)
|
|
|
|
{
|
|
|
|
for(i = 0;i < irCount*irSize;i+=irSize)
|
|
|
|
{
|
|
|
|
for(j = 0;j < irSize;j++)
|
|
|
|
{
|
2016-08-31 15:16:49 +00:00
|
|
|
coeffs[i+j] = *(data++);
|
|
|
|
coeffs[i+j] |= *(data++)<<8;
|
|
|
|
datalen -= 2;
|
2012-09-12 14:25:05 +00:00
|
|
|
}
|
|
|
|
}
|
2016-08-31 15:16:49 +00:00
|
|
|
|
|
|
|
delays = data;
|
|
|
|
data += irCount;
|
|
|
|
datalen -= irCount;
|
2012-09-12 14:25:05 +00:00
|
|
|
for(i = 0;i < irCount;i++)
|
|
|
|
{
|
|
|
|
if(delays[i] > maxDelay)
|
|
|
|
{
|
|
|
|
ERR("Invalid delays[%d]: %d (%d)\n", i, delays[i], maxDelay);
|
|
|
|
failed = AL_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!failed)
|
|
|
|
{
|
2016-02-17 03:56:44 +00:00
|
|
|
size_t total = sizeof(struct Hrtf);
|
2017-03-31 09:15:24 +00:00
|
|
|
total += sizeof(Hrtf->azCount[0])*evCount;
|
2016-09-07 12:37:01 +00:00
|
|
|
total = (total+1)&~1; /* Align for (u)short fields */
|
2017-03-31 09:15:24 +00:00
|
|
|
total += sizeof(Hrtf->evOffset[0])*evCount;
|
|
|
|
total += sizeof(Hrtf->coeffs[0])*irSize*irCount;
|
|
|
|
total += sizeof(Hrtf->delays[0])*irCount;
|
2016-02-20 13:32:42 +00:00
|
|
|
total += al_string_length(filename)+1;
|
2016-02-17 03:56:44 +00:00
|
|
|
|
2016-07-07 17:31:43 +00:00
|
|
|
Hrtf = al_calloc(16, total);
|
2012-09-12 14:25:05 +00:00
|
|
|
if(Hrtf == NULL)
|
|
|
|
{
|
|
|
|
ERR("Out of memory.\n");
|
|
|
|
failed = AL_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!failed)
|
|
|
|
{
|
2016-09-07 12:37:01 +00:00
|
|
|
char *base = (char*)Hrtf;
|
|
|
|
uintptr_t offset = sizeof(*Hrtf);
|
|
|
|
|
2012-09-12 14:25:05 +00:00
|
|
|
Hrtf->sampleRate = rate;
|
|
|
|
Hrtf->irSize = irSize;
|
|
|
|
Hrtf->evCount = evCount;
|
2016-09-07 12:37:01 +00:00
|
|
|
Hrtf->azCount = ((ALubyte*)(base + offset)); offset += evCount*sizeof(Hrtf->azCount[0]);
|
|
|
|
offset = (offset+1)&~1; /* Align for (u)short fields */
|
|
|
|
Hrtf->evOffset = ((ALushort*)(base + offset)); offset += evCount*sizeof(Hrtf->evOffset[0]);
|
|
|
|
Hrtf->coeffs = ((ALshort*)(base + offset)); offset += irSize*irCount*sizeof(Hrtf->coeffs[0]);
|
|
|
|
Hrtf->delays = ((ALubyte*)(base + offset)); offset += irCount*sizeof(Hrtf->delays[0]);
|
|
|
|
Hrtf->filename = ((char*)(base + offset));
|
2012-09-12 14:25:05 +00:00
|
|
|
Hrtf->next = NULL;
|
2016-02-17 03:56:44 +00:00
|
|
|
|
|
|
|
memcpy((void*)Hrtf->azCount, azCount, sizeof(azCount[0])*evCount);
|
|
|
|
memcpy((void*)Hrtf->evOffset, evOffset, sizeof(evOffset[0])*evCount);
|
|
|
|
memcpy((void*)Hrtf->coeffs, coeffs, sizeof(coeffs[0])*irSize*irCount);
|
|
|
|
memcpy((void*)Hrtf->delays, delays, sizeof(delays[0])*irCount);
|
2016-02-20 13:32:42 +00:00
|
|
|
memcpy((void*)Hrtf->filename, al_string_get_cstr(filename), al_string_length(filename)+1);
|
2012-09-12 14:25:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
free(azCount);
|
|
|
|
free(evOffset);
|
|
|
|
free(coeffs);
|
2016-02-17 03:56:44 +00:00
|
|
|
return Hrtf;
|
2012-09-12 14:25:05 +00:00
|
|
|
}
|
|
|
|
|
2016-08-31 15:16:49 +00:00
|
|
|
static struct Hrtf *LoadHrtf01(const ALubyte *data, size_t datalen, const_al_string filename)
|
2012-09-12 14:25:05 +00:00
|
|
|
{
|
2014-11-22 12:20:17 +00:00
|
|
|
const ALubyte maxDelay = HRTF_HISTORY_LENGTH-1;
|
2012-09-12 14:25:05 +00:00
|
|
|
struct Hrtf *Hrtf = NULL;
|
|
|
|
ALboolean failed = AL_FALSE;
|
|
|
|
ALuint rate = 0, irCount = 0;
|
|
|
|
ALubyte irSize = 0, evCount = 0;
|
2016-08-31 15:16:49 +00:00
|
|
|
const ALubyte *azCount = NULL;
|
2012-09-12 14:25:05 +00:00
|
|
|
ALushort *evOffset = NULL;
|
|
|
|
ALshort *coeffs = NULL;
|
2016-08-31 15:16:49 +00:00
|
|
|
const ALubyte *delays = NULL;
|
2012-09-12 14:25:05 +00:00
|
|
|
ALuint i, j;
|
|
|
|
|
2016-08-31 15:16:49 +00:00
|
|
|
if(datalen < 6)
|
|
|
|
{
|
|
|
|
ERR("Unexpected end of %s data (req %d, rem "SZFMT"\n",
|
|
|
|
al_string_get_cstr(filename), 6, datalen);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
rate = *(data++);
|
|
|
|
rate |= *(data++)<<8;
|
|
|
|
rate |= *(data++)<<16;
|
|
|
|
rate |= *(data++)<<24;
|
|
|
|
datalen -= 4;
|
2012-09-12 14:25:05 +00:00
|
|
|
|
2016-08-31 15:16:49 +00:00
|
|
|
irSize = *(data++);
|
|
|
|
datalen -= 1;
|
2012-09-12 14:25:05 +00:00
|
|
|
|
2016-08-31 15:16:49 +00:00
|
|
|
evCount = *(data++);
|
|
|
|
datalen -= 1;
|
2012-09-12 14:25:05 +00:00
|
|
|
|
|
|
|
if(irSize < MIN_IR_SIZE || irSize > MAX_IR_SIZE || (irSize%MOD_IR_SIZE))
|
|
|
|
{
|
|
|
|
ERR("Unsupported HRIR size: irSize=%d (%d to %d by %d)\n",
|
|
|
|
irSize, MIN_IR_SIZE, MAX_IR_SIZE, MOD_IR_SIZE);
|
|
|
|
failed = AL_TRUE;
|
|
|
|
}
|
|
|
|
if(evCount < MIN_EV_COUNT || evCount > MAX_EV_COUNT)
|
|
|
|
{
|
|
|
|
ERR("Unsupported elevation count: evCount=%d (%d to %d)\n",
|
|
|
|
evCount, MIN_EV_COUNT, MAX_EV_COUNT);
|
|
|
|
failed = AL_TRUE;
|
|
|
|
}
|
|
|
|
if(failed)
|
|
|
|
return NULL;
|
|
|
|
|
2016-08-31 15:16:49 +00:00
|
|
|
if(datalen < evCount)
|
|
|
|
{
|
|
|
|
ERR("Unexpected end of %s data (req %d, rem "SZFMT"\n",
|
|
|
|
al_string_get_cstr(filename), evCount, datalen);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
azCount = data;
|
|
|
|
data += evCount;
|
|
|
|
datalen -= evCount;
|
|
|
|
|
2012-09-12 14:25:05 +00:00
|
|
|
evOffset = malloc(sizeof(evOffset[0])*evCount);
|
|
|
|
if(azCount == NULL || evOffset == NULL)
|
|
|
|
{
|
|
|
|
ERR("Out of memory.\n");
|
|
|
|
failed = AL_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!failed)
|
|
|
|
{
|
|
|
|
for(i = 0;i < evCount;i++)
|
|
|
|
{
|
|
|
|
if(azCount[i] < MIN_AZ_COUNT || azCount[i] > MAX_AZ_COUNT)
|
|
|
|
{
|
|
|
|
ERR("Unsupported azimuth count: azCount[%d]=%d (%d to %d)\n",
|
|
|
|
i, azCount[i], MIN_AZ_COUNT, MAX_AZ_COUNT);
|
|
|
|
failed = AL_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!failed)
|
|
|
|
{
|
|
|
|
evOffset[0] = 0;
|
|
|
|
irCount = azCount[0];
|
|
|
|
for(i = 1;i < evCount;i++)
|
|
|
|
{
|
|
|
|
evOffset[i] = evOffset[i-1] + azCount[i-1];
|
|
|
|
irCount += azCount[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
coeffs = malloc(sizeof(coeffs[0])*irSize*irCount);
|
2016-08-31 15:16:49 +00:00
|
|
|
if(coeffs == NULL)
|
2012-09-12 14:25:05 +00:00
|
|
|
{
|
|
|
|
ERR("Out of memory.\n");
|
|
|
|
failed = AL_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-31 15:16:49 +00:00
|
|
|
if(!failed)
|
|
|
|
{
|
|
|
|
size_t reqsize = 2*irSize*irCount + irCount;
|
|
|
|
if(datalen < reqsize)
|
|
|
|
{
|
|
|
|
ERR("Unexpected end of %s data (req "SZFMT", rem "SZFMT"\n",
|
|
|
|
al_string_get_cstr(filename), reqsize, datalen);
|
|
|
|
failed = AL_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-12 14:25:05 +00:00
|
|
|
if(!failed)
|
|
|
|
{
|
|
|
|
for(i = 0;i < irCount*irSize;i+=irSize)
|
|
|
|
{
|
|
|
|
for(j = 0;j < irSize;j++)
|
|
|
|
{
|
|
|
|
ALshort coeff;
|
2016-08-31 15:16:49 +00:00
|
|
|
coeff = *(data++);
|
|
|
|
coeff |= *(data++)<<8;
|
|
|
|
datalen -= 2;
|
2012-09-12 14:25:05 +00:00
|
|
|
coeffs[i+j] = coeff;
|
|
|
|
}
|
|
|
|
}
|
2016-08-31 15:16:49 +00:00
|
|
|
|
|
|
|
delays = data;
|
|
|
|
data += irCount;
|
|
|
|
datalen -= irCount;
|
2012-09-12 14:25:05 +00:00
|
|
|
for(i = 0;i < irCount;i++)
|
|
|
|
{
|
|
|
|
if(delays[i] > maxDelay)
|
|
|
|
{
|
|
|
|
ERR("Invalid delays[%d]: %d (%d)\n", i, delays[i], maxDelay);
|
|
|
|
failed = AL_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!failed)
|
|
|
|
{
|
2016-02-17 03:56:44 +00:00
|
|
|
size_t total = sizeof(struct Hrtf);
|
2017-03-31 09:15:24 +00:00
|
|
|
total += sizeof(Hrtf->azCount[0])*evCount;
|
2016-09-07 12:37:01 +00:00
|
|
|
total = (total+1)&~1; /* Align for (u)short fields */
|
2017-03-31 09:15:24 +00:00
|
|
|
total += sizeof(Hrtf->evOffset[0])*evCount;
|
|
|
|
total += sizeof(Hrtf->coeffs[0])*irSize*irCount;
|
|
|
|
total += sizeof(Hrtf->delays[0])*irCount;
|
2016-02-20 13:32:42 +00:00
|
|
|
total += al_string_length(filename)+1;
|
2016-02-17 03:56:44 +00:00
|
|
|
|
2016-07-07 17:31:43 +00:00
|
|
|
Hrtf = al_calloc(16, total);
|
2012-09-12 14:25:05 +00:00
|
|
|
if(Hrtf == NULL)
|
|
|
|
{
|
|
|
|
ERR("Out of memory.\n");
|
|
|
|
failed = AL_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!failed)
|
|
|
|
{
|
2016-09-07 12:37:01 +00:00
|
|
|
char *base = (char*)Hrtf;
|
|
|
|
uintptr_t offset = sizeof(*Hrtf);
|
|
|
|
|
2012-09-12 14:25:05 +00:00
|
|
|
Hrtf->sampleRate = rate;
|
|
|
|
Hrtf->irSize = irSize;
|
|
|
|
Hrtf->evCount = evCount;
|
2016-09-07 12:37:01 +00:00
|
|
|
Hrtf->azCount = ((ALubyte*)(base + offset)); offset += evCount*sizeof(Hrtf->azCount[0]);
|
|
|
|
offset = (offset+1)&~1; /* Align for (u)short fields */
|
|
|
|
Hrtf->evOffset = ((ALushort*)(base + offset)); offset += evCount*sizeof(Hrtf->evOffset[0]);
|
|
|
|
Hrtf->coeffs = ((ALshort*)(base + offset)); offset += irSize*irCount*sizeof(Hrtf->coeffs[0]);
|
|
|
|
Hrtf->delays = ((ALubyte*)(base + offset)); offset += irCount*sizeof(Hrtf->delays[0]);
|
|
|
|
Hrtf->filename = ((char*)(base + offset));
|
2012-09-12 14:25:05 +00:00
|
|
|
Hrtf->next = NULL;
|
2016-02-17 03:56:44 +00:00
|
|
|
|
|
|
|
memcpy((void*)Hrtf->azCount, azCount, sizeof(azCount[0])*evCount);
|
|
|
|
memcpy((void*)Hrtf->evOffset, evOffset, sizeof(evOffset[0])*evCount);
|
|
|
|
memcpy((void*)Hrtf->coeffs, coeffs, sizeof(coeffs[0])*irSize*irCount);
|
|
|
|
memcpy((void*)Hrtf->delays, delays, sizeof(delays[0])*irCount);
|
2016-02-20 13:32:42 +00:00
|
|
|
memcpy((void*)Hrtf->filename, al_string_get_cstr(filename), al_string_length(filename)+1);
|
2012-09-12 14:25:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
free(evOffset);
|
|
|
|
free(coeffs);
|
2016-02-17 03:56:44 +00:00
|
|
|
return Hrtf;
|
2012-09-12 14:25:05 +00:00
|
|
|
}
|
|
|
|
|
2015-10-06 07:23:11 +00:00
|
|
|
static void AddFileEntry(vector_HrtfEntry *list, al_string *filename)
|
|
|
|
{
|
2016-02-20 13:32:42 +00:00
|
|
|
HrtfEntry entry = { AL_STRING_INIT_STATIC(), NULL };
|
2016-02-21 12:46:14 +00:00
|
|
|
struct Hrtf *hrtf = NULL;
|
|
|
|
const HrtfEntry *iter;
|
2016-08-31 15:16:49 +00:00
|
|
|
struct FileMapping fmap;
|
2015-10-06 07:23:11 +00:00
|
|
|
const char *name;
|
2016-02-24 12:21:03 +00:00
|
|
|
const char *ext;
|
2015-10-06 11:01:53 +00:00
|
|
|
int i;
|
2015-10-06 07:23:11 +00:00
|
|
|
|
2016-07-25 04:59:02 +00:00
|
|
|
#define MATCH_FNAME(i) (al_string_cmp_cstr(*filename, (i)->hrtf->filename) == 0)
|
|
|
|
VECTOR_FIND_IF(iter, const HrtfEntry, *list, MATCH_FNAME);
|
|
|
|
if(iter != VECTOR_END(*list))
|
|
|
|
{
|
|
|
|
TRACE("Skipping duplicate file entry %s\n", al_string_get_cstr(*filename));
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
#undef MATCH_FNAME
|
|
|
|
|
2015-10-06 11:01:53 +00:00
|
|
|
entry.hrtf = LoadedHrtfs;
|
|
|
|
while(entry.hrtf)
|
|
|
|
{
|
2016-02-20 13:32:42 +00:00
|
|
|
if(al_string_cmp_cstr(*filename, entry.hrtf->filename) == 0)
|
2016-02-21 12:46:14 +00:00
|
|
|
{
|
2016-07-25 04:59:02 +00:00
|
|
|
TRACE("Skipping load of already-loaded file %s\n", al_string_get_cstr(*filename));
|
|
|
|
goto skip_load;
|
2016-02-21 12:46:14 +00:00
|
|
|
}
|
2015-10-06 11:01:53 +00:00
|
|
|
entry.hrtf = entry.hrtf->next;
|
|
|
|
}
|
|
|
|
|
2016-02-21 12:46:14 +00:00
|
|
|
TRACE("Loading %s...\n", al_string_get_cstr(*filename));
|
2016-08-31 15:16:49 +00:00
|
|
|
fmap = MapFileToMem(al_string_get_cstr(*filename));
|
|
|
|
if(fmap.ptr == NULL)
|
2015-10-06 11:01:53 +00:00
|
|
|
{
|
2016-02-21 12:46:14 +00:00
|
|
|
ERR("Could not open %s\n", al_string_get_cstr(*filename));
|
|
|
|
goto done;
|
|
|
|
}
|
2015-10-06 11:01:53 +00:00
|
|
|
|
2016-08-31 15:16:49 +00:00
|
|
|
if(fmap.len < sizeof(magicMarker01))
|
|
|
|
ERR("%s data is too short ("SZFMT" bytes)\n", al_string_get_cstr(*filename), fmap.len);
|
|
|
|
else if(memcmp(fmap.ptr, magicMarker01, sizeof(magicMarker01)) == 0)
|
2016-02-21 12:46:14 +00:00
|
|
|
{
|
2016-08-31 15:16:49 +00:00
|
|
|
TRACE("Detected data set format v1\n");
|
|
|
|
hrtf = LoadHrtf01((const ALubyte*)fmap.ptr+sizeof(magicMarker01),
|
|
|
|
fmap.len-sizeof(magicMarker01), *filename
|
|
|
|
);
|
2016-02-21 12:46:14 +00:00
|
|
|
}
|
2016-08-31 15:16:49 +00:00
|
|
|
else if(memcmp(fmap.ptr, magicMarker00, sizeof(magicMarker00)) == 0)
|
|
|
|
{
|
|
|
|
TRACE("Detected data set format v0\n");
|
|
|
|
hrtf = LoadHrtf00((const ALubyte*)fmap.ptr+sizeof(magicMarker00),
|
|
|
|
fmap.len-sizeof(magicMarker00), *filename
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ERR("Invalid header in %s: \"%.8s\"\n", al_string_get_cstr(*filename), (const char*)fmap.ptr);
|
|
|
|
UnmapFileMem(&fmap);
|
2015-10-06 11:01:53 +00:00
|
|
|
|
2016-02-21 12:46:14 +00:00
|
|
|
if(!hrtf)
|
|
|
|
{
|
|
|
|
ERR("Failed to load %s\n", al_string_get_cstr(*filename));
|
|
|
|
goto done;
|
2015-10-06 11:01:53 +00:00
|
|
|
}
|
|
|
|
|
2016-02-21 12:46:14 +00:00
|
|
|
hrtf->next = LoadedHrtfs;
|
|
|
|
LoadedHrtfs = hrtf;
|
|
|
|
TRACE("Loaded HRTF support for format: %s %uhz\n",
|
|
|
|
DevFmtChannelsString(DevFmtStereo), hrtf->sampleRate);
|
|
|
|
entry.hrtf = hrtf;
|
|
|
|
|
2016-07-25 04:59:02 +00:00
|
|
|
skip_load:
|
2015-10-06 11:01:53 +00:00
|
|
|
/* TODO: Get a human-readable name from the HRTF data (possibly coming in a
|
2015-10-06 07:23:11 +00:00
|
|
|
* format update). */
|
2016-09-02 04:05:24 +00:00
|
|
|
name = strrchr(al_string_get_cstr(*filename), '/');
|
|
|
|
if(!name) name = strrchr(al_string_get_cstr(*filename), '\\');
|
|
|
|
if(!name) name = al_string_get_cstr(*filename);
|
|
|
|
else ++name;
|
|
|
|
|
2016-02-24 12:21:03 +00:00
|
|
|
ext = strrchr(name, '.');
|
2015-10-06 07:23:11 +00:00
|
|
|
|
2015-10-06 11:01:53 +00:00
|
|
|
i = 0;
|
2015-10-06 07:23:11 +00:00
|
|
|
do {
|
2016-02-24 12:21:03 +00:00
|
|
|
if(!ext)
|
|
|
|
al_string_copy_cstr(&entry.name, name);
|
|
|
|
else
|
2016-02-24 12:53:32 +00:00
|
|
|
al_string_copy_range(&entry.name, name, ext);
|
2015-10-06 07:23:11 +00:00
|
|
|
if(i != 0)
|
|
|
|
{
|
|
|
|
char str[64];
|
|
|
|
snprintf(str, sizeof(str), " #%d", i+1);
|
|
|
|
al_string_append_cstr(&entry.name, str);
|
|
|
|
}
|
|
|
|
++i;
|
|
|
|
|
|
|
|
#define MATCH_NAME(i) (al_string_cmp(entry.name, (i)->name) == 0)
|
2016-02-21 12:46:14 +00:00
|
|
|
VECTOR_FIND_IF(iter, const HrtfEntry, *list, MATCH_NAME);
|
2015-10-06 07:23:11 +00:00
|
|
|
#undef MATCH_NAME
|
2016-04-15 19:22:54 +00:00
|
|
|
} while(iter != VECTOR_END(*list));
|
2015-10-06 07:23:11 +00:00
|
|
|
|
|
|
|
TRACE("Adding entry \"%s\" from file \"%s\"\n", al_string_get_cstr(entry.name),
|
2016-02-20 13:32:42 +00:00
|
|
|
al_string_get_cstr(*filename));
|
2015-10-06 07:23:11 +00:00
|
|
|
VECTOR_PUSH_BACK(*list, entry);
|
|
|
|
|
2016-02-21 12:46:14 +00:00
|
|
|
done:
|
2016-02-20 13:32:42 +00:00
|
|
|
al_string_deinit(filename);
|
2015-10-06 07:23:11 +00:00
|
|
|
}
|
|
|
|
|
2016-08-31 15:16:49 +00:00
|
|
|
/* Unfortunate that we have to duplicate AddFileEntry to take a memory buffer
|
|
|
|
* for input instead of opening the given filename.
|
2016-07-13 02:02:19 +00:00
|
|
|
*/
|
|
|
|
static void AddBuiltInEntry(vector_HrtfEntry *list, const ALubyte *data, size_t datalen, al_string *filename)
|
|
|
|
{
|
|
|
|
HrtfEntry entry = { AL_STRING_INIT_STATIC(), NULL };
|
|
|
|
struct Hrtf *hrtf = NULL;
|
|
|
|
const HrtfEntry *iter;
|
|
|
|
int i;
|
|
|
|
|
2016-07-25 04:59:02 +00:00
|
|
|
#define MATCH_FNAME(i) (al_string_cmp_cstr(*filename, (i)->hrtf->filename) == 0)
|
|
|
|
VECTOR_FIND_IF(iter, const HrtfEntry, *list, MATCH_FNAME);
|
|
|
|
if(iter != VECTOR_END(*list))
|
|
|
|
{
|
|
|
|
TRACE("Skipping duplicate file entry %s\n", al_string_get_cstr(*filename));
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
#undef MATCH_FNAME
|
|
|
|
|
2016-07-13 02:02:19 +00:00
|
|
|
entry.hrtf = LoadedHrtfs;
|
|
|
|
while(entry.hrtf)
|
|
|
|
{
|
|
|
|
if(al_string_cmp_cstr(*filename, entry.hrtf->filename) == 0)
|
|
|
|
{
|
2016-07-25 04:59:02 +00:00
|
|
|
TRACE("Skipping load of already-loaded file %s\n", al_string_get_cstr(*filename));
|
|
|
|
goto skip_load;
|
2016-07-13 02:02:19 +00:00
|
|
|
}
|
|
|
|
entry.hrtf = entry.hrtf->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("Loading %s...\n", al_string_get_cstr(*filename));
|
|
|
|
if(datalen < sizeof(magicMarker01))
|
|
|
|
{
|
|
|
|
ERR("%s data is too short ("SZFMT" bytes)\n", al_string_get_cstr(*filename), datalen);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(memcmp(data, magicMarker01, sizeof(magicMarker01)) == 0)
|
|
|
|
{
|
|
|
|
TRACE("Detected data set format v1\n");
|
2016-08-31 15:16:49 +00:00
|
|
|
hrtf = LoadHrtf01(data+sizeof(magicMarker01),
|
|
|
|
datalen-sizeof(magicMarker01), *filename
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else if(memcmp(data, magicMarker00, sizeof(magicMarker00)) == 0)
|
|
|
|
{
|
|
|
|
TRACE("Detected data set format v0\n");
|
|
|
|
hrtf = LoadHrtf00(data+sizeof(magicMarker00),
|
|
|
|
datalen-sizeof(magicMarker00), *filename
|
2016-07-13 02:02:19 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ERR("Invalid header in %s: \"%.8s\"\n", al_string_get_cstr(*filename), data);
|
|
|
|
|
|
|
|
if(!hrtf)
|
|
|
|
{
|
|
|
|
ERR("Failed to load %s\n", al_string_get_cstr(*filename));
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
hrtf->next = LoadedHrtfs;
|
|
|
|
LoadedHrtfs = hrtf;
|
|
|
|
TRACE("Loaded HRTF support for format: %s %uhz\n",
|
|
|
|
DevFmtChannelsString(DevFmtStereo), hrtf->sampleRate);
|
|
|
|
entry.hrtf = hrtf;
|
|
|
|
|
2016-07-25 04:59:02 +00:00
|
|
|
skip_load:
|
2016-07-13 02:02:19 +00:00
|
|
|
i = 0;
|
|
|
|
do {
|
|
|
|
al_string_copy(&entry.name, *filename);
|
|
|
|
if(i != 0)
|
|
|
|
{
|
|
|
|
char str[64];
|
|
|
|
snprintf(str, sizeof(str), " #%d", i+1);
|
|
|
|
al_string_append_cstr(&entry.name, str);
|
|
|
|
}
|
|
|
|
++i;
|
|
|
|
|
|
|
|
#define MATCH_NAME(i) (al_string_cmp(entry.name, (i)->name) == 0)
|
|
|
|
VECTOR_FIND_IF(iter, const HrtfEntry, *list, MATCH_NAME);
|
|
|
|
#undef MATCH_NAME
|
|
|
|
} while(iter != VECTOR_END(*list));
|
|
|
|
|
|
|
|
TRACE("Adding built-in entry \"%s\"\n", al_string_get_cstr(entry.name));
|
|
|
|
VECTOR_PUSH_BACK(*list, entry);
|
|
|
|
|
|
|
|
done:
|
|
|
|
al_string_deinit(filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef ALSOFT_EMBED_HRTF_DATA
|
2016-11-10 20:37:07 +00:00
|
|
|
#define IDR_DEFAULT_44100_MHR 1
|
|
|
|
#define IDR_DEFAULT_48000_MHR 2
|
2016-07-13 02:02:19 +00:00
|
|
|
|
|
|
|
static const ALubyte *GetResource(int UNUSED(name), size_t *size)
|
|
|
|
{
|
|
|
|
*size = 0;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
#include "hrtf_res.h"
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
static const ALubyte *GetResource(int name, size_t *size)
|
|
|
|
{
|
|
|
|
HMODULE handle;
|
|
|
|
HGLOBAL res;
|
|
|
|
HRSRC rc;
|
|
|
|
|
|
|
|
GetModuleHandleExW(
|
|
|
|
GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT | GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
|
|
|
|
(LPCWSTR)GetResource, &handle
|
|
|
|
);
|
|
|
|
rc = FindResourceW(handle, MAKEINTRESOURCEW(name), MAKEINTRESOURCEW(MHRTYPE));
|
|
|
|
res = LoadResource(handle, rc);
|
|
|
|
|
|
|
|
*size = SizeofResource(handle, rc);
|
|
|
|
return LockResource(res);
|
|
|
|
}
|
|
|
|
|
2016-11-11 05:51:45 +00:00
|
|
|
#elif defined(__APPLE__)
|
|
|
|
|
|
|
|
#include <Availability.h>
|
|
|
|
#include <mach-o/getsect.h>
|
2016-11-11 21:14:02 +00:00
|
|
|
#include <mach-o/ldsyms.h>
|
2016-11-11 05:51:45 +00:00
|
|
|
|
|
|
|
static const ALubyte *GetResource(int name, size_t *size)
|
|
|
|
{
|
|
|
|
#if defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && (__MAC_OS_X_VERSION_MAX_ALLOWED >= 1070)
|
2016-11-11 21:14:02 +00:00
|
|
|
/* NOTE: OSX 10.7 and up need to call getsectiondata(&_mh_dylib_header, ...). However, that
|
2016-11-11 05:51:45 +00:00
|
|
|
* call requires 10.7.
|
|
|
|
*/
|
|
|
|
if(name == IDR_DEFAULT_44100_MHR)
|
2016-11-11 21:14:02 +00:00
|
|
|
return getsectiondata(&_mh_dylib_header, "binary", "default_44100", size);
|
2016-11-11 05:51:45 +00:00
|
|
|
if(name == IDR_DEFAULT_48000_MHR)
|
2016-11-11 21:14:02 +00:00
|
|
|
return getsectiondata(&_mh_dylib_header, "binary", "default_48000", size);
|
2016-11-11 05:51:45 +00:00
|
|
|
#else
|
|
|
|
if(name == IDR_DEFAULT_44100_MHR)
|
2016-11-11 21:14:02 +00:00
|
|
|
return getsectdata("binary", "default_44100", size);
|
2016-11-11 05:51:45 +00:00
|
|
|
if(name == IDR_DEFAULT_48000_MHR)
|
2016-11-11 21:14:02 +00:00
|
|
|
return getsectdata("binary", "default_48000", size);
|
2016-11-11 05:51:45 +00:00
|
|
|
#endif
|
|
|
|
*size = 0;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-07-13 02:02:19 +00:00
|
|
|
#else
|
|
|
|
|
|
|
|
extern const ALubyte _binary_default_44100_mhr_start[] HIDDEN_DECL;
|
|
|
|
extern const ALubyte _binary_default_44100_mhr_end[] HIDDEN_DECL;
|
|
|
|
extern const ALubyte _binary_default_44100_mhr_size[] HIDDEN_DECL;
|
|
|
|
|
|
|
|
extern const ALubyte _binary_default_48000_mhr_start[] HIDDEN_DECL;
|
|
|
|
extern const ALubyte _binary_default_48000_mhr_end[] HIDDEN_DECL;
|
|
|
|
extern const ALubyte _binary_default_48000_mhr_size[] HIDDEN_DECL;
|
|
|
|
|
|
|
|
static const ALubyte *GetResource(int name, size_t *size)
|
|
|
|
{
|
|
|
|
if(name == IDR_DEFAULT_44100_MHR)
|
|
|
|
{
|
|
|
|
/* Make sure all symbols are referenced, to ensure the compiler won't
|
|
|
|
* ignore the declarations and lose the visibility attribute used to
|
|
|
|
* hide them (would be nice if ld or objcopy could automatically mark
|
|
|
|
* them as hidden when generating them, but apparently they can't).
|
|
|
|
*/
|
|
|
|
const void *volatile ptr =_binary_default_44100_mhr_size;
|
|
|
|
(void)ptr;
|
|
|
|
*size = _binary_default_44100_mhr_end - _binary_default_44100_mhr_start;
|
|
|
|
return _binary_default_44100_mhr_start;
|
|
|
|
}
|
|
|
|
if(name == IDR_DEFAULT_48000_MHR)
|
|
|
|
{
|
|
|
|
const void *volatile ptr =_binary_default_48000_mhr_size;
|
|
|
|
(void)ptr;
|
|
|
|
*size = _binary_default_48000_mhr_end - _binary_default_48000_mhr_start;
|
|
|
|
return _binary_default_48000_mhr_start;
|
|
|
|
}
|
|
|
|
*size = 0;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2015-10-06 07:23:11 +00:00
|
|
|
vector_HrtfEntry EnumerateHrtf(const_al_string devname)
|
|
|
|
{
|
|
|
|
vector_HrtfEntry list = VECTOR_INIT_STATIC();
|
2016-02-21 10:44:02 +00:00
|
|
|
const char *defaulthrtf = "";
|
2016-02-23 18:54:42 +00:00
|
|
|
const char *pathlist = "";
|
|
|
|
bool usedefaults = true;
|
2015-10-06 07:23:11 +00:00
|
|
|
|
2016-02-23 18:54:42 +00:00
|
|
|
if(ConfigValueStr(al_string_get_cstr(devname), NULL, "hrtf-paths", &pathlist))
|
2015-10-06 07:23:11 +00:00
|
|
|
{
|
2016-02-23 18:54:42 +00:00
|
|
|
while(pathlist && *pathlist)
|
2015-10-06 07:23:11 +00:00
|
|
|
{
|
|
|
|
const char *next, *end;
|
|
|
|
|
2016-02-23 18:54:42 +00:00
|
|
|
while(isspace(*pathlist) || *pathlist == ',')
|
|
|
|
pathlist++;
|
|
|
|
if(*pathlist == '\0')
|
|
|
|
continue;
|
|
|
|
|
|
|
|
next = strchr(pathlist, ',');
|
|
|
|
if(next)
|
2015-10-06 07:23:11 +00:00
|
|
|
end = next++;
|
2016-02-23 18:54:42 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
end = pathlist + strlen(pathlist);
|
|
|
|
usedefaults = false;
|
|
|
|
}
|
2015-10-06 07:23:11 +00:00
|
|
|
|
2016-02-23 18:54:42 +00:00
|
|
|
while(end != pathlist && isspace(*(end-1)))
|
2015-10-06 07:23:11 +00:00
|
|
|
--end;
|
2016-02-23 18:54:42 +00:00
|
|
|
if(end != pathlist)
|
2015-10-06 07:23:11 +00:00
|
|
|
{
|
2016-02-23 18:54:42 +00:00
|
|
|
al_string pname = AL_STRING_INIT_STATIC();
|
2015-10-06 07:23:11 +00:00
|
|
|
vector_al_string flist;
|
|
|
|
|
2016-02-23 18:54:42 +00:00
|
|
|
al_string_append_range(&pname, pathlist, end);
|
2015-10-06 07:23:11 +00:00
|
|
|
|
2016-02-23 18:54:42 +00:00
|
|
|
flist = SearchDataFiles(".mhr", al_string_get_cstr(pname));
|
2015-10-06 07:23:11 +00:00
|
|
|
VECTOR_FOR_EACH_PARAMS(al_string, flist, AddFileEntry, &list);
|
|
|
|
VECTOR_DEINIT(flist);
|
|
|
|
|
2016-02-23 18:54:42 +00:00
|
|
|
al_string_deinit(&pname);
|
2015-10-06 07:23:11 +00:00
|
|
|
}
|
|
|
|
|
2016-02-23 18:54:42 +00:00
|
|
|
pathlist = next;
|
2015-10-06 07:23:11 +00:00
|
|
|
}
|
|
|
|
}
|
2016-02-23 18:54:42 +00:00
|
|
|
else if(ConfigValueExists(al_string_get_cstr(devname), NULL, "hrtf_tables"))
|
|
|
|
ERR("The hrtf_tables option is deprecated, please use hrtf-paths instead.\n");
|
|
|
|
|
|
|
|
if(usedefaults)
|
|
|
|
{
|
2016-07-13 02:02:19 +00:00
|
|
|
vector_al_string flist;
|
|
|
|
const ALubyte *rdata;
|
|
|
|
size_t rsize;
|
|
|
|
|
|
|
|
flist = SearchDataFiles(".mhr", "openal/hrtf");
|
2016-02-23 18:54:42 +00:00
|
|
|
VECTOR_FOR_EACH_PARAMS(al_string, flist, AddFileEntry, &list);
|
|
|
|
VECTOR_DEINIT(flist);
|
2016-07-13 02:02:19 +00:00
|
|
|
|
|
|
|
rdata = GetResource(IDR_DEFAULT_44100_MHR, &rsize);
|
|
|
|
if(rdata != NULL && rsize > 0)
|
|
|
|
{
|
|
|
|
al_string ename = AL_STRING_INIT_STATIC();
|
|
|
|
al_string_copy_cstr(&ename, "Built-In 44100hz");
|
|
|
|
AddBuiltInEntry(&list, rdata, rsize, &ename);
|
|
|
|
}
|
|
|
|
|
|
|
|
rdata = GetResource(IDR_DEFAULT_48000_MHR, &rsize);
|
|
|
|
if(rdata != NULL && rsize > 0)
|
|
|
|
{
|
|
|
|
al_string ename = AL_STRING_INIT_STATIC();
|
|
|
|
al_string_copy_cstr(&ename, "Built-In 48000hz");
|
|
|
|
AddBuiltInEntry(&list, rdata, rsize, &ename);
|
|
|
|
}
|
2016-02-23 18:54:42 +00:00
|
|
|
}
|
2015-10-06 07:23:11 +00:00
|
|
|
|
2016-02-23 14:52:13 +00:00
|
|
|
if(VECTOR_SIZE(list) > 1 && ConfigValueStr(al_string_get_cstr(devname), NULL, "default-hrtf", &defaulthrtf))
|
2016-02-21 10:44:02 +00:00
|
|
|
{
|
|
|
|
const HrtfEntry *iter;
|
|
|
|
/* Find the preferred HRTF and move it to the front of the list. */
|
|
|
|
#define FIND_ENTRY(i) (al_string_cmp_cstr((i)->name, defaulthrtf) == 0)
|
|
|
|
VECTOR_FIND_IF(iter, const HrtfEntry, list, FIND_ENTRY);
|
2016-09-10 14:55:33 +00:00
|
|
|
#undef FIND_ENTRY
|
|
|
|
if(iter == VECTOR_END(list))
|
|
|
|
WARN("Failed to find default HRTF \"%s\"\n", defaulthrtf);
|
|
|
|
else if(iter != VECTOR_BEGIN(list))
|
2016-02-21 10:44:02 +00:00
|
|
|
{
|
|
|
|
HrtfEntry entry = *iter;
|
|
|
|
memmove(&VECTOR_ELEM(list,1), &VECTOR_ELEM(list,0),
|
2016-04-15 19:22:54 +00:00
|
|
|
(iter-VECTOR_BEGIN(list))*sizeof(HrtfEntry));
|
2016-02-21 10:44:02 +00:00
|
|
|
VECTOR_ELEM(list,0) = entry;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-06 07:23:11 +00:00
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2015-10-06 11:01:53 +00:00
|
|
|
void FreeHrtfList(vector_HrtfEntry *list)
|
|
|
|
{
|
|
|
|
#define CLEAR_ENTRY(i) do { \
|
|
|
|
al_string_deinit(&(i)->name); \
|
|
|
|
} while(0)
|
|
|
|
VECTOR_FOR_EACH(HrtfEntry, *list, CLEAR_ENTRY);
|
|
|
|
VECTOR_DEINIT(*list);
|
|
|
|
#undef CLEAR_ENTRY
|
|
|
|
}
|
|
|
|
|
2015-10-06 07:23:11 +00:00
|
|
|
|
2012-09-11 08:59:42 +00:00
|
|
|
void FreeHrtfs(void)
|
|
|
|
{
|
2016-02-17 03:56:44 +00:00
|
|
|
struct Hrtf *Hrtf = LoadedHrtfs;
|
|
|
|
LoadedHrtfs = NULL;
|
2012-09-11 08:59:42 +00:00
|
|
|
|
2016-02-17 03:56:44 +00:00
|
|
|
while(Hrtf != NULL)
|
2012-09-11 08:59:42 +00:00
|
|
|
{
|
2016-02-17 03:56:44 +00:00
|
|
|
struct Hrtf *next = Hrtf->next;
|
2016-07-07 17:31:43 +00:00
|
|
|
al_free(Hrtf);
|
2016-02-17 03:56:44 +00:00
|
|
|
Hrtf = next;
|
2011-06-03 08:06:00 +00:00
|
|
|
}
|
2011-09-18 17:09:32 +00:00
|
|
|
}
|