Skip to content

Commit adbe6af

Browse files
committed
player visualizer example
1 parent 5fcf1d5 commit adbe6af

File tree

22 files changed

+1315
-148
lines changed

22 files changed

+1315
-148
lines changed

build/@types/web-audio-api-player/library/audio.d.ts

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,52 @@
1+
/// <reference types="webaudioapi" />
2+
export interface IWaveTable {
3+
}
4+
export interface IAudioContext {
5+
destination: AudioDestinationNode;
6+
sampleRate: number;
7+
currentTime: number;
8+
listener: AudioListener;
9+
activeSourceCount: number;
10+
state: string;
11+
createBuffer(numberOfChannels: number, length: number, sampleRate: number): AudioBuffer;
12+
createBuffer(buffer: ArrayBuffer, mixToMono: boolean): AudioBuffer;
13+
decodeAudioData(audioData: ArrayBuffer, decodeSuccessCallback?: Function, decodeErrorCallback?: Function): void;
14+
createBufferSource(): AudioBufferSourceNode;
15+
createMediaElementSource(mediaElement: HTMLMediaElement): MediaElementAudioSourceNode;
16+
createMediaStreamSource(mediaStreamMediaStream: MediaStream): MediaStreamAudioSourceNode;
17+
createMediaStreamDestination(): MediaStreamAudioDestinationNode;
18+
createScriptProcessor(bufferSize: number, numberOfInputChannels?: number, numberOfOutputChannels?: number): ScriptProcessorNode;
19+
createAnalyser(): AnalyserNode;
20+
createGain(): GainNode;
21+
createDelay(maxDelayTime?: number): DelayNode;
22+
createBiquadFilter(): BiquadFilterNode;
23+
createWaveShaper(): WaveShaperNode;
24+
createPanner(): PannerNode;
25+
createConvolver(): ConvolverNode;
26+
createChannelSplitter(numberOfOutputs?: number): ChannelSplitterNode;
27+
createChannelMerger(numberOfInputs?: number): ChannelMergerNode;
28+
createDynamicsCompressor(): DynamicsCompressorNode;
29+
createOscillator(): OscillatorNode;
30+
createWaveTable(real: Float32Array, imag: Float32Array): IWaveTable;
31+
onstatechange(): void;
32+
close(): Promise<void>;
33+
suspend(): Promise<void>;
34+
resume(): Promise<void>;
35+
}
136
export interface IAudioGraph {
237
gainNode: GainNode;
338
pannerNode?: PannerNode;
439
stereoPannerNode?: StereoPannerNode;
40+
delayNode?: DelayNode;
41+
scriptProcessorNode?: ScriptProcessorNode;
42+
analyserNode?: AnalyserNode;
43+
biquadFilterNode?: BiquadFilterNode;
44+
channelMergeNode?: ChannelMergerNode;
45+
channelSplitterNode?: ChannelSplitterNode;
46+
convolverNode?: ConvolverNode;
47+
dynamicCompressorNode?: DynamicsCompressorNode;
48+
oscillatorNode?: OscillatorNode;
49+
waveShaperNode?: WaveShaperNode;
550
}
651
export interface IAudioGraphOptions {
752
volume: number;
@@ -11,20 +56,23 @@ export interface ISourceNodeOptions {
1156
onEnded: Function;
1257
}
1358
export declare class PlayerAudio {
14-
protected _context: AudioContext;
59+
protected _audioContext: IAudioContext | null;
1560
protected _contextState: string;
1661
protected _audioGraph: IAudioGraph | null;
17-
constructor();
62+
constructor(customAudioContext?: IAudioContext, customAudioGraph?: IAudioGraph);
1863
decodeAudio(arrayBuffer: ArrayBuffer): Promise<AudioBuffer>;
19-
protected _getAudioContext(): Promise<{}>;
64+
protected _createAudioContext(): IAudioContext;
65+
protected _bindContextStateListener(audioContext: IAudioContext): void;
66+
getAudioContext(): Promise<{}>;
67+
setAudioContext(audioContext: IAudioContext): void;
2068
protected _destroyAudioContext(): void;
2169
protected _unfreezeAudioContext(): Promise<void>;
2270
protected _freezeAudioContext(): Promise<void>;
23-
protected _createAudioGraph(): void;
2471
setAudioGraph(audioGraph: IAudioGraph): void;
2572
getAudioGraph(): IAudioGraph;
2673
createSourceNode(sourceNodeOptions: ISourceNodeOptions): Promise<AudioBufferSourceNode>;
27-
connectSourceNodeToGraph(sourceNode: AudioBufferSourceNode): void;
74+
connectSourceNodeToGraphNodes(sourceNode: AudioBufferSourceNode): void;
75+
protected _createAudioGraph(): void;
2876
protected _destroyAudioGraph(): void;
2977
destroySourceNode(sourceNode: AudioBufferSourceNode): AudioBufferSourceNode;
3078
changeGainValue(volume: number): void;

build/@types/web-audio-api-player/library/core.d.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { ISound, ISoundAttributes, ISoundSource } from './sound';
2-
import { PlayerAudio } from './audio';
2+
import { PlayerAudio, IAudioGraph, IAudioContext } from './audio';
33
import { PlayerError } from './error';
44
export interface ICoreOptions {
55
volume?: number;
66
loopQueue?: boolean;
77
soundsBaseUrl?: string;
88
playingProgressIntervalTime?: number;
99
playNextOnEnded?: boolean;
10+
audioGraph?: IAudioGraph;
11+
audioContext?: IAudioContext;
1012
}
1113
export declare class PlayerCore {
1214
protected _isWebAudioApiSupported: boolean;
@@ -19,6 +21,8 @@ export declare class PlayerCore {
1921
protected _playingTimeoutID: number | null;
2022
protected _playNextOnEnded: boolean;
2123
protected _loopQueue: boolean;
24+
protected _customAudioGraph: IAudioGraph | null;
25+
protected _customAudioContext: IAudioContext | null;
2226
readonly WHERE_IN_QUEUE_AT_END: string;
2327
readonly WHERE_IN_QUEUE_AT_START: string;
2428
readonly WHERE_IN_QUEUE_AFTER_CURRENT: string;
@@ -62,4 +66,8 @@ export declare class PlayerCore {
6266
first(): void;
6367
last(): void;
6468
protected _playingProgress(sound: ISound): void;
69+
setAudioGraph(customAudioGraph: IAudioGraph): void;
70+
getAudioGraph(): IAudioGraph;
71+
setAudioContext(customAudioContext: IAudioContext): void;
72+
getAudioContext(): Promise<IAudioContext>;
6573
}

build/library/audio.js

Lines changed: 73 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/library/core.js

Lines changed: 37 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# editorconfig.org
2+
root = true
3+
4+
[*]
5+
charset = utf-8
6+
indent_style = space
7+
indent_size = 4
8+
end_of_line = lf
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true
11+
12+
[*.{md,json}]
13+
charset = utf-8
14+
indent_style = space
15+
indent_size = 2
16+
trim_trailing_whitespace = false
17+
insert_final_newline = false
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
###############################################################################
2+
# Set default behavior to automatically normalize line endings.
3+
###############################################################################
4+
* text=auto
5+
6+
###############################################################################
7+
# enfore LF for all JS and TS files
8+
###############################################################################
9+
*.js eol=lf
10+
*.ts eol=lf
11+
12+
###############################################################################
13+
# Set the merge driver for project and solution files
14+
#
15+
# Merging from the command prompt will add diff markers to the files if there
16+
# are conflicts (Merging from VS is not affected by the settings below, in VS
17+
# the diff markers are never inserted). Diff markers may cause the following
18+
# file extensions to fail to load in VS. An alternative would be to treat
19+
# these files as binary and thus will always conflict and require user
20+
# intervention with every merge.
21+
###############################################################################
22+
*.sln merge=binary
23+
*.csproj merge=binary
24+
*.vbproj merge=binary
25+
*.vcxproj merge=binary
26+
*.vcproj merge=binary
27+
*.dbproj merge=binary
28+
*.fsproj merge=binary
29+
*.lsproj merge=binary
30+
*.wixproj merge=binary
31+
*.modelproj merge=binary
32+
*.sqlproj merge=binary
33+
*.wwaproj merge=binary
34+
35+
###############################################################################
36+
# behavior for image files
37+
#
38+
# image files are treated as binary by default.
39+
###############################################################################
40+
*.jpg binary
41+
*.png binary
42+
*.gif binary
43+
44+
###############################################################################
45+
# diff behavior for common document formats
46+
#
47+
# Convert binary document formats to text before diffing them. This feature
48+
# is only available from the command line.
49+
###############################################################################
50+
*.doc diff=astextplain
51+
*.DOC diff=astextplain
52+
*.docx diff=astextplain
53+
*.DOCX diff=astextplain
54+
*.dot diff=astextplain
55+
*.DOT diff=astextplain
56+
*.pdf diff=astextplain
57+
*.PDF diff=astextplain
58+
*.rtf diff=astextplain
59+
*.RTF diff=astextplain
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
6+
# Runtime data
7+
pids
8+
*.pid
9+
*.seed
10+
11+
# Compiled binary addons (http://nodejs.org/api/addons.html)
12+
build/Release
13+
14+
# Dependency directories
15+
node_modules
16+
jspm_packages
17+
18+
# Optional npm cache directory
19+
.npm
20+
21+
# Optional REPL history
22+
.node_repl_history
23+
24+
# visual studio
25+
.vs
26+
*.njsproj
27+
*.sln
28+
obj
29+
30+
# build
31+
build

examples/visualizer-player/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2014 chris weber
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# web audio API player - visualizer player example
2+
3+
## build
4+
5+
run gulp build in the root of this repository, to build the player itself
6+
7+
```
8+
cd /web-audio-api-player
9+
gulp build
10+
```
11+
12+
now build the example itself
13+
14+
```
15+
cd /web-audio-api-player/examples/visualizer-player
16+
gulp build
17+
```
18+
19+
## run
20+
21+
launch the server
22+
23+
```
24+
node build/server
25+
```
26+
27+
## TODOs
28+

0 commit comments

Comments
 (0)