buddy

node MVC discord bot
Log | Files | Refs | README

WebmDemuxer.js (719B)


      1 const WebmBaseDemuxer = require('../core/WebmBase');
      2 
      3 const VORBIS_HEAD = Buffer.from([...'vorbis'].map(x => x.charCodeAt(0)));
      4 
      5 /**
      6  * Demuxes a Webm stream (containing Vorbis audio) to output a Vorbis stream.
      7  * @memberof vorbis
      8  * @extends core.WebmBaseDemuxer
      9  */
     10 class WebmDemuxer extends WebmBaseDemuxer {
     11   _checkHead(data) {
     12     if (data.readUInt8(0) !== 2 || !data.slice(4, 10).equals(VORBIS_HEAD)) {
     13       throw Error('Audio codec is not Vorbis!');
     14     }
     15 
     16     this.push(data.slice(3, 3 + data.readUInt8(1)));
     17     this.push(data.slice(3 + data.readUInt8(1), 3 + data.readUInt8(1) + data.readUInt8(2)));
     18     this.push(data.slice(3 + data.readUInt8(1) + data.readUInt8(2)));
     19   }
     20 }
     21 
     22 module.exports = WebmDemuxer;