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 whereA 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 orFFIAudioif 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 theInstructiontype, which is an ADT representation of instructions to an audio engine.
Members
connectXToY :: Int -> Int -> audio -> enginedisconnectXFromY :: Int -> Int -> audio -> engineDisconnect pointer x from pointer y. For example, disconnect a sine wave oscillator from a gain unit.
destroyUnit :: Int -> audio -> engineDestroy 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.
rebaseAllUnits :: Array { from :: Int, to :: Int } -> audio -> engineRebases the pointers to audio units.
makeAllpass :: Int -> AudioParameter -> AudioParameter -> audio -> engineMake an allpass filter.
makeBandpass :: Int -> AudioParameter -> AudioParameter -> audio -> engineMake a bandpass filter.
makeConstant :: Int -> OnOff -> AudioParameter -> audio -> engineMake a constant source, ie a stream of 0s.
makeConvolver :: Int -> String -> audio -> engineMake a convolution unit, aka reverb.
makeDelay :: Int -> AudioParameter -> audio -> engineMake a delay unit.
makeDynamicsCompressor :: Int -> AudioParameter -> AudioParameter -> AudioParameter -> AudioParameter -> AudioParameter -> audio -> engineMake a compressor/expander.
makeGain :: Int -> AudioParameter -> audio -> engineMake a gain unit.
makeHighpass :: Int -> AudioParameter -> AudioParameter -> audio -> engineMake a highpass filter.
makeHighshelf :: Int -> AudioParameter -> AudioParameter -> audio -> engineMake a highshelf filter.
makeLoopBuf :: Int -> String -> OnOff -> AudioParameter -> Number -> Number -> audio -> engineMake a looping audio buffer node.
makeLowpass :: Int -> AudioParameter -> AudioParameter -> audio -> engineMake a lowpass filter.
makeLowshelf :: Int -> AudioParameter -> AudioParameter -> audio -> engineMake a lowshelf filter.
makeMicrophone :: Int -> audio -> engineMake a microphone.
makeNotch :: Int -> AudioParameter -> AudioParameter -> audio -> engineMake a notch filter.
makePeaking :: Int -> AudioParameter -> AudioParameter -> AudioParameter -> audio -> engineMake a peaking filter.
makePeriodicOsc :: Int -> String -> OnOff -> AudioParameter -> audio -> engineMake a periodic oscillator.
makePlayBuf :: Int -> String -> Number -> OnOff -> AudioParameter -> audio -> engineMake an audio buffer node.
makeRecorder :: Int -> String -> audio -> engineMake a recorder.
makeSawtoothOsc :: Int -> OnOff -> AudioParameter -> audio -> engineMake a sawtooth oscillator.
makeSinOsc :: Int -> OnOff -> AudioParameter -> audio -> engineMake a sine-wave oscillator.
makeSpeaker :: Int -> audio -> engineMake a node representing the loudspeaker. For sound to be rendered, it must go to a loudspeaker.
makeSquareOsc :: Int -> OnOff -> AudioParameter -> audio -> engineMake a square-wave oscillator.
makeStereoPanner :: Int -> AudioParameter -> audio -> engineMake a stereo panner
makeTriangleOsc :: Int -> OnOff -> AudioParameter -> audio -> engineMake a triangle-wave oscillator.
makeWaveShaper :: Int -> String -> Oversample -> audio -> engineMake a wave shaper.
setBuffer :: Int -> String -> audio -> engineSets the buffer to read from in a playBuf or loopBuf
setPeriodicOsc :: Int -> String -> audio -> engineSets the periodic oscillator to read from in a periodicOsc
setOn :: Int -> audio -> engineTurn on a generator (an oscillator or playback node).
setOff :: Int -> audio -> engineTurn off a generator (an oscillator or playback node).
setLoopStart :: Int -> Number -> audio -> engineSet the start position of a looping audio buffer node.
setLoopEnd :: Int -> Number -> audio -> engineSet the end position of a looping audio buffer node.
setRatio :: Int -> AudioParameter -> audio -> engineSet the ratio of a compressor.
setOffset :: Int -> AudioParameter -> audio -> engineSet the offset of a constant source node.
setAttack :: Int -> AudioParameter -> audio -> engineSet the attack of a compressor.
setGain :: Int -> AudioParameter -> audio -> engineSet the gain of a gain node or filter.
setQ :: Int -> AudioParameter -> audio -> engineSet the q of a biquad filter.
setPan :: Int -> AudioParameter -> audio -> engineSet the pan of a stereo panner.
setThreshold :: Int -> AudioParameter -> audio -> engineSet the threshold of a compressor.
setRelease :: Int -> AudioParameter -> audio -> engineSet the release of a compressor.
setKnee :: Int -> AudioParameter -> audio -> engineSet the knee of a compressor.
setDelay :: Int -> AudioParameter -> audio -> engineSet the delay of a delay node.
setPlaybackRate :: Int -> AudioParameter -> audio -> engineSet the playback rate of an audio node buffer or loop buffer.
setFrequency :: Int -> AudioParameter -> audio -> engineSet the frequency of an oscillator or filter.
Instances
#AudioContext Source
data AudioContext :: TypeAn AudioContext
#BrowserAudioBuffer Source
data BrowserAudioBuffer :: TypeAn AudioBuffer.
#BrowserCamera Source
data BrowserCamera :: TypeThe MediaStream object for a camera.
#BrowserFloatArray Source
data BrowserFloatArray :: Type
#BrowserMicrophone Source
data BrowserMicrophone :: TypeThe MediaStream object for a microphone.
#BrowserPeriodicWave Source
data BrowserPeriodicWave :: TypeA PeriodicWave.
#FFIAudio' Source
type FFIAudio' = { 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 ornullif 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 usingPlayBuforLoopBuf. See theatari-speaksexample 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
#FFIAudioParameter' Source
type FFIAudioParameter' = { param :: Number, timeOffset :: Number, transition :: String }An AudioParameter with the transition field stringly-typed for easier rendering in the FFI.
Instances
#MediaRecorder Source
data MediaRecorder :: Type
#audioBuffer Source
audioBuffer :: forall bch blen. Pos bch => Pos blen => Int -> Vec bch (Vec blen Number) -> AudioBufferMake 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 AudioContextMake 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.
#defaultFFIAudio Source
defaultFFIAudio :: AudioContext -> Foreign -> FFIAudio'#getAudioClockTime Source
getAudioClockTime :: AudioContext -> Effect NumberGets 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 BooleanIs this MIME type supported by this browser.
#makeAudioBuffer Source
makeAudioBuffer :: AudioContext -> AudioBuffer -> Effect BrowserAudioBufferFor 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 BrowserFloatArrayMake 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 BrowserPeriodicWaveMake 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 ForeignCreate 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 UnitFor 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 :: FFIAudio -> Array (FFIAudio -> Effect Unit) -> Effect UnitRender 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 UnitStops a media recorder
- Modules
- FRP.
Event. MIDI - WAGS.
Change - WAGS.
Connect - WAGS.
Control. Functions - WAGS.
Control. MemoizedState - WAGS.
Control. Qualified - WAGS.
Control. Thunkable - WAGS.
Control. Types - WAGS.
Create - WAGS.
Cursor - WAGS.
Debug - WAGS.
Destroy - WAGS.
Disconnect - WAGS.
Graph. Constructors - WAGS.
Graph. Decorators - WAGS.
Graph. Getter - WAGS.
Graph. Optionals - WAGS.
Graph. Parameter - WAGS.
Interpret - WAGS.
Move - WAGS.
MoveNode - WAGS.
Rebase - WAGS.
Rendered - WAGS.
Run - WAGS.
Universe. AudioUnit - WAGS.
Universe. Bin - WAGS.
Universe. BinN - WAGS.
Universe. EdgeProfile - WAGS.
Universe. Graph - WAGS.
Universe. Node - WAGS.
Universe. Skolems - WAGS.
Universe. Universe - WAGS.
Util - WAGS.
Validation
Connect pointer x to pointer y. For example, connect a sine wave oscillator to a highpass filter.