Skip to content

Commit

Permalink
Added mysofa_open_advanced method in API
Browse files Browse the repository at this point in the history
To define neighbors search algorithm angular and radial steps
upon SOFA file opening (user controlled loading time optimization)
  • Loading branch information
PyrApple committed Aug 13, 2018
1 parent 03a73fc commit ae6dbe7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
15 changes: 10 additions & 5 deletions src/hrtf/easy.c
Expand Up @@ -16,7 +16,7 @@
*
*/

static struct MYSOFA_EASY* mysofa_open_default(const char *filename, float samplerate, int *filterlength, int *err, bool applyNorm)
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)
{
struct MYSOFA_EASY *easy = malloc(sizeof(struct MYSOFA_EASY));
if(!easy) {
Expand Down Expand Up @@ -62,8 +62,8 @@ static struct MYSOFA_EASY* mysofa_open_default(const char *filename, float sampl
return NULL;
}

easy->neighborhood = mysofa_neighborhood_init(easy->hrtf,
easy->lookup);
easy->neighborhood = mysofa_neighborhood_init_withstepdefine(easy->hrtf,
easy->lookup,neighbor_angle_step,neighbor_radius_step);

*filterlength = easy->hrtf->N;

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

MYSOFA_EXPORT struct MYSOFA_EASY* mysofa_open(const char *filename, float samplerate, int *filterlength, int *err)
{
return mysofa_open_default(filename,samplerate,filterlength,err,true);
return mysofa_open_default(filename,samplerate,filterlength,err,true,MYSOFA_DEFAULT_NEIGH_STEP_ANGLE,MYSOFA_DEFAULT_NEIGH_STEP_RADIUS);
}

MYSOFA_EXPORT struct MYSOFA_EASY* mysofa_open_no_norm(const char *filename, float samplerate, int *filterlength, int *err)
{
return mysofa_open_default(filename,samplerate,filterlength,err,false);
return mysofa_open_default(filename,samplerate,filterlength,err,false,MYSOFA_DEFAULT_NEIGH_STEP_ANGLE,MYSOFA_DEFAULT_NEIGH_STEP_RADIUS);
}

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)
{
return mysofa_open_default(filename,samplerate,filterlength,err,norm,neighbor_angle_step,neighbor_radius_step);
}

MYSOFA_EXPORT struct MYSOFA_EASY* mysofa_open_cached(const char *filename, float samplerate, int *filterlength, int *err)
Expand Down
6 changes: 6 additions & 0 deletions src/hrtf/mysofa.h
Expand Up @@ -6,11 +6,14 @@

#ifndef MYSOFA_H_INCLUDED
#define MYSOFA_H_INCLUDED
#define MYSOFA_DEFAULT_NEIGH_STEP_ANGLE 0.5
#define MYSOFA_DEFAULT_NEIGH_STEP_RADIUS 0.01
#ifdef __cplusplus
extern "C" {
#endif

#include <stdint.h>
#include <stdbool.h>

/** attributes */
struct MYSOFA_ATTRIBUTE {
Expand Down Expand Up @@ -102,6 +105,8 @@ extern "C" {

struct MYSOFA_NEIGHBORHOOD *mysofa_neighborhood_init(struct MYSOFA_HRTF *hrtf,
struct MYSOFA_LOOKUP *lookup);
struct MYSOFA_NEIGHBORHOOD *mysofa_neighborhood_init_withstepdefine(struct MYSOFA_HRTF *hrtf,
struct MYSOFA_LOOKUP *lookup,float neighbor_angle_step,float neighbor_radius_step);
int* mysofa_neighborhood(struct MYSOFA_NEIGHBORHOOD *neighborhood, int pos);
void mysofa_neighborhood_free(struct MYSOFA_NEIGHBORHOOD *neighborhood);

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

struct MYSOFA_EASY* mysofa_open(const char *filename, float samplerate, int *filterlength, int *err);
struct MYSOFA_EASY* mysofa_open_no_norm(const char *filename, float samplerate, int *filterlength, int *err);
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);
struct MYSOFA_EASY* mysofa_open_cached(const char *filename, float samplerate, int *filterlength, int *err);
void mysofa_getfilter_short(struct MYSOFA_EASY* easy, float x, float y, float z,
short *IRleft, short *IRright,
Expand Down
10 changes: 8 additions & 2 deletions src/hrtf/neighbors.c
Expand Up @@ -8,19 +8,25 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <float.h>
#include "mysofa_export.h"
#include "mysofa.h"
#include "tools.h"

MYSOFA_EXPORT struct MYSOFA_NEIGHBORHOOD *mysofa_neighborhood_init(struct MYSOFA_HRTF *hrtf,
struct MYSOFA_LOOKUP *lookup) {
return mysofa_neighborhood_init_withstepdefine(hrtf,lookup,MYSOFA_DEFAULT_NEIGH_STEP_ANGLE,MYSOFA_DEFAULT_NEIGH_STEP_RADIUS);
}

MYSOFA_EXPORT struct MYSOFA_NEIGHBORHOOD *mysofa_neighborhood_init_withstepdefine(struct MYSOFA_HRTF *hrtf,
struct MYSOFA_LOOKUP *lookup,
float angleStep,
float radiusStep) {
int i, index;
float *origin, *test;
float radius, radius2;
float theta, theta2;
float phi, phi2;
float angleStep = 0.5;
float radiusStep = 0.01;

struct MYSOFA_NEIGHBORHOOD *neighbor = malloc(
sizeof(struct MYSOFA_NEIGHBORHOOD));
Expand Down

0 comments on commit ae6dbe7

Please sign in to comment.