예제 #1
0
        private void btnSaveChunkWave_Click(object sender, EventArgs e)
        {
            AudioChunk chunk = GetSelectedChunk();

            if (chunk != null)
            {
                SaveFileDialog dlg = new SaveFileDialog();

                dlg.Filter           = "wave files (*.wav)|*.wav|All files (*.*)|*.*";
                dlg.RestoreDirectory = true;
                dlg.FileName         = "chunk";
                dlg.DefaultExt       = ".wav";

                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    using (FileStream stream = new FileStream(dlg.FileName, FileMode.Create, FileAccess.Write))
                    {
                        WaveStreamWriter streamWriter = new WaveStreamWriter(stream);

                        if (chunk.Oscillators.Count > 0)
                        {
                            streamWriter.WriteChunk(chunk);
                        }

                        streamWriter.Close();
                    }
                }
            }
        }
예제 #2
0
        private void btnTestFullChunk_Click(object sender, EventArgs e)
        {
            AudioChunk chunk = GetSelectedChunk();

            if (chunk == null)
            {
                return;
            }

            using (MemoryStream stream = new MemoryStream())
            {
                WaveStreamWriter streamWriter = new WaveStreamWriter(stream);

                if (chunk.Oscillators.Count > 0)
                {
                    streamWriter.WriteChunk(chunk);
                }

                streamWriter.Close();

                PlayStream(stream);
            }
        }
