BGC Tools
Static Public Member Functions | Static Private Member Functions | Private Attributes
BGC.Audio.Spatial Class Reference

A collection of common operations related to Spatialization of Audio More...

Collaboration diagram for BGC.Audio.Spatial:
Collaboration graph
[legend]

Static Public Member Functions

static int NearestValidOffset (double offset)
 
static IBGCStream GetFilter (double angle)
 

Static Private Member Functions

static string GetFilterFilename (int position)
 

Private Attributes

const string HRTFDirectory = "HRTF"
 

Detailed Description

A collection of common operations related to Spatialization of Audio

Definition at line 11 of file Spatial.cs.

Member Function Documentation

◆ GetFilter()

static IBGCStream BGC.Audio.Spatial.GetFilter ( double  angle)
inlinestatic

Definition at line 26 of file Spatial.cs.

References BGC.Audio.WaveEncoding.LoadBGCStream().

Referenced by BGC.Audio.BGCStreamExtensions.Spatialize().

27  {
28  int position = NearestValidOffset(angle);
29 
30  string path = GetFilterFilename(position);
31 
32  bool loadSuccess = WaveEncoding.LoadBGCStream(
33  filepath: path,
34  stream: out IBGCStream filter);
35 
36  if (!loadSuccess)
37  {
38  Debug.LogError($"Failed to load impulse response function from path {path}");
39  return null;
40  }
41 
42  return filter;
43  }
static int NearestValidOffset(double offset)
Definition: Spatial.cs:15
static string GetFilterFilename(int position)
Definition: Spatial.cs:45
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetFilterFilename()

static string BGC.Audio.Spatial.GetFilterFilename ( int  position)
inlinestaticprivate

Definition at line 45 of file Spatial.cs.

References BGC.IO.DataManagement.PathForDataFile().

46  {
47  string filePrefix;
48 
49  if (position == 0)
50  {
51  filePrefix = "0";
52  }
53  else
54  {
55  string directionPrefix = (position > 0) ? "pos" : "neg";
56 
57  position = Math.Abs(position);
58 
59  int decimalPlace = position % 10;
60  int integralPlace = position / 10;
61 
62  filePrefix = $"{directionPrefix}{integralPlace}p{decimalPlace}";
63  }
64 
65  return DataManagement.PathForDataFile(HRTFDirectory, $"{filePrefix}_impulse.wav");
66  }
const string HRTFDirectory
Definition: Spatial.cs:13
static string PathForDataFile(string dataDirectory, string fileName)
Returns the full path for specified datafile in a data directory
Here is the call graph for this function:

◆ NearestValidOffset()

static int BGC.Audio.Spatial.NearestValidOffset ( double  offset)
inlinestatic

Definition at line 15 of file Spatial.cs.

References BGC.Mathematics.GeneralMath.Clamp().

16  {
17  if (offset < -90.0 || offset > 90.0)
18  {
19  Debug.LogError($"Spatialization offset ({offset})is outside of bounds [-90.0,90.0]. Clamping.");
20  offset = GeneralMath.Clamp(offset, -90.0, 90.0);
21  }
22 
23  return (int)Math.Round(10.0 * offset);
24  }
static decimal Clamp(decimal value, decimal min, decimal max)
Here is the call graph for this function:

Field Documentation

◆ HRTFDirectory

const string BGC.Audio.Spatial.HRTFDirectory = "HRTF"
private

Definition at line 13 of file Spatial.cs.


The documentation for this class was generated from the following file: