Implements Web Audio API to create a simple wave oscillator visualizer. Original designed classes and architecture heavily inspired by examples on MDN. See MDN example
I wrote a blog article discussing the Web Audio API and explaining the program here.
This project is an iteration of an effort called Code Something Weekly. The article explaining how and why is found here
Kind: global class
- AudioPlayer
- new AudioPlayer(opts)
- .changeGain(volume) ⇒
undefined
- .changeFrequency(f, df) ⇒
undefined
- .getAnalyzerBinCount(f) ⇒
number
- .getAnalyzerFFTSize(f) ⇒
number
- .getAnalyzerTimeBytes(f, dataArray) ⇒
undefined
- .togglePlay() ⇒
undefined
Param | Type | Default | Description |
---|---|---|---|
opts | Object |
(required) | |
opts.ctx | Object |
(required) The AudioContext Object | |
[opts.volume] | number |
0.5 |
the overall volume |
[opts.f1] | number |
130.81 |
the frequency of wave 1 |
[opts.f2] | number |
164.81 |
the frequency of wave 2 |
[opts.f3] | number |
196.00 |
the frequency of wave 3 |
Adjusts the overall volume
Kind: instance method of AudioPlayer
Param | Type | Description |
---|---|---|
volume | number |
between (0.0, 1.0) |
Adjusts the value of a frequency.
Kind: instance method of AudioPlayer
Param | Type | Description |
---|---|---|
f | number |
(1, 3). The frequency to change. |
df | number |
the amount to change the frequency |
Returns 1/2 the FFT value for a given source. Represents the number of data values for visualization in the frequency domain. Use to assign the length of an unsigned 8-bit array (ie: Uint8Array [binCount])
Kind: instance method of AudioPlayer
Param | Type | Description |
---|---|---|
f | number |
The frequency (1, 3) to obtain the bin count |
Returns the fftSize which is an unsigned long value and represents the window size in samples that is used when performing a Fast Fourier Transform.
Kind: instance method of AudioPlayer
Returns: number
- - an unsigned long
Param | Type | Description |
---|---|---|
f | number |
The frequency (1, 3) for which to get the FFT size. |
Copies the current time domain data into the provided array. Must be of type Uint8Array.
Kind: instance method of AudioPlayer
Param | Type | Description |
---|---|---|
f | number |
The frequency (1, 3) to get the time btyes |
dataArray | Uint8Array |
Starts or stops the audio player.
Kind: instance method of AudioPlayer