WebPd

WebPd aims to allow a subset of Pure Data audio patches to run in the browser without plugins. Right now the focus is on DSP objects, to enable you to mock up audio engines in Pd, put them on the web, and control them with Javascript.

Here are the test pages (i.e. examples of Pd patches which run in a webpage on Firefox). To run these, you will need the experimental Firefox Audio Data API builds from here. More information about the Audio Data API is available online.

This is changing very fast right now and new FireFox builds are coming out every day. If you want to keep abreast of the latest changes, here is the WebPd mailing list: http://groups.google.com/group/web-pure-data/. You might also like to check my blog.

Copyright Chris McCormick, 2010. Licensed under the terms of the AGPLv3 or a later version of that license.

Documentation

Here is the official Pure Data documentation by Miller Puckette, the creator of Pure Data. Note: very little of the full Pure Data functionality has been implemented yet. Most things probably won't work.

Contributing

Right now I'm really looking for people to contribute DSP/audio objects (or 'tilde' objects with names ending with '~'). The messaging side of Pd is not yet implemented. Here's how you can contribute code:

Source code

svn

You can use SVN to get a read-only copy of the source code from http://code.google.com/p/web-pure-data/ with the command svn checkout http://web-pure-data.googlecode.com/svn/trunk/ webpd-readonly. Feel free to send me patches using diff, or else I can give you commit access to Google Code repository.

bzr

You can use bzr to get the source code, which is what I use for local development.

The advantage of using bzr is that you can make local commits in your copy of the source, and once you are finished you can push those commits to me in one bunch. With SVN you can't push the changes back into the repository unless I give you commit access on the project.

git

You could also use git-svn to fetch a copy of the source from the google code repository, and I will merge git pushes if you make them available somewhere like github. Use the git-svn instructions from github if you'd like to do that.

Anatomy of a PdObject

Here is the source code of the [+~] object, which adds two audio inlets together, with verbose comments. You can find this code inside pd.js in the PdObjects array. The really important bit is the "dsptick" method which is where the actual audio processing goes on. You can copy and paste this object to implement new Pd objects.

// Use the object name as it appears in the Pd patch here
"+~": {
    // Endpoints are special objects where audio finishes up and exits the patch.
    // e.g. [dac~] (audio output), [outlet~] (output to another patch), and [print~] (output to the console)
    // Most objects aren't endpoints.
    "endpoint": false,

    // How many audio outlets i have - an audio buffer will be created for each outlet.
    "buffers": 1,

    // This method is run when the object is created.
    // You can do stuff in here like read in the arguments and initialise variables.
    "init": function(args) {
        if (args.length >= 6) {
            this.val = parseFloat(args[5]);
        }
        this.pd.log(this.inlets);
    },

    // This is the most important method, and gets called each time the dsp graph is computed (every frame).
    // In here you should usually be taking a vector of audio data from your inlets with this.inletBuffer(0)
    // and then applying some function to every piece of audio data, and then placing the resulting output
    // into this object's outlet buffer.
    "dsptick": function() {
        // This part checks whether the object was initialised with a fixed float value. e.g. [+~ 0.5]
        // If it has been initialised with a fixed float, then we want to multiply every piece of data
        // in the audio buffer by that fixed value.
        if (this.val) {
            // Get the incoming data buffer.
            var i1 = this.inletBuffer(0);
            // Loop through the incoming data and multiply each value by our fixed integer.
            // Store the result in our outlet buffer.
            for (var i=0; i < i1.length; i++) {
                this.outlets[0][i] = i1[i] + this.val;
            }
        // If we are instead multiplying two audio streams together we execute this bit.
        } else {
            // Get the incoming data buffers of both audio streams.
            var i1 = this.inletBuffer(0);
            var i2 = this.inletBuffer(1);
            // Loop through the incoming data from both streams, multiplying them together.
            // Store the result in our outlet buffer.
            for (var i=0; i < i1.length; i++) {
                this.outlets[0][i] = i1[i] + i2[i];
            }
        }
    },
},

Have fun!

Unimplemented objects

(show)

Implemented objects are prefixed with a '>', whilst unimplemented objects are prefixed with a '<'.

AUDIO MATH
----------

