/// <summary>
        /// Обработчик изменения текущей таблицы сэмплов.
        /// </summary>
        /// <param name="value">Нормированное новое значение параметра.</param>
        private void SetWaveTable(float value)
        {
            var newWaveTable = Converters.ToWaveTable(value);

            if (waveTable != newWaveTable)
            {
                waveTable = newWaveTable;
                foreach (var oscillator in oscillators)
                {
                    oscillator.SetWaveTable(waveTable.Clone());
                }
            }
        }
 /// <summary>
 /// Метод, записывающий объект WaveTableOscillator в поток.
 /// </summary>
 /// <param name="stream"></param>
 /// <param name="obj"></param>
 public static void Serialize(Stream stream, WaveTableOscillator obj)
 {
     using (var writer = new BinaryWriter(stream, System.Text.Encoding.Default, true))
     {
         writer.Write(obj.waveTablesAmount);
         foreach (var waveTable in obj.waveTables)
         {
             writer.Write(waveTable.Length);
             writer.Write(waveTable.PhaseIncrement);
             foreach (var sample in waveTable.Samples)
             {
                 writer.Write(sample);
             }
         }
     }
 }
Example #3
0
        /// <summary>
        /// Метод, обеспечивающий создание таблиц сэмплов.
        /// </summary>
        private static void GetOrGenerateWaveTables()
        {
            var directory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            var path      = directory + @"\waveTables.bin";

            try
            {
                using (var file = new FileStream(path, FileMode.Open))
                {
                    WaveTables = new WaveTableOscillator[6];
                    for (int i = 0; i < WaveTables.Length; ++i)
                    {
                        WaveTables[i] = WaveTableOscillator.Deserialize(file);
                    }
                }
            }
            catch (IOException)
            {
                if (!Directory.Exists(directory))
                {
                    Directory.CreateDirectory(directory);
                }
                using (var file = new FileStream(path, FileMode.Create))
                {
                    WaveTables = new[]
                    {
                        new WaveTableOscillator(SineGenerator, 1, 1),
                        new WaveTableOscillator(TriangleGenerator, 20, DefaultSampleRate / 2),
                        new WaveTableOscillator(SawGenerator, 20, DefaultSampleRate / 2),
                        new WaveTableOscillator(SquareGenerator, 20, DefaultSampleRate / 2),
                        new WaveTableOscillator(HalfSquareGenerator, 20, DefaultSampleRate / 2),
                        new WaveTableOscillator(QuarterSquareGenerator, 20, DefaultSampleRate / 2),
                    };
                    foreach (var vt in WaveTables)
                    {
                        WaveTableOscillator.Serialize(file, vt);
                    }
                }
            }
        }
Example #4
0
 /// <summary>
 /// Устанавливает новый объект класса WaveTable.
 /// </summary>
 /// <param name="waveTable"></param>
 public void SetWaveTable(WaveTableOscillator waveTable)
 {
     this.waveTable = waveTable;
     this.waveTable.SetPhaseIncrement(phaseIncrement);
 }