BGC Tools
Public Member Functions | Private Member Functions | Private Attributes
BGC.Tests.SynthesisTests Class Reference
Collaboration diagram for BGC.Tests.SynthesisTests:
Collaboration graph
[legend]

Public Member Functions

void TestSineWave ()
 
void TestSquareWave ()
 
void TestSawtoothWave ()
 
void TestTriangleWave ()
 
void TestBiQuadFilters ()
 
void TestCarrierModifiedFakeVoices ()
 
void TestFunFakeVoice ()
 
void TestFakeVoice ()
 
void TestAllPassFilterSynth ()
 
void TestAllPassFilterSpeech ()
 
void TestFDComposer ()
 
void TestFDComposerPure ()
 
void TestPhaseReEncoder ()
 
void TestSTM ()
 
void SmallSineFMTest ()
 
void SmallAnalyticFMTest ()
 
void FMTestBell ()
 
void FMTestDrum ()
 
void FMTestBrass ()
 
void FMTestPiano ()
 
void FMTestTrianglePiano ()
 
void TestFrequencyShifter ()
 
void SynthTestSnare ()
 
void FMTestOvertones ()
 
void TestFMFilterSynth ()
 
void TestFMFilterVoice ()
 

Private Member Functions

bool TryAllpassFilters (IBGCStream stream, string baseName)
 
bool TryAllPassFilter (IBGCStream stream, in Complex64 coeff, int delay, string name)
 
IEnumerable< double > GetExpFrequencies (double freqLB, double freqUB, int freqCount)
 
bool TryFMParams (IBGCStream stream, string baseName)
 
bool TryFMFilter (IBGCStream stream, float rate, float depth, string name)
 

Private Attributes

const float DURATION = 5f
 
const float LEVEL = 70f
 

Detailed Description

Definition at line 17 of file SynthesisTests.cs.

Member Function Documentation

◆ FMTestBell()

void BGC.Tests.SynthesisTests.FMTestBell ( )
inline

Definition at line 834 of file SynthesisTests.cs.

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

835  {
837 
839  filepath: DataManagement.PathForDataFile("Test", "FMTestBell.wav"),
840  stream: new AnalyticWave(1f, 200f)
841  .FrequencyModulation(280, 10)
842  .ToBGCStream()
843  .ADSR(0.01f, 1.0f, 0.9f, 0.4f)
844  .Window(DURATION, smoothingSamples: 10)
845  .Normalize(LEVEL),
846  overwrite: true);
847  }
static void Initialize()
Definition: Calibration.cs:54
Manages calibration values and processes
Definition: Calibration.cs:13
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:

◆ FMTestBrass()

void BGC.Tests.SynthesisTests.FMTestBrass ( )
inline

Definition at line 866 of file SynthesisTests.cs.

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

867  {
869 
871  filepath: DataManagement.PathForDataFile("Test", "FMTestBrass.wav"),
872  stream: new AnalyticWave(1f, 660)
873  .FrequencyModulation(10, 220)
874  .ToBGCStream()
875  .ADSR(0.25f, 0.25f, 0.8f, 1000f)
876  .Window(DURATION, smoothingSamples: 10)
877  .Normalize(LEVEL),
878  overwrite: true);
879  }
static void Initialize()
Definition: Calibration.cs:54
Manages calibration values and processes
Definition: Calibration.cs:13
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:

◆ FMTestDrum()

void BGC.Tests.SynthesisTests.FMTestDrum ( )
inline

Definition at line 850 of file SynthesisTests.cs.

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

851  {
853 
855  filepath: DataManagement.PathForDataFile("Test", "FMTestDrum.wav"),
856  stream: new AnalyticWave(1f, 80f)
857  .FrequencyModulation(55, 15)
858  .ToBGCStream()
859  .ADSR(0.01f, 0.125f, 1.0f, 0.05f)
860  .Window(1f, smoothingSamples: 10)
861  .Normalize(LEVEL),
862  overwrite: true);
863  }
static void Initialize()
Definition: Calibration.cs:54
Manages calibration values and processes
Definition: Calibration.cs:13
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:

◆ FMTestOvertones()

void BGC.Tests.SynthesisTests.FMTestOvertones ( )
inline

Definition at line 1020 of file SynthesisTests.cs.

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

1021  {
1023 
1025  filepath: DataManagement.PathForDataFile("Test", "FMTestOvertones_010.wav"),
1026  stream: new SineWave(1f, 440)
1027  .Window(DURATION)
1028  .FrequencyModulation(1320, 10)
1029  .Normalize(LEVEL),
1030  overwrite: true);
1031 
1033  filepath: DataManagement.PathForDataFile("Test", "FMTestOvertones_020.wav"),
1034  stream: new SineWave(1f, 440)
1035  .Window(DURATION)
1036  .FrequencyModulation(1320, 20)
1037  .Normalize(LEVEL),
1038  overwrite: true);
1039 
1041  filepath: DataManagement.PathForDataFile("Test", "FMTestOvertones_060.wav"),
1042  stream: new SineWave(1f, 440)
1043  .Window(DURATION)
1044  .FrequencyModulation(1320, 60)
1045  .Normalize(LEVEL),
1046  overwrite: true);
1047  }
static void Initialize()
Definition: Calibration.cs:54
Manages calibration values and processes
Definition: Calibration.cs:13
Operations for Loading and Saving WAV files Some documentation on the WAV format is available here: h...
Definition: WaveEncoding.cs:14
Sine wave stream with specified amplitude, frequency, and initialPhase. One period is cached and the ...
Definition: SineWave.cs:15
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:

◆ FMTestPiano()

void BGC.Tests.SynthesisTests.FMTestPiano ( )
inline

Definition at line 882 of file SynthesisTests.cs.

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

883  {
885 
886  double baseFreq = 440.0;
887 
888  IAnalyticStream noteStream = new AnalyticStreamAdder(
889  new AnalyticWave(1.0, baseFreq),
890  new AnalyticWave(0.5, 3 * baseFreq),
891  new AnalyticWave(0.25, 5 * baseFreq),
892  new AnalyticWave(0.125, 7 * baseFreq));
893 
895  filepath: DataManagement.PathForDataFile("Test", "FMTestPiano.wav"),
896  stream: noteStream
897  .FrequencyModulation(15, 2.5)
898  .ToBGCStream()
899  .ADSR(0.25f, 0.25f, 0.8f, 1f)
900  .Window(DURATION, smoothingSamples: 10)
901  .Normalize(LEVEL),
902  overwrite: true);
903  }
static void Initialize()
Definition: Calibration.cs:54
Manages calibration values and processes
Definition: Calibration.cs:13
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:

◆ FMTestTrianglePiano()

void BGC.Tests.SynthesisTests.FMTestTrianglePiano ( )
inline

