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

Resampling methods More...

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

Static Public Member Functions

static float [] FactorUpscaler (float[] samples, int factor, int channels)
 
static float [] Resample (float[] samples, double oldSamplingRate, double newSamplingRate, int channels)
 
static short [] Resample (short[] samples, double oldSamplingRate, double newSamplingRate, int channels)
 

Static Public Attributes

static float [] leftSamples
 

Static Private Member Functions

static float [] float [] rightSamples Resample ((float[] leftSamples, float[] rightSamples) samples, double oldSamplingRate, double newSamplingRate, int channels)
 

Detailed Description

Resampling methods

Definition at line 8 of file LinearInterpolation.cs.

Member Function Documentation

◆ FactorUpscaler()

static float [] BGC.Audio.LinearInterpolation.FactorUpscaler ( float []  samples,
int  factor,
int  channels 
)
inlinestatic

Definition at line 23 of file LinearInterpolation.cs.

Referenced by BGC.Tests.WAVEncodingTests.UpScalingTest().

27  {
28  int inputSampleCount = samples.Length / channels;
29  int outputSampleCount = factor * inputSampleCount;
30  float[] outputSamples = new float[outputSampleCount * channels];
31 
32  for (int chan = 0; chan < channels; chan++)
33  {
34  for (int j = 0; j < inputSampleCount; j++)
35  {
36  outputSamples[factor * j * channels + chan] = samples[j * channels + chan];
37  }
38  }
39 
40  return outputSamples;
41  }
Here is the caller graph for this function:

◆ Resample() [1/3]

static float [] float [] rightSamples BGC.Audio.LinearInterpolation.Resample ( (float[] leftSamples, float[] rightSamples)  samples,
double  oldSamplingRate,
double  newSamplingRate,
int  channels 
)
inlinestaticprivate

Definition at line 10 of file LinearInterpolation.cs.

Referenced by BGC.Audio.WaveEncoding.LoadBGCSimple(), BGC.Audio.WaveEncoding.LoadBGCStream(), BGC.Audio.WaveEncoding.LoadFile(), BGC.Audio.WaveEncoding.LoadPCMFile(), and BGC.Audio.WaveEncoding.LoadStereoFile().

15  {
16  float[] newLeftSamples = Resample(samples.leftSamples, oldSamplingRate, newSamplingRate, 1);
17  float[] newRightSamples = Resample(samples.rightSamples, oldSamplingRate, newSamplingRate, 1);
18 
19  return (newLeftSamples, newRightSamples);
20  }
static float [] float [] rightSamples Resample((float[] leftSamples, float[] rightSamples) samples, double oldSamplingRate, double newSamplingRate, int channels)
Here is the caller graph for this function:

◆ Resample() [2/3]

static float [] BGC.Audio.LinearInterpolation.Resample ( float []  samples,
double  oldSamplingRate,
double  newSamplingRate,
int  channels 
)
inlinestatic

Definition at line 44 of file LinearInterpolation.cs.

49  {
50  //Smaller than 1 when downsampling
51  double rateRatio = newSamplingRate / oldSamplingRate;
52  //Larger than 1 when downsampling
53  double invRateRatio = oldSamplingRate / newSamplingRate;
54 
55  int inputSampleCount = samples.Length / channels;
56  int outputSampleCount = (int)Math.Floor(inputSampleCount * rateRatio);
57  float[] outputSamples = new float[outputSampleCount * channels];
58 
59  double i;
60  int i0;
61  int i1;
62 
63  for (int chan = 0; chan < channels; chan++)
64  {
65  for (int j = 0; j < outputSampleCount; j++)
66  {
67  i = j * invRateRatio;
68  i0 = (int)i;
69  i1 = i0 + 1;
70 
71  outputSamples[j * channels + chan] = (float)((i1 - i) * samples[i0 * channels + chan] + (i - i0) * samples[i1 * channels + chan]);
72  }
73  }
74 
75  return outputSamples;
76  }

◆ Resample() [3/3]

static short [] BGC.Audio.LinearInterpolation.Resample ( short []  samples,
double  oldSamplingRate,
double  newSamplingRate,
int  channels 
)
inlinestatic

Definition at line 78 of file LinearInterpolation.cs.

83  {
84  //Smaller than 1 when downsampling
85  double rateRatio = newSamplingRate / oldSamplingRate;
86  //Larger than 1 when downsampling
87  double invRateRatio = oldSamplingRate / newSamplingRate;
88 
89  int inputSampleCount = samples.Length / channels;
90  int outputSampleCount = (int)Math.Ceiling(inputSampleCount * rateRatio);
91  short[] outputSamples = new short[outputSampleCount * channels];
92 
93  double i;
94  int i0;
95  int i1;
96 
97  for (int chan = 0; chan < channels; chan++)
98  {
99  for (int j = 0; j < outputSampleCount; j++)
100  {
101  i = j * invRateRatio;
102  i0 = (int)i;
103  i1 = i0 + 1;
104 
105  outputSamples[j * channels + chan] = (short)Math.Round((i1 - i) * samples[i0 * channels + chan] + (i - i0) * samples[i1 * channels + chan]);
106  }
107  }
108 
109  return outputSamples;
110  }

Field Documentation

◆ leftSamples

float [] BGC.Audio.LinearInterpolation.leftSamples
static

Definition at line 10 of file LinearInterpolation.cs.


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