Skip to content

Commit ae6dbe7

Browse files
committed
Added mysofa_open_advanced method in API
To define neighbors search algorithm angular and radial steps upon SOFA file opening (user controlled loading time optimization)
1 parent 03a73fc commit ae6dbe7

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

src/hrtf/easy.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
*/
1818

19-
static struct MYSOFA_EASY* mysofa_open_default(const char *filename, float samplerate, int *filterlength, int *err, bool applyNorm)
19+
static struct MYSOFA_EASY* mysofa_open_default(const char *filename, float samplerate, int *filterlength, int *err, bool applyNorm, float neighbor_angle_step, float neighbor_radius_step)
2020
{
2121
struct MYSOFA_EASY *easy = malloc(sizeof(struct MYSOFA_EASY));
2222
if(!easy) {
@@ -62,8 +62,8 @@ static struct MYSOFA_EASY* mysofa_open_default(const char *filename, float sampl
6262
return NULL;
6363
}
6464

65-
easy->neighborhood = mysofa_neighborhood_init(easy->hrtf,
66-
easy->lookup);
65+
easy->neighborhood = mysofa_neighborhood_init_withstepdefine(easy->hrtf,
66+
easy->lookup,neighbor_angle_step,neighbor_radius_step);
6767

6868
*filterlength = easy->hrtf->N;
6969

@@ -72,12 +72,17 @@ static struct MYSOFA_EASY* mysofa_open_default(const char *filename, float sampl
7272

7373
MYSOFA_EXPORT struct MYSOFA_EASY* mysofa_open(const char *filename, float samplerate, int *filterlength, int *err)
7474
{
75-
return mysofa_open_default(filename,samplerate,filterlength,err,true);
75+
return mysofa_open_default(filename,samplerate,filterlength,err,true,MYSOFA_DEFAULT_NEIGH_STEP_ANGLE,MYSOFA_DEFAULT_NEIGH_STEP_RADIUS);
7676
}
7777

7878
MYSOFA_EXPORT struct MYSOFA_EASY* mysofa_open_no_norm(const char *filename, float samplerate, int *filterlength, int *err)
7979
{
80-
return mysofa_open_default(filename,samplerate,filterlength,err,false);
80+
return mysofa_open_default(filename,samplerate,filterlength,err,false,MYSOFA_DEFAULT_NEIGH_STEP_ANGLE,MYSOFA_DEFAULT_NEIGH_STEP_RADIUS);
81+
}
82+
83+
MYSOFA_EXPORT struct MYSOFA_EASY* mysofa_open_advanced(const char *filename, float samplerate, int *filterlength, int *err, bool norm, float neighbor_angle_step, float neighbor_radius_step)
84+
{
85+
return mysofa_open_default(filename,samplerate,filterlength,err,norm,neighbor_angle_step,neighbor_radius_step);
8186
}
8287

8388
MYSOFA_EXPORT struct MYSOFA_EASY* mysofa_open_cached(const char *filename, float samplerate, int *filterlength, int *err)

src/hrtf/mysofa.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@
66

77
#ifndef MYSOFA_H_INCLUDED
88
#define MYSOFA_H_INCLUDED
9+
#define MYSOFA_DEFAULT_NEIGH_STEP_ANGLE 0.5
10+
#define MYSOFA_DEFAULT_NEIGH_STEP_RADIUS 0.01
911
#ifdef __cplusplus
1012
extern "C" {
1113
#endif
1214

1315
#include <stdint.h>
16+
#include <stdbool.h>
1417

1518
/** attributes */
1619
struct MYSOFA_ATTRIBUTE {
@@ -102,6 +105,8 @@ extern "C" {
102105

103106
struct MYSOFA_NEIGHBORHOOD *mysofa_neighborhood_init(struct MYSOFA_HRTF *hrtf,
104107
struct MYSOFA_LOOKUP *lookup);
108+
struct MYSOFA_NEIGHBORHOOD *mysofa_neighborhood_init_withstepdefine(struct MYSOFA_HRTF *hrtf,
109+
struct MYSOFA_LOOKUP *lookup,float neighbor_angle_step,float neighbor_radius_step);
105110
int* mysofa_neighborhood(struct MYSOFA_NEIGHBORHOOD *neighborhood, int pos);
106111
void mysofa_neighborhood_free(struct MYSOFA_NEIGHBORHOOD *neighborhood);
107112

@@ -128,6 +133,7 @@ extern "C" {
128133

129134
struct MYSOFA_EASY* mysofa_open(const char *filename, float samplerate, int *filterlength, int *err);
130135
struct MYSOFA_EASY* mysofa_open_no_norm(const char *filename, float samplerate, int *filterlength, int *err);
136+
struct MYSOFA_EASY* mysofa_open_advanced(const char *filename, float samplerate, int *filterlength, int *err, bool norm, float neighbor_angle_step, float neighbor_radius_step);
131137
struct MYSOFA_EASY* mysofa_open_cached(const char *filename, float samplerate, int *filterlength, int *err);
132138
void mysofa_getfilter_short(struct MYSOFA_EASY* easy, float x, float y, float z,
133139
short *IRleft, short *IRright,

src/hrtf/neighbors.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,25 @@
88
#include <stdlib.h>
99
#include <string.h>
1010
#include <stdio.h>
11+
#include <float.h>
1112
#include "mysofa_export.h"
1213
#include "mysofa.h"
1314
#include "tools.h"
1415

1516
MYSOFA_EXPORT struct MYSOFA_NEIGHBORHOOD *mysofa_neighborhood_init(struct MYSOFA_HRTF *hrtf,
1617
struct MYSOFA_LOOKUP *lookup) {
18+
return mysofa_neighborhood_init_withstepdefine(hrtf,lookup,MYSOFA_DEFAULT_NEIGH_STEP_ANGLE,MYSOFA_DEFAULT_NEIGH_STEP_RADIUS);
19+
}
20+
21+
MYSOFA_EXPORT struct MYSOFA_NEIGHBORHOOD *mysofa_neighborhood_init_withstepdefine(struct MYSOFA_HRTF *hrtf,
22+
struct MYSOFA_LOOKUP *lookup,
23+
float angleStep,
24+
float radiusStep) {
1725
int i, index;
1826
float *origin, *test;
1927
float radius, radius2;
2028
float theta, theta2;
2129
float phi, phi2;
22-
float angleStep = 0.5;
23-
float radiusStep = 0.01;
2430

2531
struct MYSOFA_NEIGHBORHOOD *neighbor = malloc(
2632
sizeof(struct MYSOFA_NEIGHBORHOOD));

0 commit comments

Comments
 (0)