WaveFile

wavefile. WaveFile

A class to manipulate wav files.

Constructor

new WaveFile(wavopt)

Source:
Parameters:
Name Type Attributes Description
wav Uint8Array <optional>
A wave file buffer.
Throws:
  • If container is not RIFF, RIFX or RF64.
    Type
    Error
  • If format is not WAVE.
    Type
    Error
  • If no 'fmt ' chunk is found.
    Type
    Error
  • If no 'data' chunk is found.
    Type
    Error

Extends

Members

bitDepth :string

Source:
Overrides:
The bit depth code according to the samples.
Type:
  • string

(protected, non-null) dataType :Object

Source:
Overrides:
Type:
  • Object

(protected) WAV_AUDIO_FORMATS :number

Source:
Overrides:
Properties:
Name Type Description
4 number
8 number
8a number
8m number
16 number
24 number
32 number
32f number
64 number
Audio formats. Formats not listed here should be set to 65534, the code for WAVE_FORMAT_EXTENSIBLE
Type:
  • number

Methods

deleteCuePoint(index)

Source:
Overrides:
Remove a cue point from a wave file.
Parameters:
Name Type Description
index number the index of the point. First is 1, second is 2, and so on.

deleteTag(tag) → {boolean}

Source:
Overrides:
Remove a RIFF tag from the INFO chunk.
Parameters:
Name Type Description
tag string The tag name.
Returns:
True if a tag was deleted.
Type
boolean

fromALaw(bitDepthCodeopt)

Source:
Overrides:
Decode a 8-bit A-Law wave file into a 16-bit wave file.
Parameters:
Name Type Attributes Default Description
bitDepthCode string <optional>
'16' The new bit depth of the samples. One of '8' ... '32' (integers), '32f' or '64' (floats).

fromBase64(base64String)

Source:
Use a .wav file encoded as a base64 string to load the WaveFile object.
Parameters:
Name Type Description
base64String string A .wav file as a base64 string.
Throws:
If any property of the object appears invalid.
Type
Error

fromBuffer(wavBuffernon-null, samplesopt)

Source:
Overrides:
Set up the WaveFileParser object from a byte buffer.
Parameters:
Name Type Attributes Default Description
wavBuffer Uint8Array The buffer.
samples boolean <optional>
true True if the samples should be loaded.
Throws:
  • If container is not RIFF, RIFX or RF64.
    Type
    Error
  • If format is not WAVE.
    Type
    Error
  • If no 'fmt ' chunk is found.
    Type
    Error
  • If no 'data' chunk is found.
    Type
    Error

fromDataURI(dataURI)

Source:
Use a .wav file encoded as a DataURI to load the WaveFile object.
Parameters:
Name Type Description
dataURI string A .wav file as DataURI.
Throws:
If any property of the object appears invalid.
Type
Error

fromIMAADPCM(bitDepthCodeopt)

Source:
Overrides:
Decode a 4-bit IMA ADPCM wave file as a 16-bit wave file.
Parameters:
Name Type Attributes Default Description
bitDepthCode string <optional>
'16' The new bit depth of the samples. One of '8' ... '32' (integers), '32f' or '64' (floats).

fromMuLaw(bitDepthCodeopt)

Source:
Overrides:
Decode a 8-bit mu-Law wave file into a 16-bit wave file.
Parameters:
Name Type Attributes Default Description
bitDepthCode string <optional>
'16' The new bit depth of the samples. One of '8' ... '32' (integers), '32f' or '64' (floats).

fromScratch(numChannels, sampleRate, bitDepthCode, samplesnon-null, optionsopt)

Source:
Overrides:
Set up the WaveFileCreator object based on the arguments passed. Existing chunks are reset.
Parameters:
Name Type Attributes Description
numChannels number The number of channels.
sampleRate number The sample rate. Integers like 8000, 44100, 48000, 96000, 192000.
bitDepthCode string The audio bit depth code. One of '4', '8', '8a', '8m', '16', '24', '32', '32f', '64' or any value between '8' and '32' (like '12').
samples Array | TypedArray The samples.
options Object <optional>
Optional. Used to force the container as RIFX with {'container': 'RIFX'}
Throws:
If any argument does not meet the criteria.
Type
Error

get_PMX() → {string}

Source:
Overrides:
Get the value of the _PMX chunk.
Returns:
The contents of the _PMX chunk.
Type
string

getiXML() → {string}

Source:
Overrides:
Return the value of the iXML chunk.
Returns:
The contents of the iXML chunk.
Type
string

(protected) getLISTIndex(listType) → (nullable) {number}

Source:
Overrides:
Return the index of a list by its type.
Parameters:
Name Type Description
listType string The list type ('adtl', 'INFO')
Returns:
Type
number

getSample(index) → {number}

Source:
Overrides:
Return the sample at a given index.
Parameters:
Name Type Description
index number The sample index.
Throws:
If the sample index is off range.
Type
Error
Returns:
The sample.
Type
number

getSamples(interleavedopt, OutputObjectopt) → (non-null) {Array|TypedArray}

Source:
Overrides:
Return the samples packed in a Float64Array.
Parameters:
Name Type Attributes Default Description
interleaved boolean <optional>
false True to return interleaved samples, false to return the samples de-interleaved.
OutputObject function <optional>
Float64Array The sample container.
Returns:
the samples.
Type
Array | TypedArray

