Module losc.timetag
OSC Timetag.
Time tags are represented by a 64 bit fixed point number. The first 32 bits specify the number of seconds since midnight on January 1, 1900, and the last 32 bits specify fractional parts of a second to a precision of about 200 picoseconds. This is the representation used by Internet NTP timestamps.
Info:
- Copyright: David Granström 2021
- License: MIT
- Author: David Granström
Functions
Timetag.__add (a, b) | Add a time offset to a Timetag. |
High level API
Timetag.new ([seconds[, fractions[, precision]]]) | New using a seconds and fractions. |
Timetag.new_from_timestamp (time[, precision]) | Create a new OSC Timetag from a timestamp. |
Timetag:timestamp (precision) | Get a timestamp value with arbitrary precision. |
Timetag:seconds () | Get seconds. |
Timetag:fractions () | Get fractions. |
Low level API
Timetag.new_raw ([tbl[, seconds[, fractions]]]) | Create a new Timetag. |
Timetag.get_timestamp (tbl[, precision]) | Get a timestamp with arbitrary precision. |
Timetag.pack (tbl) | Pack an OSC Timetag. |
Timetag.unpack (data, offset) | Unpack an OSC Timetag. |
Functions
- Timetag.__add (a, b)
-
Add a time offset to a Timetag.
This overloads the
+
operator for Timetags and should not be called directly.Parameters:
- a
- b
Usage:
local tt = Timetag.new(os.time()) + 0.25
High level API
- Timetag.new ([seconds[, fractions[, precision]]])
-
New using a seconds and fractions.
Given nil arguments will return a timetag with special value "immediate".
Parameters:
- seconds integer Timestamp seconds. (optional)
- fractions integer Timestamp fractions. (optional)
- precision
integer
The fraction precision. default 1000 (
milliseconds
) (optional)
See also:
Usage:
local tt = Timetag.new() -- immediate
local tt = Timetag.new(os.time())
local tt = Timetag.new(tv.sec, tv.usec, 1e6)
- Timetag.new_from_timestamp (time[, precision])
-
Create a new OSC Timetag from a timestamp.
Parameters:
- time The timestamp to use.
- precision The fraction precision. default 1000 (optional)
Returns:
-
A Timetag object.
Usage:
local tt = Timetag.new_from_timestamp(time)
- Timetag:timestamp (precision)
-
Get a timestamp value with arbitrary precision.
Parameters:
- precision
The precision to use. default 1000 (
milliseconds
)
Returns:
-
Timestamp value.
Usage:
local tt = Timetag.new(os.time(), 500) local timestamp = tt:timestamp()
- precision
The precision to use. default 1000 (
- Timetag:seconds ()
-
Get seconds.
Returns:
-
Timetag seconds.
- Timetag:fractions ()
-
Get fractions.
Returns:
-
Timetag fractions.
Low level API
- Timetag.new_raw ([tbl[, seconds[, fractions]]])
-
Create a new Timetag.
Parameters:
- tbl Table with timetag content. (optional)
- seconds Seconds since January 1st 1900 in the UTC timezone. (optional)
- fractions
Fractions expressed as 1/2^32 of a second.
If there are no arguments a timetag with special value of "immediate" will be returned. (optional)
- Timetag.get_timestamp (tbl[, precision])
-
Get a timestamp with arbitrary precision.
Parameters:
- tbl Table with seconds and fractions.
- precision The fraction precision. default 1000 (optional)
Returns:
-
Timetag value.
- Timetag.pack (tbl)
-
Pack an OSC Timetag.
The returned object is suitable for sending via a transport layer such as UDP or TCP.
Parameters:
- tbl table The timetag to pack.
Returns:
-
OSC data packet (byte string).
Usage:
local tt = {seconds = os.time(), fractions = 0} local data = Timetag.pack(tt)
- Timetag.unpack (data, offset)
-
Unpack an OSC Timetag.
Parameters:
- data The data to unpack.
- offset The initial offset into data.
Returns:
-
First is a table with seconds and fractions, second is index of the bytes read + 1.