Definition at line 906 of file SynthesisTests.cs.

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

907  {
909 
910  float baseFreq = 440.0f;
911 
912  IBGCStream noteStream = new StreamAdder(
913  new TriangleWave(1.0f, baseFreq));
914 
916  filepath: DataManagement.PathForDataFile("Test", "FMTestTrianglePiano.wav"),
917  stream: noteStream
918  .FrequencyModulation(15, 2.5)
919  .ADSR(0.25f, 0.25f, 0.8f, 1f)
920  .Window(DURATION, smoothingSamples: 10)
921  .Normalize(LEVEL),
922  overwrite: true);
923  }
static void Initialize()
Definition: Calibration.cs:54
Manages calibration values and processes
Definition: Calibration.cs:13
Additive Synthesis - Output samples are equal to the linear sum of input samples. ...
Definition: StreamAdder.cs:10
Operations for Loading and Saving WAV files Some documentation on the WAV format is available here: h...
Definition: WaveEncoding.cs:14
Triangle wave stream with specified amplitude, frequency, and duty-cycle.
Definition: TriangleWave.cs:10
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:

◆ GetExpFrequencies()

IEnumerable<double> BGC.Tests.SynthesisTests.GetExpFrequencies ( double  freqLB,
double  freqUB,
int  freqCount 
)
inlineprivate

Definition at line 662 of file SynthesisTests.cs.

663  {
664  double ratio = freqUB / freqLB;
665 
666  for (int i = 0; i < freqCount; i++)
667  {
668  yield return freqLB * Math.Pow(ratio, i / (double)(freqCount - 1));
669  }
670  }

◆ SmallAnalyticFMTest()

void BGC.Tests.SynthesisTests.SmallAnalyticFMTest ( )
inline

Definition at line 798 of file SynthesisTests.cs.

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

799  {
801 
803  filepath: DataManagement.PathForDataFile("Test", $"SmallFM_20Hz.wav"),
804  stream: new AnalyticWave(1f, 440f)
805  .FrequencyModulation(2, 20)
806  .ToBGCStream()
807  .Window(DURATION)
808  .Normalize(LEVEL),
809  overwrite: true);
810 
812  filepath: DataManagement.PathForDataFile("Test", $"SmallFM_00Hz.wav"),
813  stream: new AnalyticWave(1f, 440f)
814  .FrequencyModulation(2, 0)
815  .ToBGCStream()
816  .Window(DURATION)
817  .Normalize(LEVEL),
818  overwrite: true);
819 
820  IAnalyticStream leftStream = new AnalyticWave(1f, 440f)
821  .Window(DURATION)
822  .Fork(out IAnalyticStream rightStream);
823 
824  leftStream = leftStream.FrequencyModulation(2, 20);
825  rightStream = rightStream.FrequencyModulation(2, -20);
826 
828  filepath: DataManagement.PathForDataFile("Test", $"SmallFM_Invr.wav"),
829  stream: new StreamMergeFilter(leftStream.ToBGCStream(), rightStream.ToBGCStream()).Normalize(LEVEL),
830  overwrite: true);
831  }
static void Initialize()
Definition: Calibration.cs:54
Manages calibration values and processes
Definition: Calibration.cs:13
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
Takes multiple streams and applies each to a different channel in the output
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:

◆ SmallSineFMTest()

void BGC.Tests.SynthesisTests.SmallSineFMTest ( )
inline

Definition at line 735 of file SynthesisTests.cs.

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

736  {
738 
739  {
740  //Sine -> FM 2, 20
741  bool success = WaveEncoding.SaveStream(
742  filepath: DataManagement.PathForDataFile("Test", "SineFM_2Hz_p20Hz.wav"),
743  stream: new SineWave(1f, 440f)
744  .Window(DURATION)
745  .FrequencyModulation(2, 20)
746  .Normalize(LEVEL),
747  overwrite: true);
748 
749  Assert.IsTrue(success);
750  }
751 
752  {
753  //Sine -> FM 2, -20
754  bool success = WaveEncoding.SaveStream(
755  filepath: DataManagement.PathForDataFile("Test", "SineFM_2Hz_n20Hz.wav"),
756  stream: new SineWave(1f, 440f)
757  .Window(DURATION)
758  .FrequencyModulation(2, -20)
759  .Normalize(LEVEL),
760  overwrite: true);
761 
762  Assert.IsTrue(success);
763  }
764 
765  {
766  //Sine -> FM 2, 0 (Should be unmodified)
767  bool success = WaveEncoding.SaveStream(
768  filepath: DataManagement.PathForDataFile("Test", "SineFM_2Hz_000Hz.wav"),
769  stream: new SineWave(1f, 440f)
770  .Window(DURATION)
771  .FrequencyModulation(2, 0)
772  .Normalize(LEVEL),
773  overwrite: true);
774 
775  Assert.IsTrue(success);
776  }
777 
778  {
779  //FM Inverted
780  //Sine -> Left(FM 2, 20) + Right(FM 2, -20)
781  IBGCStream leftStream = new SineWave(1f, 440f)
782  .Window(DURATION)
783  .Fork(out IBGCStream rightStream);
784 
785  leftStream = leftStream.FrequencyModulation(2, 20);
786  rightStream = rightStream.FrequencyModulation(2, -20);
787 
788  bool success = WaveEncoding.SaveStream(
789  filepath: DataManagement.PathForDataFile("Test", "SineFM_2Hz_p20Hz_INV.wav"),
790  stream: new StreamMergeFilter(leftStream, rightStream).Normalize(LEVEL),
791  overwrite: true);
792 
793  Assert.IsTrue(success);
794  }
795  }
static void Initialize()
Definition: Calibration.cs:54
Manages calibration values and processes
Definition: Calibration.cs:13
Operations for Loading and Saving WAV files Some documentation on the WAV format is available here: h...
Definition: WaveEncoding.cs:14
Sine wave stream with specified amplitude, frequency, and initialPhase. One period is cached and the ...
Definition: SineWave.cs:15
static string PathForDataFile(string dataDirectory, string fileName)
Returns the full path for specified datafile in a data directory
Takes multiple streams and applies each to a different channel in the output
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:

◆ SynthTestSnare()

void BGC.Tests.SynthesisTests.SynthTestSnare ( )
inline

Definition at line 991 of file SynthesisTests.cs.

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