> +~
< -~
> *~
< /~
< max~
< min~
< clip~
< q8_rsqrt~
< q8_sqrt~
< wrap~
< fft~
< ifft~
< rfft~
< rifft~
< pow~
< log~
< exp~
< abs~
< framp~
< mtof~
< ftom~
< rmstodb~
< dbtorms~
< rmstopow~
< powtorms~

AUDIO GLUE
----------

> dac~
< adc~
< sig~
< line~
< vline~
< threshold~
< snapshot~
< vsnapshot~
< bang~
< samplerate~
< send~, s~
< receive~, r~
< throw~
< catch~
< block~
< switch~
< readsf~
< writesf~

AUDIO SOURCES
-------------

> phasor~
< cos~
> osc~
< tabwrite~
< tabplay~
< tabread4~
< tabosc4~
< tabsend~
< tabreceive~

AUDIO FILTERS
-------------

< vcf~
< noise~
< env~
< hip~
< lop~
< bp~
< biquad~
< samphold~
< print~
< rpole~
< rzero~
< rzero_rev~
< cpole~
< czero~
< czero_rev~

AUDIO DELAY
-----------

< delwrite~
< delread~
< vd~

< pd
< table
< inlet
< outlet
< inlet~
< outlet~

GLUE
----

< bang, b, bng
< float, f
< symbol
< int
< send, s
< receive, r
< select, sel
< route
< pack
< unpack
< trigger, t
< spigot
< moses
< until
< print
< makefilename
< change
< swap
< value
< toggle
< list (prepend, append, trim, length)

TIME
----

< delay, del
< metro
< line
< timer
< cputime
< realtime
< pipe

MATH
----

< +
< -
< *
< /
< pow

< ==
< !=
< >
< <
< >=
< <=

< &
< &&
< |
< ||
< %

< mtof
< powtodb
< rmstodb
< ftom
< dbtopow
< dbtorms

< mod
< div
< sin
< cos
< tan

< atan
< atan2
< sqrt
< log
< exp
< abs

< random
< max
< min
< clip
< wrap

MIDI
----

< notein
< ctlin
< pgmin
< bendin
< touchin
< polytouchin
< midiin
< sysexin

< noteout
< ctlout
< pgmout
< bendout
< touchout
< polytouchout
< midiout

< makenote
< stripnote

TABLES
------

< tabread
< tabread4
< tabwrite
< soundfiler

MISC
----

< loadbang
< serial
< netsend
< netreceive
< qlist
< textfile
< openpanel
< savepanel
< bag
< poly
< key
< keyup
< keyname
< declare

DATA STRUCTURES
---------------

< struct
< drawcurve
< filledcurve
< drawpolygon
< filledpolygon
< plot
< drawnumber

ACCESSING DATA
--------------

< pointer
< get
< set
< element
< getsize
< setsize
< append
< sublist

OBSOLETE
--------

< namecanvas
< scalar
< scope~
< template


bzr log

(show)
------------------------------------------------------------
revno: 81
committer: Chris McCormick 
branch nick: webpd
timestamp: Sun 2010-06-06 16:22:48 +0800
message:
  Silently drop messages to unconnected outlets, just like Pd.
------------------------------------------------------------
revno: 80
committer: Chris McCormick 
branch nick: webpd
timestamp: Sun 2010-06-06 16:05:22 +0800
message:
  Added a test for list meta-element to message-dollar-args, added handling of list atom to toarray() method.
------------------------------------------------------------
revno: 79
committer: Chris McCormick 
branch nick: webpd
timestamp: Sun 2010-06-06 15:46:18 +0800
message:
  Improved atom handling with PdObject method toarray - turns string/float to an array of values.
------------------------------------------------------------
revno: 78
committer: Chris McCormick 
branch nick: webpd
timestamp: Sun 2010-06-06 15:29:43 +0800
message:
  Got the [pack] object working with tests.
------------------------------------------------------------
revno: 77
committer: Chris McCormick 
branch nick: webpd
timestamp: Sat 2010-06-05 18:46:14 +0800
message:
  Added stuff to remember to the TODO list.
------------------------------------------------------------
revno: 76
committer: Chris McCormick 
branch nick: webpd
timestamp: Sat 2010-06-05 18:35:24 +0800
message:
  Forgot unit tests for add. Renamed multiply~.
