diff --git a/types/audio-context/audio-context-tests.ts b/types/audio-context/audio-context-tests.ts new file mode 100644 index 0000000000..a8bf728bb7 --- /dev/null +++ b/types/audio-context/audio-context-tests.ts @@ -0,0 +1,11 @@ +import getContext = require("audio-context"); + +const context = getContext(); +const myContext = getContext(22000); +const yourOptions: getContext.Options = { + sampleRate: 44000, + offline: true, + length: 3000, + channels: 2 +}; +const yourContext = getContext(yourOptions); diff --git a/types/audio-context/index.d.ts b/types/audio-context/index.d.ts new file mode 100644 index 0000000000..1dab416b01 --- /dev/null +++ b/types/audio-context/index.d.ts @@ -0,0 +1,34 @@ +// Type definitions for audio-context 1.0 +// Project: https://github.com/audiojs/audio-context +// Definitions by: Jeff Peterson +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 + +/** + * Options for your audio context: + * @param sampleRate if specified, will set the context sampleRate. + * @param latencyHint if specified, will control latency. One of 'balanced', 'playback', 'interaction' (default) or number. + * @param offline if specified, will create OfflineAudioContext. + * @param length if specified, will set number of frames for offline context. + * @param channels if specified, will set number of channels for offline context. + * @param contextAttributes any other options for the context. + */ +declare namespace getContext { + interface Options { + sampleRate?: number; + latencyHint?: string | number; + offline?: boolean; + length?: number; + channels?: number; + contextAttributes?: object; + } +} + +/** + * Gets an audio context from your web browser. + * @param options Takes an Options object or just provide a sample rate. + * @returns the audio context or null if there was an error or not a web browser. + */ +declare function getContext(options?: getContext.Options | number): AudioContext | null; + +export = getContext; diff --git a/types/audio-context/tsconfig.json b/types/audio-context/tsconfig.json new file mode 100644 index 0000000000..0b6aed0cdd --- /dev/null +++ b/types/audio-context/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "audio-context-tests.ts" + ] +} diff --git a/types/audio-context/tslint.json b/types/audio-context/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/audio-context/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/audio-play/audio-play-tests.ts b/types/audio-play/audio-play-tests.ts new file mode 100644 index 0000000000..7fb831b772 --- /dev/null +++ b/types/audio-play/audio-play-tests.ts @@ -0,0 +1,6 @@ +import audioPlay = require("audio-play"); + +const buffer = new AudioBuffer({length: 2, sampleRate: 22000}); +const thisSound = audioPlay(buffer, { autoplay: true }, () => console.log('stopped!')); +thisSound.pause(); +thisSound.play(); diff --git a/types/audio-play/index.d.ts b/types/audio-play/index.d.ts new file mode 100644 index 0000000000..d659087d12 --- /dev/null +++ b/types/audio-play/index.d.ts @@ -0,0 +1,44 @@ +// Type definitions for audio-play 2.2 +// Project: https://github.com/audiojs/audio-play +// Definitions by: Jeff Peterson +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 3.0 + +/** + * Creates and plays/pauses a sound effect or music. + * @param buffer Handle to the audio buffer created by an audio loader + * @param how An options object that defines parameters for playback of the audio buffer + * @param cb A callback that is executed when playback stops + * @returns a handle to the player, which can then call pause and play functions + */ +declare function audioPlay(buffer: AudioBuffer, how: audioPlay.Options, cb: () => void): audioPlay.AudioPlayHandle; + +declare namespace audioPlay { + interface AudioPlayHandle { + play: () => any; + pause: () => any; + } + + /** + * Various options for audio playback + * @param start The timestamp at which to start the audio. Can be negative to start from end. (Default: 0) + * @param end The timestamp the audio ends at. (Default: length of audio buffer) + * @param autoplay Plays back the audio immediately upon loading. (Default: false) + * @param loop Continuously loops the buffer until paused. (Default: false) + * @param context Handle to an audio context. If not provided, one is provided for you. + * @param volume (not implemented) Playback the audio at a percentage of full volume. (Default: 1) + * @param detune (not implemented) Percentage of fine-tuning. (Default: 0) + * @param rate (not implemented) Playback rate, in percent, of the audio. (Default: 1) + */ + interface Options { + start?: number; + end?: number; + autoplay?: boolean; + loop?: boolean; + rate?: number; + detune?: number; + volume?: number; + context?: AudioContext; + } +} +export = audioPlay; diff --git a/types/audio-play/tsconfig.json b/types/audio-play/tsconfig.json new file mode 100644 index 0000000000..e7efba31cb --- /dev/null +++ b/types/audio-play/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "esModuleInterop": true + }, + "files": [ + "index.d.ts", + "audio-play-tests.ts" + ] +} diff --git a/types/audio-play/tslint.json b/types/audio-play/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/audio-play/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }