Skip to content

Commit e2b2ba2

Browse files
committed
Merge branch 'release/M20190724'
2 parents 7936648 + 69f8c9d commit e2b2ba2

25 files changed

+3352
-622
lines changed

.gitmodules

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@
66
path = 3dti_ResourceManager/third_party_libraries/cereal
77
url = https://github.com/USCiLab/cereal.git
88
branch = master
9+
[submodule "3dti_ResourceManager/third_party_libraries/eigen"]
10+
path = 3dti_ResourceManager/third_party_libraries/eigen
11+
url = https://github.com/eigenteam/eigen-git-mirror.git
12+
branch = master

3dti_ResourceManager/HRTF/HRTFFactory.cpp

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ namespace HRTF
102102

103103
//////////////////////////////////////////////////////////////////////
104104

105-
bool CreateFromSofa(const std::string & sofafile, shared_ptr<Binaural::CListener> listener)
105+
bool CreateFromSofa(const std::string & sofafile, shared_ptr<Binaural::CListener> listener, bool & specifiedDelays)
106106
{
107-
if (LoadHRTFTableFromSOFA(sofafile, listener))
107+
if (LoadHRTFTableFromSOFA(sofafile, listener, specifiedDelays))
108108
{
109109
listener->GetHRTF()->EndSetup();
110110
return true;
@@ -118,9 +118,9 @@ namespace HRTF
118118

119119
//////////////////////////////////////////////////////////////////////
120120

121-
bool Create3DTIFromSofa(const std::string & sofafile, shared_ptr<Binaural::CListener> listener)
121+
bool Create3DTIFromSofa(const std::string & sofafile, shared_ptr<Binaural::CListener> listener, bool & specifiedDelays)
122122
{
123-
if (!LoadHRTFTableFromSOFA(sofafile, listener))
123+
if (!LoadHRTFTableFromSOFA(sofafile, listener, specifiedDelays))
124124
{
125125
SET_RESULT(RESULT_ERROR_UNKNOWN, "Sofa exception creating HRTF, please consider previous messages from the sofa library");
126126
return false;
@@ -130,7 +130,7 @@ namespace HRTF
130130

131131
//////////////////////////////////////////////////////////////////////
132132

133-
bool LoadHRTFTableFromSOFA(const std::string & sofafile, shared_ptr<Binaural::CListener> listener)
133+
bool LoadHRTFTableFromSOFA(const std::string & sofafile, shared_ptr<Binaural::CListener> listener, bool & specifiedDelays)
134134
{
135135
std::ostream & output = std::cout;
136136
try {
@@ -178,6 +178,23 @@ namespace HRTF
178178

179179
// Prepare HRTF
180180
const unsigned int nSamples = (unsigned int)hrir.GetNumDataSamples(); // For example: 512 samples.
181+
182+
if (delays.size() == data.size() / nSamples){
183+
specifiedDelays = true;
184+
}
185+
else {
186+
if (delays.size() == 2)
187+
{
188+
specifiedDelays = false;
189+
SET_RESULT(RESULT_WARNING, "This HRTF file does not contain individual delays for each HRIR. Therefore, some comb filter effect can be perceived due to interpolations and custom head radius should not be used");
190+
}
191+
else
192+
{
193+
SET_RESULT(RESULT_ERROR_BADSIZE, "SOFA gives incoherent number of HRIRs and delays");
194+
return false;
195+
}
196+
}
197+
181198
double distance = pos[array2DIndex(0, 2, nMeasurements, dims[1])]; //We consider that every HRIR are meased at the same distance, so we get the firts one
182199
listener->GetHRTF()->BeginSetup(nSamples, distance);
183200

@@ -192,14 +209,14 @@ namespace HRTF
192209
while (elevation < 0) elevation += 360; // TODO: check who should do this
193210

194211
const int left_ear = 0;
195-
hrir_value.leftDelay = delays[array2DIndex(i, left_ear, nMeasurements, 2)];
212+
hrir_value.leftDelay = delays[specifiedDelays ? array2DIndex(i, left_ear, nMeasurements, 2) : 0];
196213
for (std::size_t k = 0; k < nSamples; k++)
197214
{
198215
const std::size_t index = array3DIndex(i, left_ear, k, nMeasurements, 2, nSamples);
199216
hrir_value.leftHRIR[k] = data[index];
200217
}
201218
const int right_ear = 1;
202-
hrir_value.rightDelay = delays[array2DIndex(i, right_ear, nMeasurements, 2)];
219+
hrir_value.rightDelay = delays[specifiedDelays ? array2DIndex(i, right_ear, nMeasurements, 2) : 1];
203220
for (std::size_t k = 0; k < nSamples; k++)
204221
{
205222
const std::size_t index = array3DIndex(i, right_ear, k, nMeasurements, 2, nSamples);

3dti_ResourceManager/HRTF/HRTFFactory.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ namespace HRTF
4040
* \param [out] listener affected by the hrtf
4141
* \eh On error, an error code is reported to the error handler.
4242
*/
43-
bool CreateFromSofa(const std::string & sofafile, shared_ptr<Binaural::CListener> listener);
43+
bool CreateFromSofa(const std::string & sofafile, shared_ptr<Binaural::CListener> listener, bool & specifiedDelays);
4444

4545
/** \brief Loads an HRTF from SOFA file so a 3DTI file can be created later
4646
* \param [in] path of the sofa file
4747
* \param [out] listener affected by the hrtf
4848
* \eh On error, an error code is reported to the error handler. */
49-
bool Create3DTIFromSofa(const std::string & sofafile, shared_ptr<Binaural::CListener> listener);
49+
bool Create3DTIFromSofa(const std::string & sofafile, shared_ptr<Binaural::CListener> listener, bool & specifiedDelays);
5050

51-
bool LoadHRTFTableFromSOFA(const std::string & sofafile, shared_ptr<Binaural::CListener> listener);
51+
bool LoadHRTFTableFromSOFA(const std::string & sofafile, shared_ptr<Binaural::CListener> listener, bool & specifiedDelays);
5252

5353
//static CHRTF CreateFromListen(const std::vector<std::string> & listenFiles);
5454
};
Submodule eigen added at a1b9c26

3dti_Toolkit/Common/Fprocessor.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,27 @@ namespace Common {
222222
}
223223
}
224224

225+
void CFprocessor::ProcessToPowerPhase(const std::vector<float>& inputBuffer, std::vector<float>& powerBuffer, std::vector<float>& phaseBuffer)
226+
{
227+
ASSERT(inputBuffer.size() > 0, RESULT_ERROR_BADSIZE, "Bad input size", "");
228+
229+
if (inputBuffer.size() > 0) {
230+
231+
powerBuffer.clear();
232+
phaseBuffer.clear();
233+
234+
int end = (int)(inputBuffer.size()*0.5);
235+
236+
for (int i = 0; i < end; i++)
237+
{
238+
float real = inputBuffer[2 * i];
239+
float img = inputBuffer[2 * i + 1];
240+
241+
powerBuffer.push_back(real*real + img*img);
242+
phaseBuffer.push_back(std::atan2(img, real));
243+
}
244+
}
245+
}
225246

226247
void CFprocessor::ProcessToRealImaginary(const std::vector<float>& moduleBuffer, const std::vector<float>& phaseBuffer, std::vector<float>& outputBuffer)
227248
{

3dti_Toolkit/Common/Fprocessor.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,15 @@ namespace Common {
9090
*/
9191
static void ProcessToModulePhase(const std::vector<float>& inputBuffer, std::vector<float>& moduleBuffer, std::vector<float>& phaseBuffer);
9292

93+
/** \brief Process a buffer with complex numbers to get two separated vectors one with the powers and other with the phases.
94+
* \details This method return two vectors with the power and phase of the vector introduced.
95+
* \param [in] inputBuffer Vector of samples that has real and imaginary parts interlaced. inputBuffer[i] = Re[Xj], x[i+1] = Img[Xj]
96+
* \param [out] powerBuffer Vector of real numbers that are the power of the complex numbers. moduleBuffer[i] = inputBuffer[2 * i]^2 * inputBuffer[2 * i + 1]^2
97+
* \param [out] phaseBuffer Vector of real numbers that are the argument of the complex numbers. phaseBuffer [i] = atan(inputBuffer[2 * i + 1] / inputBuffer[2 * i]^2)
98+
* \throws May throw exceptions and errors to debugger
99+
*/
100+
static void ProcessToPowerPhase(const std::vector<float>& inputBuffer, std::vector<float>& powerBuffer, std::vector<float>& phaseBuffer);
101+
93102
/** \brief Process two buffers with module and phase of complex numbers, in order to get a vector with complex numbers in binomial way
94103
* \details This method return one vectors that has real and imaginary parts interlaced. inputBuffer[i] = Re[Xj], x[i+1] = Img[Xj]
95104
* \param [in] moduleBuffer Vector of samples that represents the module of complex numbers.

0 commit comments

Comments
 (0)