Git Product home page Git Product logo

wavutils's Introduction

WavUtils

Classes for reading and writing Wav files in C++.

  • Read or write incrementally (frame by frame), or all at once
  • Support for 8/16/24/32-bit int samples, or 32/64-bit float samples
  • Conversion to/from 16-bit int format, while reading or writing
  • In-Memory conversion to/from 16-bit int format
  • Little-Endian; supports iOS, Android NDK, Windows, and OSX (post-PowerPC)

Usage

Read:

#include "WavReader.hpp"
...
WavReader* wr = new WavReader();
wr->initialize(inputWavFilePath);
wr->prepareToRead();  // Metadata available after this
wr->readData(sampleData, wr->getSampleDataSize());
wr->finishReading();

Write:

#include "WavWriter.hpp"
...
WavWriter* ww = new WavWriter();
ww->initialize(outputWavFilePath,
               sampleRate,
               numChannels,  // 1 || 2
               samplesAreInts, // false for 32/64-bit float vals
               byteDepth);  // 1, 2, 3, 4 for int samples; 4 or 8 for float samples
ww->startWriting(); //Writes header
ww->writeData(sampleData, sampleDataSize);
ww->finishReading();

Incrementally Read & Write:

...
wr->readData(bufferA, bufferASize);
wr->readData(bufferB, bufferBSize);
...
ww->writeData(bufferA, bufferASize);
ww->writeData(bufferB, bufferBSize);
...

Conversion to/from Int16 Samples, during Read & Write

...
wr->readDataToInt16s(int16Samples,
                     numInt16Samples);

ww->writeDataFromInt16s(int16Samples,
                        numInt16Samples);
...

In-Memory Conversion to/from Int16 Samples

...
wr->readInt16SampleFromArray(sampleData,  // Wav-format "source" sample data array
                             sampleDataSize,
                             sampleIndex,  //Index of sample to be read
                             int16SampleCh1,  // Sample's channel-1 value, as int16
                             int16SampleCh2);  // Sample's channel-2 value (if available), as int16
...
ww->writeInt16SampleToArray(int16SampleCh1,  // Sample's channel-1 value, as int16
                            int16SampleCh2,  // Sample's channel-2 value (if available), as int16
                            sampleIndex,  //Index of sample to be written
                            sampleData,  // Wav-format "target" sample data array
                            sampleDataSize);
...

wavutils's People

Contributors

kleydon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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.