posted: November 06, 2009
I’m in the middle of working on my Silverlight audio synthesis API which lets you very easily define audio signal chains. I’ve now built support to include the ability to wire up your UI controls into the “fluent” calls.
Let’s say you have a Slider control in your XAML:
<Slider
x:Name="freqSlider"
Minimum="40"
Maximum="1000"
Value="440"/>
Let’s say you want to play a sine wave that changes its frequency with the Slider’s changing value. All you have to do is this:
StereoPcmStreamSource source = new StereoPcmStreamSource();
source.Input =
Oscillator.Create()
.SetFrequency(this.freqSlider, Slider.ValueProperty)
.SendToMixer();
MyMediaElement.SetSource(source);
You can try an exmaple of this app out for yourself.
I’ve added similar UI “injection” methods for attenuation, panning, and modulation:
Oscillator.Create(120)
.SetFrequency(this.frequencySlider, Slider.ValueProperty)
.WaveForm(this.waveFormList, ListBox.SelectedItemProperty)
.AmplitudeModulate(this.ampHz, Slider.ValueProperty)
.Pan(this.panSlider, Slider.ValueProperty)
.Attenuate(this.volumeSlider, Slider.ValueProperty)
.SendToMixer(this.mixer);
If UI injection isn’t your thing, you can hard-code all these values too:
Oscillator.Create(120)
.WaveForm(WaveForm.Sine)
.FrequencyModulate(2, 10000)
.FrequencyModulationWaveForm(WaveForm.Saw)
.AmplitudeModulate(50)
.Pan(short.MinValue)
.Attenuate(-3)
.SendToMixer();
Full code and a larger demo app are coming soon.