------------------------------------------------------------
revno: 75
committer: Chris McCormick 
branch nick: webpd
timestamp: Sat 2010-06-05 18:28:40 +0800
message:
  Add object based on multiply object.
------------------------------------------------------------
revno: 74
committer: Chris McCormick 
branch nick: webpd
timestamp: Sat 2010-06-05 18:22:01 +0800
message:
  multiply passes extra args back to inlet 1 to set multiplier.
------------------------------------------------------------
revno: 73
committer: Chris McCormick 
branch nick: webpd
timestamp: Sat 2010-06-05 17:28:10 +0800
message:
  Added the non-dsp multiply object.
------------------------------------------------------------
revno: 72
committer: Chris McCormick 
branch nick: webpd
timestamp: Sat 2010-06-05 17:03:14 +0800
message:
  Tweaking tests console output.
------------------------------------------------------------
revno: 71
committer: Chris McCormick 
branch nick: webpd
timestamp: Sat 2010-06-05 16:55:50 +0800
message:
  Got [unpack] object working with tests, and improved unit testing by segretating "stdout" and "stderr".
------------------------------------------------------------
revno: 70
committer: Chris McCormick 
branch nick: webpd
timestamp: Sat 2010-06-05 16:10:42 +0800
message:
  Fixed a small bug in trigger
------------------------------------------------------------
revno: 69
committer: Chris McCormick 
branch nick: webpd
timestamp: Sat 2010-06-05 16:07:14 +0800
message:
  Improved tests by displaying expected output (goldenfile) if present. Fixed message dollar args to match goldenfile.
------------------------------------------------------------
revno: 68
committer: Chris McCormick 
branch nick: webpd
timestamp: Sat 2010-06-05 11:58:21 +0800
message:
  Added TODO list file.
------------------------------------------------------------
revno: 67
committer: Chris McCormick 
branch nick: webpd
timestamp: Thu 2010-06-03 11:19:04 +0800
message:
  Got dollar args in messages working plus tests.
------------------------------------------------------------
revno: 66
committer: Chris McCormick 
branch nick: webpd
timestamp: Wed 2010-06-02 17:24:17 +0800
message:
  If float value is already an actual float in pd.tofloat(), return that.
------------------------------------------------------------
revno: 65
committer: Chris McCormick 
branch nick: webpd
timestamp: Wed 2010-06-02 16:48:45 +0800
message:
  Left in stray console.log statements.
------------------------------------------------------------
revno: 64
committer: Chris McCormick 
branch nick: webpd
timestamp: Wed 2010-06-02 16:41:42 +0800
message:
  Got basic line~ object test working.
------------------------------------------------------------
revno: 63
committer: Chris McCormick 
branch nick: webpd
timestamp: Wed 2010-06-02 13:33:43 +0800
message:
  Loadbang multi-message test now passing.
------------------------------------------------------------
revno: 62
committer: Chris McCormick 
branch nick: webpd
timestamp: Wed 2010-06-02 13:28:33 +0800
message:
  Moved some objects around and got the message tokenizer working, with a test at test-tokenizer.html.
------------------------------------------------------------
revno: 61
committer: Chris McCormick 
branch nick: webpd
timestamp: Tue 2010-06-01 18:20:57 +0800
message:
  mtof~ object and unit tests.
------------------------------------------------------------
revno: 60
committer: Chris McCormick 
branch nick: webpd
timestamp: Tue 2010-06-01 18:01:36 +0800
message:
  Float object (left inlet only) with tests.
------------------------------------------------------------
revno: 59
committer: Chris McCormick 
branch nick: webpd
timestamp: Mon 2010-05-31 23:26:58 +0800
message:
  Added console to xmen demo.
------------------------------------------------------------
revno: 58
committer: Chris McCormick 
branch nick: webpd
timestamp: Mon 2010-05-31 23:24:31 +0800
message:
  Trigger object with tests and goldenfiles.
------------------------------------------------------------
revno: 57
committer: Chris McCormick 
branch nick: webpd
timestamp: Sun 2010-05-30 16:01:22 +0800
message:
  Configurable audio Array type.
------------------------------------------------------------
revno: 56
committer: Chris McCormick 
branch nick: webpd
timestamp: Sun 2010-05-30 15:53:50 +0800
message:
  Nit - forgot a console.log statement.
