linear-timecode
Advanced tools
+16
-12
@@ -281,3 +281,3 @@ var p = { exports: {} }, h = typeof Reflect == "object" ? Reflect : null, m = h && typeof h.apply == "function" ? h.apply : function(e, n, r) { | ||
| const c = this.rate / o / 2; | ||
| c > 900 && c <= 1520 ? r += "0" : c > 1520 && c < 3e3 && (s ? (r += "1", s = 0) : s = 1), o = 0; | ||
| c > 900 && c <= 1560 ? r += "0" : c > 1560 && c < 3e3 && (s ? (r += "1", s = 0) : s = 1), o = 0; | ||
| } | ||
@@ -288,15 +288,19 @@ i = a; | ||
| for (this.framerate = Math.round(u / 80), e.bit_buffer = "".concat(e.bit_buffer, r); e.bit_buffer.length >= 80; ) | ||
| this.parse_bits(e.bit_buffer); | ||
| if (!this.parse_bits(e.bit_buffer)) { | ||
| e.bit_buffer.length > 160 && (e.bit_buffer = e.bit_buffer.slice(160)); | ||
| break; | ||
| } | ||
| }, this.parse_bits = function(n) { | ||
| var r = n.indexOf("111111111111", 0); | ||
| if (r) | ||
| if (n.substring(r - 2, r) === "00" && n.substring(r + 12, r + 14) === "01") { | ||
| for (var i = [], o = r - 66; o < r + 14; o += 8) { | ||
| var s = n.substring(o, o + 8).split("").reverse().join(""), u = parseInt(s, 2); | ||
| i.push(u); | ||
| } | ||
| var a = new T(this.framerate); | ||
| a.decode_frame(i), this.last_frame = a, this.emit("frame", a), e.bit_buffer = e.bit_buffer.slice(r + 14); | ||
| } else | ||
| return; | ||
| if (!r) | ||
| return !1; | ||
| if (n.substring(r - 2, r) === "00" && n.substring(r + 12, r + 14) === "01") { | ||
| for (var i = [], o = r - 66; o < r + 14; o += 8) { | ||
| var s = n.substring(o, o + 8).split("").reverse().join(""), u = parseInt(s, 2); | ||
| i.push(u); | ||
| } | ||
| var a = new T(this.framerate); | ||
| return a.decode_frame(i), this.last_frame = a, this.emit("frame", a), e.bit_buffer = e.bit_buffer.slice(r + 14), !0; | ||
| } else | ||
| return !1; | ||
| }, Object.setPrototypeOf(this, P.EventEmitter.prototype); | ||
@@ -303,0 +307,0 @@ } |
@@ -1,1 +0,1 @@ | ||
| (function(h,l){typeof exports=="object"&&typeof module<"u"?l(exports):typeof define=="function"&&define.amd?define(["exports"],l):(h=typeof globalThis<"u"?globalThis:h||self,l(h["Linear-Timecode"]={}))})(this,function(h){"use strict";var l={exports:{}},d=typeof Reflect=="object"?Reflect:null,_=d&&typeof d.apply=="function"?d.apply:function(e,n,r){return Function.prototype.apply.call(e,n,r)},v;d&&typeof d.ownKeys=="function"?v=d.ownKeys:Object.getOwnPropertySymbols?v=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:v=function(e){return Object.getOwnPropertyNames(e)};function T(t){console&&console.warn&&console.warn(t)}var L=Number.isNaN||function(e){return e!==e};function f(){f.init.call(this)}l.exports=f,l.exports.once=P,f.EventEmitter=f,f.prototype._events=void 0,f.prototype._eventsCount=0,f.prototype._maxListeners=void 0;var g=10;function p(t){if(typeof t!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t)}Object.defineProperty(f,"defaultMaxListeners",{enumerable:!0,get:function(){return g},set:function(t){if(typeof t!="number"||t<0||L(t))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+t+".");g=t}}),f.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},f.prototype.setMaxListeners=function(e){if(typeof e!="number"||e<0||L(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this};function y(t){return t._maxListeners===void 0?f.defaultMaxListeners:t._maxListeners}f.prototype.getMaxListeners=function(){return y(this)},f.prototype.emit=function(e){for(var n=[],r=1;r<arguments.length;r++)n.push(arguments[r]);var i=e==="error",o=this._events;if(o!==void 0)i=i&&o.error===void 0;else if(!i)return!1;if(i){var s;if(n.length>0&&(s=n[0]),s instanceof Error)throw s;var u=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw u.context=s,u}var a=o[e];if(a===void 0)return!1;if(typeof a=="function")_(a,this,n);else for(var c=a.length,m=O(a,c),r=0;r<c;++r)_(m[r],this,n);return!0};function b(t,e,n,r){var i,o,s;if(p(n),o=t._events,o===void 0?(o=t._events=Object.create(null),t._eventsCount=0):(o.newListener!==void 0&&(t.emit("newListener",e,n.listener?n.listener:n),o=t._events),s=o[e]),s===void 0)s=o[e]=n,++t._eventsCount;else if(typeof s=="function"?s=o[e]=r?[n,s]:[s,n]:r?s.unshift(n):s.push(n),i=y(t),i>0&&s.length>i&&!s.warned){s.warned=!0;var u=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");u.name="MaxListenersExceededWarning",u.emitter=t,u.type=e,u.count=s.length,T(u)}return t}f.prototype.addListener=function(e,n){return b(this,e,n,!1)},f.prototype.on=f.prototype.addListener,f.prototype.prependListener=function(e,n){return b(this,e,n,!0)};function R(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function w(t,e,n){var r={fired:!1,wrapFn:void 0,target:t,type:e,listener:n},i=R.bind(r);return i.listener=n,r.wrapFn=i,i}f.prototype.once=function(e,n){return p(n),this.on(e,w(this,e,n)),this},f.prototype.prependOnceListener=function(e,n){return p(n),this.prependListener(e,w(this,e,n)),this},f.prototype.removeListener=function(e,n){var r,i,o,s,u;if(p(n),i=this._events,i===void 0)return this;if(r=i[e],r===void 0)return this;if(r===n||r.listener===n)--this._eventsCount===0?this._events=Object.create(null):(delete i[e],i.removeListener&&this.emit("removeListener",e,r.listener||n));else if(typeof r!="function"){for(o=-1,s=r.length-1;s>=0;s--)if(r[s]===n||r[s].listener===n){u=r[s].listener,o=s;break}if(o<0)return this;o===0?r.shift():M(r,o),r.length===1&&(i[e]=r[0]),i.removeListener!==void 0&&this.emit("removeListener",e,u||n)}return this},f.prototype.off=f.prototype.removeListener,f.prototype.removeAllListeners=function(e){var n,r,i;if(r=this._events,r===void 0)return this;if(r.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):r[e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete r[e]),this;if(arguments.length===0){var o=Object.keys(r),s;for(i=0;i<o.length;++i)s=o[i],s!=="removeListener"&&this.removeAllListeners(s);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(n=r[e],typeof n=="function")this.removeListener(e,n);else if(n!==void 0)for(i=n.length-1;i>=0;i--)this.removeListener(e,n[i]);return this};function x(t,e,n){var r=t._events;if(r===void 0)return[];var i=r[e];return i===void 0?[]:typeof i=="function"?n?[i.listener||i]:[i]:n?N(i):O(i,i.length)}f.prototype.listeners=function(e){return x(this,e,!0)},f.prototype.rawListeners=function(e){return x(this,e,!1)},f.listenerCount=function(t,e){return typeof t.listenerCount=="function"?t.listenerCount(e):E.call(t,e)},f.prototype.listenerCount=E;function E(t){var e=this._events;if(e!==void 0){var n=e[t];if(typeof n=="function")return 1;if(n!==void 0)return n.length}return 0}f.prototype.eventNames=function(){return this._eventsCount>0?v(this._events):[]};function O(t,e){for(var n=new Array(e),r=0;r<e;++r)n[r]=t[r];return n}function M(t,e){for(;e+1<t.length;e++)t[e]=t[e+1];t.pop()}function N(t){for(var e=new Array(t.length),n=0;n<e.length;++n)e[n]=t[n].listener||t[n];return e}function P(t,e){return new Promise(function(n,r){function i(s){t.removeListener(e,o),r(s)}function o(){typeof t.removeListener=="function"&&t.removeListener("error",i),n([].slice.call(arguments))}j(t,e,o,{once:!0}),e!=="error"&&A(t,i,{once:!0})})}function A(t,e,n){typeof t.on=="function"&&j(t,"error",e,n)}function j(t,e,n,r){if(typeof t.on=="function")r.once?t.once(e,n):t.on(e,n);else if(typeof t.addEventListener=="function")t.addEventListener(e,function i(o){r.once&&t.removeEventListener(e,i),n(o)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof t)}var S=l.exports;function C(t){this.hours=0,this.minutes=0,this.seconds=0,this.frames=0,typeof t=="number"?this.framerate=t:this.framerate=0,this.dropframe=!1,this.colorframe=!1,this.user_bits=[0,0,0,0,0,0,0,0],this.decode_frame=function(e){if(e.length!=10){console.error("Invalid LTC payload size: ",e.length);return}if((e[9]<<8|e[8])!=49148){console.error("Invalid LTC sync code");return}var r=e[0]&15,i=e[1]&3;this.frames=i*10+r;var o=e[2]&15,s=e[3]&7;this.seconds=s*10+o;var u=e[4]&15,a=e[5]&7;this.minutes=a*10+u;var c=e[6]&15,m=e[7]&3;this.hours=m*10+c,this.dropframe=!!(e[1]>>2&1),this.colorframe=!!(e[1]>>3&1)},this.toString=function(){var e="".concat(this.hours<10?"0":"",this.hours.toString(),":",this.minutes<10?"0":"",this.minutes.toString(),":",this.seconds<10?"0":"",this.seconds.toString(),":",this.frames<10?"0":"",this.frames.toString());return e}}function F(t){this.rate=t,this.framerate=0,this.last_frame=null;var e={prev_sample:null,counter:0,middle_transition:0,bit_buffer:""};this.decode=function(n){var r="",{prev_sample:i,counter:o,middle_transition:s}=e;i==null&&(i=n[0]),n.forEach(a=>{if(i>0&&a>0)o++;else if(i<0&&a<0)o++;else{const c=this.rate/o/2;c>900&&c<=1520?r+="0":c>1520&&c<3e3&&(s?(r+="1",s=0):s=1),o=0}i=a}),e={...e,prev_sample:i,counter:o,middle_transition:s};var u=r.length/(n.length/this.rate);for(this.framerate=Math.round(u/80),e.bit_buffer="".concat(e.bit_buffer,r);e.bit_buffer.length>=80;)this.parse_bits(e.bit_buffer)},this.parse_bits=function(n){var r=n.indexOf("111111111111",0);if(r)if(n.substring(r-2,r)==="00"&&n.substring(r+12,r+14)==="01"){for(var i=[],o=r-66;o<r+14;o+=8){var s=n.substring(o,o+8).split("").reverse().join(""),u=parseInt(s,2);i.push(u)}var a=new C(this.framerate);a.decode_frame(i),this.last_frame=a,this.emit("frame",a),e.bit_buffer=e.bit_buffer.slice(r+14)}else return},Object.setPrototypeOf(this,S.EventEmitter.prototype)}h.Decoder=F,h.Timecode=C,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})}); | ||
| (function(l,h){typeof exports=="object"&&typeof module<"u"?h(exports):typeof define=="function"&&define.amd?define(["exports"],h):(l=typeof globalThis<"u"?globalThis:l||self,h(l["Linear-Timecode"]={}))})(this,function(l){"use strict";var h={exports:{}},d=typeof Reflect=="object"?Reflect:null,_=d&&typeof d.apply=="function"?d.apply:function(e,n,r){return Function.prototype.apply.call(e,n,r)},v;d&&typeof d.ownKeys=="function"?v=d.ownKeys:Object.getOwnPropertySymbols?v=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:v=function(e){return Object.getOwnPropertyNames(e)};function T(t){console&&console.warn&&console.warn(t)}var L=Number.isNaN||function(e){return e!==e};function f(){f.init.call(this)}h.exports=f,h.exports.once=P,f.EventEmitter=f,f.prototype._events=void 0,f.prototype._eventsCount=0,f.prototype._maxListeners=void 0;var g=10;function p(t){if(typeof t!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t)}Object.defineProperty(f,"defaultMaxListeners",{enumerable:!0,get:function(){return g},set:function(t){if(typeof t!="number"||t<0||L(t))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+t+".");g=t}}),f.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},f.prototype.setMaxListeners=function(e){if(typeof e!="number"||e<0||L(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this};function y(t){return t._maxListeners===void 0?f.defaultMaxListeners:t._maxListeners}f.prototype.getMaxListeners=function(){return y(this)},f.prototype.emit=function(e){for(var n=[],r=1;r<arguments.length;r++)n.push(arguments[r]);var i=e==="error",o=this._events;if(o!==void 0)i=i&&o.error===void 0;else if(!i)return!1;if(i){var s;if(n.length>0&&(s=n[0]),s instanceof Error)throw s;var u=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw u.context=s,u}var a=o[e];if(a===void 0)return!1;if(typeof a=="function")_(a,this,n);else for(var c=a.length,m=O(a,c),r=0;r<c;++r)_(m[r],this,n);return!0};function b(t,e,n,r){var i,o,s;if(p(n),o=t._events,o===void 0?(o=t._events=Object.create(null),t._eventsCount=0):(o.newListener!==void 0&&(t.emit("newListener",e,n.listener?n.listener:n),o=t._events),s=o[e]),s===void 0)s=o[e]=n,++t._eventsCount;else if(typeof s=="function"?s=o[e]=r?[n,s]:[s,n]:r?s.unshift(n):s.push(n),i=y(t),i>0&&s.length>i&&!s.warned){s.warned=!0;var u=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");u.name="MaxListenersExceededWarning",u.emitter=t,u.type=e,u.count=s.length,T(u)}return t}f.prototype.addListener=function(e,n){return b(this,e,n,!1)},f.prototype.on=f.prototype.addListener,f.prototype.prependListener=function(e,n){return b(this,e,n,!0)};function R(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function w(t,e,n){var r={fired:!1,wrapFn:void 0,target:t,type:e,listener:n},i=R.bind(r);return i.listener=n,r.wrapFn=i,i}f.prototype.once=function(e,n){return p(n),this.on(e,w(this,e,n)),this},f.prototype.prependOnceListener=function(e,n){return p(n),this.prependListener(e,w(this,e,n)),this},f.prototype.removeListener=function(e,n){var r,i,o,s,u;if(p(n),i=this._events,i===void 0)return this;if(r=i[e],r===void 0)return this;if(r===n||r.listener===n)--this._eventsCount===0?this._events=Object.create(null):(delete i[e],i.removeListener&&this.emit("removeListener",e,r.listener||n));else if(typeof r!="function"){for(o=-1,s=r.length-1;s>=0;s--)if(r[s]===n||r[s].listener===n){u=r[s].listener,o=s;break}if(o<0)return this;o===0?r.shift():M(r,o),r.length===1&&(i[e]=r[0]),i.removeListener!==void 0&&this.emit("removeListener",e,u||n)}return this},f.prototype.off=f.prototype.removeListener,f.prototype.removeAllListeners=function(e){var n,r,i;if(r=this._events,r===void 0)return this;if(r.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):r[e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete r[e]),this;if(arguments.length===0){var o=Object.keys(r),s;for(i=0;i<o.length;++i)s=o[i],s!=="removeListener"&&this.removeAllListeners(s);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(n=r[e],typeof n=="function")this.removeListener(e,n);else if(n!==void 0)for(i=n.length-1;i>=0;i--)this.removeListener(e,n[i]);return this};function x(t,e,n){var r=t._events;if(r===void 0)return[];var i=r[e];return i===void 0?[]:typeof i=="function"?n?[i.listener||i]:[i]:n?N(i):O(i,i.length)}f.prototype.listeners=function(e){return x(this,e,!0)},f.prototype.rawListeners=function(e){return x(this,e,!1)},f.listenerCount=function(t,e){return typeof t.listenerCount=="function"?t.listenerCount(e):E.call(t,e)},f.prototype.listenerCount=E;function E(t){var e=this._events;if(e!==void 0){var n=e[t];if(typeof n=="function")return 1;if(n!==void 0)return n.length}return 0}f.prototype.eventNames=function(){return this._eventsCount>0?v(this._events):[]};function O(t,e){for(var n=new Array(e),r=0;r<e;++r)n[r]=t[r];return n}function M(t,e){for(;e+1<t.length;e++)t[e]=t[e+1];t.pop()}function N(t){for(var e=new Array(t.length),n=0;n<e.length;++n)e[n]=t[n].listener||t[n];return e}function P(t,e){return new Promise(function(n,r){function i(s){t.removeListener(e,o),r(s)}function o(){typeof t.removeListener=="function"&&t.removeListener("error",i),n([].slice.call(arguments))}j(t,e,o,{once:!0}),e!=="error"&&A(t,i,{once:!0})})}function A(t,e,n){typeof t.on=="function"&&j(t,"error",e,n)}function j(t,e,n,r){if(typeof t.on=="function")r.once?t.once(e,n):t.on(e,n);else if(typeof t.addEventListener=="function")t.addEventListener(e,function i(o){r.once&&t.removeEventListener(e,i),n(o)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof t)}var S=h.exports;function C(t){this.hours=0,this.minutes=0,this.seconds=0,this.frames=0,typeof t=="number"?this.framerate=t:this.framerate=0,this.dropframe=!1,this.colorframe=!1,this.user_bits=[0,0,0,0,0,0,0,0],this.decode_frame=function(e){if(e.length!=10){console.error("Invalid LTC payload size: ",e.length);return}if((e[9]<<8|e[8])!=49148){console.error("Invalid LTC sync code");return}var r=e[0]&15,i=e[1]&3;this.frames=i*10+r;var o=e[2]&15,s=e[3]&7;this.seconds=s*10+o;var u=e[4]&15,a=e[5]&7;this.minutes=a*10+u;var c=e[6]&15,m=e[7]&3;this.hours=m*10+c,this.dropframe=!!(e[1]>>2&1),this.colorframe=!!(e[1]>>3&1)},this.toString=function(){var e="".concat(this.hours<10?"0":"",this.hours.toString(),":",this.minutes<10?"0":"",this.minutes.toString(),":",this.seconds<10?"0":"",this.seconds.toString(),":",this.frames<10?"0":"",this.frames.toString());return e}}function F(t){this.rate=t,this.framerate=0,this.last_frame=null;var e={prev_sample:null,counter:0,middle_transition:0,bit_buffer:""};this.decode=function(n){var r="",{prev_sample:i,counter:o,middle_transition:s}=e;i==null&&(i=n[0]),n.forEach(a=>{if(i>0&&a>0)o++;else if(i<0&&a<0)o++;else{const c=this.rate/o/2;c>900&&c<=1560?r+="0":c>1560&&c<3e3&&(s?(r+="1",s=0):s=1),o=0}i=a}),e={...e,prev_sample:i,counter:o,middle_transition:s};var u=r.length/(n.length/this.rate);for(this.framerate=Math.round(u/80),e.bit_buffer="".concat(e.bit_buffer,r);e.bit_buffer.length>=80;)if(!this.parse_bits(e.bit_buffer)){e.bit_buffer.length>160&&(e.bit_buffer=e.bit_buffer.slice(160));break}},this.parse_bits=function(n){var r=n.indexOf("111111111111",0);if(!r)return!1;if(n.substring(r-2,r)==="00"&&n.substring(r+12,r+14)==="01"){for(var i=[],o=r-66;o<r+14;o+=8){var s=n.substring(o,o+8).split("").reverse().join(""),u=parseInt(s,2);i.push(u)}var a=new C(this.framerate);return a.decode_frame(i),this.last_frame=a,this.emit("frame",a),e.bit_buffer=e.bit_buffer.slice(r+14),!0}else return!1},Object.setPrototypeOf(this,S.EventEmitter.prototype)}l.Decoder=F,l.Timecode=C,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})}); |
+1
-1
| { | ||
| "name": "linear-timecode", | ||
| "version": "0.0.2", | ||
| "version": "0.0.3", | ||
| "description": "Encode and Decode Linear Timecode", | ||
@@ -5,0 +5,0 @@ "author": { |
22146
1.01%341
1.19%