WAGS.Interpret
- Package
- purescript-wags
- Repository
- mikesol/purescript-wags
Interpret audio in an engine using the AudioInterpret
class.
WAGS ships with two engines - Effect Unit
for real audio and Instruction
for an ADT representation of audio.
#AudioInterpret Source
class AudioInterpret audio engine where
A class with all possible instructions for interpreting audio. The class is paramaterized by two types:
audio
: an audio context, which could be nothing (ieUnit
) if there is audio orFFIAudio
if there is audio.engine
: the output of the engine. For real audio, this isEffect Unit
, as playing something from a loudspeaker is a side effect that doesn't return anything. For testing, this is theInstruction
type, which is an ADT representation of instructions to an audio engine.
Members
connectXToY :: String -> String -> audio -> engine
disconnectXFromY :: String -> String -> audio -> engine
Disconnect pointer x from pointer y. For example, disconnect a sine wave oscillator from a gain unit.
destroyUnit :: String -> audio -> engine
Destroy pointer x. For example, drop a sine wave oscillator from an audio graph. Note that this does not invoke garbage collection - it just removes the reference to the node, allowing it to be garbage collected.
makeAllpass :: String -> AudioParameter -> AudioParameter -> audio -> engine
Make an allpass filter.
makeBandpass :: String -> AudioParameter -> AudioParameter -> audio -> engine
Make a bandpass filter.
makeConstant :: String -> APOnOff -> AudioParameter -> audio -> engine
Make a constant source, ie a stream of 0s.
makeConvolver :: String -> String -> audio -> engine
Make a convolution unit, aka reverb.
makeDelay :: String -> AudioParameter -> audio -> engine
Make a delay unit.
makeDynamicsCompressor :: String -> AudioParameter -> AudioParameter -> AudioParameter -> AudioParameter -> AudioParameter -> audio -> engine
Make a compressor/expander.
makeGain :: String -> AudioParameter -> audio -> engine
Make a gain unit.
makeHighpass :: String -> AudioParameter -> AudioParameter -> audio -> engine
Make a highpass filter.
makeHighshelf :: String -> AudioParameter -> AudioParameter -> audio -> engine
Make a highshelf filter.
makeLoopBufWithDeferredBuffer :: String -> audio -> engine
Make a looping audio buffer node with a deferred buffer.
makeLoopBuf :: String -> String -> APOnOff -> AudioParameter -> Number -> Number -> audio -> engine
Make a looping audio buffer node.
makeLowpass :: String -> AudioParameter -> AudioParameter -> audio -> engine
Make a lowpass filter.
makeLowshelf :: String -> AudioParameter -> AudioParameter -> audio -> engine
Make a lowshelf filter.
makeMicrophone :: audio -> engine
Make a microphone.
makeNotch :: String -> AudioParameter -> AudioParameter -> audio -> engine
Make a notch filter.
makePeaking :: String -> AudioParameter -> AudioParameter -> AudioParameter -> audio -> engine
Make a peaking filter.
makePeriodicOscWithDeferredOsc :: String -> audio -> engine
Make a periodic oscillator.
makePeriodicOsc :: String -> String -> APOnOff -> AudioParameter -> audio -> engine
Make a periodic oscillator.
makePeriodicOscV :: forall (a :: Type). String -> (Vec a Number) /\ (Vec a Number) -> APOnOff -> AudioParameter -> audio -> engine
Make a periodic oscillator
makePlayBufWithDeferredBuffer :: String -> audio -> engine
Make an audio buffer node with a deferred buffer.
makePlayBuf :: String -> String -> Number -> APOnOff -> AudioParameter -> audio -> engine
Make an audio buffer node.
makeRecorder :: String -> String -> audio -> engine
Make a recorder.
makeSawtoothOsc :: String -> APOnOff -> AudioParameter -> audio -> engine
Make a sawtooth oscillator.
makeSinOsc :: String -> APOnOff -> AudioParameter -> audio -> engine
Make a sine-wave oscillator.
makeSpeaker :: audio -> engine
Make a node representing the loudspeaker. For sound to be rendered, it must go to a loudspeaker.
makeSquareOsc :: String -> APOnOff -> AudioParameter -> audio -> engine
Make a square-wave oscillator.
makeStereoPanner :: String -> AudioParameter -> audio -> engine
Make a stereo panner
makeTriangleOsc :: String -> APOnOff -> AudioParameter -> audio -> engine
Make a triangle-wave oscillator.
makeWaveShaper :: String -> String -> Oversample -> audio -> engine
Make a wave shaper.
setBuffer :: String -> String -> audio -> engine
Sets the buffer to read from in a playBuf or loopBuf
setPeriodicOsc :: String -> String -> audio -> engine
Sets the periodic oscillator to read from in a periodicOsc
setPeriodicOscV :: forall (a :: Type). String -> (Vec a Number) /\ (Vec a Number) -> audio -> engine
Sets the periodic oscillator to read from in a periodicOsc
setOnOff :: String -> APOnOff -> audio -> engine
Turn on or off a generator (an oscillator or playback node).
setBufferOffset :: String -> Number -> audio -> engine
Set the offset for a playbuf
setLoopStart :: String -> Number -> audio -> engine
Set the start position of a looping audio buffer node.
setLoopEnd :: String -> Number -> audio -> engine
Set the end position of a looping audio buffer node.
setRatio :: String -> AudioParameter -> audio -> engine
Set the ratio of a compressor.
setOffset :: String -> AudioParameter -> audio -> engine
Set the offset of a constant source node.
setAttack :: String -> AudioParameter -> audio -> engine
Set the attack of a compressor.
setGain :: String -> AudioParameter -> audio -> engine
Set the gain of a gain node or filter.
setQ :: String -> AudioParameter -> audio -> engine
Set the q of a biquad filter.
setPan :: String -> AudioParameter -> audio -> engine
Set the pan of a stereo panner.
setThreshold :: String -> AudioParameter -> audio -> engine
Set the threshold of a compressor.
setRelease :: String -> AudioParameter -> audio -> engine
Set the release of a compressor.
setKnee :: String -> AudioParameter -> audio -> engine
Set the knee of a compressor.
setDelay :: String -> AudioParameter -> audio -> engine
Set the delay of a delay node.
setPlaybackRate :: String -> AudioParameter -> audio -> engine
Set the playback rate of an audio node buffer or loop buffer.
setFrequency :: String -> AudioParameter -> audio -> engine
Set the frequency of an oscillator or filter.
Instances
AudioInterpret Unit Instruction
AudioInterpret FFIAudioSnapshot (Effect Unit)
(AudioInterpret a c, AudioInterpret b d) => AudioInterpret (Tuple a b) (Tuple c d)
#AudioContext Source
data AudioContext :: Type
An AudioContext
#FFIAudioWithBehaviors Source
type FFIAudioWithBehaviors = { buffers :: Behavior (Object BrowserAudioBuffer), context :: AudioContext, floatArrays :: Behavior (Object BrowserFloatArray), microphone :: Behavior (Nullable BrowserMicrophone), periodicWaves :: Behavior (Object BrowserPeriodicWave), recorders :: Behavior (Object (MediaRecorder -> Effect Unit)), units :: Foreign, writeHead :: Number }
#BrowserAudioBuffer Source
data BrowserAudioBuffer :: Type
An AudioBuffer.
#BrowserCamera Source
data BrowserCamera :: Type
The MediaStream object for a camera.
#BrowserFloatArray Source
data BrowserFloatArray :: Type
#BrowserMicrophone Source
data BrowserMicrophone :: Type
The MediaStream object for a microphone.
#BrowserPeriodicWave Source
data BrowserPeriodicWave :: Type
A PeriodicWave.
#FFIAudioSnapshot' Source
type FFIAudioSnapshot' = { buffers :: Object BrowserAudioBuffer, context :: AudioContext, floatArrays :: Object BrowserFloatArray, microphone :: Nullable BrowserMicrophone, periodicWaves :: Object BrowserPeriodicWave, recorders :: Object (MediaRecorder -> Effect Unit), units :: Foreign, writeHead :: Number }
The audio information that goes to the ffi during rendering.
context
- the audio context. To create anAudioContext
, usecontext
.writeHead
- the moment in time in the audio context at which we are writing. The easing algorithm provided to run makes sure that this is always slightly ahead of the actual audio context time. When starting a scene, this should be set to0.0
.units
- an object in which audio units are cached and retrieved. To create this, usemakeUnitCache
.microphone
- the browser microphone ornull
if we do not have one.recorders
- an object recorder rendering functions. Because media recorders do not yet exist when a scene starts, we provide rendering functions and then fill in the actual recorders once the rendering starts.buffers
- an object containing named audio buffers for playback usingPlayBuf
orLoopBuf
. See theatari-speaks
example to see how a buffer is used.floatArrays
- arrays of 32=bit floats used for wave shaping.periodicWaves
- array of periodic waves used for creating oscillator nodes.
Instances
#FFIAudioSnapshot Source
#FFINumericAudioParameter Source
type FFINumericAudioParameter = { cancel :: Boolean, param :: Number, timeOffset :: Number, transition :: String }
An AudioParameter with the transition
field stringly-typed for easier rendering in the FFI and cancelation as a boolean
Instances
#MediaRecorder Source
data MediaRecorder :: Type
#audioBuffer Source
audioBuffer :: forall bch blen. Pos bch => Pos blen => Int -> Vec bch (Vec blen Number) -> AudioBuffer
Make a multi-channel audio buffer. Each vector into the multi-channel buffer must be the same length.
#audioWorkletAddModule Source
audioWorkletAddModule :: AudioContext -> String -> Effect (Promise Unit)
For a given audio context, add the audio worklet module at a given URI.
#context Source
context :: Effect AudioContext
Make a new audio context.
#decodeAudioDataFromBase64EncodedString Source
decodeAudioDataFromBase64EncodedString :: AudioContext -> String -> Effect (Promise BrowserAudioBuffer)
Given an audio context and a base-64-encoded audio file, decode the content of the string to an audio buffer.
#decodeAudioDataFromUri Source
decodeAudioDataFromUri :: AudioContext -> String -> Effect (Promise BrowserAudioBuffer)
Given an audio context and a URI, decode the content of the URI to an audio buffer.
#getAudioClockTime Source
getAudioClockTime :: AudioContext -> Effect Number
Gets the audio clock time from an audio context.
#getMicrophoneAndCamera Source
getMicrophoneAndCamera :: Boolean -> Boolean -> Aff { camera :: Maybe BrowserCamera, microphone :: Maybe BrowserMicrophone }
#isTypeSupported Source
isTypeSupported :: String -> Effect Boolean
Is this MIME type supported by this browser.
#makeAudioBuffer Source
makeAudioBuffer :: AudioContext -> AudioBuffer -> Effect BrowserAudioBuffer
For a given audio context, use an audio buffer to create a browser audio buffer. This is useful when doing DSP in the browser. Note that AudioBuffer
is a purescript type whereas BrowserAudioBuffer
is an optimized browser-based type. That means that, once you write to BrowserAudioBuffer
, it is effectively a blob and its contents cannot be retrieved using the WAGS API.
#makeFloatArray Source
makeFloatArray :: Array Number -> Effect BrowserFloatArray
Make a float 32 array. Useful when creating a waveshaper node.
#makePeriodicWave Source
makePeriodicWave :: forall len. Pos len => AudioContext -> Vec len Number -> Vec len Number -> Effect BrowserPeriodicWave
Make a browser periodic wave. A PureScript-ified version of the periodic wave constructor from the Web Audio API. Given an audio context, a vector of real parts of complex numbers, and a vector of imaginary parts of complex numbers, build a periodic wave interpretable by the Web Audio API.
#makeUnitCache Source
makeUnitCache :: Effect Foreign
Create a unit cache. This returns a fresh empty object {}
that is used to cache audio units.
#mediaRecorderToUrl Source
mediaRecorderToUrl :: String -> (String -> Effect Unit) -> MediaRecorder -> Effect Unit
For a given MIME type, pass the URL-ified content of a media recorder as a string to a handler.
mediaRecorderToUrl "audio/ogg" setAudioTagUrlToThisContent recorder
#renderAudio Source
renderAudio :: Array (Effect Unit) -> Effect Unit
Render audio from an array of audio rendering instructions. This is conceptually the same as
taking Array Effect Unit -> Effect Unit
and doing map fold <<< sequence
.
The reason this version is used is because it is ~2x more computationally efficient,
which is important in order to be able to hit audio deadlines.
#stopMediaRecorder Source
stopMediaRecorder :: MediaRecorder -> Effect Unit
Stops a media recorder
- Modules
- FRP.
Event. MIDI - WAGS.
Change - WAGS.
Change. Optionals - WAGS.
Comonad - WAGS.
Connect - WAGS.
Control. Functions - WAGS.
Control. Functions. Validated - WAGS.
Control. Indexed - WAGS.
Control. Types - WAGS.
Create - WAGS.
Create. Optionals - WAGS.
CreateT - WAGS.
Debug - WAGS.
Destroy - WAGS.
Disconnect - WAGS.
Edgeable - WAGS.
Graph. AudioUnit - WAGS.
Graph. Edge - WAGS.
Graph. Graph - WAGS.
Graph. Node - WAGS.
Graph. Oversample - WAGS.
Graph. Paramable - WAGS.
Graph. Parameter - WAGS.
Interpret - WAGS.
Math - WAGS.
Patch - WAGS.
Rendered - WAGS.
Run - WAGS.
Util - WAGS.
Validation
Connect pointer x to pointer y. For example, connect a sine wave oscillator to a highpass filter.