------------------------------------------------------------
revno: 55
committer: Chris McCormick 
branch nick: webpd
timestamp: Sun 2010-05-30 15:49:53 +0800
message:
  Improved audio buffer filling and non-audio-enabled Firefox performance.
------------------------------------------------------------
revno: 54
committer: Chris McCormick 
branch nick: webpd
timestamp: Sat 2010-05-29 22:01:52 +0800
message:
  Relicensed this code under the terms of the AGPLv3.
------------------------------------------------------------
revno: 53
committer: Chris McCormick 
branch nick: webpd
timestamp: Sat 2010-05-29 21:45:31 +0800
message:
  xmen demo tweaks and some info.
------------------------------------------------------------
revno: 52
committer: Chris McCormick 
branch nick: webpd
timestamp: Sat 2010-05-29 18:12:07 +0800
message:
  xmen demo tweaks.
------------------------------------------------------------
revno: 51
committer: Chris McCormick 
branch nick: webpd
timestamp: Sat 2010-05-29 18:07:52 +0800
message:
  Fixed message function overriding in int/dsp chains. Got xmen sample looper demo working.
------------------------------------------------------------
revno: 50
committer: Chris McCormick 
branch nick: webpd
timestamp: Sat 2010-05-29 14:19:29 +0800
message:
  Fixed a bug in table loading - loading the idx element into position 0.
------------------------------------------------------------
revno: 49
committer: Chris McCormick 
branch nick: webpd
timestamp: Sat 2010-05-29 13:31:51 +0800
message:
  xmen sample looper is basically working (but clicky bugs)
------------------------------------------------------------
revno: 48
committer: Chris McCormick 
branch nick: webpd
timestamp: Sat 2010-05-29 13:19:44 +0800
message:
  Got tabread working. Had to refactor tables stuff into being a proper object.
------------------------------------------------------------
revno: 47
committer: Chris McCormick 
branch nick: webpd
timestamp: Sat 2010-05-29 12:26:04 +0800
message:
  Very basic message test working.
------------------------------------------------------------
revno: 46
committer: Chris McCormick 
branch nick: webpd
timestamp: Sat 2010-05-29 11:48:47 +0800
message:
  Add and subtract dsp tests.
------------------------------------------------------------
revno: 45
committer: Chris McCormick 
branch nick: webpd
timestamp: Sat 2010-05-29 11:26:44 +0800
message:
  Got table data reading working. Added a debug mode for console output.
------------------------------------------------------------
revno: 44
committer: Chris McCormick 
branch nick: webpd
timestamp: Fri 2010-05-28 21:46:50 +0800
message:
  "Two bad objects" test, and got loadbang working with a very basic callback scheduler.
------------------------------------------------------------
revno: 43
committer: Chris McCormick 
branch nick: webpd
timestamp: Fri 2010-05-28 20:17:12 +0800
message:
  Fixed a bug where undefined object types throw an error.
------------------------------------------------------------
revno: 42
committer: Chris McCormick 
branch nick: webpd
timestamp: Fri 2010-05-28 20:01:14 +0800
message:
  Objects follow new dsp inlet scheme, fixed phasor~ to be non-jumping, improved osc~ calculation, osc~ into osc~ test runs.
    ------------------------------------------------------------
    revno: 41.1.3
    committer: Chris McCormick 
    branch nick: webpd
    timestamp: Fri 2010-05-28 18:14:46 +0800
    message:
      Minor tweaks to tests.
    ------------------------------------------------------------
    revno: 41.1.2
    committer: Chris McCormick 
    branch nick: webpd
    timestamp: Fri 2010-05-28 18:04:42 +0800
    message:
      Fixed phasor~ breakage, improved osc~ calculation slightly. Removed spurious console.log statement.
    ------------------------------------------------------------
    revno: 41.1.1
    committer: Chris McCormick 
    branch nick: webpd
    timestamp: Fri 2010-05-28 18:01:00 +0800
    message:
      Made all objects use the new dsp inlet scheme. Fixed phasor~ to be non-jumping at frequency changes.
------------------------------------------------------------
revno: 41
committer: Chris McCormick 
branch nick: webpd
timestamp: Fri 2010-05-28 17:36:50 +0800
message:
  Make dsp inlets behave consistently with regards to incoming integer messages.
