mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-11 20:40:20 +00:00
update web audio api
This commit is contained in:
Vendored
+82
-47
@@ -12,7 +12,7 @@
|
||||
*
|
||||
* var context = new AudioContext();
|
||||
*/
|
||||
interface AudioContext {
|
||||
interface AudioContext extends EventTarget {
|
||||
/**
|
||||
* An AudioDestinationNode with a single input representing the final destination for all audio (to be rendered to the audio hardware). All AudioNodes actively rendering audio will directly or indirectly connect to destination.
|
||||
*/
|
||||
@@ -33,11 +33,6 @@ interface AudioContext {
|
||||
*/
|
||||
listener: AudioListener;
|
||||
|
||||
/**
|
||||
* The number of AudioBufferSourceNodes that are currently playing.
|
||||
*/
|
||||
activeSourceCount: number;
|
||||
|
||||
/**
|
||||
* Creates an AudioBuffer of the given size. The audio data in the buffer will be zero-initialized (silent). An exception will be thrown if the numberOfChannels or sampleRate are out-of-bounds.
|
||||
* @param numberOfChannels how many channels the buffer will have. An implementation must support at least 32 channels.
|
||||
@@ -69,9 +64,9 @@ interface AudioContext {
|
||||
* 5. The audioData neutered state will be restored to normal
|
||||
* 6. The successCallback function will be scheduled to run on the main thread's event loop given the AudioBuffer from step (4) as an argument.
|
||||
*
|
||||
* @param ArrayBuffer containing audio file data.
|
||||
* @param callback function which will be invoked when the decoding is finished. The single argument to this callback is an AudioBuffer representing the decoded PCM audio data.
|
||||
* @param callback function which will be invoked if there is an error decoding the audio file data.
|
||||
* @param audioData an ArrayBuffer containing audio file data.
|
||||
* @param successCallback callback function which will be invoked when the decoding is finished. The single argument to this callback is an AudioBuffer representing the decoded PCM audio data.
|
||||
* @param errorCallback callback function which will be invoked if there is an error decoding the audio file data.
|
||||
*/
|
||||
decodeAudioData(audioData: ArrayBuffer, successCallback: (decodedData: AudioBuffer) => any, errorCallback?: Function): void;
|
||||
|
||||
@@ -102,7 +97,7 @@ interface AudioContext {
|
||||
* @param numberOfInputChannels (defaults to 2) the number of channels for this node's input. Values of up to 32 must be supported.
|
||||
* @param numberOfOutputChannels (defaults to 2) the number of channels for this node's output. Values of up to 32 must be supported.
|
||||
*/
|
||||
createScriptProcessor(bufferSize: number, numberOfInputChannels?: number, numberOfOutputChannels?: number): ScriptProcessorNode;
|
||||
createScriptProcessor(bufferSize?: number, numberOfInputChannels?: number, numberOfOutputChannels?: number): ScriptProcessorNode;
|
||||
|
||||
/**
|
||||
* Creates a AnalyserNode.
|
||||
@@ -119,7 +114,6 @@ interface AudioContext {
|
||||
* @param maxDelayTime the maximum delay time in seconds allowed for the delay line. If specified, this value must be greater than zero and less than three minutes or a NOT_SUPPORTED_ERR exception will be thrown.
|
||||
*/
|
||||
createDelay(maxDelayTime?: number): DelayNode;
|
||||
//createDelayNode(maxDelayTime?: number): DelayNode;
|
||||
|
||||
/**
|
||||
* Creates a BiquadFilterNode representing a second order filter which can be configured as one of several common filter types.
|
||||
@@ -180,10 +174,6 @@ declare var webkitAudioContext: {
|
||||
new (): AudioContext;
|
||||
}
|
||||
|
||||
interface OfflineRenderSuccessCallback{
|
||||
(renderedData: AudioBuffer): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* OfflineAudioContext is a particular type of AudioContext for rendering/mixing-down (potentially) faster than real-time. It does not render to the audio hardware, but instead renders as quickly as possible, calling a render callback function upon completion with the result provided as an AudioBuffer. It is constructed by specifying the numberOfChannels, length, and sampleRate as follows:
|
||||
*
|
||||
@@ -191,13 +181,36 @@ interface OfflineRenderSuccessCallback{
|
||||
*/
|
||||
interface OfflineAudioContext extends AudioContext{
|
||||
startRendering(): void;
|
||||
oncomplete: OfflineRenderSuccessCallback;
|
||||
oncomplete: EventHandler;
|
||||
}
|
||||
|
||||
declare var OfflineAudioContext: {
|
||||
new (numberOfChannels: number, length: number, sampleRate: number): OfflineAudioContext;
|
||||
}
|
||||
|
||||
declare var webkitOfflineAudioContext: {
|
||||
new (numberOfChannels: number, length: number, sampleRate: number): OfflineAudioContext;
|
||||
}
|
||||
|
||||
interface OfflineAudioCompletionEvent extends Event {
|
||||
/**
|
||||
* An AudioBuffer containing the rendered audio data once an OfflineAudioContext has finished rendering. It will have a number of channels equal to the numberOfChannels parameter of the OfflineAudioContext constructor.
|
||||
*/
|
||||
renderedBuffer: AudioBuffer;
|
||||
}
|
||||
|
||||
|
||||
declare enum ChannelCountMode {
|
||||
'max',
|
||||
'clamped-max',
|
||||
'explicit'
|
||||
}
|
||||
|
||||
declare enum ChannelInterpretation {
|
||||
speakers,
|
||||
discrete
|
||||
}
|
||||
|
||||
/**
|
||||
* AudioNodes are the building blocks of an AudioContext. This interface represents audio sources, the audio destination, and intermediate processing modules. These modules can be connected together to form processing graphs for rendering audio to the audio hardware. Each node can have inputs and/or outputs. An AudioSourceNode has no inputs and a single output. An AudioDestinationNode has one input and no outputs and represents the final destination to the audio hardware. Most processing nodes such as filters will have one input and one output. Each type of AudioNode differs in the details of how it processes or synthesizes audio. But, in general, AudioNodes will process its inputs (if it has any), and generate audio for its outputs (if it has any).
|
||||
*
|
||||
@@ -279,6 +292,25 @@ interface AudioNode extends EventTarget {
|
||||
* The number of outputs coming out of the AudioNode. This will be 0 for an AudioDestinationNode.
|
||||
*/
|
||||
numberOfOutputs: number;
|
||||
|
||||
/**
|
||||
* The number of channels used when up-mixing and down-mixing connections to any inputs to the node. The default value is 2 except for specific nodes where its value is specially determined. This attribute has no effect for nodes with no inputs. If this value is set to zero, the implementation MUST throw a NOT_SUPPORTED_ERR exception.
|
||||
*/
|
||||
channelCount: number;
|
||||
|
||||
/**
|
||||
* Determines how channels will be counted when up-mixing and down-mixing connections to any inputs to the node . This attribute has no effect for nodes with no inputs.
|
||||
*
|
||||
* See the Channel up-mixing and down-mixing section for more information on this attribute.
|
||||
*/
|
||||
channelCountMode: ChannelCountMode;
|
||||
|
||||
/**
|
||||
* Determines how individual channels will be treated when up-mixing and down-mixing connections to any inputs to the node. This attribute has no effect for nodes with no inputs.
|
||||
*
|
||||
* See the Channel up-mixing and down-mixing section for more information on this attribute.
|
||||
*/
|
||||
channelInterpretation: ChannelInterpretation;
|
||||
}
|
||||
|
||||
|
||||
@@ -371,7 +403,7 @@ interface AudioParam {
|
||||
* @param value the value the parameter will linearly ramp to at the given time.
|
||||
* @param endTime the time in the same time coordinate system as AudioContext.currentTime.
|
||||
*/
|
||||
linearRampToValueAtTime(value: number, time: number): void;
|
||||
linearRampToValueAtTime(value: number, endTime: number): void;
|
||||
|
||||
/**
|
||||
* Schedules an exponential continuous change in parameter value from the previous scheduled parameter value to the given value. Parameters representing filter frequencies and playback rate are best changed exponentially because of the way humans perceive sound.
|
||||
@@ -420,7 +452,7 @@ interface AudioParam {
|
||||
* @param duration the amount of time in seconds (after the time parameter) where values will be calculated according to the values parameter..
|
||||
*
|
||||
*/
|
||||
setValueCurveAtTime(values: Float32Array, time: number, duration: number): void;
|
||||
setValueCurveAtTime(values: Float32Array, startTime: number, duration: number): void;
|
||||
|
||||
/**
|
||||
* Cancels all scheduled parameter changes with times greater than or equal to startTime.
|
||||
@@ -506,17 +538,12 @@ interface AudioBuffer {
|
||||
}
|
||||
|
||||
/**
|
||||
* This interface represents an audio source from an in-memory audio asset in an AudioBuffer. It generally will be used for short audio assets which require a high degree of scheduling flexibility (can playback in rhythmically perfect ways). The playback state of an AudioBufferSourceNode goes through distinct stages during its lifetime in this order: UNSCHEDULED_STATE, SCHEDULED_STATE, PLAYING_STATE, FINISHED_STATE. The start() method causes a transition from the UNSCHEDULED_STATE to SCHEDULED_STATE. Depending on the time argument passed to start(), a transition is made from the SCHEDULED_STATE to PLAYING_STATE, at which time sound is first generated. Following this, a transition from the PLAYING_STATE to FINISHED_STATE happens when either the buffer's audio data has been completely played (if the loop attribute is false), or when the stop() method has been called and the specified time has been reached. Please see more details in the start() and stop() description. Once an AudioBufferSourceNode has reached the FINISHED state it will no longer emit any sound. Thus start() and stop() may not be issued multiple times for a given AudioBufferSourceNode.
|
||||
* This interface represents an audio source from an in-memory audio asset in an AudioBuffer. It is useful for playing short audio assets which require a high degree of scheduling flexibility (can playback in rhythmically perfect ways). The start() method is used to schedule when sound playback will happen. The playback will stop automatically when the buffer's audio data has been completely played (if the loop attribute is false), or when the stop() method has been called and the specified time has been reached. Please see more details in the start() and stop() description. start() and stop() may not be issued multiple times for a given AudioBufferSourceNode.
|
||||
*
|
||||
* numberOfInputs : 0
|
||||
* numberOfOutputs : 1
|
||||
*/
|
||||
interface AudioBufferSourceNode extends AudioSourceNode {
|
||||
|
||||
/**
|
||||
* The playback state, initialized to UNSCHEDULED_STATE.
|
||||
*/
|
||||
playbackState: number;
|
||||
interface AudioBufferSourceNode extends AudioNode {
|
||||
|
||||
/**
|
||||
* Represents the audio asset to be played.
|
||||
@@ -546,7 +573,7 @@ interface AudioBufferSourceNode extends AudioSourceNode {
|
||||
/**
|
||||
* A property used to set the EventHandler for the ended event that is dispatched to AudioBufferSourceNode node types. When the playback of the buffer for an AudioBufferSourceNode is finished, an event of type Event will be dispatched to the event handler.
|
||||
*/
|
||||
onended: EventListener;
|
||||
onended: EventHandler;
|
||||
|
||||
/**
|
||||
* Schedules a sound to playback at an exact time.
|
||||
@@ -571,7 +598,7 @@ interface AudioBufferSourceNode extends AudioSourceNode {
|
||||
* numberOfInputs : 0
|
||||
* numberOfOutputs : 1
|
||||
*/
|
||||
interface MediaElementAudioSourceNode extends AudioSourceNode {
|
||||
interface MediaElementAudioSourceNode extends AudioNode {
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -590,7 +617,7 @@ interface ScriptProcessorNode extends AudioNode {
|
||||
/**
|
||||
* An event listener which is called periodically for audio processing. An event of type AudioProcessingEvent will be passed to the event handler.
|
||||
*/
|
||||
onaudioprocess: EventListener;
|
||||
onaudioprocess: EventHandler;
|
||||
|
||||
/**
|
||||
* The size of the buffer (in sample-frames) which needs to be processed each time onprocessaudio is called. Legal values are (256, 512, 1024, 2048, 4096, 8192, 16384).
|
||||
@@ -604,11 +631,6 @@ interface ScriptProcessorNode extends AudioNode {
|
||||
* The event handler processes audio from the input (if any) by accessing the audio data from the inputBuffer attribute. The audio data which is the result of the processing (or the synthesized data if there are no inputs) is then placed into the outputBuffer.
|
||||
*/
|
||||
interface AudioProcessingEvent extends Event {
|
||||
/**
|
||||
* The ScriptProcessorNode associated with this processing event.
|
||||
*/
|
||||
node: ScriptProcessorNode;
|
||||
|
||||
/**
|
||||
* The time when the audio will be played in the same time coordinate system as AudioContext.currentTime. playbackTime allows for very tight synchronization between processing directly in JavaScript with the other events in the context's rendering graph.
|
||||
*/
|
||||
@@ -634,12 +656,7 @@ declare enum PanningModelType {
|
||||
/**
|
||||
* A higher quality spatialization algorithm using a convolution with measured impulse responses from human subjects. This panning method renders stereo output.
|
||||
*/
|
||||
HRTF,
|
||||
|
||||
/**
|
||||
* An algorithm which spatializes multi-channel audio using sound field algorithms.
|
||||
*/
|
||||
soundfield
|
||||
HRTF
|
||||
}
|
||||
|
||||
declare enum DistanceModelType {
|
||||
@@ -1056,6 +1073,12 @@ interface BiquadFilterNode extends AudioNode {
|
||||
getFrequencyResponse(frequencyHz: Float32Array, magResponse: Float32Array, phaseResponse: Float32Array): void;
|
||||
}
|
||||
|
||||
declare enum OverSampleType {
|
||||
'none',
|
||||
'2x',
|
||||
'4x'
|
||||
}
|
||||
|
||||
/**
|
||||
* WaveShaperNode is an AudioNode processor implementing non-linear distortion effects.
|
||||
*
|
||||
@@ -1069,6 +1092,19 @@ interface WaveShaperNode extends AudioNode {
|
||||
* The shaping curve used for the waveshaping effect. The input signal is nominally within the range -1 -> +1. Each input sample within this range will index into the shaping curve with a signal level of zero corresponding to the center value of the curve array. Any sample value less than -1 will correspond to the first value in the curve array. Any sample value less greater than +1 will correspond to the last value in the curve array.
|
||||
*/
|
||||
curve: Float32Array;
|
||||
|
||||
/**
|
||||
* Specifies what type of oversampling (if any) should be used when applying the shaping curve. The default value is "none", meaning the curve will be applied directly to the input samples. A value of "2x" or "4x" can improve the quality of the processing by avoiding some aliasing, with the "4x" value yielding the highest quality. For some applications, it's better to use no oversampling in order to get a very precise shaping curve.
|
||||
*
|
||||
* A value of "2x" or "4x" means that the following steps must be performed:
|
||||
*
|
||||
* 1. Up-sample the input samples to 2x or 4x the sample-rate of the AudioContext. Thus for each processing block of 128 samples, generate 256 (for 2x) or 512 (for 4x) samples.
|
||||
* 2. Apply the shaping curve.
|
||||
* 3. Down-sample the result back to the sample-rate of the AudioContext. Thus taking the 256 (or 512) processed samples, generating 128 as the final result.
|
||||
*
|
||||
* The exact up-sampling and down-sampling filters are not specified, and can be tuned for sound quality (low aliasing, etc.), low latency, and performance.
|
||||
*/
|
||||
oversample: OverSampleType
|
||||
}
|
||||
|
||||
declare enum OscillatorType {
|
||||
@@ -1099,18 +1135,12 @@ declare enum OscillatorType {
|
||||
* numberOfInputs : 0
|
||||
* numberOfOutputs : 1 (mono output)
|
||||
*/
|
||||
interface OscillatorNode extends AudioSourceNode {
|
||||
interface OscillatorNode extends AudioNode {
|
||||
/**
|
||||
* The shape of the periodic waveform. It may directly be set to any of the type constant values except for "custom". The setPeriodicWave() method can be used to set a custom waveform, which results in this attribute being set to "custom". The default value is "sine".
|
||||
*/
|
||||
type: OscillatorType;
|
||||
|
||||
/**
|
||||
* defined as in AudioBufferSourceNode.
|
||||
* @readonly
|
||||
*/
|
||||
playbackState: number;
|
||||
|
||||
/**
|
||||
* The frequency (in Hertz) of the periodic waveform. This parameter is a-rate
|
||||
* @readonly
|
||||
@@ -1136,6 +1166,11 @@ interface OscillatorNode extends AudioSourceNode {
|
||||
* Sets an arbitrary custom periodic waveform given a PeriodicWave.
|
||||
*/
|
||||
setPeriodicWave(periodicWave: PeriodicWave): void;
|
||||
|
||||
/**
|
||||
* A property used to set the EventHandler (described in HTML) for the ended event that is dispatched to OscillatorNode node types. When the playback of the buffer for an OscillatorNode is finished, an event of type Event (described in HTML) will be dispatched to the event handler.
|
||||
*/
|
||||
onended: EventHandler
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1150,7 +1185,7 @@ interface PeriodicWave {
|
||||
* numberOfInputs : 0
|
||||
* numberOfOutputs : 1
|
||||
*/
|
||||
interface MediaStreamAudioSourceNode extends AudioSourceNode {
|
||||
interface MediaStreamAudioSourceNode extends AudioNode {
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user