@@ -240,6 +240,7 @@ void tvconv_setFiltersAndPositions
240
240
)
241
241
{
242
242
tvconv_data * pData = (tvconv_data * ) hTVCnv ;
243
+ vectorND tmp ;
243
244
244
245
if (pData -> codecStatus != CODEC_STATUS_NOT_INITIALISED )
245
246
return ; /* re-init not required, or already happening */
@@ -263,16 +264,22 @@ void tvconv_setFiltersAndPositions
263
264
error = saf_sofa_open (& sofa , pData -> sofa_filepath , SAF_SOFA_READER_OPTION_NETCDF );
264
265
265
266
if (error == SAF_SOFA_OK ){
266
-
267
267
strcpy (pData -> progressBarText ,"Loading IRs" );
268
268
pData -> progressBar0_1 = 0.5f ;
269
269
270
270
pData -> ir_fs = (int )sofa .DataSamplingRate ;
271
271
pData -> ir_length = sofa .DataLengthIR ;
272
272
pData -> nIrChannels = sofa .nReceivers ;
273
273
pData -> nListenerPositions = sofa .nListeners ;
274
+
274
275
/* 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
+
276
283
277
284
pData -> irs = (float * * )realloc2d ((void * * )pData -> irs , pData -> nListenerPositions , pData -> nIrChannels * pData -> ir_length , sizeof (float ));
278
285
int tmp_length = pData -> nIrChannels * pData -> ir_length ;
@@ -347,13 +354,14 @@ int tvconv_getNumIRs(void* const hTVCnv)
347
354
int tvconv_getNumListenerPositions (void * const hTVCnv )
348
355
{
349
356
tvconv_data * pData = (tvconv_data * )(hTVCnv );
350
- return pData -> nListenerPositions ;
357
+
358
+ return pData -> codecStatus == CODEC_STATUS_INITIALISED ? pData -> nListenerPositions : 0 ;
351
359
}
352
360
353
361
float tvconv_getListenerPosition (void * const hTVCnv , int index , int dim )
354
362
{
355
363
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 ;
357
365
}
358
366
359
367
int tvconv_getListenerPositionIdx (void * const hTVCnv )
0 commit comments