Skip to content

Commit cca09c5

Browse files
committed
Updates README and doc comments.
1 parent 6bb69c5 commit cca09c5

File tree

2 files changed

+37
-12
lines changed

2 files changed

+37
-12
lines changed

README.md

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,25 @@
11
osc.js
22
======
33

4-
osc.js is a library for reading and writing [Open Sound Control](http://opensoundcontrol.org) messages in JavaScript. It has no dependencies on a particular environment or type of transport. As a result, it can be used in Node.js or in a web browser.
4+
osc.js is a library for reading and writing [Open Sound Control](http://opensoundcontrol.org) messages in JavaScript. It has no dependencies on the type of environment or transport used. As a result, it works both in Node.js and in a web browser.
55

66
Why osc.js?
77
-----------
88

9-
There are several other OSC libraries written in JavaScript. All of them depend on Node.js-specific APIs, which means they can't be run in a browser. osc.js uses only cross-platform APIs (specifically, `TypedArrays` and `DataView`) to ensure that it can run equally well in Node.js or in a web browser. This makes it suitable for entirely in-browser applications such as those on Chrome OS and Firefox OS.
9+
There are several other OSC libraries written in JavaScript. All of them depend on Node.js-specific APIs, which means they can't be run in a browser. osc.js uses only cross-platform APIs (specifically, `TypedArrays` and `DataView`) to ensure that it can run in any modern JavaScript environment.
1010

1111
What Does it Do?
1212
----------------
1313

14-
osc.js reads and writes OSC-formatted binary data into plain JavaScript objects. It provides adaptors for reading/writing Node.js Buffer objects as well as standard ArrayBuffer objects.
14+
osc.js reads and writes OSC-formatted binary data into plain JavaScript objects. It provides adaptors for Node.js Buffer objects as well as standard ArrayBuffer objects.
1515

1616
You can receive OSC data in whatever manner works best for your application: serial port APIs such as node-serialport or chrome.serial, socket APIs such as Node.js dgram or WebRTC data channels, WebSockets or binary XHR messages should all work. Connect osc.js up to your source of incoming/outgoing data, and you're all set.
1717

1818
Status
1919
------
2020

21-
osc.js is in early, active development. It does not yet (but will) support:
21+
osc.js is new and still in development. It does not yet (but will) support:
2222

2323
* Bundles
24-
* Time tags
25-
* int64 types
26-
* float64 types
27-
* char32 types
2824
* color types
2925
* MIDI types

osc.js

+33-4
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ var osc = osc || {};
329329
};
330330

331331
/**
332-
* Reads an OSC time tag.
332+
* Reads an OSC time tag ("t").
333333
*
334334
* @param {DataView} dv the DataView instance to read from
335335
* @param {Object} offsetState an offset state object containing the current index into dv
@@ -346,7 +346,17 @@ var osc = osc || {};
346346
};
347347
};
348348

349-
// TODO: Unit tests.
349+
/**
350+
* Writes an OSC time tag ("t").
351+
*
352+
* Takes, as its argument, a time tag object containing either a "raw" or "native property."
353+
* The raw timestamp must conform to the NTP standard representation, consisting of two unsigned int32
354+
* values. The first represents the number of seconds since January 1, 1900; the second, fractions of a second.
355+
* "Native" JavaScript timestamps are specified as a Number representing milliseconds since January 1, 1970.
356+
*
357+
* @param {Object} timeTag time tag object containing either a native JS timestamp (in ms) or a NTP timestamp pair
358+
* @return {Uint8Array} raw bytes for the written time tag
359+
*/
350360
osc.writeTimeTag = function (timeTag) {
351361
var raw = timeTag.raw ? timeTag.raw : osc.jsTimeToNTP(timeTag.native),
352362
arr = new Uint8Array(8), // Two Unit32s.
@@ -358,6 +368,13 @@ var osc = osc || {};
358368
return arr;
359369
};
360370

371+
/**
372+
* Produces a time tag consisting of a JavaScript timestamp that is
373+
* in the future by the specified number of seconds.
374+
*
375+
* @param {Number} secs the number of seconds in the future
376+
* @return {Object} the time tag
377+
*/
361378
// TODO: Unit tests.
362379
osc.futureTimeTag = function (secs) {
363380
var ms = sec * 1000,
@@ -368,7 +385,14 @@ var osc = osc || {};
368385
};
369386
};
370387

371-
// TODO: Unit tests.
388+
/**
389+
* Converts OSC's standard time tag representation (which is the NTP format)
390+
* into the JavaScript/UNIX format in milliseconds.
391+
*
392+
* @param {Number} secs1900 the number of seconds since 1900
393+
* @param {Number} frac the number of fractions of a second (between 0 and 2^32)
394+
* @return {Number} a JavaScript-compatible timestamp in milliseconds
395+
*/
372396
osc.ntpToJSTime = function (secs1900, frac) {
373397
var secs1970 = secs1900 - osc.SEVENTY_YEARS_SECS,
374398
ms1970 = secs1970 * 1000,
@@ -378,7 +402,12 @@ var osc = osc || {};
378402
return msTime;
379403
};
380404

381-
// TODO: Unit tests.
405+
/**
406+
* Converts a JavaScript timestamp into OSC's standard NTP timestamp format.
407+
*
408+
* @param {Number} jsTime the JavaScript timestamp
409+
* @return {Array} a tuple consisting of the number of seconds since 1900 and the number of fractions of a second
410+
*/
382411
osc.jsTimeToNTP = function (jsTime) {
383412
var ms = Math.floor(jsTime),
384413
secs = ms / 1000,

0 commit comments

Comments
 (0)