3.1.1 • Published 5 years ago

audio-oscillator v3.1.1

Weekly downloads
4
License
MIT
Repository
github
Last release
5 years ago

audio-oscillator Build Status unstable Greenkeeper badge

Generate periodic oscillation data.

Usage

$ npm install audio-oscillator

const oscillate = require('audio-oscillator/sine')
const output = require('web-audio-write')()

// render sine sound stream
;(async function frame() {
  await output(oscillate(new AudioBuffer({
    channels: 2, sampleRate: 44100, length: 1024
  }), 440))
  frame()
})()

API

let array = oscillate.<waveform>(length=1024|dst, frequency=440|options?)

Generate periodic-function waveform samples into a dst float array / array of arrays / AudioBuffer. If length is provided, a new mono array is created. The phase of consequently generated chunks is aligned, if the same array is passed multiple times.

let oscillate = require('audio-oscillator')

let samples = new Float64Array(1024)

oscillate.sine(samples, 440)

// output array has additional properties of the data
// samples.phase, samples.frequency, samples.detune, samples.sampleRate

// next data phase is aligned with the previous data
oscillate.sine(samples)

options

PropertyDefaultMeaning
frequency, f440Frequency of oscillations, in Hz.
detune0Detune of oscillations -100...+100, in cents.
phase, t0Normalized initial phase of waveform, 0..1.
sampleRate, rate44100Sample rate of output data.

waveform

Available waveforms with their additional options:

TypeWaveshapeParameters
'sin'sine
'cos'cosine
'saw'sawtoothinverse=false
'tri'triangleratio=0.5
'rect'squareratio=0.5
'series'fourierreal=[0, 1], imag=[0, 0], normalize=true
'clausen'clausenlimit=10
'step'stepsamples=10

Related

License

© 2017 Dmitry Yv. MIT License

3.1.1

5 years ago

3.1.0

5 years ago

3.0.1

5 years ago

3.0.0

5 years ago

2.3.0

6 years ago

2.2.0

7 years ago

2.1.0

7 years ago

2.0.0

7 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago