Exemple #1
0
        public static void WriteToFile(string file, Array samples, int sampleRate = 44100)
        {
            var writer = new WaveWriter();

            writer.SampleRate = sampleRate;
            using (var stream = new FileStream(file, FileMode.Create))
            {
                writer.WriteWave(stream, samples);
            }
        }
Exemple #2
0
        public void PlayWave(ISound wave, bool sync = false)
        {
            var samples = CreateWave <short>(wave);

            using (var buffer = new MemoryStream())
            {
                var writer = new WaveWriter();
                writer.SampleRate = SampleRate;
                writer.WriteWave(buffer, samples);
                buffer.Position = 0;

                var player = new SoundPlayer(buffer);
                if (sync)
                {
                    player.PlaySync();
                }
                else
                {
                    player.Play();
                }
            }
        }