Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

hexadecy/libvorbis.js

 
 

Repository files navigation

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.

Install

bower install libvorbis.js

Download

See releases.

Build

Requirements

  • emscripten compiler
  • TypeScript 1.5+ compiler (npm install -g typescript)
  • uglifyjs (npm install -g uglifyjs)

Instructions

git submodule init
git submodule update
./build.sh

Demos

Microphone recorder.

API

declare module libvorbis {
    interface OggVbrEncoderOptions {
        channels: number;
        sampleRate: number;
        quality: number;
    }
    
    class OggVbrEncoder {
        constructor(module: OggVbrModule, options: OggVbrEncoderOptions);
        
        static create(options: OggVbrEncoderOptions): Promise<OggVbrEncoder>;
        
        /**
         * Performs a encoding step on the provided PCM channel data.
         * It may or may not produce an output ArrayBuffer.
         *
         * @param channelData An array of PCM data buffers (one for each channel).
         */
        encode(channelData: Float32Array[]): ArrayBuffer;
        
        /**
         * Finalizes the OGG Vorbis stream.
         * It may or may not produce an output ArrayBuffer.
         */
        finish(): ArrayBuffer;
    }
    
    interface OggVbrAsyncEncoderOptions {
        workerURL: string;
        moduleURL: string;
        encoderOptions: OggVbrEncoderOptions;
    }
    
    class OggVbrAsyncEncoder {
        /**
         * Call static method create() to instantiate this class!
         */
        constructor(worker: Worker, onData: (data: ArrayBuffer) => void, onFinished: () => void);
        
        static create(options: OggVbrAsyncEncoderOptions,
                      onData: (data: ArrayBuffer) => void,
                      onFinished: () => void): Promise<OggVbrAsyncEncoder>;
        
        /**
         * Performs a encoding step on the provided PCM channel data.
         *
         * @param channelData An array of PCM data buffers (one for each channel).
         */
        encode(channelData: Float32Array[]): void;
        
        /**
         * Performs a encoding step on the provided PCM channel data.
         * Warning: passed buffers will be transferred to the Worker, rendering
         * them unusable from this thread.
         *
         * @param channelData An array of PCM data buffers (one for each channel).
         */
        encodeTransfer(channelData: Float32Array[]): void;
        
        /**
         * Finalizes the OGG Vorbis stream.
         */
        finish(): void;
    }
}

Credits

Packages

No packages published

Languages

  • TypeScript 64.7%
  • C 20.0%
  • Shell 15.3%