wavefile-reader
Copyright (c) 2019 Rafael da Silva Rocha.
https://github.com/rochars/wavefile-reader
Read data from wav files.
Install
npm install wavefile-reader
Use
Node
const wavefileReader = ;let wav = ;
or
const WaveFileReader = WaveFileReader;let wav = ;
or
;let wav = ;
Node.js Example
const WaveFileReader = WaveFileReader; // Load a wav file buffer as a WaveFileReader objectlet wav = ;wav; // Check some of the file propertiesconsole;console;console; // You can also load a file during object creation:wav = buffer;console;console;console;
Browser
Use the wavefile-reader.js file in the dist folder:
Or load it from the jsDelivr CDN:
Or load it from unpkg:
API
The WaveFileReader methods
/** * Set up the WaveFileReader object from a byte buffer. * @param * @param * @throws * @throws * @throws * @throws */WaveFileReader {}
The WaveFileReader properties
/** * The container identifier. * "RIFF", "RIFX" and "RF64" are supported. * @type */WaveFileReadercontainer = '';/** * @type */WaveFileReaderchunkSize = 0;/** * The format. * Always 'WAVE'. * @type */WaveFileReaderformat = '';/** * The data of the "fmt" chunk. * @type {!Object<string, *>} */WaveFileReaderfmt = /** @type */ chunkId: '' /** @type */ chunkSize: 0 /** @type */ audioFormat: 0 /** @type */ numChannels: 0 /** @type */ sampleRate: 0 /** @type */ byteRate: 0 /** @type */ blockAlign: 0 /** @type */ bitsPerSample: 0 /** @type */ cbSize: 0 /** @type */ validBitsPerSample: 0 /** @type */ dwChannelMask: 0 /** * 4 32-bit values representing a 128-bit ID * @type */ subformat: ;/** * The data of the "fact" chunk. * @type {!Object<string, *>} */WaveFileReaderfact = /** @type */ chunkId: '' /** @type */ chunkSize: 0 /** @type */ dwSampleLength: 0;/** * The data of the "cue " chunk. * @type {!Object<string, *>} */WaveFileReadercue = /** @type */ chunkId: '' /** @type */ chunkSize: 0 /** @type */ dwCuePoints: 0 /** @type {!Array<!Object>} */ points: ;/** * The data of the "smpl" chunk. * @type {!Object<string, *>} */WaveFileReadersmpl = /** @type */ chunkId: '' /** @type */ chunkSize: 0 /** @type */ dwManufacturer: 0 /** @type */ dwProduct: 0 /** @type */ dwSamplePeriod: 0 /** @type */ dwMIDIUnityNote: 0 /** @type */ dwMIDIPitchFraction: 0 /** @type */ dwSMPTEFormat: 0 /** @type */ dwSMPTEOffset: 0 /** @type */ dwNumSampleLoops: 0 /** @type */ dwSamplerData: 0 /** @type {!Array<!Object>} */ loops: ;/** * The data of the "bext" chunk. * @type {!Object<string, *>} */WaveFileReaderbext = /** @type */ chunkId: '' /** @type */ chunkSize: 0 /** @type */ description: '' //256 /** @type */ originator: '' //32 /** @type */ originatorReference: '' //32 /** @type */ originationDate: '' //10 /** @type */ originationTime: '' //8 /** * 2 32-bit values, timeReference high and low * @type */ timeReference: 0 0 /** @type */ version: 0 //WORD /** @type */ UMID: '' // 64 chars /** @type */ loudnessValue: 0 //WORD /** @type */ loudnessRange: 0 //WORD /** @type */ maxTruePeakLevel: 0 //WORD /** @type */ maxMomentaryLoudness: 0 //WORD /** @type */ maxShortTermLoudness: 0 //WORD /** @type */ reserved: '' //180 /** @type */ codingHistory: '' // string, unlimited;/** * The data of the "ds64" chunk. * Used only with RF64 files. * @type {!Object<string, *>} */WaveFileReaderds64 = /** @type */ chunkId: '' /** @type */ chunkSize: 0 /** @type */ riffSizeHigh: 0 // DWORD /** @type */ riffSizeLow: 0 // DWORD /** @type */ dataSizeHigh: 0 // DWORD /** @type */ dataSizeLow: 0 // DWORD /** @type */ originationTime: 0 // DWORD /** @type */ sampleCountHigh: 0 // DWORD /** @type */ sampleCountLow: 0 // DWORD /** @type */ //"tableLength": 0, // DWORD /** @type */ //"table": [];/** * The data of the "data" chunk. * @type {!Object<string, *>} */WaveFileReaderdata = /** @type */ chunkId: '' /** @type */ chunkSize: 0 /** @type */ samples: 0;/** * The data of the "LIST" chunks. * Each item in this list look like this: * { * chunkId: '', * chunkSize: 0, * format: '', * subChunks: [] * } * @type {!Array<!Object>} */WaveFileReaderLIST = ;/** * The data of the "junk" chunk. * @type {!Object<string, *>} */WaveFileReaderjunk = /** @type */ chunkId: '' /** @type */ chunkSize: 0 /** @type */ chunkData: ;/** * The bit depth code according to the samples. * @type */WaveFileReaderbitDepth = '';
Cue points
Items in cue.points are objects like this:
/** @type */ dwName: 0 // a cue point ID /** @type */ dwPosition: 0 /** @type */ fccChunk: 0 /** @type */ dwChunkStart: 0 /** @type */ dwBlockStart: 0 /** @type */ dwSampleOffset: 0
Sample loops
Items in smpl.loops are objects like this:
/** @type */ dwName: '' // a cue point ID /** @type */ dwType: 0 /** @type */ dwStart: 0 /** @type */ dwEnd: 0 /** @type */ dwFraction: 0 /** @type */ dwPlayCount: 0
LIST chunk
"LIST" chunk data is stored as follows:
/** * An array of the "LIST" chunks present in the file. * @type {!Array<!Object>} */WaveFileReaderLIST = ;
Items in WaveFileReader.LIST are objects like this:
/** @type */ chunkId: '' // always 'LIST' /** @type */ chunkSize: 0 /** @type */ format: '' // 'adtl' or 'INFO' /** @type {!Array<!Object>} */ subChunks: ;
Where "subChunks" are the subChunks of the "LIST" chunk. A single file may have many "LIST" chunks as long as their formats ("INFO", "adtl", etc) are not the same. wavefile-reader can read "LIST" chunks of format "INFO" and "adtl".
For "LIST" chunks with the "INFO" format, "subChunks" will be an array of objects like this:
/** @type */ chunkId: '' // some RIFF tag /** @type */ chunkSize 0 /** @type */ value: ''
Where "chunkId" may be any RIFF tag:
https://sno.phy.queensu.ca/~phil/exiftool/TagNames/RIFF.html#Info
Contributing to wavefile-reader
wavefile-reader welcomes all contributions from anyone willing to work in good faith with other contributors and the community. No contribution is too small and all contributions are valued.
See CONTRIBUTING.md for details.
Style guide
wavefile-reader code should follow the Google JavaScript Style Guide:
https://google.github.io/styleguide/jsguide.html
Code of conduct
This project is bound by a Code of Conduct: The Contributor Covenant, version 1.4, also available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
References
Papers
https://tech.ebu.ch/docs/tech/tech3285.pdf
https://tech.ebu.ch/docs/tech/tech3306-2009.pdf
http://www-mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/WAVE.html
https://www.loc.gov/preservation/digital/formats/fdd/fdd000356.shtml
http://www-mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/Docs/riffmci.pdf
https://sites.google.com/site/musicgapi/technical-documents/wav-file-format
http://www.neurophys.wisc.edu/auditory/riff-format.txt
https://sno.phy.queensu.ca/~phil/exiftool/TagNames/RIFF.html#Info
Software
https://github.com/erikd/libsndfile
https://gist.github.com/hackNightly/3776503
https://github.com/chirlu/sox/blob/master/src/wav.c
Other
https://developercertificate.org/
https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
https://google.github.io/styleguide/jsguide.html
LICENSE
Copyright (c) 2019 Rafael da Silva Rocha.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.