Skip to content

Commit 0eea6d5

Browse files
committed
bug fix in tvconv
1 parent 25f6ed3 commit 0eea6d5

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

examples/src/tvconv/tvconv.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ void tvconv_setFiltersAndPositions
240240
)
241241
{
242242
tvconv_data* pData = (tvconv_data*) hTVCnv;
243+
vectorND tmp;
243244

244245
if (pData->codecStatus != CODEC_STATUS_NOT_INITIALISED)
245246
return; /* re-init not required, or already happening */
@@ -263,16 +264,22 @@ void tvconv_setFiltersAndPositions
263264
error = saf_sofa_open(&sofa, pData->sofa_filepath, SAF_SOFA_READER_OPTION_NETCDF);
264265

265266
if(error==SAF_SOFA_OK){
266-
267267
strcpy(pData->progressBarText,"Loading IRs");
268268
pData->progressBar0_1 = 0.5f;
269269

270270
pData->ir_fs = (int)sofa.DataSamplingRate;
271271
pData->ir_length = sofa.DataLengthIR;
272272
pData->nIrChannels = sofa.nReceivers;
273273
pData->nListenerPositions = sofa.nListeners;
274+
274275
/* copy only the first source position, because number of source positions might be incorrect in sofa */
275-
memcpy(pData->sourcePosition, sofa.SourcePosition, sizeof(vectorND));
276+
if(!strcmp(sofa.SourcePositionType, "spherical")){
277+
memcpy(tmp, sofa.SourcePosition, sizeof(vectorND));
278+
unitSph2cart((float*)tmp, 1, 1, pData->sourcePosition);
279+
}
280+
else
281+
memcpy(pData->sourcePosition, sofa.SourcePosition, sizeof(vectorND));
282+
276283

277284
pData->irs = (float**)realloc2d((void**)pData->irs, pData->nListenerPositions, pData->nIrChannels*pData->ir_length, sizeof(float));
278285
int tmp_length = pData->nIrChannels * pData->ir_length;
@@ -347,13 +354,14 @@ int tvconv_getNumIRs(void* const hTVCnv)
347354
int tvconv_getNumListenerPositions(void* const hTVCnv)
348355
{
349356
tvconv_data *pData = (tvconv_data*)(hTVCnv);
350-
return pData->nListenerPositions;
357+
358+
return pData->codecStatus==CODEC_STATUS_INITIALISED ? pData->nListenerPositions : 0;
351359
}
352360

353361
float tvconv_getListenerPosition(void* const hTVCnv, int index, int dim)
354362
{
355363
tvconv_data *pData = (tvconv_data*)(hTVCnv);
356-
return pData->listenerPositions[index][dim];
364+
return pData->codecStatus==CODEC_STATUS_INITIALISED ? pData->listenerPositions[index][dim] : 0.0f;
357365
}
358366

359367
int tvconv_getListenerPositionIdx(void* const hTVCnv)

0 commit comments

Comments
 (0)