getTag(tag) → (nullable) {string}

Source:
Overrides:
Return the value of a RIFF tag in the INFO chunk.
Parameters:
Name Type Description
tag string The tag name.
Returns:
The value if the tag is found, null otherwise.
Type
string

listCuePoints() → (non-null) {Array.<Object>}

Source:
Overrides:
Return an array with all cue points in the file, in the order they appear in the file. Objects representing cue points/regions look like this: { position: 500, // the position in milliseconds label: 'cue marker 1', end: 1500, // the end position in milliseconds dwName: 1, dwPosition: 0, fccChunk: 'data', dwChunkStart: 0, dwBlockStart: 0, dwSampleOffset: 22050, // the position as a sample offset dwSampleLength: 3646827, // length as a sample count, 0 if not a region dwPurposeID: 544106354, dwCountry: 0, dwLanguage: 0, dwDialect: 0, dwCodePage: 0, }
Returns:
Type
Array.<Object>

listTags() → (non-null) {Object.<string, string>}

Source:
Overrides:
Return a Object with the RIFF tags in the file.
Returns:
The file tags.
Type
Object.<string, string>

set_PMX(_PMXValue)

Source:
Overrides:
Set the value of the _PMX chunk.
Parameters:
Name Type Description
_PMXValue string The value for the _PMX chunk.
Throws:
If the value is not a string.
Type
TypeError

setCuePoint(pointDatanon-null)

Source:
Overrides:
Create a cue point in the wave file.
Parameters:
Name Type Description
pointData Object A object with the data of the cue point. # Only required attribute to create a cue point: pointData.position: The position of the point in milliseconds # Optional attribute for cue points: pointData.label: A string label for the cue point # Extra data used for regions pointData.end: A number representing the end of the region, in milliseconds, counting from the start of the file. If no end attr is specified then no region is created. # You may also specify the following attrs for regions, all optional: pointData.dwPurposeID pointData.dwCountry pointData.dwLanguage pointData.dwDialect pointData.dwCodePage

setiXML(iXMLValue)

Source:
Overrides:
Set the value of the iXML chunk.
Parameters:
Name Type Description
iXMLValue string The value for the iXML chunk.
Throws:
If the value is not a string.
Type
TypeError

setSample(index, sample)

Source:
Overrides:
Set the sample at a given index.
Parameters:
Name Type Description
index number The sample index.
sample number The sample.
Throws:
If the sample index is off range.
Type
Error

setTag(tag, value)

Source:
Overrides:
Write a RIFF tag in the INFO chunk. If the tag do not exist, then it is created. It if exists, it is overwritten.
Parameters:
Name Type Description
tag string The tag name.
value string The tag value.
Throws:
If the tag name is not valid.
Type
Error

toALaw()

Source:
Overrides:
Encode a 16-bit wave file as 8-bit A-Law.

toBase64() → {string}

Source:
Return a base64 string representig the WaveFile object as a .wav file.
Throws:
If any property of the object appears invalid.
Type
Error
Returns:
A .wav file as a base64 string.
Type
string

toBitDepth(newBitDepth, changeResolutionopt)

Source:
Overrides:
Change the bit depth of the samples.
Parameters:
Name Type Attributes Default Description
newBitDepth string The new bit depth of the samples. One of '8' ... '32' (integers), '32f' or '64' (floats)
changeResolution boolean <optional>
true A boolean indicating if the resolution of samples should be actually changed or not.
Throws:
If the bit depth is not valid.
Type
Error

toBuffer() → (non-null) {Uint8Array}

Source:
Overrides:
Return a byte buffer representig the WaveFileParser object as a .wav file. The return value of this method can be written straight to disk.
Throws:
  • If bit depth is invalid.
    Type
    Error
  • If the number of channels is invalid.
    Type
    Error
  • If the sample rate is invalid.
    Type
    Error
Returns:
A wav file.
Type
Uint8Array

toDataURI() → {string}

Source:
Return a DataURI string representig the WaveFile object as a .wav file. The return of this method can be used to load the audio in browsers.
Throws:
If any property of the object appears invalid.
Type
Error
Returns:
A .wav file as a DataURI.
Type
string

toIMAADPCM()

Source:
Overrides:
Encode a 16-bit wave file as 4-bit IMA ADPCM.
Throws:
  • If sample rate is not 8000.
    Type
    Error
  • If number of channels is not 1.
    Type
    Error

toMuLaw()

Source:
Overrides:
Encode 16-bit wave file as 8-bit mu-Law.

toRIFF()

Source:
Overrides:
Force a file as RIFF.

toRIFX()

Source:
Overrides:
Force a file as RIFX.

toSampleRate(sampleRate, optionsopt)

Source:
Overrides:
Convert the sample rate of the file.
Parameters:
Name Type Attributes Description
sampleRate number The target sample rate.
options Object <optional>
The extra configuration, if needed.

updateLabel(pointIndex, label)

Source:
Overrides:
Update the label of a cue point.
Parameters:
Name Type Description
pointIndex number The ID of the cue point.
label string The new text for the label.