992  {
993  IBGCStream shiftedTriA =
994  new TriangleWave(1f, 111f)
995  .ToAnalyticStream()
996  .Fork(out IAnalyticStream triOscB)
997  .FrequencyShift(175.0)
998  .ToBGCStream();
999 
1000  IBGCStream shiftedTriB = triOscB.FrequencyShift(224.0)
1001  .ToBGCStream();
1002 
1004  filepath: DataManagement.PathForDataFile("Test", "SnareDrum.wav"),
1005  stream:
1007  new StreamAdder(
1008  shiftedTriA,
1009  shiftedTriB,
1010  new SineWave(0.5, 180.0),
1011  new SineWave(0.5, 330.0))
1012  .ADSR(0.01f, 0.125f, 1.0f, 0.05f)
1013  .Window(0.5f, smoothingSamples: 10),
1014  LEVEL)
1015  .Center(1f),
1016  overwrite: true);
1017  }
Upchannels and scales an underlying single-channel stream to the specified level (dB SPL) ...
Additive Synthesis - Output samples are equal to the linear sum of input samples. ...
Definition: StreamAdder.cs:10
Operations for Loading and Saving WAV files Some documentation on the WAV format is available here: h...
Definition: WaveEncoding.cs:14
Sine wave stream with specified amplitude, frequency, and initialPhase. One period is cached and the ...
Definition: SineWave.cs:15
Triangle wave stream with specified amplitude, frequency, and duty-cycle.
Definition: TriangleWave.cs:10
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:

◆ TestAllPassFilterSpeech()

void BGC.Tests.SynthesisTests.TestAllPassFilterSpeech ( )
inline

Definition at line 481 of file SynthesisTests.cs.

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

482  {
484 
485  string speechFile = DataManagement.PathForDataFile("Test", "000000.wav");
486  if (!File.Exists(speechFile))
487  {
488  throw new Exception($"Test utilizes CRM missing sentence: {speechFile}");
489  }
490 
492  filepath: speechFile,
493  stream: out IBGCStream speechStream);
494 
495  speechStream = speechStream.Center(speechStream.Duration() + 0.4f);
496 
497  bool success = TryAllpassFilters(
498  stream: speechStream,
499  baseName: "CRMS");
500 
501  Assert.IsTrue(success);
502  }
static bool LoadBGCStream(string filepath, out IBGCStream stream)
Loads a WAV file from the filepath as a SimpleAudioClip, returns success.
Definition: WaveEncoding.cs:32
static void Initialize()
Definition: Calibration.cs:54
bool TryAllpassFilters(IBGCStream stream, string baseName)
Manages calibration values and processes
Definition: Calibration.cs:13
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
Here is the call graph for this function:

◆ TestAllPassFilterSynth()

void BGC.Tests.SynthesisTests.TestAllPassFilterSynth ( )
inline

Definition at line 458 of file SynthesisTests.cs.

References BGC.Audio.Calibration.Initialize().

459  {
461 
462  IBGCStream[] synthStreams = new IBGCStream[]
463  {
464  new SineWave(1f, 440f).Window(DURATION),
465  new SquareWave(1f, 440f).Window(DURATION),
466  new SawtoothWave(1f, 440f).Window(DURATION),
467  new TriangleWave(1f, 440f).Window(DURATION)
468  };
469 
470  foreach (IBGCStream stream in synthStreams)
471  {
472  bool success = TryAllpassFilters(
473  stream: stream,
474  baseName: stream.GetType().Name.Substring(0, 4));
475 
476  Assert.IsTrue(success);
477  }
478  }
Square wave stream.
Definition: SquareWave.cs:10
static void Initialize()
Definition: Calibration.cs:54
bool TryAllpassFilters(IBGCStream stream, string baseName)
Manages calibration values and processes
Definition: Calibration.cs:13
Sawtooth stream with specified frequency and amplitude
Definition: SawtoothWave.cs:10
Sine wave stream with specified amplitude, frequency, and initialPhase. One period is cached and the ...
Definition: SineWave.cs:15
Triangle wave stream with specified amplitude, frequency, and duty-cycle.
Definition: TriangleWave.cs:10
Here is the call graph for this function:

◆ TestBiQuadFilters()

void BGC.Tests.SynthesisTests.TestBiQuadFilters ( )
inline

Definition at line 97 of file SynthesisTests.cs.

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

98  {
100 
101  {
102  //Bandpass Filtered Sine Wave, Matched Frequency
103  IBGCStream stream =
104  new SquareWave(1f, 400f)
105  .BiQuadBandpassFilter(400f)
106  .Window(DURATION)
107  .Normalize(LEVEL);
108 
109  bool success = WaveEncoding.SaveStream(
110  filepath: DataManagement.PathForDataFile("Test", "BiQuadMostThroughBandWave.wav"),
111  stream: stream,
112  overwrite: true);
113 
114  Assert.IsTrue(success);
115  }
116 
117  {
118  //Bandpass Filtered Sine Wave, 2x Frequency
119  IBGCStream stream =
120  new SquareWave(1f, 400f)
121  .BiQuadBandpassFilter(800f)
122  .Window(DURATION)
123  .Normalize(LEVEL);
124 
125  bool success = WaveEncoding.SaveStream(
126  filepath: DataManagement.PathForDataFile("Test", "BiQuadTooHighBandWave.wav"),
127  stream: stream,
128  overwrite: true);
129 
130  Assert.IsTrue(success);
131  }
132  {
133  //Bandpass Filtered Sine Wave, Half Frequency
134  IBGCStream stream =
135  new SquareWave(1f, 400f)
136  .BiQuadBandpassFilter(200f)
137  .Window(DURATION)
138  .Normalize(LEVEL);
139 
140  bool success = WaveEncoding.SaveStream(
141  filepath: DataManagement.PathForDataFile("Test", "BiQuadTooLowBandWave.wav"),
142  stream: stream,
143  overwrite: true);
144 
145  Assert.IsTrue(success);
146  }
147 
148  {
149  //Notch Filtered Square Wave, Matched Frequency
150  IBGCStream stream =
151  new SquareWave(1f, 400f)
152  .BiQuadNotchFilter(400f)
153  .Window(DURATION)
154  .Normalize(LEVEL);
155 
156  bool success = WaveEncoding.SaveStream(
157  filepath: DataManagement.PathForDataFile("Test", "BiQuadNotchFilteredSquareWave.wav"),
158  stream: stream,
159  overwrite: true);
160 
161  Assert.IsTrue(success);
162  }
163 
164  {
165  //Notch Filtered Sine Wave, Matched Frequency
166  IBGCStream stream =
167  new SineWave(1f, 400f)
168  .BiQuadNotchFilter(400f)
169  .Window(DURATION)
170  .Normalize(LEVEL);
171 
172  bool success = WaveEncoding.SaveStream(
173  filepath: DataManagement.PathForDataFile("Test", "BiQuadNotchFilteredSineWave.wav"),
174  stream: stream,
175  overwrite: true);
176 
177  Assert.IsTrue(success);
178  }
179 
180  {
181  //Notch Filtered Sine Wave, +10 Hz Mismatch
182  IBGCStream stream =
183  new SineWave(1f, 400f)
184  .BiQuadNotchFilter(410f)
185  .Window(DURATION)
186  .Normalize(LEVEL);
187 
188  bool success = WaveEncoding.SaveStream(
189  filepath: DataManagement.PathForDataFile("Test", "BiQuadNotchFiltered410SineWave.wav"),
190  stream: stream,
191  overwrite: true);
192 
193  Assert.IsTrue(success);
194  }
195  }
Square wave stream.
Definition: SquareWave.cs:10
static void Initialize()
Definition: Calibration.cs:54
Manages calibration values and processes
Definition: Calibration.cs:13
Operations for Loading and Saving WAV files Some documentation on the WAV format is available here: h...
Definition: WaveEncoding.cs:14
Sine wave stream with specified amplitude, frequency, and initialPhase. One period is cached and the ...
Definition: SineWave.cs:15
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:

