Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getSamples() has wrong return type declaration #36

Open
brun0ne opened this issue Apr 10, 2023 · 0 comments
Open

getSamples() has wrong return type declaration #36

brun0ne opened this issue Apr 10, 2023 · 0 comments

Comments

@brun0ne
Copy link

brun0ne commented Apr 10, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant