BGC Tools
Public Member Functions | Private Member Functions
BGC.Tests.TestOverlapAdd Class Reference

Public Member Functions

void TestPhaseVocoding ()
 
void TestCarlileShuffler ()
 
void TestNewConvolution ()
 
void TestNewSpatialization ()
 
void TestNewFFTs ()
 

Private Member Functions

void DumpData (float[] data, string name)
 

Detailed Description

Definition at line 12 of file TestOverlapAdd.cs.

Member Function Documentation

◆ DumpData()

void BGC.Tests.TestOverlapAdd.DumpData ( float []  data,
string  name 
)
inlineprivate

Definition at line 243 of file TestOverlapAdd.cs.

244  {
245  using (StreamWriter writer = new StreamWriter($"Stimuli/{name}.csv"))
246  {
247  foreach (float sample in data)
248  {
249  writer.WriteLine(sample.ToString());
250  }
251  }
252  }

◆ TestCarlileShuffler()

void BGC.Tests.TestOverlapAdd.TestCarlileShuffler ( )
inline

Definition at line 72 of file TestOverlapAdd.cs.

References BGC.Audio.WaveEncoding.LoadBGCSimple(), BGC.IO.DataManagement.PathForDataFile(), and BGC.Audio.WaveEncoding.SaveFile().

73  {
74  string baseFile = "000000";
75 
77  filepath: DataManagement.PathForDataFile("Test", $"{baseFile}.wav"),
78  simpleAudioClip: out SimpleAudioClip song);
79 
80  Debug.Log($"Pre RMS: {Mathf.Sqrt(song.Samples.Sum(x => x * x) / song.Samples.Length)} N:{song.Samples.Length}");
81 
82  song = song.CarlileShuffle().Cache();
83 
84  Debug.Log($"Post RMS: {Mathf.Sqrt(song.Samples.Sum(x => x * x) / song.Samples.Length)} N:{song.Samples.Length}");
85 
86  //Write to File
88  filepath: DataManagement.PathForDataFile("Test", $"{baseFile}_Carlile.wav"),
89  channels: song.Channels,
90  samples: song.Samples,
91  overwrite: true);
92 
93  }
static bool LoadBGCSimple(string filepath, out SimpleAudioClip simpleAudioClip)
Loads a WAV file from the filepath as a SimpleAudioClip, returns success.
Definition: WaveEncoding.cs:54
Operations for Loading and Saving WAV files Some documentation on the WAV format is available here: h...
Definition: WaveEncoding.cs:14
static bool SaveFile(string filepath, int channels, float[] samples, bool overwrite=false)
Save the samples passed in as a WAVE file with the specified filepath. Returns success.
static string PathForDataFile(string dataDirectory, string fileName)
Returns the full path for specified datafile in a data directory
Simplest implementation of a samplebuffer-based stream.
Here is the call graph for this function:

◆ TestNewConvolution()

void BGC.Tests.TestOverlapAdd.TestNewConvolution ( )
inline

Definition at line 96 of file TestOverlapAdd.cs.

References BGC.Audio.WaveEncoding.LoadBGCStream(), BGC.IO.DataManagement.PathForDataFile(), and BGC.Audio.WaveEncoding.SaveStream().

97  {
98  string baseFile = "000000";
99 
101  filepath: DataManagement.PathForDataFile("Test", $"{baseFile}.wav"),
102  stream: out IBGCStream stream);
103 
104  Debug.Log($"Pre RMS: {string.Join(", ", stream.CalculateRMS().Select(x => x.ToString()).ToArray())}");
105 
106  {
107 
108  float[] filter1 = new float[150];
109  filter1[25] = 1f;
110 
111 
112  float[] filter2 = new float[150];
113 
114  for (int i = 0; i < 150; i++)
115  {
116  filter2[i] = 1f / Mathf.Sqrt(150);
117  }
118 
119  IBGCStream convolved = stream.MultiConvolve(filter1, filter2);
120 
121 
122  string rms = string.Join(", ", convolved.CalculateRMS().Select(x => x.ToString()).ToArray());
123 
124  Debug.Log($"Post RMS: {rms}");
125 
126  //Write to File
128  filepath: DataManagement.PathForDataFile("Test", $"{baseFile}_Convolved.wav"),
129  stream: convolved,
130  overwrite: true);
131  }
132 
133  {
134  float[] filter1 = new float[150];
135  filter1[25] = 1f / Mathf.Sqrt(2);
136  filter1[26] = 1f / Mathf.Sqrt(2);
137 
138 
139  float[] filter2 = new float[150];
140 
141  for (int i = 0; i < 150; i++)
142  {
143  filter2[i] = 1f / 150f;
144  }
145 
146  IBGCStream convolved = stream.MultiConvolve(filter1, filter2);
147 
148 
149  string rms = string.Join(", ", convolved.CalculateRMS().Select(x => x.ToString()).ToArray());
150 
151  Debug.Log($"Post RMS: {rms}");
152 
153  //Write to File
155  filepath: DataManagement.PathForDataFile("Test", $"{baseFile}_Convolved2.wav"),
156  stream: convolved,
157  overwrite: true);
158  }
159 
160  }
static bool LoadBGCStream(string filepath, out IBGCStream stream)
Loads a WAV file from the filepath as a SimpleAudioClip, returns success.
Definition: WaveEncoding.cs:32
Operations for Loading and Saving WAV files Some documentation on the WAV format is available here: h...
Definition: WaveEncoding.cs:14
static string PathForDataFile(string dataDirectory, string fileName)
Returns the full path for specified datafile in a data directory
static bool SaveStream(string filepath, IBGCStream stream, bool overwrite=false)
Save the samples passed in as a WAVE file with the specified filepath. Returns success.
Here is the call graph for this function:

◆ TestNewFFTs()

void BGC.Tests.TestOverlapAdd.TestNewFFTs ( )
inline

Definition at line 218 of file TestOverlapAdd.cs.

References BGC.Mathematics.Fourier.Forward(), and BGC.Mathematics.Fourier.Inverse().

219  {
220  Complex32[] samples = new Complex32[1000];
221 
222  for (int i = 0; i < samples.Length; i++)
223  {
224  samples[i] = 1f;
225  }
226 
227  Fourier.Forward(samples);
228 
229  for (int i = 0; i < 10; i++)
230  {
231  Debug.Log($"{i}: {samples[i]}");
232  }
233 
234  Fourier.Inverse(samples);
235 
236  for (int i = 0; i < 10; i++)
237  {
238  Debug.Log($"{i}: {samples[i]}");
239  }
240  }
Represents a complex number with single-precision floating point components
Definition: Complex32.cs:41
Support for Fourier Transforms. Borrows heavily from Mathnet.Numerics.
Definition: Fourier.cs:41
static void Inverse(Complex32[] spectrum)
Definition: Fourier.cs:64
static void Forward(Complex32[] samples)
Definition: Fourier.cs:43
Here is the call graph for this function:

◆ TestNewSpatialization()

void BGC.Tests.TestOverlapAdd.TestNewSpatialization ( )
inline

Definition at line 163 of file TestOverlapAdd.cs.

References BGC.Audio.WaveEncoding.LoadBGCStream(), BGC.IO.DataManagement.PathForDataFile(), and BGC.Audio.WaveEncoding.SaveStream().