◆ TestCarrierModifiedFakeVoices()

void BGC.Tests.SynthesisTests.TestCarrierModifiedFakeVoices ( )
inline

Definition at line 197 of file SynthesisTests.cs.

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

198  {
200 
201  // F2: 500
202  // F3: 1000
203  // F4: 2000
204 
205  double qFactor = 200;
206 
207  Func<IBGCStream> makeCarrierA = () =>
209  rms: 1.0,
210  freqLB: 20,
211  freqUB: 10000,
212  frequencyCount: 10000,
213  distribution: AnalyticNoiseStream.AmplitudeDistribution.Brown)
214  .ToBGCStream();
215 
216  Func<IBGCStream> makeCarrierB = () =>
217  new SawtoothWave(
218  amplitude: 1.0,
219  frequency: 120);
220 
221  Func<IBGCStream>[] carrierFuncs = new Func<IBGCStream>[]
222  {
223  makeCarrierA,
224  makeCarrierB
225  };
226 
227  for (int i = 0; i < 2; i++)
228  {
229  for (int j = 0; j < 2; j++)
230  {
232  filepath: DataManagement.PathForDataFile("Test", $"testVoice{i}{j}.wav"),
233  stream: new StreamAdder(
234  carrierFuncs[i]()
235  .BiQuadBandpassFilter(
236  criticalFrequency: 500,
237  qFactor: qFactor),
238  carrierFuncs[j]()
239  .BiQuadBandpassFilter(
240  criticalFrequency: 1500,
241  qFactor: qFactor))
242  .Window(0.5)
243  .SlowRangeFitter(),
244  overwrite: true);
245  }
246  }
247  }
static void Initialize()
Definition: Calibration.cs:54
Manages calibration values and processes
Definition: Calibration.cs:13
Additive Synthesis - Output samples are equal to the linear sum of input samples. ...
Definition: StreamAdder.cs:10
Operations for Loading and Saving WAV files Some documentation on the WAV format is available here: h...
Definition: WaveEncoding.cs:14
Sawtooth stream with specified frequency and amplitude
Definition: SawtoothWave.cs:10
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:

◆ TestFakeVoice()

void BGC.Tests.SynthesisTests.TestFakeVoice ( )
inline

Definition at line 362 of file SynthesisTests.cs.

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

363  {
365 
366  // F2: 500
367  // F3: 1000
368  // F4: 2000
369 
370  double qFactor = 100;
371 
372  //IBGCStream f2 = new AnalyticNoiseStream(
373  // rms: 1.0,
374  // freqLB: 20,
375  // freqUB: 10000,
376  // frequencyCount: 10000,
377  // distribution: AnalyticNoiseStream.AmplitudeDistribution.Pink)
378  // .ToBGCStream()
379  // .ContinuousFilter(
380  // envelopeStream: new Audio.Envelopes.SigmoidEnvelope(2.0),
381  // filterType: ContinuousFilter.FilterType.BandPass,
382  // freqLB: 500,
383  // freqUB: 540,
384  // qFactor: 100.0);
385 
386 
387  //Func<IBGCStream> makeCarrier = () =>
388  //new AnalyticNoiseStream(
389  // rms: 1.0,
390  // freqLB: 20,
391  // freqUB: 10000,
392  // frequencyCount: 10000,
393  // distribution: AnalyticNoiseStream.AmplitudeDistribution.Brown)
394  // .ToBGCStream();
395 
396  //Func<IBGCStream> makeCarrier = () =>
397  // new SawtoothWave(
398  // amplitude: 1.0,
399  // frequency: 120);
400 
401  Func<IBGCStream> makeCarrier = () =>
402  new StreamAdder(
403  new SawtoothWave(
404  amplitude: 1.0,
405  frequency: 120),
407  rms: 0.2,
408  freqLB: 20,
409  freqUB: 10000,
410  frequencyCount: 10000,
411  distribution: AnalyticNoiseStream.AmplitudeDistribution.Brown)
412  .ToBGCStream());
413 
414  //Func<IBGCStream> makeCarrier = () =>
415  // new SquareWave(
416  // 1.0,
417  // 280.0,
418  // 0.1);
419 
420  IBGCStream f2 = makeCarrier()
421  .ContinuousFilter(
422  envelopeStream: new Audio.Envelopes.EnvelopeConcatenator(
423  new Audio.Envelopes.SigmoidEnvelope(0.1),
424  new Audio.Envelopes.ConstantEnvelope(1.0, 0.1)),
425  filterType: ContinuousFilter.FilterType.BandPass,
426  freqLB: 400,
427  freqUB: 700,
428  qFactor: qFactor);
429 
430  IBGCStream f3 = makeCarrier()
431  .ContinuousFilter(
432  envelopeStream: new Audio.Envelopes.LinearEnvelope(0.05, 0.15),
433  filterType: ContinuousFilter.FilterType.BandPass,
434  freqLB: 1500,
435  freqUB: 1000,
436  qFactor: qFactor);
437 
438  IBGCStream f4 = makeCarrier()
439  .ContinuousFilter(
440  envelopeStream: new Audio.Envelopes.ConstantEnvelope(1.0, 0.2),
441  filterType: ContinuousFilter.FilterType.BandPass,
442  freqLB: 2000,
443  freqUB: 2000,
444  qFactor: qFactor);
445 
446  IBGCStream fakeVoice = new StreamAdder(f2, f3, f4)
447  .Window(.2)
448  .Center(1)
449  .SlowRangeFitter();
450 
452  filepath: DataManagement.PathForDataFile("Test", "testVoice.wav"),
453  stream: fakeVoice);
454  }
static void Initialize()
Definition: Calibration.cs:54
Manages calibration values and processes
Definition: Calibration.cs:13
Additive Synthesis - Output samples are equal to the linear sum of input samples. ...
Definition: StreamAdder.cs:10
Operations for Loading and Saving WAV files Some documentation on the WAV format is available here: h...
Definition: WaveEncoding.cs:14
This implementation is based on a naive adaptation of the BiQuad filter in this pacakge, which is based on the one found in CSCore, which in turn was based on http://www.earlevel.com/main/2011/01/02/biquad-formulas/
Sawtooth stream with specified frequency and amplitude
Definition: SawtoothWave.cs:10
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:

