Skip to content

Commit

Permalink
Add options for creating AudioContext
Browse files Browse the repository at this point in the history
- MusicMixer takes optional parameter for AudioContextOptions, which is
  passed to the constructor of the AudioContext
- Add getter for the MusicMixer's AudioContext
  • Loading branch information
almic committed Apr 24, 2024
1 parent 89d9750 commit 398ef43
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/MusicMixer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import * as defaults from './defaults.js';
* MusicMixer
*/
class MusicMixer {
private readonly audioContext: AudioContext = new AudioContext();
private readonly audioContext: AudioContext;
private readonly gainNode: GainNode;
private tracks: {
[name: string]: Track;
} = {};

constructor() {
constructor(options?: AudioContextOptions) {
this.audioContext = new AudioContext(options);
this.gainNode = this.audioContext.createGain();
this.gainNode.connect(this.audioContext.destination);
}
Expand Down Expand Up @@ -99,6 +100,10 @@ class MusicMixer {
return this;
}

get context(): AudioContext {
return this.audioContext;
}

get currentTime(): number {
return this.audioContext.currentTime;
}
Expand Down

0 comments on commit 398ef43

Please sign in to comment.