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 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); } }
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); } }