◆ TestFDComposer()

void BGC.Tests.SynthesisTests.TestFDComposer ( )
inline

Definition at line 573 of file SynthesisTests.cs.

References BGC.Mathematics.Complex64.FromPolarCoordinates(), BGC.Audio.Calibration.Initialize(), BGC.IO.DataManagement.PathForDataFile(), BGC.Mathematics.CustomRandom.RayleighDistribution(), and BGC.Audio.WaveEncoding.SaveStream().

574  {
576 
577  System.Random randomizer = new System.Random();
578 
579  IEnumerable<double> frequencies = GetExpFrequencies(500, 10000, 10000);
580 
581  IEnumerable<ComplexCarrierTone> carriers = frequencies.Select(freq =>
582  new ComplexCarrierTone(
583  frequency: freq,
584  amplitude: Complex64.FromPolarCoordinates(
585  magnitude: CustomRandom.RayleighDistribution(randomizer.NextDouble()),
586  phase: 2.0 * Math.PI * randomizer.NextDouble()))).ToArray();
587 
588 
589  for (int frameExp = 10; frameExp < 16; frameExp++)
590  {
591  for (int overlapExp = 1; overlapExp < 6; overlapExp++)
592  {
593  int frameSize = 1 << frameExp;
594  int overlap = 1 << overlapExp;
595 
597  carrierTones: carriers,
598  frameSize: frameSize,
599  overlapFactor: overlap)
600  .Truncate(totalDuration: 1.0)
601  .StandardizeRMS(0.008)
602  .Cache();
603 
604  Debug.Log($"(FrameSize, Overlap): ({frameSize},{overlap}). " +
605  $"RMSExp: 0.008 " +
606  $"RMSActual: {composed.GetChannelRMS().First()}");
607 
609  filepath: DataManagement.PathForDataFile("Test", $"FDNoise_{frameExp:D2}_{overlapExp}.wav"),
610  stream: composed,
611  overwrite: true);
612  }
613  }
614  }
static void Initialize()
Definition: Calibration.cs:54
Manages calibration values and processes
Definition: Calibration.cs:13
Operations for Loading and Saving WAV files Some documentation on the WAV format is available here: h...
Definition: WaveEncoding.cs:14
static double RayleighDistribution(double input)
Translates an evenly distributed random number in the range [0,1) into a Rayleigh-Distributed one...
Represents a complex number with double-precision floating point components
Definition: Complex64.cs:39
static Complex64 FromPolarCoordinates(double magnitude, double phase)
Creates a complex number from a point&#39;s polar coordinates.
IEnumerable< double > GetExpFrequencies(double freqLB, double freqUB, int freqCount)
Suboptimal attempt to do frame-based rendering of a set of carrier tones.
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.
Double, Complex64-based description of a single carrier tone, for tone composition.
Here is the call graph for this function:

◆ TestFDComposerPure()

void BGC.Tests.SynthesisTests.TestFDComposerPure ( )
inline

Definition at line 617 of file SynthesisTests.cs.

References BGC.Mathematics.Complex64.FromPolarCoordinates(), BGC.Audio.Calibration.Initialize(), BGC.IO.DataManagement.PathForDataFile(), and BGC.Audio.WaveEncoding.SaveStream().

618  {
620 
621  System.Random randomizer = new System.Random();
622 
623  //Maximally inharmonic
624  double frequency = 1 / ((1 / 441.0) + 0.5 / 44100.0);
625 
627  {
628  new ComplexCarrierTone(
629  frequency: frequency,
630  amplitude: Complex64.FromPolarCoordinates(
631  magnitude: 1.0,
632  phase: 2.0 * Math.PI * randomizer.NextDouble()))
633  };
634 
635  for (int frameExp = 10; frameExp < 16; frameExp++)
636  {
637  for (int overlapExp = 1; overlapExp < 6; overlapExp++)
638  {
639  int frameSize = 1 << frameExp;
640  int overlap = 1 << overlapExp;
641 
643  carrierTones: carriers,
644  frameSize: frameSize,
645  overlapFactor: overlap)
646  .Truncate(totalDuration: 1.0)
647  .StandardizeRMS(0.008)
648  .Cache();
649 
650  Debug.Log($"(FrameSize, Overlap): ({frameSize},{overlap}). " +
651  $"RMSExp: 0.008 " +
652  $"RMSActual: {composed.GetChannelRMS().First()}");
653 
655  filepath: DataManagement.PathForDataFile("Test", $"FDClean_{frameExp:D2}_{overlapExp}.wav"),
656  stream: composed.StandardizeRMS(),
657  overwrite: true);
658  }
659  }
660  }
static void Initialize()
Definition: Calibration.cs:54
Manages calibration values and processes
Definition: Calibration.cs:13
Operations for Loading and Saving WAV files Some documentation on the WAV format is available here: h...
Definition: WaveEncoding.cs:14
Represents a complex number with double-precision floating point components
Definition: Complex64.cs:39
static Complex64 FromPolarCoordinates(double magnitude, double phase)
Creates a complex number from a point&#39;s polar coordinates.
Suboptimal attempt to do frame-based rendering of a set of carrier tones.
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.
Double, Complex64-based description of a single carrier tone, for tone composition.
Here is the call graph for this function:

◆ TestFMFilterSynth()

void BGC.Tests.SynthesisTests.TestFMFilterSynth ( )
inline

Definition at line 1050 of file SynthesisTests.cs.

References BGC.Audio.Calibration.Initialize().

1051  {
1053 
1054  IBGCStream[] synthStreams = new IBGCStream[]
1055  {
1056  new SineWave(1f, 440f).Window(DURATION),
1057  new SquareWave(1f, 440f).Window(DURATION),
1058  new SawtoothWave(1f, 440f).Window(DURATION),
1059  new TriangleWave(1f, 440f).Window(DURATION)
1060  };
1061 
1062  foreach (IBGCStream stream in synthStreams)
1063  {
1064  bool success = TryFMParams(
1065  stream: stream,
1066  baseName: stream.GetType().Name.Substring(0, 4));
1067 
1068  Assert.IsTrue(success);
1069  }
1070  }
Square wave stream.
Definition: SquareWave.cs:10
static void Initialize()
Definition: Calibration.cs:54
Manages calibration values and processes
Definition: Calibration.cs:13
bool TryFMParams(IBGCStream stream, string baseName)
Sawtooth stream with specified frequency and amplitude
Definition: SawtoothWave.cs:10
Sine wave stream with specified amplitude, frequency, and initialPhase. One period is cached and the ...
Definition: SineWave.cs:15
Triangle wave stream with specified amplitude, frequency, and duty-cycle.
Definition: TriangleWave.cs:10
Here is the call graph for this function:

