protected override double[] generate(int nSamples) { double[] outData = new double[nSamples]; Random rand = new Random(); //if a new random is created every time, it doesn't update fast enough! int freqInSamples = (int)((1 / freq) * SynthesisBase.SampleRate); int numChunks = nSamples / freqInSamples; WaveAudio chunk = null; for (int i = 0; i < numChunks; i++) { if (i % this.chunksbeforeswitch == 0) { if (chunk == null) { //seed with Sine wave chunk = new Sine(210, amplitude / 4).CreateWaveAudio(1 / freq + 0.01); } else { WaveAudio newchunk = new RedNoise(amplitude, rednoisefactor, rand).CreateWaveAudio(1 / freq + 0.01); chunk = WaveAudio.Mix(chunk, this.smoothing, newchunk, 1 - this.smoothing); } } Array.Copy(chunk.data[0], 0, outData, i * freqInSamples, freqInSamples); } //fill in the rest if (numChunks * freqInSamples < nSamples) { Array.Copy(chunk.data[0], 0, outData, numChunks * freqInSamples, nSamples - numChunks * freqInSamples); } return(outData); }
public static void operations_test(AudioPlayer pl) { WaveAudio noteLongLow = new Triangle(Triangle.FrequencyFromMidiNote(60), 0.5).CreateWaveAudio(1.0); WaveAudio noteShortHi = new Triangle(Triangle.FrequencyFromMidiNote(64), 0.5).CreateWaveAudio(0.5); pl.Play(WaveAudio.Concatenate(noteLongLow, noteShortHi)); pl.Play(WaveAudio.Concatenate(noteShortHi, noteLongLow)); pl.Play(WaveAudio.Mix(noteShortHi, noteLongLow)); pl.Play(WaveAudio.Mix(noteLongLow, noteShortHi)); WaveAudio tmp = new Sine(200,1.0).CreateWaveAudio(4.0); tmp.setNumChannels(2, true); pl.Play(WaveAudio.Modulate(new WaveAudio(mediadir+"d44k16bit2ch.wav"), tmp)); WaveAudio cp; cp = noteLongLow.Clone(); cp.FadeIn(0.3); pl.Play(cp); cp = noteLongLow.Clone(); cp.FadeOut(0.3); pl.Play(cp); cp = noteLongLow.Clone(); cp.Amplify(0.5); pl.Play(cp); cp = noteLongLow.Clone(); cp.Amplify(2.0); pl.Play(cp); }
protected override double[] generate(int nSamples) { double[] outData = new double[nSamples]; Random rand = new Random(); //if a new random is created every time, it doesn't update fast enough! int freqInSamples = (int)((1 / freq) * SynthesisBase.SampleRate); int numChunks = nSamples / freqInSamples; WaveAudio chunk = null; for (int i = 0; i < numChunks; i++) { if (i % this.chunksbeforeswitch == 0) { if (chunk == null) { //seed with Sine wave chunk = new Sine(210, amplitude / 4).CreateWaveAudio(1 / freq + 0.01); } else { WaveAudio newchunk = new RedNoise(amplitude, rednoisefactor, rand).CreateWaveAudio(1 / freq + 0.01); chunk = WaveAudio.Mix(chunk, this.smoothing, newchunk, 1 - this.smoothing); } } Array.Copy(chunk.data[0], 0, outData, i * freqInSamples, freqInSamples); } //fill in the rest if (numChunks * freqInSamples < nSamples) Array.Copy(chunk.data[0], 0, outData, numChunks * freqInSamples, nSamples - numChunks * freqInSamples); return outData; }
// normally one seperates ui and engine, as the other experiments do, but here I did it the fast way. public WaveAudio viblab_Generate() { WaveAudio w; // get source if (this.vibLab_chkSound.Checked) { if (this.m_vibLab_filename == null) { MessageBox.Show("You haven't opened a sound."); return null; } //I think we already loaded this. So it's kind of wasteful. Too tired to fix this though. w = new WaveAudio(this.m_vibLab_filename); } else { double freq = (this.vibLab_source_bar.Value / 100.0) * 440 + 100; w = new Sine(freq, 0.7).CreateWaveAudio(20.0); } if (vibLab_panel1.Visible) { if (vibLab_chkTrem1.Checked) w = Effects.Tremolo(w, this.vibLab_valueFreq1, this.vibLab_valueWidth1); else w = Effects.Vibrato(w, this.vibLab_valueFreq1, this.vibLab_valueWidth1); } if (vibLab_panel2.Visible) { if (vibLab_chkTrem2.Checked) w = Effects.Tremolo(w, this.vibLab_valueFreq2, this.vibLab_valueWidth2); else w = Effects.Vibrato(w, this.vibLab_valueFreq2, this.vibLab_valueWidth2); } if (vibLab_panel3.Visible) { if (vibLab_chkTrem3.Checked) w = Effects.Tremolo(w, this.vibLab_valueFreq3, this.vibLab_valueWidth3); else w = Effects.Vibrato(w, this.vibLab_valueFreq3, this.vibLab_valueWidth3); } return w; }