예제 #3
0
        private void button_Click(object sender, RoutedEventArgs e)
        {
            using (FileStream stream = new FileStream(".\\output.wav", FileMode.Create, FileAccess.Write, FileShare.None, 8 * 1024 * 1024))
            {
                WaveStreamWriter streamWriter = new WaveStreamWriter(stream);

                int duration          = 100;
                int repeatGlobalCount = 10;
                int freq = 60;

                AudioChunk motorChunk      = SampleHelper.MakeChordChunk(400, 30, 6000);
                Oscillator silence600      = SampleHelper.MakeSilenceOscillator(600);
                AudioChunk smallBassChunk1 = SampleHelper.MakeBassChunk(40, 80, 12000);
                Oscillator silence200      = SampleHelper.MakeSilenceOscillator(200);
                Oscillator silence100      = SampleHelper.MakeSilenceOscillator(100);
                AudioChunk smallBassChunk2 = SampleHelper.MakeBassChunk2(40, 80, 12000);


                Oscillator sine     = new Oscillator(WaveType.Sine, 40, 80, 12000, 2);
                Oscillator square   = new Oscillator(WaveType.Square, 40, 80, 12000, 2);
                Oscillator triangle = new Oscillator(WaveType.Triangle, 40, 80, 12000, 2);
                Oscillator sawtooth = new Oscillator(WaveType.Sawtooth, 40, 80, 12000, 2);

                streamWriter.WriteOscillator(sine);
                streamWriter.WriteOscillator(silence200);

                streamWriter.WriteOscillator(sine);
                streamWriter.WriteOscillator(silence200);
                streamWriter.WriteOscillator(silence200);

                streamWriter.WriteOscillator(square);
                streamWriter.WriteOscillator(silence200);

                streamWriter.WriteOscillator(square);
                streamWriter.WriteOscillator(silence200);
                streamWriter.WriteOscillator(silence200);

                streamWriter.WriteOscillator(triangle);
                streamWriter.WriteOscillator(silence200);

                streamWriter.WriteOscillator(triangle);
                streamWriter.WriteOscillator(silence200);
                streamWriter.WriteOscillator(silence200);


                streamWriter.WriteOscillator(sawtooth);
                streamWriter.WriteOscillator(silence200);

                streamWriter.WriteOscillator(sawtooth);
                streamWriter.WriteOscillator(silence200);
                streamWriter.WriteOscillator(silence200);



                //for (int j = 0; j < 1; j++)
                //{
                //    for (int i = 0; i < 2; i++)
                //    {
                //        for (int z = 0; z < 3; z++)
                //        {
                //            streamWriter.WriteChunk(smallBassChunk1);
                //            streamWriter.WriteOscillator(silence200);
                //        }

                //        for (int z = 0; z < 2; z++)
                //        {
                //            streamWriter.WriteChunk(smallBassChunk1);
                //            streamWriter.WriteOscillator(silence100);
                //        }
                //    }


                //    for (int i = 0; i < 4; i++)
                //    {
                //        for (int z = 0; z < 3; z++)
                //        {
                //            streamWriter.WriteChunk(smallBassChunk2);
                //            streamWriter.WriteOscillator(silence200);
                //        }

                //        for (int z = 0; z < 2; z++)
                //        {
                //            streamWriter.WriteChunk(smallBassChunk2);
                //            streamWriter.WriteOscillator(silence100);
                //        }
                //    }

                //}


                //for (int i = 0; i < 3; i++)
                //{
                //    streamWriter.WriteChunk(motorChunk);
                //    streamWriter.WriteOscillator(silence600);
                //}

                //for (int z = 0; z < 10; z++)
                //{
                //    streamWriter.WriteChunk(smallBassChunk2);
                //    streamWriter.WriteOscillator(silence200);
                //}


                //freq = 60;

                //for (int z = 0; z < 5; z++)
                //{
                //    streamWriter.WriteChunk(SampleHelper.MakeChordChunk(duration * 2, freq, 3000));
                //    streamWriter.WriteSilenceChunk(100);
                //    streamWriter.WriteChunk(SampleHelper.MakeChordChunk(duration * 2, freq, 3000));
                //    streamWriter.WriteSilenceChunk(50);
                //    streamWriter.WriteChunk(SampleHelper.MakeChordChunk(duration * 2, freq, 3000));
                //    streamWriter.WriteSilenceChunk(duration);
                //}


                //for (int j = 0; j < 2; j++)
                //{
                //    freq = 60;
                //    for (int k = 0; k < 3; k++)
                //    {
                //        //WriteSample(MakeSample(duration, 50, 300), writer);
                //        //WriteSample(MakeSilenceSample(200), writer);
                //        SequenceHelper.WriteSample(SequenceHelper.MakeSample(duration * 2, freq, 3000), writer);
                //        SequenceHelper.WriteSilenceSample(100, writer);
                //        SequenceHelper.WriteSample(SequenceHelper.MakeSample(duration * 2, freq, 3000), writer);
                //        SequenceHelper.WriteSilenceSample(50, writer);
                //        SequenceHelper.WriteSample(SequenceHelper.MakeSample(duration * 2, freq, 3000), writer);
                //        SequenceHelper.WriteSilenceSample(duration, writer);

                //    }

                //    freq = ((j % 2) != 0) ? 180 : 260;
                //    int repeatSeq = ((j % 2) == 0) ? 2 : 2;
                //    duration = ((j % 2) == 0) ? 100 : 100;

                //    SequenceHelper.WriteUpDownSample(4000, 1500, 500, freq, 1000, writer);

                //    SequenceHelper.WriteSilenceSample(duration * 2, writer);



                //    //for (int i = 0; i < repeatSeq; i++)
                //    //{
                //    //    WriteSample(MakeSample(duration * 3, 50, 300), writer);

                //    //    //if (j != (repeatGlobalCount - 1))
                //    //    //    WriteSample(MakeSample(duration, 30, 3000), writer);
                //    //}


                //}
                streamWriter.Close();
            }

            SoundPlayer player = new SoundPlayer(".\\output.wav");

            player.Load();

            player.PlaySync();

            Application.Current.MainWindow.Close();

            //OscToFile(@".\SampleSine.wav", new Oscillator(WaveType.Sine, 1000, 4000, 300, 2));
            //OscToFile(@".\SampleSawtooth.wav", new Oscillator(WaveType.Sawtooth, 1000, 4000, 300, 2));
            //OscToFile(@".\SampleSquare.wav", new Oscillator(WaveType.Square, 1000, 4000, 300, 2));
        }
