예제 #1
0
        static void Test_PartialTimeline()
        {
            var format = new WaveFormat {
                bytesPerSample = 2,
                sampleRate     = 44100,
                channels       = 2,
            };

            // fill timeline
            var   timeline = new PartialTimeline(format);
            float level    = 0.3f;

            timeline.AddPartial(1000, 880.0, 100, 3000 - 100 - 1, level, -1f, 0f);
            timeline.AddPartial(0, 440.0, 100, 2000 - 100 - 1, level, 0f, -4f);
            timeline.AddPartial(500, 660.0, 100, 2000 - 100 - 1, level, 1f, -2f);

            // export to wave file
            string file = "timeline1.wav";

            using (var w = new WaveWriter(format, file)) {
                byte[] buffer = new byte[format.bytesPerSample * format.sampleRate]; // for 1 sec
                while (timeline.Fill(buffer))
                {
                    w.Write(buffer);
                }
            }
        }
예제 #2
0
        static void Test_WaveWriter()
        {
            var format = new WaveFormat {
                bytesPerSample = 2,
                sampleRate     = 44100,
                channels       = 1,
            };

            byte[] buffer = new byte[format.bytesPerSample * format.sampleRate]; // for 1 sec

            string file = "test1.wav";

            using (var w = new WaveWriter(format, file))
            {
#if false
                WaveFormat.Clear(buffer);
                w.Write(buffer);
#else
                var provider = new PartialProvider();
                provider.Initialize(format);

                //provider.AddFrequency(440.0, 1500, 0.5f); // without envelope
                provider.AddPartial(440, 100, 2000, 0.5f, -4f);
                provider.FlushPartials();

                while (!provider.IsEmpty())
                {
                    provider.Fill(buffer);
                    w.Write(buffer);
                }
#endif
            }
        }
예제 #3
0
 public static void WriteWavFile(byte[] fullDataBuffer, WaveFormat format, string wavFilePath)
 {
     using (var w = new WaveWriter(format, wavFilePath)) {
         w.Write(fullDataBuffer);
     }
 }