Skip to content

Some WebAudio signatures use number[] instead of Float32Array #23160

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

Closed
iccir opened this issue Apr 5, 2018 · 5 comments
Closed

Some WebAudio signatures use number[] instead of Float32Array #23160

iccir opened this issue Apr 5, 2018 · 5 comments
Assignees
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Fixed A PR has been merged for this issue Help Wanted You can do this

Comments

@iccir
Copy link

iccir commented Apr 5, 2018

TypeScript Version: 2.8.1

Search Terms: WebAudio, setValueCurveAtTime

Code

let context: AudioContext;

function demo(conext: AudioContext) {
    let gainNode = context.createGain();
    let sampleCount = Math.floor(0.25 * context.sampleRate);

    let values = new Float32Array(100);
    for (let i = 0; i < sampleCount; i++) {
        values[i] = i / sampleCount;
    }

    gainNode.gain.setValueCurveAtTime(values, 0, sampleCount / context.sampleRate);
}

Expected behavior:
GainNode's first parameter should be a Float32Array per the WebAudio specification. TypeScript's lib.d.ts file thinks it's a number[]. The above code shouldn't warn.

Actual behavior:
Argument of type 'Float32Array' is not assignable to parameter of type 'number[]'

Playground Link: http://www.typescriptlang.org/play/#src=%2F%2F%20WebAudio%20setValueCurveAtTime%20issue%0D%0A%0D%0Alet%20context%3A%20AudioContext%3B%0D%0A%0D%0Afunction%20demo(conext%3A%20AudioContext)%20%7B%0D%0A%20%20%20%20let%20gainNode%20%3D%20context.createGain()%3B%0D%0A%20%20%20%20let%20sampleCount%20%3D%20Math.floor(0.25%20*%20context.sampleRate)%3B%0D%0A%0D%0A%20%20%20%20let%20values%20%3D%20new%20Float32Array(100)%3B%0D%0A%20%20%20%20for%20(let%20i%20%3D%200%3B%20i%20%3C%20sampleCount%3B%20i%2B%2B)%20%7B%0D%0A%20%20%20%20%20%20%20%20values%5Bi%5D%20%3D%20i%20%2F%20sampleCount%3B%0D%0A%20%20%20%20%7D%0D%0A%0D%0A%20%20%20%20gainNode.gain.setValueCurveAtTime(values%2C%200%2C%20sampleCount%20%2F%20context.sampleRate)%3B%0D%0A%7D%0D%0A

Related Issues:

@iccir
Copy link
Author

iccir commented Apr 5, 2018

Additionally, I believe that the following signatures use number[] instead of the correct Float32Array:

interface WaveShaperOptions extends AudioNodeOptions {
    curve?: number[];
    oversample?: OverSampleType;
}

interface PeriodicWaveOptions extends PeriodicWaveConstraints {
    imag?: number[];
    real?: number[];
}

However, I'm not able to figure out why PeriodicWaveOptions extends PeriodicWaveConstraints or how AudioNodeOptions is ever used.

@iccir
Copy link
Author

iccir commented Apr 5, 2018

I explored making a PR. However, this signature comes from browser.webidl.preprocessed.json in TSJS-lib-generator, so it's possibly an Edge issue.

@mhegazy
Copy link
Contributor

mhegazy commented Apr 5, 2018

We have mechanisms to override types from the widl file. Look at microsoft/TypeScript-DOM-lib-generator#404 as a reference.

@mhegazy mhegazy added Bug A bug in TypeScript Help Wanted You can do this Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript labels Apr 5, 2018
@mhegazy mhegazy added this to the Community milestone Apr 5, 2018
@mhegazy
Copy link
Contributor

mhegazy commented Apr 5, 2018

PRs welcomed. You can find more information about contributing lib.d.ts fixes at https://github.com/Microsoft/TypeScript/blob/master/CONTRIBUTING.md#contributing-libdts-fixes.

@iccir
Copy link
Author

iccir commented Apr 5, 2018

Thanks! I fixed it for setValueCurveAtTime. I held off on changing PeriodicWaveOptions/AudioNodeOptions as I couldn't figure out how they are used.

@mhegazy mhegazy added the Fixed in TSJS repo Fix merged in https://github.com/Microsoft/TSJS-lib-generator, but not ported yet label Apr 5, 2018
@mhegazy mhegazy self-assigned this Apr 5, 2018
@mhegazy mhegazy modified the milestones: Community, TypeScript 2.9 Apr 5, 2018
@mhegazy mhegazy modified the milestones: TypeScript 2.9, TypeScript 3.0 May 8, 2018
@mhegazy mhegazy added Fixed A PR has been merged for this issue and removed Fixed in TSJS repo Fix merged in https://github.com/Microsoft/TSJS-lib-generator, but not ported yet labels Jun 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Fixed A PR has been merged for this issue Help Wanted You can do this
Projects
None yet
Development

No branches or pull requests

2 participants