How to use the standardized-audio-context.AudioBuffer function in standardized-audio-context

To help you get started, we’ve selected a few standardized-audio-context examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github chrisguttandin / audio-context-timers / src / module.ts View on Github external
import { generateUniqueNumber } from 'fast-unique-numbers';
import { AudioBuffer, AudioBufferSourceNode, MinimalAudioContext, isSupported } from 'standardized-audio-context';
import { TFunctionMap, TTimerType } from './types';

const MINIMAL_AUDIO_CONTEXT = new MinimalAudioContext();

const AUDIO_BUFFER = new AudioBuffer({ length: 2, sampleRate: MINIMAL_AUDIO_CONTEXT.sampleRate });

const SAMPLE_DURATION = 2 / MINIMAL_AUDIO_CONTEXT.sampleRate;

const SCHEDULED_TIMEOUT_FUNCTIONS: TFunctionMap = new Map();

const SCHEDULED_INTERVAL_FUNCTIONS: TFunctionMap = new Map();

const callIntervalFunction = (id: number, type: TTimerType) => {
    const functions = (type === 'interval') ? SCHEDULED_INTERVAL_FUNCTIONS : SCHEDULED_TIMEOUT_FUNCTIONS;

    if (functions.has(id)) {
        const func = functions.get(id);

        if (func !== undefined) {
            func();