164  {
165  string baseFile = "000000";
166 
168  filepath: DataManagement.PathForDataFile("Test", $"{baseFile}.wav"),
169  stream: out IBGCStream stream);
170 
171  Debug.Log($"Pre RMS: {string.Join(", ", stream.CalculateRMS().Select(x => x.ToString()).ToArray())}");
172 
173  {
174  IBGCStream spatialized = stream.Spatialize(0f);
175 
176  string rms = string.Join(", ", spatialized.CalculateRMS().Select(x => x.ToString()).ToArray());
177 
178  Debug.Log($"Post RMS: {rms}");
179 
180  //Write to File
182  filepath: DataManagement.PathForDataFile("Test", $"{baseFile}_Spatialized_0.wav"),
183  stream: spatialized,
184  overwrite: true);
185  }
186 
187  {
188  IBGCStream spatialized = stream.Spatialize(25f);
189 
190  string rms = string.Join(", ", spatialized.CalculateRMS().Select(x => x.ToString()).ToArray());
191 
192  Debug.Log($"Post RMS: {rms}");
193 
194  //Write to File
196  filepath: DataManagement.PathForDataFile("Test", $"{baseFile}_Spatialized_25.wav"),
197  stream: spatialized,
198  overwrite: true);
199  }
200 
201  {
202  IBGCStream spatialized = stream.Spatialize(-25f);
203 
204  string rms = string.Join(", ", spatialized.CalculateRMS().Select(x => x.ToString()).ToArray());
205 
206  Debug.Log($"Post RMS: {rms}");
207 
208  //Write to File
210  filepath: DataManagement.PathForDataFile("Test", $"{baseFile}_Spatialized_n25.wav"),
211  stream: spatialized,
212  overwrite: true);
213  }
214 
215  }
static bool LoadBGCStream(string filepath, out IBGCStream stream)
Loads a WAV file from the filepath as a SimpleAudioClip, returns success.
Definition: WaveEncoding.cs:32
Operations for Loading and Saving WAV files Some documentation on the WAV format is available here: h...
Definition: WaveEncoding.cs:14
static string PathForDataFile(string dataDirectory, string fileName)
Returns the full path for specified datafile in a data directory
static bool SaveStream(string filepath, IBGCStream stream, bool overwrite=false)
Save the samples passed in as a WAVE file with the specified filepath. Returns success.
Here is the call graph for this function:

◆ TestPhaseVocoding()

void BGC.Tests.TestOverlapAdd.TestPhaseVocoding ( )
inline

Definition at line 15 of file TestOverlapAdd.cs.

References BGC.Audio.SimpleAudioClip.Channels, BGC.Audio.WaveEncoding.LoadBGCSimple(), BGC.IO.DataManagement.PathForDataFile(), BGC.Audio.SimpleAudioClip.Samples, and BGC.Audio.WaveEncoding.SaveFile().

16  {
17  //string baseFile = "Boston_HitchARide";
18  string baseFile = "000000";
19 
21  filepath: DataManagement.PathForDataFile("Test", $"{baseFile}.wav"),
22  simpleAudioClip: out SimpleAudioClip song);
23 
24  song = song.Window(10f).Cache();
25 
26  //First, write unmodified
28  filepath: DataManagement.PathForDataFile("Test", $"{baseFile}_Unmodified.wav"),
29  channels: song.Channels,
30  samples: song.Samples,
31  overwrite: true);
32 
33  //Next, Slow it down 5%
34  {
35  SimpleAudioClip slowed_05 = song.PhaseVocode(0.95f).Cache();
36 
37  //Next, write it slowed 5%
39  filepath: DataManagement.PathForDataFile("Test", $"{baseFile}_Slowed_05.wav"),
40  channels: slowed_05.Channels,
41  samples: slowed_05.Samples,
42  overwrite: true);
43  }
44 
45  //Next, Slow it down 25%
46  {
47  SimpleAudioClip slowed_25 = song.PhaseVocode(0.75f).Cache();
48 
49  //Next, write it slowed 5%
51  filepath: DataManagement.PathForDataFile("Test", $"{baseFile}_Slowed_25.wav"),
52  channels: slowed_25.Channels,
53  samples: slowed_25.Samples,
54  overwrite: true);
55  }
56 
57  //Next, Slow it down 50%
58  {
59  SimpleAudioClip slowed_50 = song.PhaseVocode(0.5f).Cache();
60 
61  //Next, write it slowed 5%
63  filepath: DataManagement.PathForDataFile("Test", $"{baseFile}_Slowed_50.wav"),
64  channels: slowed_50.Channels,
65  samples: slowed_50.Samples,
66  overwrite: true);
67  }
68 
69  }
static bool LoadBGCSimple(string filepath, out SimpleAudioClip simpleAudioClip)
Loads a WAV file from the filepath as a SimpleAudioClip, returns success.
Definition: WaveEncoding.cs:54
Operations for Loading and Saving WAV files Some documentation on the WAV format is available here: h...
Definition: WaveEncoding.cs:14
static bool SaveFile(string filepath, int channels, float[] samples, bool overwrite=false)
Save the samples passed in as a WAVE file with the specified filepath. Returns success.
static string PathForDataFile(string dataDirectory, string fileName)
Returns the full path for specified datafile in a data directory
Simplest implementation of a samplebuffer-based stream.
Here is the call graph for this function:

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