------------------------------------------------------------
revno: 40
committer: Chris McCormick 
branch nick: webpd
timestamp: Fri 2010-05-28 15:21:52 +0800
message:
  PdObject.message now knows which inlet the message came in on.
------------------------------------------------------------
revno: 39
committer: Chris McCormick 
branch nick: webpd
timestamp: Fri 2010-05-28 14:28:02 +0800
message:
  Updated location of the builds.
------------------------------------------------------------
revno: 38
committer: Chris McCormick 
branch nick: webpd
timestamp: Wed 2010-05-26 23:20:25 +0800
message:
  README updated with build location
------------------------------------------------------------
revno: 37
committer: Chris McCormick 
branch nick: webpd
timestamp: Wed 2010-05-26 21:56:10 +0800
message:
  Removed lag on processing demo for humphd
------------------------------------------------------------
revno: 36
committer: Chris McCormick 
branch nick: webpd
timestamp: Tue 2010-05-25 19:45:41 +0800
message:
  Small bugfix where div with id of "console" does not exist.
------------------------------------------------------------
revno: 35
committer: Chris McCormick 
branch nick: webpd
timestamp: Tue 2010-05-25 19:12:39 +0800
message:
  Added image to processing.js + Ps.js demo.
------------------------------------------------------------
revno: 34
committer: Chris McCormick 
branch nick: webpd
timestamp: Tue 2010-05-25 19:08:35 +0800
message:
  Updated visible source in processing demo.
------------------------------------------------------------
revno: 33
committer: Chris McCormick 
branch nick: webpd
timestamp: Tue 2010-05-25 19:06:40 +0800
message:
  Added a processing.js + Pd.js demo.
------------------------------------------------------------
revno: 32
committer: Chris McCormick 
branch nick: webpd
timestamp: Tue 2010-05-25 19:05:03 +0800
message:
  Stop osc~ jumping at freq changes
------------------------------------------------------------
revno: 31
committer: Chris McCormick 
branch nick: webpd
timestamp: Tue 2010-05-25 05:02:57 +0000
message:
  Documentation nit.
------------------------------------------------------------
revno: 30
committer: Chris McCormick 
branch nick: webpd
timestamp: Tue 2010-05-25 12:52:40 +0800
message:
  README changes.
------------------------------------------------------------
revno: 29
committer: Chris McCormick 
branch nick: webpd
timestamp: Tue 2010-05-25 12:20:57 +0800
message:
  README wording and tests page layout.
------------------------------------------------------------
revno: 28
committer: Chris McCormick 
branch nick: webpd
timestamp: Mon 2010-05-24 22:31:49 +0800
message:
  Potential unit tests as a reminder.
------------------------------------------------------------
revno: 27
committer: Chris McCormick 
branch nick: webpd
timestamp: Mon 2010-05-24 14:26:31 +0000
message:
  Added send button to receive-osc-frequency unittest.
------------------------------------------------------------
revno: 26
committer: Chris McCormick 
branch nick: webpd
timestamp: Mon 2010-05-24 14:26:08 +0000
message:
  Fixed broken cgi scripts
------------------------------------------------------------
revno: 25
committer: Chris McCormick 
branch nick: webpd
timestamp: Mon 2010-05-24 22:13:51 +0800
message:
  Nit
------------------------------------------------------------
revno: 24
committer: Chris McCormick 
branch nick: webpd
timestamp: Mon 2010-05-24 22:09:39 +0800
message:
  Unit tests and code for oscillator with no arument and receive alias, and made audio inlets behave like Pd if they have no input (zero).
------------------------------------------------------------
revno: 23
committer: Chris McCormick 
branch nick: webpd
timestamp: Mon 2010-05-24 21:03:29 +0800
message:
  Got basic messages working and the [r] ("receive") object working.
------------------------------------------------------------
revno: 22
committer: Chris McCormick 
branch nick: webpd
timestamp: Mon 2010-05-24 19:46:41 +0800
message:
  Dynamically load interface HTML.
------------------------------------------------------------
revno: 21
committer: Chris McCormick 
branch nick: webpd
timestamp: Mon 2010-05-24 19:13:22 +0800
message:
  Create a null PdObject when we do not know a particular object type.
