All Projects → audiojs → audio-oscillator

audiojs / audio-oscillator

Licence: MIT license
Generate periodic oscillation into an array/audiobuffer

Programming Languages

javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to audio-oscillator

audio-buffer-from
Create audio-buffer from any source data
Stars: ✭ 20 (-25.93%)
Mutual labels:  audiojs
pcm-convert
Convert pcm data from any to any format
Stars: ✭ 30 (+11.11%)
Mutual labels:  audiojs
audio-spectrum
Draw spectrum of audio data
Stars: ✭ 16 (-40.74%)
Mutual labels:  audiojs

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
let buf = new AudioBuffer({ channels: 2, sampleRate: 44100, length: 1024 })
;(async function frame() {
  await output(oscillate(buf, { frequency: 440 })))
  frame()
})()

API

let array = oscillate.<waveform>(length|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

Property Default Meaning
frequency, f 440 Frequency of oscillations, in Hz.
detune 0 Detune of oscillations -100...+100, in cents.
phase, t 0 Normalized initial phase of waveform, 0..1.
sampleRate, rate 44100 Sample rate of output data.

waveform

Available waveforms with their additional options:

Type Waveshape Parameters
'sin' sine
'cos' cosine
'saw' sawtooth inverse=false
'tri' triangle ratio=0.5
'rect' square ratio=0.5
'series' fourier real=[0, 1], imag=[0, 0], normalize=true
'clausen' clausen limit=10
'step' step samples=10

Related

License

© 2017 Dmitry Yv. MIT License

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].