Class SoundContext
- Namespace
- Sigil.Sound
- Assembly
- Sigil.Sound.dll
The entry point for live playback: one running output that you Sigil.Sound.SoundContext.Play(Sigil.Sound.Sound,System.Nullable{System.Double}) sounds into and an audio callback (Web Audio, a sound card, a test) pulls frames from with Sigil.Sound.SoundContext.Render(System.Span{Sigil.Sound.StereoFrame}). Every Sigil.Sound.SoundContext.Play(Sigil.Sound.Sound,System.Nullable{System.Double}) hot-swaps what is playing, crossfading from the previous sound.
public sealed class SoundContext : IDisposableInheritance
Implements
Inherited Members
Examples
using Sigil.Sound;
using static Sigil.Sound.Sounds;
var output = new SoundContext(sampleRate: 48_000);
output.Play(Saw(110).LowPass(Sine(0.25).Range(200, 2000)));
// In the audio callback:
output.Render(frames);
Remarks
Sigil.Sound.SoundContext.Play(Sigil.Sound.Sound,System.Nullable{System.Double}) and Sigil.Sound.SoundContext.Stop(System.Nullable{System.Double}) compile on the calling thread and may be called while another thread renders. Sigil.Sound.SoundContext.Render(System.Span{Sigil.Sound.StereoFrame}) is real-time safe and must only be called from one thread.
Constructors
SoundContext(int, int, double, HostClock?)
public SoundContext(int sampleRate = 48000, int blockSize = 256, double fadeSeconds = 0.02, HostClock? clock = null)Parameters
sampleRateint-
Frames per second.
blockSizeint-
The largest block rendered at once.
fadeSecondsdouble-
The default crossfade length of Sigil.Sound.SoundContext.Play(Sigil.Sound.Sound,System.Nullable{System.Double}) and Sigil.Sound.SoundContext.Stop(System.Nullable{System.Double}).
clockHostClock?-
A host clock for sounds to follow; see Sigil.Sound.HostClock. This context advances it after every block it renders, so do not advance it elsewhere. Its sample rate must equal
sampleRate.
Properties
Current
What is playing now; Sigil.Sound.Sounds.Silence until the first Sigil.Sound.SoundContext.Play(Sigil.Sound.Sound,System.Nullable{System.Double}).
public Sound Current { get; }Property Value
FramesRendered
Frames rendered since this output was created.
public long FramesRendered { get; }Property Value
RenderContext
The sample rate and block size this output renders with.
public RenderContext RenderContext { get; }Property Value
Time
Seconds rendered since this output was created.
public double Time { get; }Property Value
Methods
Dispose()
Releases everything the running sounds hold. Stop rendering first.
public void Dispose()Play(Sound, double?)
Crossfades from whatever is playing to sound.
public void Play(Sound sound, double? fadeSeconds = null)Parameters
Render(Span<StereoFrame>)
Fills output with the next frames, in blocks of at most Sigil.Sound.RenderContext.BlockSize.
public void Render(Span<StereoFrame> output)Parameters
outputSpan<StereoFrame>
Stop(double?)
Fades to silence.
public void Stop(double? fadeSeconds = null)Parameters
fadeSecondsdouble?