------------------------------------------------------------
revno: 20
committer: Chris McCormick 
branch nick: webpd
timestamp: Mon 2010-05-24 19:04:05 +0800
message:
  cgi script move did not get committed.
------------------------------------------------------------
revno: 19
committer: Chris McCormick 
branch nick: webpd
timestamp: Mon 2010-05-24 17:25:49 +0800
message:
  Moved cgi scripts into cgi-bin subfolder
------------------------------------------------------------
revno: 18
committer: Chris McCormick 
branch nick: webpd
timestamp: Sun 2010-05-23 15:29:02 +0800
message:
  Put tilde objects at the top of the OBJECTS.txt file.
------------------------------------------------------------
revno: 17
committer: Chris McCormick 
branch nick: webpd
timestamp: Sun 2010-05-23 07:23:52 +0000
message:
  Updated location of experimental Firefox builds.
------------------------------------------------------------
revno: 16
committer: Chris McCormick 
branch nick: webpd
timestamp: Sun 2010-05-23 07:19:20 +0000
message:
  Fixed broken cgi scripts.
------------------------------------------------------------
revno: 15
committer: Chris McCormick 
branch nick: webpd
timestamp: Sun 2010-05-23 15:13:26 +0800
message:
  Making the web presence nicer, documentation, etc.
------------------------------------------------------------
revno: 14
committer: Chris McCormick 
branch nick: webpd
timestamp: Sat 2010-05-22 23:10:53 +0800
message:
  osc~ uses cos() according to Mathieu Bouchard
------------------------------------------------------------
revno: 13
committer: Chris McCormick 
branch nick: webpd
timestamp: Sat 2010-05-22 17:30:20 +0800
message:
  Ported pd.js to FF-audio 13a, added play/pause buttons, and the 2 [dac~] test.
------------------------------------------------------------
revno: 12
committer: Chris McCormick 
branch nick: webpd
timestamp: Sat 2010-05-22 15:28:11 +0800
message:
  Added list of all Pd objects and coverage scripts.
------------------------------------------------------------
revno: 11
committer: Chris McCormick 
branch nick: webpd
timestamp: Sat 2010-05-22 15:03:49 +0800
message:
  Updated basic-sound demo from FF 13a
------------------------------------------------------------
revno: 10
committer: Chris McCormick 
branch nick: webpd
timestamp: Sat 2010-05-22 14:43:47 +0800
message:
  added phasor~
------------------------------------------------------------
revno: 9
committer: Chris McCormick 
branch nick: webpd
timestamp: Fri 2010-05-21 18:39:19 +0800
message:
  Added README file
------------------------------------------------------------
revno: 8
committer: Chris McCormick 
branch nick: webpd
timestamp: Fri 2010-05-21 12:44:41 +0800
message:
  Added test for multiply vs constant.
------------------------------------------------------------
revno: 7
committer: Chris McCormick 
branch nick: webpd
timestamp: Fri 2010-05-21 12:37:42 +0800
message:
  Refactored PdObject code into a proper Javascript style function/class/object and added the [+~] operator.
------------------------------------------------------------
revno: 6
committer: Chris McCormick 
branch nick: webpd
timestamp: Fri 2010-05-21 12:18:17 +0800
message:
  Multiply operator working. Fixed a bug in object instantiation.
------------------------------------------------------------
revno: 5
committer: Chris McCormick 
branch nick: webpd
timestamp: Fri 2010-05-21 01:28:17 +0800
message:
  Woohoo, got sound out! Improved console.
------------------------------------------------------------
revno: 4
committer: Chris McCormick 
branch nick: webpd
timestamp: Fri 2010-05-21 01:10:13 +0800
message:
  osc~ now outputs some kind of sine wave.
------------------------------------------------------------
revno: 3
committer: Chris McCormick 
branch nick: webpd
timestamp: Fri 2010-05-21 00:51:55 +0800
message:
  Got endpoints running inlets recursively
------------------------------------------------------------
revno: 2
committer: Chris McCormick 
branch nick: webpd
timestamp: Tue 2010-05-18 12:56:28 +0800
message:
  Got very basic Pd graph parsing working.
------------------------------------------------------------
revno: 1
committer: Chris McCormick 
branch nick: webpd
timestamp: Tue 2010-05-18 10:58:56 +0800
message:
  Initial commit of very basic testing framework for pd.js project.