◆ TestFMFilterVoice()

void BGC.Tests.SynthesisTests.TestFMFilterVoice ( )
inline

Definition at line 1073 of file SynthesisTests.cs.

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

1074  {
1076 
1077  string speechFile = DataManagement.PathForDataFile("Test", "000000.wav");
1078  if (!File.Exists(speechFile))
1079  {
1080  throw new Exception($"Test utilizes CRM missing sentence: {speechFile}");
1081  }
1082 
1084  filepath: speechFile,
1085  stream: out IBGCStream speechStream);
1086 
1087  speechStream = speechStream.Center(speechStream.Duration() + 0.4f);
1088 
1089  bool success = TryFMParams(
1090  stream: speechStream,
1091  baseName: "CRMS");
1092 
1093  Assert.IsTrue(success);
1094  }
static bool LoadBGCStream(string filepath, out IBGCStream stream)
Loads a WAV file from the filepath as a SimpleAudioClip, returns success.
Definition: WaveEncoding.cs:32
static void Initialize()
Definition: Calibration.cs:54
Manages calibration values and processes
Definition: Calibration.cs:13
Operations for Loading and Saving WAV files Some documentation on the WAV format is available here: h...
Definition: WaveEncoding.cs:14
bool TryFMParams(IBGCStream stream, string baseName)
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:

◆ TestFrequencyShifter()

void BGC.Tests.SynthesisTests.TestFrequencyShifter ( )
inline

Definition at line 926 of file SynthesisTests.cs.

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

927  {
929 
931  filepath: DataManagement.PathForDataFile("Test", "FS450Sine.wav"),
932  stream: new AnalyticWave(1.0, 450.0)
933  .ToBGCStream()
934  .Window(DURATION)
935  .Normalize(LEVEL),
936  overwrite: true);
937 
939  filepath: DataManagement.PathForDataFile("Test", "FS500Sine.wav"),
940  stream: new AnalyticWave(1.0, 500.0)
941  .ToBGCStream()
942  .Window(DURATION)
943  .Normalize(LEVEL),
944  overwrite: true);
945 
947  filepath: DataManagement.PathForDataFile("Test", "FS440Sine.wav"),
948  stream: new AnalyticWave(1.0, 440.0)
949  .ToBGCStream()
950  .Window(DURATION)
951  .Normalize(LEVEL),
952  overwrite: true);
953 
955  filepath: DataManagement.PathForDataFile("Test", "FS450ShiftedSine.wav"),
956  stream: new AnalyticWave(1.0, 440.0)
957  .FrequencyShift(10.0)
958  .ToBGCStream()
959  .Window(DURATION)
960  .Normalize(LEVEL),
961  overwrite: true);
962 
964  filepath: DataManagement.PathForDataFile("Test", "FS500ShiftedSine.wav"),
965  stream: new AnalyticWave(1.0, 440.0)
966  .FrequencyShift(60.0)
967  .ToBGCStream()
968  .Window(DURATION)
969  .Normalize(LEVEL),
970  overwrite: true);
971 
973  filepath: DataManagement.PathForDataFile("Test", "FS450Tri.wav"),
974  stream: new TriangleWave(1f, 450f)
975  .Window(DURATION)
976  .Normalize(LEVEL),
977  overwrite: true);
978 
980  filepath: DataManagement.PathForDataFile("Test", "FS450ShiftedTri.wav"),
981  stream: new TriangleWave(1f, 440f)
982  .ToAnalyticStream()
983  .FrequencyShift(10.0)
984  .ToBGCStream()
985  .Window(DURATION)
986  .Normalize(LEVEL),
987  overwrite: true);
988  }
static void Initialize()
Definition: Calibration.cs:54
Manages calibration values and processes
Definition: Calibration.cs:13
Operations for Loading and Saving WAV files Some documentation on the WAV format is available here: h...
Definition: WaveEncoding.cs:14
Triangle wave stream with specified amplitude, frequency, and duty-cycle.
Definition: TriangleWave.cs:10
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:

◆ TestFunFakeVoice()

void BGC.Tests.SynthesisTests.TestFunFakeVoice ( )
inline

Definition at line 250 of file SynthesisTests.cs.

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

251  {
253 
254  // F2: 500
255  // F3: 1000
256  // F4: 2000
257 
258  double qFactor = 200;
259 
260  //IBGCStream f2 = new AnalyticNoiseStream(
261  // rms: 1.0,
262  // freqLB: 20,
263  // freqUB: 10000,
264  // frequencyCount: 10000,
265  // distribution: AnalyticNoiseStream.AmplitudeDistribution.Pink)
266  // .ToBGCStream()
267  // .ContinuousFilter(
268  // envelopeStream: new Audio.Envelopes.SigmoidEnvelope(2.0),
269  // filterType: ContinuousFilter.FilterType.BandPass,
270  // freqLB: 500,
271  // freqUB: 540,
272  // qFactor: 100.0);
273 
274 
275  //Func<IBGCStream> makeCarrier = () =>
276  //new AnalyticNoiseStream(
277  // rms: 1.0,
278  // freqLB: 20,
279  // freqUB: 10000,
280  // frequencyCount: 10000,
281  // distribution: AnalyticNoiseStream.AmplitudeDistribution.Brown)
282  // .ToBGCStream();
283 
284  //Func<IBGCStream> makeCarrier = () =>
285  // new SawtoothWave(
286  // amplitude: 1.0,
287  // frequency: 120);
288 
289  Func<IBGCStream> makeCarrier = () =>
290  new StreamAdder(
291  new SawtoothWave(
292  amplitude: 1.0,
293  frequency: 120),
295  rms: 0.2,
296  freqLB: 20,
297  freqUB: 10000,
298  frequencyCount: 10000,
299  distribution: AnalyticNoiseStream.AmplitudeDistribution.Brown)
300  .ToBGCStream());
301 
302  //Func<IBGCStream> makeCarrier = () =>
303  // new SquareWave(
304  // 1.0,
305  // 280.0,
306  // 0.1);
307 
308  //IBGCStream f2 = makeCarrier()
309  // .ContinuousFilter(
310  // envelopeStream: new SineWave(1.0, 4),
311  // filterType: ContinuousFilter.FilterType.BandPass,
312  // freqLB: 1500,
313  // freqUB: 1000,
314  // qFactor: qFactor);
315 
316  {
317  IBGCStream f1 = makeCarrier()
318  .BiQuadBandpassFilter(
319  criticalFrequency: 500,
320  qFactor: qFactor);
321 
322  IBGCStream f2 = makeCarrier()
323  .BiQuadBandpassFilter(
324  criticalFrequency: 1500,
325  qFactor: qFactor);
326 
327  IBGCStream fakeVoice = new StreamAdder(f1, f2)
328  .Window(0.2)
329  .Center(0.5)
330  .SlowRangeFitter();
331 
333  filepath: DataManagement.PathForDataFile("Test", "testVoiceA.wav"),
334  stream: fakeVoice,
335  overwrite: true);
336  }
337 
338  {
339  IBGCStream f1 = makeCarrier()
340  .BiQuadBandpassFilter(
341  criticalFrequency: 750,
342  qFactor: qFactor);
343 
344  IBGCStream f2 = makeCarrier()
345  .BiQuadBandpassFilter(
346  criticalFrequency: 2000,
347  qFactor: qFactor);
348 
349  IBGCStream fakeVoice = new StreamAdder(f1, f2)
350  .Window(0.2)
351  .Center(0.5)
352  .SlowRangeFitter();
353 
355  filepath: DataManagement.PathForDataFile("Test", "testVoiceB.wav"),
356  stream: fakeVoice,
357  overwrite: true);
358  }
359  }
static void Initialize()
Definition: Calibration.cs:54
Manages calibration values and processes
Definition: Calibration.cs:13
Additive Synthesis - Output samples are equal to the linear sum of input samples. ...
Definition: StreamAdder.cs:10
Operations for Loading and Saving WAV files Some documentation on the WAV format is available here: h...
Definition: WaveEncoding.cs:14
Sawtooth stream with specified frequency and amplitude
Definition: SawtoothWave.cs:10
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:

