Coder Social home page Coder Social logo

par-ity / platypus Goto Github PK

View Code? Open in Web Editor NEW

This project forked from zhuker/lamejs

0.0 1.0 0.0 4.6 MB

mp3 encoder in javascript

Home Page: https://par-ity.github.io/platypus

License: Other

JavaScript 78.93% HTML 9.82% CSS 11.25%
audio mp3 lame realtime recorder recording authoring editing encoder javascript

platypus's Introduction

2021 Update

This was my first big web project and it is structurally quite monolithic and problematic - error handling and setIntervals and driven by global mutations and such.the control flow is quite difficult to follow but largely appears to work performantly.

I've made a few fixes and changes, mostly unloading resources on error and modularising the feature detection script, and because of better browser-security a breaking change around asking for user media. running the feature detection module on input fixed this.

Diagrams

I/O diagram of how realtime microphone data is processed

This node diagram outline the core roles of the API’s and Web Worker in turning microphone access into a mp3 and displaying that to the user.

The paths within light blue areas are callbacks which repeat until stopped to handle the live stream:

The Microphone → Canvas Display loop repeats (max: 60 fps) to produce the visualisation.

The Microphone → Mp3 Buffer loop fires once for every 16384 bytes the processor receives.

The red arrow between Mp3 Array Buffer and Blob URL is not a loop - it indicates data is sent back to main.js once per recording to be constructed into a Blob and displayed. the light red Blob URL node represents the end of these resources runtime.

Because the real encoding work is done on repeat to build up the Mp3 Buffer, when the user clicks stop the buffer is sent back to main.js, they can expect to get an mp3 to play almost immediately.

Diagram of how mp3 frames are sliced for audio editing

Mpeg-1 layer 3 (mp3) encoding uses a ‘padding-bit’ to ensure the frame uses sensible values like 418 bytes instead of an absurd float like 417.95918367. The LAME FAQ specifies if a padding-bit exists, then the bits per frame value is to be rounded to the nearest byte. If no padding-bit exists (as in other mpeg layers) float values are to be rounded down to the nearest byte.

2017 Readme

An audio tool which uses the Web Audio API to record, visualize and edit mp3 blobs

Adapted from Zhuker's excellent LAME.js library https://github.com/zhuker/lamejs

The full 4.47mb Library can be found there but is omitted here to reduce app size

Platypus uses a callback polyfill for the Streams API getUserMedia promise

Platypus uses a monkey patch to alias Web Audio API syntax for WebKit browsers

Platypus uses FileSaver.js to give blob downloads semantic filenames instead of UID's

~ | ~

This repo also contains a feature detection script for all core dependencies and also
run Platypus audio specific tests properties on the following two bugs:

  • Sometimes the audio blob is properly encoded but the browser fails to display it;
    to counteract this a sample blob mp3 from Platypus is included to test blob URLs

  • Sometimes the hardware and browser prefers sample rates and buffer sizes which
    can cause a sporadic mixture of sped-up playback and high-end artifacts; while this
    is currently fixed via a forced huge bufferSize of 16384 bytes, new devices and
    operating systems may have issues reoccur. To help debug them the preferred
    sample and buffer values are also saved.

When run, this script saves the level of support and preferred sample/buffer values;
these are all returned as an object to the IsMicSupported global module for access

platypus's People

Contributors

diathelia avatar par-ity avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.