Code Monkey home page Code Monkey logo

flac.js's Introduction

flac.js Build Status

JavaScript FLAC (audio format) de- and encoder

Project Website โ€ข Minimal demo

flac.js encodes or decodes whole files to FLAC, the Free Lossless Audio Codec. Supported input formats are wav, rf64, w64, aif, flac (flac in its native container as well as in oga/ogg). It is supposed to do the same as the flac executable that can be built from the FLAC sources.

This version of flac.js was built with Emscripten 1.37.20; flac 1.3.2; libogg 1.3.3

Building

If you just want to use flac.js, you don't have to build it. In this case, see using instead.

Prerequisites

  • A recent linux build system
  • Emscripten installed and activated

Build script

git clone --recursive git://github.com/Rillke/flac.js.git flac.js
cd flac.js
./make.sh

Using

A pre-compiled script together with some auxiliary scripts making use from JavaScript easier is in the /worker directory. iframe.html is a minimal usage example. Test it live. It starts the encoding process posting command: 'encode' to the worker:

var worker = new Worker( 'worker/EmsWorkerProxy.js' );

// Input data
var fileName = 'pcmData.raw';
var inData = {
	// File name
	fileName: {
		// Must be Uint8
		fileData
	}
}

// Files to be read and posted back
// after encoding completed
var outData = {
	// File name
	'encoded.flac': {
		// MIME type
		'MIME': 'audio/flac'
	}
};

worker.onmessage = function( e ) {
	// Handle incoming data
};

worker.onerror = function( e ) {
	// Handle error
};

// Arguments
var args = [
    "--endian=little", // endianness of samples
    "--sign=unsigned", // representation of numbers
    "--channels=1", // channel count
    "--bps=8", // bits per second
    "--sample-rate=16000", // sample rate in Hz
    fileName
];

// Post all data and the encode command
// to the web worker
worker.postMessage( {
	command: 'encode',
	args: args,
	outData: outData,
	fileData: inData
} );
  • command: 'encode'|'prefetch' DOMString that either starts encoding (or decoding) or prefetching the worker script. Posting a prefetch command in advance is optional, depends on the user experience you'd like to create and does not require further arguments. If the script is not prefetched, it will be downloaded when 'encode' is invoked.
  • args: Array holding the command line arguments (DOMString)
  • outData: Object literal of information about the files that should be read out of the worker's file system after encoding completed
  • fileData: Object literal of input file data mapping file names to Uint8Arrays

A more extensive example is available on the project's website.

Contributing

Submit patches to this GitHub repository or file issues.

License

See LICENSE.md

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.