public static short[] CreateSong(IList <RPCCommand> data, WaveFunction waveType, double volume, bool clip, int frequency) { var song = new WaveSong(); song.NoClipping = !clip; song.Volume = volume; int time = 0; var channels = new Dictionary <int, WaveSong.Track>(); foreach (var cmd in data) { WaveSong.Track playing; switch (cmd.Type) { case RPCCommandType.Delay: time += cmd.DelayValue; break; case RPCCommandType.SetCountdown: double freq = LoadMDT.CountdownToFrequency(cmd.Data); if (!channels.TryGetValue(cmd.Channel, out playing) || playing.Wave.Frequency != freq) { if (playing.Wave != null) { playing.Wave.Duration = time - playing.Start; } playing = new WaveSong.Track(time, new Wave(freq, 0) { Type = waveType }); song.Waves.Add(playing); channels[cmd.Channel] = playing; } break; case RPCCommandType.ClearCountdown: if (channels.TryGetValue(cmd.Channel, out playing)) { if (playing.Wave != null) { playing.Wave.Duration = time - playing.Start; } channels.Remove(cmd.Channel); } break; } } foreach (WaveSong.Track playing in channels.Values) { playing.Wave.Duration = time - playing.Start; } return(song.GetSamples <short>(frequency)); }
public static short[] CreateSong(IList <RPCCommand> data, WaveFunction waveType, double volume, bool clip, int frequency, double?clickLength, bool temper) { var song = new WaveSong(); song.NoClipping = !clip; song.Volume = volume; bool informed = false; int time = 0; var channels = new Dictionary <int, WaveSong.Track>(); foreach (var cmd in data) { WaveSong.Track playing; switch (cmd.Type) { case RPCCommandType.Delay: time += cmd.DelayValue; break; case RPCCommandType.SetCountdown: double freq = LoadMDT.CountdownToFrequency(cmd.Data); if (temper) { freq = TemperFrequency(freq); } if (!channels.TryGetValue(cmd.Channel, out playing) || playing.Wave.Frequency != freq) { double phase = 0; if (playing.Wave != null) { playing.Wave.Duration = time - playing.Start; phase = playing.Wave.RemainingPhaseShift; } playing = new WaveSong.Track(time, new Wave(freq, 0) { Type = waveType, PhaseShiftCoef = phase }); song.Waves.Add(playing); channels[cmd.Channel] = playing; } break; case RPCCommandType.ClearCountdown: if (channels.TryGetValue(cmd.Channel, out playing)) { if (playing.Wave != null) { playing.Wave.Duration = time - playing.Start; if (playing.Wave.Duration == 0) { if (clickLength != null) { playing.Wave.Duration = 1000 * clickLength.Value / playing.Wave.Frequency; } else if (!informed) { Console.WriteLine("Song contains zero-length waves. Use --clicks 0.5 to render them as clicks."); informed = true; } } } channels.Remove(cmd.Channel); } break; } } foreach (WaveSong.Track playing in channels.Values) { playing.Wave.Duration = time - playing.Start; } return(song.GetSamples <short>(frequency)); }
public static short[] CreateSong(IList<RPCCommand> data, WaveFunction waveType, double volume, bool clip, int frequency, double? clickLength) { var song = new WaveSong(); song.NoClipping = !clip; song.Volume = volume; bool informed = false; int time = 0; var channels = new Dictionary<int,WaveSong.Track>(); foreach(var cmd in data) { WaveSong.Track playing; switch(cmd.Type) { case RPCCommandType.Delay: time += cmd.DelayValue; break; case RPCCommandType.SetCountdown: double freq = LoadMDT.CountdownToFrequency(cmd.Data); if(!channels.TryGetValue(cmd.Channel, out playing) || playing.Wave.Frequency != freq) { double phase = 0; if(playing.Wave != null) { playing.Wave.Duration = time-playing.Start; phase = playing.Wave.RemainingPhaseShift; } playing = new WaveSong.Track(time, new Wave(freq, 0){Type = waveType, PhaseShiftCoef = phase}); song.Waves.Add(playing); channels[cmd.Channel] = playing; } break; case RPCCommandType.ClearCountdown: if(channels.TryGetValue(cmd.Channel, out playing)) { if(playing.Wave != null) { playing.Wave.Duration = time-playing.Start; if(playing.Wave.Duration == 0) { if(clickLength != null) { playing.Wave.Duration = 1000*clickLength.Value/playing.Wave.Frequency; }else if(!informed) { Console.WriteLine("Song contains zero-length waves. Use --clicks 0.5 to render them as clicks."); informed = true; } } } channels.Remove(cmd.Channel); } break; } } foreach(WaveSong.Track playing in channels.Values) { playing.Wave.Duration = time-playing.Start; } return song.GetSamples<short>(frequency); }