Skip to content

Commit

Permalink
Update web build
Browse files Browse the repository at this point in the history
  • Loading branch information
almic committed Apr 25, 2024
1 parent ec06242 commit 5650e47
Show file tree
Hide file tree
Showing 9 changed files with 489 additions and 65 deletions.
26 changes: 23 additions & 3 deletions docs/js/lib/AudioSourceNode.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AudioAdjustmentOptions } from './automation.js';
import HRTFPannerNode from './HRTFPannerNode.js';
declare class AudioSourceNodeEvent {
#private;
readonly type: string;
Expand Down Expand Up @@ -52,6 +53,7 @@ declare class AudioSourceNode {
private sourceNode;
private readonly gainNode;
private readonly stereoPannerNode;
private hrtfPannerNode;
private path;
private _isDestroyed;
private _isStarted;
Expand Down Expand Up @@ -95,7 +97,21 @@ declare class AudioSourceNode {
load(path: string): Promise<void>;
volume(volume: number, options?: AudioAdjustmentOptions): AudioSourceNode;
pan(pan: number, options?: AudioAdjustmentOptions): AudioSourceNode;
pan3d(): AudioSourceNode;
/**
* Attach an {@link HRTFPannerNode} to spatialize this {@link AudioSourceNode}. This will disconnect all current
* outputs on this {@link AudioSourceNode} to prevent creating cycles. You must call `connect()` again in order to
* continue sending output to your destination.
*
* You should not use the `pan()` method in conjunction with the {@link HRTFPannerNode}.
*
* @param hrtfPannerNode {@link HRTFPannerNode} to attach
* @returns this {@link AudioSourceNode}
*/
set hrtfPanner(hrtfPannerNode: HRTFPannerNode | null);
/**
* @returns the currently assigned {@link HRTFPannerNode} or `null` if none is set
*/
get hrtfPanner(): HRTFPannerNode | null;
/**
* This method may be called multiple times during the lifetime of the AudioSourceNode.
* To acheive this utility, the active sourceNode is "released" following a call to stop(),
Expand Down Expand Up @@ -209,10 +225,14 @@ declare class AudioSourceNode {
get loop(): boolean;
set loop(value: boolean);
get loopStart(): number;
set loopStart(value: number);
set loopStart(seconds: number);
get loopEnd(): number;
set loopEnd(value: number);
set loopEnd(seconds: number);
get playbackRate(): AudioParam;
/**
* -1 if there is no set buffer
*/
get sampleRate(): number;
get context(): AudioContext;
get channelCount(): number;
get channelCountMode(): ChannelCountMode;
Expand Down
88 changes: 60 additions & 28 deletions docs/js/lib/AudioSourceNode.js

Large diffs are not rendered by default.

64 changes: 64 additions & 0 deletions docs/js/lib/HRTFPannerNode.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* HRTF Panner that wraps two PannerNodes so they can be interpolated during updates.
* Supposedly, the one included with Web Audio APIs are "not of the best quality" and I'm all about quality.
*
* The inspiration of this implementation comes from <https://github.com/twoz/hrtf-panner-js>, by Tomasz Woźniak.
* I have not duplicated enough code to really say this contains a substantial portion, and this project is
* already under the MIT license, so I'm sure giving his name is more than enough.
*
* How this works:
* - Split stereo input into left and right channels
* - Apply a lowpass filter to each channel, keep these frequencies for last step
* - Apply a highpass filter to each channel, spatializing with the panner node
* - Merge output of panner node with incoming low frequencies, send to output
*
* This means that low frequencies will not be spatialized, because:
* "Those are in their nature non-directional: hearing a deep bass coming
* only from one direction is very unnatural to hear." - T. Woźniak
*
* TODO:
* - Implement custom HRTF from
* <https://codeandsound.wordpress.com/2015/04/08/implementing-binaural-hrtf-panner-node-with-web-audio-api/>.
*
* - Using this database:
* <https://3d3a.princeton.edu/3d3a-lab-head-related-transfer-function-database>
*
*/
declare class HRTFPannerNode {
readonly audioContext: AudioContext;
private pannerNodeMain;
private pannerNodeInterpolate;
private highpassFilter;
private lowpassFilter;
private gainPrimaryNode;
private gainSecondaryNode;
/** Tracks if the method `connectSource()` has been called previously */
private isSourceConnected;
/** Tracks the last time that an interpolation was scheduled */
private lastInterpolationTime;
/** The interpolation time, in milliseconds */
private interpolateTime;
/** The values that will be used for the next interpolation */
private nextInterpolateMap;
constructor(audioContext: AudioContext, options?: PannerOptions);
connectSource(source: AudioNode): void;
disconnectSource(source: AudioNode): void;
updatePosition(positionX: number, positionY: number, positionZ: number): void;
updateOrientation(orientationX: number, orientationY: number, orientationZ: number): void;
updatePositionOrientation(positionX: number, positionY: number, positionZ: number, orientationX: number, orientationY: number, orientationZ: number): void;
/**
* Schedules an interpolation between the `pannerNodeMain` and `pannerNodeInterpolate`, updating
* at most every `interpolateTime` milliseconds.
*/
private scheduleInterpolation;
connect(destination: AudioNode, outputIndex?: number, inputIndex?: number): AudioNode;
connect(destination: AudioParam, outputIndex?: number): void;
disconnect(): void;
disconnect(output: number): void;
disconnect(destinationNode: AudioNode): void;
disconnect(destinationNode: AudioNode, output: number): void;
disconnect(destinationNode: AudioNode, output: number, input: number): void;
disconnect(destinationParam: AudioParam): void;
disconnect(destinationParam: AudioParam, output: number): void;
}
export default HRTFPannerNode;
221 changes: 221 additions & 0 deletions docs/js/lib/HRTFPannerNode.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion docs/js/lib/MusicMixer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ declare class MusicMixer {
private readonly audioContext;
private readonly gainNode;
private tracks;
constructor();
constructor(options?: AudioContextOptions);
/**
* Create an audio source from this MusicMixer context.
*
Expand Down Expand Up @@ -48,6 +48,7 @@ declare class MusicMixer {
* @returns {MusicMixer} this MusicMixer
*/
volume(volume: number, options?: AudioAdjustmentOptions): MusicMixer;
get context(): AudioContext;
get currentTime(): number;
}
export default MusicMixer;
10 changes: 7 additions & 3 deletions docs/js/lib/MusicMixer.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions docs/js/lib/Track.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions docs/js/lib/defaults.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { AudioAdjustmentOptions } from './automation.js';
declare function buildOptions(trackSwapOptions: TrackSwapOptions | TrackSwapAdvancedOptions | undefined | null, defaultSwapOptions: TrackSwapAdvancedOptions): TrackSwapAdvancedOptions;
declare function buildOptions(audioAdjustmentOptions: AudioAdjustmentOptions | undefined | null, defaultAudioAdjustmentOptions: Required<AudioAdjustmentOptions>): Required<AudioAdjustmentOptions>;
declare function buildOptions(audioAdjustmentOptions: AudioAdjustmentOptions | undefined | null, defaultSwapOptions: TrackSwapAdvancedOptions): TrackSwapAdvancedOptions;
declare function buildOptions(pannerOptions: PannerOptions | undefined | null, defaultPannerOptions: Required<PannerOptions>): Required<PannerOptions>;
export default buildOptions;
/**
* Default behavior for an IN_OUT track audio swap
Expand Down Expand Up @@ -52,3 +53,7 @@ export declare const automationNatural: Required<AudioAdjustmentOptions>;
* Default behavior for AudioParam automations
*/
export declare const automationDefault: Required<AudioAdjustmentOptions>;
/**
* Default PannerOptions
*/
export declare const pannerDefault: Required<PannerOptions>;
Loading

0 comments on commit 5650e47

Please sign in to comment.