Giter Site home page Giter Site logo

angdev / libvorbis.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from itsjoesullivan/libvorbis.js

0.0 3.0 0.0 1.56 MB

Encode raw audio into Ogg Vorbis.

Home Page: http://garciat.com/libvorbis.js/

License: MIT License

Shell 16.25% C 28.47% JavaScript 55.27%

libvorbis.js's Introduction

libvorbis.js

What it is

This spits out a javascript file that can be used in the browser to convert PCM audio data to compressed ogg vorbis audio.

Download

See releases.

Build

  • Ensure that you have emscripten installed.
    • i.e. you need access to emcc
git submodule init
git submodule update
./build.sh

Demos

Microphone recorder.

API

(types added for descriptive purposes)

// library options object format (with default values)
object VorbisOptions {
  // location of worker script
  string workerURL = 'libvorbis.worker.js';
  
  // location of module script
  // Note: this is relative to workerURL!
  string moduleURL = 'libvorbis.module.min.js';
  
  // location of memory initializer (for minified build)
  // Note: this is relative to workerURL!
  string memoryInitializerURL = 'libvorbis.module.min.js.mem';
}

// call this to configure script routes
void Vorbis.configure(VorbisOptions options);

// opaque type representing VBR encoding state
object VorbisEncoderVBR;

// standard promises
object Promise<T>;

// unary function
object Func<Param, Return>;

// creates a new encoder instance
Promise<VorbisEncoderVBR> Vorbis.Encoding.createVBR(int channels, int sampleRate, float quality);

// writes vorbis headers
// this must be called before encoding
Promise<VorbisEncoderVBR> Vorbis.Encoding.writeHeaders(VorbisEncoderVBR encoder);

// encodes an array of buffers (one for each channel)
Func<VorbisEncoderVBR, Promise<VorbisEncoderVBR>> Vorbis.Encoding.encode(int samples, Float32Array[] buffers);

// same as above, but will transfer the buffers instead of copying
Func<VorbisEncoderVBR, Promise<VorbisEncoderVBR>> Vorbis.Encoding.encodeTransfer(int samples, Float32Array[] buffers);

// finishes encoding and produces a Blob with final contents
Promise<Blob> Vorbis.Encoding.encode(VorbisEncoderVBR encoder);

Emscripten API

(types added for descriptive purposes)

using EncoderInstance = int;
using Pointer = int;

// Creates a new encoder instance
// quality from -0.1 to 1.0
EncoderInstance Module.lib.encoder_create_vbr(int channels, int sampleRate, float quality);

// Writes initial vorbis headers to output data buffer
void Module.lib.encoder_write_headers(EncoderInstance state);

// Prepares vorbis encoding analysis buffers for the number of samples
void Module.lib.encoder_prepare_analysis_buffers(EncoderInstance state, int samples);

// Gets the analysis buffer for the specified channel
Pointer Module.lib.encoder_get_analysis_buffer(EncoderInstance state, int channel);

// Encodes data from the analysis buffers and writes to output data buffer
void Module.lib.encoder_encode(EncoderInstance state);

// Gets output data buffer
// Note: you should copy the data out (see encoder_clear_data)
Pointer Module.lib.encoder_get_data(EncoderInstance state);

// Returns size of output data buffer
long Module.lib.encoder_get_data_len(EncoderInstance state);

// Clears output data buffer
// Note: this simply tells the encoder to reuse the data buffer
void Module.lib.encoder_clear_data(EncoderInstance state);

// Signals the encoder that we are done
// The encoder may write additional data to the output data buffer
void Module.lib.encoder_finish(EncoderInstance state);

// Frees all data related to the encoder
void Module.lib.encoder_destroy(EncoderInstance state);

// The following helpers are included:

// Encodes an array of buffers (one for each channel)
void Module.lib.helpers.encode(EncoderInstance state, int samples, Float32Array[] data);

// Returns the output data buffer. Does not call encoder_clear_data.
// Note: You still need to make a copy of the data (see encoder_get_data)
Uint8Array Module.lib.helpers.get_data(EncoderInstance state);

Credits

libvorbis.js's People

Contributors

garciat avatar devongovett avatar itsjoesullivan avatar shovon avatar

Watchers

James Cloos avatar Hong Chulju avatar  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.