public WavetableData Create(int samplesPerWave) { var tableCount = 64; var waveLen = samplesPerWave; var output = new WavetableData { Name = WavetableName, Data = new double[tableCount][] }; for (int num = 0; num < tableCount; num++) { var wave = new double[waveLen]; var breakpoint = (int)(num / 64.0 * waveLen); var slope = 1.0 / waveLen; var val = 1.0; for (int i = 0; i < waveLen; i++) { if (i == breakpoint) { val = 1.0; } wave[i] = val; val -= slope; } output.Data[num] = AudioLib.Utils.Normalize(wave); } return(output); }
public static double[][][] GetWavetable(string wavetableName) { // Todo: unused tables never get unloaded if (wavetables.ContainsKey(wavetableName)) { return(wavetables[wavetableName]); } var data = WavetableData.FromFile(WavetableFiles[wavetableName]); var transformed = TransformWavetable(data.Data); wavetables[wavetableName] = transformed; return(wavetables[wavetableName]); }
public WavetableData Create(int samplesPerWave) { var tableCount = 64; var waveLen = samplesPerWave; var output = new WavetableData { Name = "Pulse Wave", Data = new double[tableCount][] }; for (int num = 0; num < tableCount; num++) { var wave = new double[waveLen]; var breakpoint = (int)((0.5 + num / 64.0 * 0.5) * waveLen); for (int i = 0; i < waveLen; i++) { wave[i] = (i <= breakpoint) ? 1.0 : -1.0; } output.Data[num] = wave; } return(output); }
public WavetableData Create(int samplesPerWave) { var tableCount = 64; var waveLen = samplesPerWave; var output = new WavetableData { Name = "Quantz Waves", Data = new double[tableCount][] }; var rand = new Random(42); var waves = Waves.Select(x => x).ToList(); while (waves.Count < tableCount) { var randomWave = Enumerable.Range(0, 8).Select(x => rand.NextDouble() * 10).ToArray(); waves.Add(randomWave); } var upsample = waveLen / 8; for (int w = 0; w < waves.Count; w++) { var wave = waves[w]; var newWave = new List <double>(); for (int i = 0; i < wave.Length; i++) { for (int j = 0; j < upsample; j++) { newWave.Add(wave[i]); } } output.Data[w] = AudioLib.Utils.Normalize(newWave.ToArray()); } return(output); }