예제 #4
0
        private void btnTestForm_Click(object sender, EventArgs e)
        {
            using (MemoryStream stream = new MemoryStream())
            {
                WaveStreamWriter streamWriter = new WaveStreamWriter(stream);

                //   streamWriter.WriteSilenceChunk(5);

                int freq     = (int)waveFormControl.Frequency;
                int duration = (int)waveFormControl.Duration;
                int amp      = (int)waveFormControl.Amplitude;

                List <Tone> tones = new List <Tone>();

                tones.Add(Tones.Item("Do3"));
                tones.Add(Tones.Item("Ré3"));
                tones.Add(Tones.Item("Mi3"));
                tones.Add(Tones.Item("Fa3"));
                tones.Add(Tones.Item("Sol3"));
                tones.Add(Tones.Item("La3"));
                tones.Add(Tones.Item("Si3"));
                tones.Add(Tones.Item("Do4"));

                //foreach (var item in tones)
                //{
                ////streamWriter.WriteOscillator(new Oscillator(WaveType.Sine, (int)numDuration.Value, item.Frequency, (int)numAmplitude.Value, 2));
                //streamWriter.WriteChunk(SampleHelper.MakeChordChunk(duration, freq, amp, 2));
                ////streamWriter.WriteChunk(SampleHelper.MakeChordChunk(duration, freq, -amp, 2));
                //streamWriter.WriteSilenceChunk(10);
                //}


                //foreach (var item in Tones.ToneList())
                //{
                //      streamWriter.WriteOscillator(new Oscillator(WaveType.Sine, 200, item.Frequency, item.Amplitude, 2));
                //      streamWriter.WriteSilenceChunk(100);

                //}
                List <WaveType> types = lvWaveForms.GetSelectedForms();
                AudioChunk      chunk = new AudioChunk();

                foreach (var item in types)
                {
                    chunk.AddOscillator(item, duration, freq, amp, 2);

                    //chunk.AddOscillator(item, duration, freq, -amp, 2);
                }
                ////chunk.AddOscillator(WaveType.Noise, duration, 40, 2000, 2);
                ////chunk.AddOscillator(WaveType.Noise, duration, 20, 1000, 2);

                ////for (int i = 0; i < 15; i++)
                ////{
                ////    chunk.AddOscillator(WaveType.Square, duration, freq - i, amp - (i * 200), 2);
                ////    chunk.AddOscillator(WaveType.Sawtooth, duration, freq - i, amp - (i * 200), 2);
                ////    //chunk.AddOscillator(WaveType.Sine, duration, freq -i, amp - (i * 100), 2);
                ////}

                if (chunk.Oscillators.Count > 0)
                {
                    streamWriter.WriteChunk(chunk);
                    streamWriter.WriteChunk(chunk);
                    streamWriter.WriteChunk(chunk);
                }

                streamWriter.Close();

                PlayStream(stream);
            }
        }
예제 #5
0
        private void btnDraftTest_Click(object sender, EventArgs e)
        {
            using (MemoryStream stream = new MemoryStream())
            {
                WaveStreamWriter streamWriter = new WaveStreamWriter(stream);

                streamWriter.WriteSilenceChunk(50);

                int freq     = (int)waveFormControl.Frequency;
                int duration = (int)waveFormControl.Duration;
                int amp      = (int)waveFormControl.Amplitude;

                List <Tone> tones = new List <Tone>();

                tones.Add(Tones.Item("Do3"));
                tones.Add(Tones.Item("Ré3"));
                tones.Add(Tones.Item("Mi3"));
                tones.Add(Tones.Item("Fa3"));
                tones.Add(Tones.Item("Sol3"));
                tones.Add(Tones.Item("La3"));
                tones.Add(Tones.Item("Si3"));
                tones.Add(Tones.Item("Do4"));

                WriteNote(streamWriter, "Ré3", 75, 300, amp);
                WriteNote(streamWriter, "Sol3", 75, 300, amp);
                WriteNote(streamWriter, "La3", 75, 300, amp);
                WriteNote(streamWriter, "Si3", 100, 300, amp);
                WriteNote(streamWriter, "La3", 125, 300, amp);
                WriteNote(streamWriter, "Sol3", 125, 750, amp);

                WriteNote(streamWriter, "Sol3", 325, 150, amp);
                WriteNote(streamWriter, "Sol3", 60, 150, amp);
                WriteNote(streamWriter, "Sol3", 60, 250, amp);

                WriteNote(streamWriter, "La3", 125, 300, amp);

                WriteNote(streamWriter, "Si3", 125, 350, amp);
                WriteNote(streamWriter, "La3", 125, 650, amp);

                //WriteNote(streamWriter, "La3", 50, 150, amp);
                //WriteNote(streamWriter, "La3", 50, 150, amp);
                //WriteNote(streamWriter, "La3", 50, 150, amp);

                //WriteNote(streamWriter, "Si3", 100, 250, amp);
                //WriteNote(streamWriter, "Do3", 100, 150, amp);
                //WriteNote(streamWriter, "Si3", 100, 200, amp);
                //WriteNote(streamWriter, "La3", 100, 300, amp);

                //WriteNote(streamWriter, "La3", 100, 150, amp);
                //WriteNote(streamWriter, "La3", 100, 150, amp);
                //WriteNote(streamWriter, "La3", 100, 150, amp);

                //WriteNote(streamWriter, "Si3", 100, 300, amp);
                //WriteNote(streamWriter, "La3", 100, 250, amp);
                //WriteNote(streamWriter, "Sol3", 100, 400, amp);
                //WriteNote(streamWriter, "La3", 100, 200, amp);

                streamWriter.Close();

                PlayStream(stream);
            }
        }