/*############################################################################*/
/*# #*/
/*# PKU HRTF C Library #*/
/*# Date: 10/11/2016 #*/
/*# Author(s): DONG PEI #*/
/*# #*/
/*############################################################################*/
#include "../pku_hrtf_lib.h"
#include "normal/pku_hrtf_20_44100.h"
#include "normal/pku_hrtf_30_44100.h"
#include "normal/pku_hrtf_40_44100.h"
#include "normal/pku_hrtf_50_44100.h"
#include "normal/pku_hrtf_75_44100.h"
#include "normal/pku_hrtf_100_44100.h"
#include "normal/pku_hrtf_130_44100.h"
#include "normal/pku_hrtf_160_44100.h"
unsigned int pku_hrtf_availability(int azimuth, int elevation, int distance, unsigned int samplerate)
{
if(elevation > 90 || elevation < -40)
return 0;
if(azimuth > 360 || azimuth < 0)
return 0;
<<<<<<< .mine
if (distance > 100 || distance < 20)
||||||| .r1432703
if (distance > 160 || distance < 20)
=======
if (distance > 130 || distance < 20)
>>>>>>> .r1487355
return 0;
if(samplerate == 44100)
return FILTERLENGTH;
return 0;
}
unsigned int pku_hrtf_get(int* pAzimuth, int* pElevation, int* pDistance, unsigned int samplerate, short* psLeft, short* psRight, int taps)
{
int nInternalElevation = 0;
int nInternalAzimuth = 0;
int nInternalDistance = 0;
int nAzimuthIndex = 0;
int* pDistanceIndex;
nInternalAzimuth = *pAzimuth;
nInternalDistance = *pDistance;
if (!pku_hrtf_availability(*pAzimuth, *pElevation, *pDistance, samplerate))
return 0;
if ((*pDistance)< 30)
nInternalDistance = 20;
if (30<(*pDistance) && (*pDistance)< 40)
nInternalDistance = 30;
if (40<(*pDistance) && (*pDistance)< 50)
nInternalDistance = 40;
if (50<(*pDistance) && (*pDistance)< 75)
nInternalDistance = 50;
if (75<(*pDistance) && (*pDistance)< 100)
nInternalDistance = 75;
if (100<(*pDistance) && (*pDistance)< 130)
nInternalDistance = 100;
if (130<(*pDistance) && (*pDistance)< 160)
nInternalDistance = 130;
switch (nInternalDistance)
{
case 20: pDistanceIndex = pku_hrtf_filter_20_44; break;
case 30: pDistanceIndex = pku_hrtf_filter_30_44; break;
case 40: pDistanceIndex = pku_hrtf_filter_40_44; break;
case 50: pDistanceIndex = pku_hrtf_filter_50_44; break;
case 75: pDistanceIndex = pku_hrtf_filter_75_44; break;
case 100: pDistanceIndex = pku_hrtf_filter_100_44; break;
case 130: pDistanceIndex = pku_hrtf_filter_130_44; break;
case 160: pDistanceIndex = pku_hrtf_filter_160_44; break;
};
nInternalElevation = *pElevation;
if (-30>nInternalElevation && nInternalElevation>-40)
nInternalElevation = -40;
if (-20>nInternalElevation && nInternalElevation>-30)
nInternalElevation = -30;
if (-10>nInternalElevation && nInternalElevation>-20)
nInternalElevation = -20;
if (0>nInternalElevation && nInternalElevation>-10)
nInternalElevation = -10;
if (10>nInternalElevation && nInternalElevation>0)
nInternalElevation = 0;
if (20>nInternalElevation && nInternalElevation>10)
nInternalElevation = 10;
if (30>nInternalElevation && nInternalElevation>20)
nInternalElevation = 20;
if (40>nInternalElevation && nInternalElevation>30)
nInternalElevation = 30;
if (50>nInternalElevation && nInternalElevation>40)
nInternalElevation = 40;
if (60>nInternalElevation && nInternalElevation>50)
nInternalElevation = 50;
if (70>nInternalElevation && nInternalElevation>60)
nInternalElevation = 60;
if (80>nInternalElevation && nInternalElevation>70)
nInternalElevation = 70;
if (90>nInternalElevation && nInternalElevation>80)
nInternalElevation = 80;
switch (nInternalElevation)
{
case -40: nAzimuthIndex = (int)((nInternalAzimuth / 360.f) * PKU_HRTF_AZI_POSITIONS_10) + PKU_HRTF_AZI_POSITIONS_10*0; break;
case -30: nAzimuthIndex = (int)((nInternalAzimuth / 360.f) * PKU_HRTF_AZI_POSITIONS_10) + PKU_HRTF_AZI_POSITIONS_10 * 1; break;
case -20: nAzimuthIndex = (int)((nInternalAzimuth / 360.f) * PKU_HRTF_AZI_POSITIONS_10) + PKU_HRTF_AZI_POSITIONS_10 * 2; break;
case -10: nAzimuthIndex = (int)((nInternalAzimuth / 360.f) * PKU_HRTF_AZI_POSITIONS_10) + PKU_HRTF_AZI_POSITIONS_10 * 3; break;
case 0: nAzimuthIndex = (int)((nInternalAzimuth / 360.f) * PKU_HRTF_AZI_POSITIONS_5) + PKU_HRTF_AZI_POSITIONS_10 * 4; break;
case 10: nAzimuthIndex = (int)((nInternalAzimuth / 360.f) * PKU_HRTF_AZI_POSITIONS_10) + PKU_HRTF_AZI_POSITIONS_5 + PKU_HRTF_AZI_POSITIONS_10 * 4; break;
case 20: nAzimuthIndex = (int)((nInternalAzimuth / 360.f) * PKU_HRTF_AZI_POSITIONS_10) + PKU_HRTF_AZI_POSITIONS_5 + PKU_HRTF_AZI_POSITIONS_10 * 5; break;
case 30: nAzimuthIndex = (int)((nInternalAzimuth / 360.f) * PKU_HRTF_AZI_POSITIONS_10) + PKU_HRTF_AZI_POSITIONS_5 + PKU_HRTF_AZI_POSITIONS_10 * 6; break;
case 40: nAzimuthIndex = (int)((nInternalAzimuth / 360.f) * PKU_HRTF_AZI_POSITIONS_10) + PKU_HRTF_AZI_POSITIONS_5 + PKU_HRTF_AZI_POSITIONS_10 * 7; break;
case 50: nAzimuthIndex = (int)((nInternalAzimuth / 360.f) * PKU_HRTF_AZI_POSITIONS_10) + PKU_HRTF_AZI_POSITIONS_5 + PKU_HRTF_AZI_POSITIONS_10 * 8; break;
case 60: nAzimuthIndex = (int)((nInternalAzimuth / 360.f) * PKU_HRTF_AZI_POSITIONS_10) + PKU_HRTF_AZI_POSITIONS_5 + PKU_HRTF_AZI_POSITIONS_10 * 9; break;
case 70: nAzimuthIndex = (int)((nInternalAzimuth / 360.f) * PKU_HRTF_AZI_POSITIONS_15) + PKU_HRTF_AZI_POSITIONS_5 + PKU_HRTF_AZI_POSITIONS_10 * 10; break;
case 80: nAzimuthIndex = (int)((nInternalAzimuth / 360.f) * PKU_HRTF_AZI_POSITIONS_30) + PKU_HRTF_AZI_POSITIONS_5 + PKU_HRTF_AZI_POSITIONS_10 * 10 + PKU_HRTF_AZI_POSITIONS_15; break;
case 90: nAzimuthIndex = (int)((nInternalAzimuth / 360.f) * PKU_HRTF_AZI_POSITIONS_360) + PKU_HRTF_AZI_POSITIONS_5 + PKU_HRTF_AZI_POSITIONS_10 * 10 + PKU_HRTF_AZI_POSITIONS_15 + PKU_HRTF_AZI_POSITIONS_30; break;
};
long temp = nAzimuthIndex * FILTERLENGTH * 2;
pDistanceIndex = pDistanceIndex + nAzimuthIndex * FILTERLENGTH * 2;
for(int i = 0; i < FILTERLENGTH; i++)
{
psLeft[i] = *pDistanceIndex;
pDistanceIndex++;
}
for (int i = 0; i < FILTERLENGTH; i++)
{
psRight[i] = *pDistanceIndex;
pDistanceIndex++;
}
return taps;
}
评论0