◆ TestPhaseReEncoder()

void BGC.Tests.SynthesisTests.TestPhaseReEncoder ( )
inline

Definition at line 673 of file SynthesisTests.cs.

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

674  {
676 
677  IBGCStream baseStream = new STMAudioClip(
678  duration: 2.0,
679  freqLB: 20,
680  freqUB: 10000,
681  frequencyCount: 10000,
682  modulationDepth: 20,
683  spectralModulationRate: 2,
684  temporalModulationRate: 4,
685  rippleDirection: STMAudioClip.RippleDirection.Up,
686  distribution: STMAudioClip.AmplitudeDistribution.Pink).StandardizeRMS();
687 
688  Debug.Log($"Base RMS: {baseStream.CalculateRMS().First()}");
689 
691  filepath: DataManagement.PathForDataFile("Test", $"ReEncoding_Initial.wav"),
692  stream: baseStream,
693  overwrite: true);
694 
695  IBGCStream fullReencodedStream = baseStream.SinglePassPhaseReencode(0.0, 0.000_100);
696 
697  Debug.Log($"After Full ReEncoding: ({string.Join(",", fullReencodedStream.CalculateRMS().Select(x => x.ToString()))})");
698 
700  filepath: DataManagement.PathForDataFile("Test", $"ReEncoding_Full.wav"),
701  stream: fullReencodedStream,
702  overwrite: true);
703 
704  IBGCStream frameReencodedStream = new FramedPhaseReencoder(baseStream, 0.0, 0.000_100);
705 
706  Debug.Log($"After Full ReEncoding: ({string.Join(",", frameReencodedStream.CalculateRMS().Select(x => x.ToString()))})");
707 
709  filepath: DataManagement.PathForDataFile("Test", $"ReEncoding_Frame.wav"),
710  stream: frameReencodedStream,
711  overwrite: true);
712  }
static void Initialize()
Definition: Calibration.cs:54
Manages calibration values and processes
Definition: Calibration.cs:13
Operations for Loading and Saving WAV files Some documentation on the WAV format is available here: h...
Definition: WaveEncoding.cs:14
Applies an ITD by adjusting the phase in the frequency domain, frame-based
Spectrotemporally modulated noise with the specified duration. AKA Ripples.
Definition: STMAudioClip.cs:12
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:

◆ TestSawtoothWave()

void BGC.Tests.SynthesisTests.TestSawtoothWave ( )
inline

Definition at line 61 of file SynthesisTests.cs.

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

62  {
64 
65  IBGCStream stream =
66  new SawtoothWave(1f, 200f)
67  .Window(DURATION)
68  .Normalize(LEVEL);
69 
70  bool success = WaveEncoding.SaveStream(
71  filepath: DataManagement.PathForDataFile("Test", "sawtoothWave.wav"),
72  stream: stream,
73  overwrite: true);
74 
75  Assert.IsTrue(success);
76  }
static void Initialize()
Definition: Calibration.cs:54
Manages calibration values and processes
Definition: Calibration.cs:13
Operations for Loading and Saving WAV files Some documentation on the WAV format is available here: h...
Definition: WaveEncoding.cs:14
Sawtooth stream with specified frequency and amplitude
Definition: SawtoothWave.cs:10
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:

◆ TestSineWave()

void BGC.Tests.SynthesisTests.TestSineWave ( )
inline

Definition at line 25 of file SynthesisTests.cs.

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

26  {
28 
29  IBGCStream stream =
30  new SineWave(1f, 440f)
31  .Window(DURATION)
32  .Normalize(LEVEL);
33 
34  bool success = WaveEncoding.SaveStream(
35  filepath: DataManagement.PathForDataFile("Test", "sineWave.wav"),
36  stream: stream,
37  overwrite: true);
38 
39  Assert.IsTrue(success);
40  }
static void Initialize()
Definition: Calibration.cs:54
Manages calibration values and processes
Definition: Calibration.cs:13
Operations for Loading and Saving WAV files Some documentation on the WAV format is available here: h...
Definition: WaveEncoding.cs:14
Sine wave stream with specified amplitude, frequency, and initialPhase. One period is cached and the ...
Definition: SineWave.cs:15
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:

◆ TestSquareWave()

void BGC.Tests.SynthesisTests.TestSquareWave ( )
inline

Definition at line 43 of file SynthesisTests.cs.

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

44  {
46 
47  IBGCStream stream =
48  new SquareWave(1f, 400f)
49  .Window(DURATION)
50  .Normalize(LEVEL);
51 
52  bool success = WaveEncoding.SaveStream(
53  filepath: DataManagement.PathForDataFile("Test", "squareWave.wav"),
54  stream: stream,
55  overwrite: true);
56 
57  Assert.IsTrue(success);
58  }
Square wave stream.
Definition: SquareWave.cs:10
static void Initialize()
Definition: Calibration.cs:54
Manages calibration values and processes
Definition: Calibration.cs:13
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:

