Skip to content

getSamples() has wrong return type declaration #36

@brun0ne

Description

@brun0ne

This is how currently getSamples() is defined in index.d.ts
getSamples(interleaved?:boolean, OutputObject?: Function): Float64Array;

It is supposed to return a Float64Array. But, according to the docs, when there are more than 2 channels, it returns an array of Float64Arrays.

If the file is stereo or have more than one channel then the samples will be returned de-interleaved in a Array of Float64Array objects, one Float64Array for each channel.

This creates confusion when you try to create some logic around it, for example, if you need to go through all channels, you might write something like this:

const numChannels = (wave.fmt as any).numChannels;
let sampleChannels: Float64Array[] = [];

if (numChannels > 1) {
    sampleChannels = wave.getSamples() as Float64Array[];
}
else {
    sampleChannels.push(wave.getSamples() as Float64Array);
}

Unfortunately, this fails. I had to change the return type in index.d.ts to: Float64Array | Float64Array[].

I think this would be the right declaration and should be changed, or the function could be changed so that it always returns an array of arrays.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions