Move makemhr's .def loading code to a separate source

This commit is contained in:
Chris Robinson
2019-03-24 19:00:58 -07:00
parent 5e6e738681
commit f392d9c138
7 changed files with 2157 additions and 2078 deletions
+2 -1
View File
@@ -1462,7 +1462,8 @@ IF(ALSOFT_UTILS)
utils/makemhr/loaddef.h
utils/makemhr/loadsofa.cpp
utils/makemhr/loadsofa.h
utils/makemhr/makemhr.cpp)
utils/makemhr/makemhr.cpp
utils/makemhr/makemhr.h)
if(NOT HAVE_GETOPT)
set(MAKEMHR_SRCS ${MAKEMHR_SRCS} utils/getopt.c utils/getopt.h)
endif()
File diff suppressed because it is too large Load Diff
+30
View File
@@ -0,0 +1,30 @@
#ifndef LOADDEF_H
#define LOADDEF_H
#include <stdio.h>
#include "makemhr.h"
// 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)
// 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;
};
void TrSetup(FILE *fp, const char *filename, TokenReaderT *tr);
int ProcessMetrics(TokenReaderT *tr, const uint fftSize, const uint truncSize, HrirDataT *hData);
int ProcessSources(const HeadModelT model, TokenReaderT *tr, HrirDataT *hData);
#endif /* LOADDEF_H */
+4
View File
@@ -0,0 +1,4 @@
#include "mysofa.h"
#include "loadsofa.h"
+6
View File
@@ -0,0 +1,6 @@
#ifndef LOADSOFA_H
#define LOADSOFA_H
#include "makemhr.h"
#endif /* LOADSOFA_H */
+11 -2077
View File
File diff suppressed because it is too large Load Diff
+128
View File
@@ -0,0 +1,128 @@
#ifndef MAKEMHR_H
#define MAKEMHR_H
#include <vector>
#include <complex>
// The maximum path length used when processing filenames.
#define MAX_PATH_LEN (256)
// 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 'distance' from source to listener for each field in
// the definition file.
#define MIN_DISTANCE (0.05)
#define MAX_DISTANCE (2.50)
// 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)
using uint = unsigned int;
/* Complex double type. */
using complex_d = std::complex<double>;
// Head model used for calculating the impulse delays.
enum HeadModelT {
HM_NONE,
HM_DATASET, // Measure the onset from the dataset.
HM_SPHERE // Calculate the onset using a spherical head model.
};
// Sample and channel type enum values.
enum SampleTypeT {
ST_S16 = 0,
ST_S24 = 1
};
// Certain iterations rely on these integer enum values.
enum ChannelTypeT {
CT_NONE = -1,
CT_MONO = 0,
CT_STEREO = 1
};
// Structured HRIR storage for stereo azimuth pairs, elevations, and fields.
struct HrirAzT {
double mAzimuth{0.0};
uint mIndex{0u};
double mDelays[2]{0.0, 0.0};
double *mIrs[2]{nullptr, nullptr};
};
struct HrirEvT {
double mElevation{0.0};
uint mIrCount{0u};
uint mAzCount{0u};
HrirAzT *mAzs{nullptr};
};
struct HrirFdT {
double mDistance{0.0};
uint mIrCount{0u};
uint mEvCount{0u};
uint mEvStart{0u};
HrirEvT *mEvs{nullptr};
};
// The HRIR metrics and data set used when loading, processing, and storing
// the resulting HRTF.
struct HrirDataT {
uint mIrRate{0u};
SampleTypeT mSampleType{ST_S24};
ChannelTypeT mChannelType{CT_NONE};
uint mIrPoints{0u};
uint mFftSize{0u};
uint mIrSize{0u};
double mRadius{0.0};
uint mIrCount{0u};
uint mFdCount{0u};
std::vector<double> mHrirsBase;
std::vector<HrirEvT> mEvsBase;
std::vector<HrirAzT> mAzsBase;
std::vector<HrirFdT> mFds;
};
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);
void MagnitudeResponse(const uint n, const complex_d *in, double *out);
void FftForward(const uint n, complex_d *inout);
void FftInverse(const uint n, complex_d *inout);
// The resampler metrics and FIR filter.
struct ResamplerT {
uint mP, mQ, mM, mL;
std::vector<double> mF;
};
void ResamplerSetup(ResamplerT *rs, const uint srcRate, const uint dstRate);
void ResamplerRun(ResamplerT *rs, const uint inN, const double *in, const uint outN, double *out);
// Performs linear interpolation.
inline double Lerp(const double a, const double b, const double f)
{ return a + f * (b - a); }
#endif /* MAKEMHR_H */