◆ TestSTM()

void BGC.Tests.SynthesisTests.TestSTM ( )
inline

Definition at line 715 of file SynthesisTests.cs.

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

716  {
718 
720  filepath: DataManagement.PathForDataFile("Test", $"Long_STM.wav"),
721  stream: new STMAudioClip(
722  duration: 95.0,
723  freqLB: 20,
724  freqUB: 10000,
725  frequencyCount: 10000,
726  modulationDepth: 20,
727  spectralModulationRate: 2,
728  temporalModulationRate: 4,
729  rippleDirection: STMAudioClip.RippleDirection.Up,
730  distribution: STMAudioClip.AmplitudeDistribution.Pink).SlowRangeFitter(),
731  overwrite: true);
732  }
static void Initialize()
Definition: Calibration.cs:54
Manages calibration values and processes
Definition: Calibration.cs:13
Operations for Loading and Saving WAV files Some documentation on the WAV format is available here: h...
Definition: WaveEncoding.cs:14
Spectrotemporally modulated noise with the specified duration. AKA Ripples.
Definition: STMAudioClip.cs:12
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:

◆ TestTriangleWave()

void BGC.Tests.SynthesisTests.TestTriangleWave ( )
inline

Definition at line 79 of file SynthesisTests.cs.

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

80  {
82 
83  IBGCStream stream =
84  new TriangleWave(1f, 440f)
85  .Window(DURATION)
86  .Normalize(LEVEL);
87 
88  bool success = WaveEncoding.SaveStream(
89  filepath: DataManagement.PathForDataFile("Test", "triangleWave.wav"),
90  stream: stream,
91  overwrite: true);
92 
93  Assert.IsTrue(success);
94  }
static void Initialize()
Definition: Calibration.cs:54
Manages calibration values and processes
Definition: Calibration.cs:13
Operations for Loading and Saving WAV files Some documentation on the WAV format is available here: h...
Definition: WaveEncoding.cs:14
Triangle wave stream with specified amplitude, frequency, and duty-cycle.
Definition: TriangleWave.cs:10
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:

◆ TryAllPassFilter()

bool BGC.Tests.SynthesisTests.TryAllPassFilter ( IBGCStream  stream,
in Complex64  coeff,
int  delay,
string  name 
)
inlineprivate

Definition at line 558 of file SynthesisTests.cs.

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

559  {
560  IBGCStream filteredStream = stream
561  .AllPass(coeff, delay)
562  .Normalize(LEVEL);
563 
564  bool success = WaveEncoding.SaveStream(
565  filepath: DataManagement.PathForDataFile("Test", $"AllPass_{name}.wav"),
566  stream: filteredStream,
567  overwrite: true);
568 
569  return success;
570  }
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:

◆ TryAllpassFilters()

bool BGC.Tests.SynthesisTests.TryAllpassFilters ( IBGCStream  stream,
string  baseName 
)
inlineprivate

Definition at line 504 of file SynthesisTests.cs.

References BGC.Mathematics.Complex64.FromPolarCoordinates().

505  {
506  List<Complex64> testCoefficients = new List<Complex64>();
507 
508  double[] magnitudes = new double[]
509  {
510  0.1,
511  0.2,
512  0.5,
513  0.8,
514  0.9,
515  1.0
516  };
517 
518  double[] angles = new double[]
519  {
520  0.0,
521  Math.PI / 3.0,
522  Math.PI / 2.0,
523  2.0 * Math.PI / 3.0,
524  Math.PI
525  };
526 
527  foreach (double m in magnitudes)
528  {
529  foreach (double angle in angles)
530  {
531  testCoefficients.Add(Complex64.FromPolarCoordinates(m, angle));
532  }
533  }
534 
535  List<int> testDelays = new List<int>()
536  {
537  1,
538  44, //1 ms
539  441, //10 ms
540  4410, //100 ms
541  };
542 
543  foreach (Complex64 coeff in testCoefficients)
544  {
545  string coeffPart = $"(m{coeff.Magnitude:0.00}p{(coeff.Phase >= 0 ? coeff.Phase : 2 * Math.PI - coeff.Phase):0.00})";
546  foreach (int delay in testDelays)
547  {
548  if (!TryAllPassFilter(stream, coeff, delay, $"{baseName}{coeffPart}{delay:0000}"))
549  {
550  return false;
551  }
552  }
553  }
554 
555  return true;
556  }
bool TryAllPassFilter(IBGCStream stream, in Complex64 coeff, int delay, string name)
Represents a complex number with double-precision floating point components
Definition: Complex64.cs:39
static Complex64 FromPolarCoordinates(double magnitude, double phase)
Creates a complex number from a point&#39;s polar coordinates.
Here is the call graph for this function:

◆ TryFMFilter()

bool BGC.Tests.SynthesisTests.TryFMFilter ( IBGCStream  stream,
float  rate,
float  depth,
string  name 
)
inlineprivate

Definition at line 1135 of file SynthesisTests.cs.

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

1136  {
1137  IBGCStream filteredStream = stream
1138  .FrequencyModulation(rate, depth)
1139  .Normalize(LEVEL);
1140 
1141  bool success = WaveEncoding.SaveStream(
1142  filepath: DataManagement.PathForDataFile("Test", $"FM_{name}.wav"),
1143  stream: filteredStream,
1144  overwrite: true);
1145 
1146  return success;
1147  }
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:

◆ TryFMParams()

bool BGC.Tests.SynthesisTests.TryFMParams ( IBGCStream  stream,
string  baseName 
)
inlineprivate

Definition at line 1096 of file SynthesisTests.cs.

1097  {
1098  float[] rates = new float[]
1099  {
1100  2f,
1101  4f,
1102  8f,
1103  16f,
1104  32f,
1105  64f
1106  };
1107 
1108  float[] depths = new float[]
1109  {
1110  10f,
1111  20f,
1112  40f,
1113  60f,
1114  80f
1115  };
1116 
1117  foreach (float rate in rates)
1118  {
1119  foreach (float depth in depths)
1120  {
1121  if (!TryFMFilter(
1122  stream: stream,
1123  rate: rate,
1124  depth: depth,
1125  name: $"{baseName}_{rate:000}_{depth:00}"))
1126  {
1127  return false;
1128  }
1129  }
1130  }
1131 
1132  return true;
1133  }
bool TryFMFilter(IBGCStream stream, float rate, float depth, string name)

Field Documentation

◆ DURATION

const float BGC.Tests.SynthesisTests.DURATION = 5f
private

Definition at line 20 of file SynthesisTests.cs.

◆ LEVEL

const float BGC.Tests.SynthesisTests.LEVEL = 70f
private

Definition at line 22 of file SynthesisTests.cs.


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