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(); } } } }
private void WriteNote(WaveStreamWriter streamWriter, string name, int durationBefore, int duration, int amplitude) { Tone tone = Tones.Item(name); if (durationBefore > 0) { streamWriter.WriteSilenceChunk(durationBefore); } streamWriter.WriteChunk(SampleHelper.MakeBassChunk2(duration, tone.Frequency, amplitude, 2)); //streamWriter.WriteOscillator(new Oscillator(WaveType.Sine, duration, tone.Frequency, amplitude, 2)); }
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); } }
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); } }