Giter Site home page Giter Site logo

purescript-audiograph's Introduction

purescript-audiograph

Latest release Build Status

This is a declarative interface into web-audio in purescript - something roughly along the lines of visual-audio-graph.

Try it out here.

Level of support for Web-Audio

The following nodes are supported at the moment - an implicit destination (output), Oscillator, AudioBufferSource, BiquadFilter, Delay, Gain, StereoPanner, Panner, Convolver and DynamicsCompressor. This includes all the nodes currently purescript-webaudio other than Analyser and MediaElementSource. Full details are given here.

Examples

Nodes may be listed in any order, ending with the key word End.

simple oscillator:

  Gain id1 { gain 2.0 } [ output ]
  Oscillator id2 { type square, frequency 440 } [ id1 ]
  End

cowbell:

  Oscillator osc2 { type square, frequency 800 } [ gain1 ]
  Oscillator osc1 { type square, frequency 540 } [ gain1 ]
  Gain gain1 { gain [ setValue 0.5,
                      setValueAtTime 0.5 t + 0,
                      exponentialRampToValueAtTime 0.01 t + 1.0
                    ] } [ filter1 ]
  BiquadFilter filter1 { type bandpass, frequency 800 } [ output ]
  End

buffer source which loads its audio buffer from a URL:

  AudioBufferSource id2 { url wav/techno.wav, loop true}  [ id1 ]
  Gain id1 { gain 2 } [ output ]
  End,

feedback:

  AudioBufferSource abs { url ogg/chop.ogg, loop true}  [ delay, output ]
  Delay delay { delayTime 0.5 } [ feedback, output ]
  Gain feedback { gain 0.8 } [ delay ]
  End

frequency modulation:

  Oscillator modulator { frequency 0.8 } [ gain1 ]
  Oscillator carrier { frequency 300.0 } [ output ]
  Gain gain1 { gain 30.0 } [ carrier.frequency ]
  End

Nodes

Each line defines a new Audio node in the graph starting with the node type and id. The curly braces define attributes for the node which are either simple scalar values or else complex Audio Params (contained within square braces). The final square braces hold the connections from that node to any other node(s) or to audio parameters on those nodes. An implicit Destination node, named output, is always present by default.

Audio Listener

An Audio Listener is an optional node with no explicit connections to other nodes in the graph. If present, it must be placed last in the node list, just before the End marker. It does have implicit connections however - it listens to the sound created by the overall graph and tends to be used in conjunction with Panner nodes.

Audio Params

These may be setValue, setValueAtTime, setTargetAtTime, linearRampToValueAtTime or exponentialRampToValueAtTime. The params which mention time use a parameter to represent the time (in seconds) which is either a simple number (absolute javascript time) or which takes the form t + n (time relative to the AudioContext start time).

Updates

Updates to a running graph can be defined in a similar manner. The update graph defines a node (or nodes) with attributes that are to be updated. The syntax is identical to that for the initial graph definition but without specifiying connections. For example, you can increase the frequency of the simple oscillator to 880Hz as follows:

simple oscillator update:

  Oscillator id2 { frequency 880 }
  End

Building the library

from the current directory:

$ npm run build

or

$ bower install
$ pulp build

User Interface

audiograph_editor is an editor (written in Halogen) for audiograph scripts that allows you to 'play' the script after each keystroke (assuming that it still conforms to the DSL).

to build:

$ npm run editor

Then host audiograph-editor/dist/index.html on your web server of choice.

Building the Simple Examples

cd to simple-examples:

$ npm run simple-examples

Then host simple-examples/dist/index.html on your web server of choice.

Contributing

Contributions would be more than welcome to help nurture it a little. purescript-webaudio only covers a relatively small proportion of the Web-Audio API at the moment. visual-audio-graph has some nice approaches to specifying custom nodes which we could perhaps steal.

Module documentation

Module documentation is published on Pursuit.

purescript-audiograph's People

Contributors

newlandsvalley avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

purescript-audiograph's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.