Code Monkey home page Code Monkey logo

adpcm-compressor's Introduction

audio-adpcm-cpp

Description

audio-adpcm-cpp is a lossy audio compression c++ library for WAVE files. The compression uses ADPCM algorithm outlined by the Interactive Multimedia Association (IMA). The algorithm compresses WAVE files to 25% of their size.

Installation

Add the folder adpcm-lib from /include in your include path. If you want to compile the library from source, include wave.cpp and adpcm.cpp from the /src folder. Alternatively, you can compile the source code to a static library and include it that way.

Source.cpp is an implementation to use the library as a command in the command line terminal with arguments.

Basic Usage

Compression

The library can compress WAVE files that have at most 2 channels (Mono and Stereo), and 16-bit sample size. Once you opened and read a WAVE file, you need the WAVE header and a pointer to the samples located in the data subchunk.

WAVEHeader wav;
ifstream in(fileName, ios::binary);

in.read((char*)&wav, sizeof(WAVEHeader));

char* samples = new char[wav.subchunk2Size];
in.read(samples, wav.subchunk2Size);

You will also need an array to store the compressed samples in, and an ADPCM header structure that will be filled during the compression. You can use the WAVE header to get how many bytes of space the compressed data will take

ADPCMHeader adp;
char* data = new char[ADPCMDataSize(wav)];

Finally, you can compress the samples.

compress(samples, data, wave, adpcm);

Decompression

You can decompress data with the ADPCM header created during compression and the compressed samples. It is recommended to also store the WAVE header with the compressed data for reconstruction.

WAVEHeader  wave;
ADPCMHeader adpcm;

ifstream in(input, ios::binary);

in.read((char*)&adpcm, sizeof(ADPCMHeader));
in.read((char*)&wave, sizeof(WAVEHeader));

char* samples = new char[wave.subchunk2Size];
char* data = new char[adpcm.dataSize];
in.read((char*)data, adpcm.dataSize);

decompress(data, samples, adpcm);

Command Line Usage

You can compile the program or use the released binary in the /bin folder to compress and decompress WAVE files through the terminal.

// Compresstion from origin.wav to compressed.adp
adpcm -c origin.wav compressed.adp

// Decompress from compressed.adp to origin.wav
adpcm -d compressed.adp origin.wav

adpcm-compressor's People

Contributors

soreing 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.