-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Soundscape test page is now functional, complete with four sounds that can be started and stopped independently, which are all under a single TrackGroup - Sound volume can be manipulated individually, and on the entire group - Now using more cool stuff with data attributes
- Loading branch information
Showing
6 changed files
with
125 additions
and
2 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,79 @@ | ||
/** | ||
* Soundscape.js | ||
*/ | ||
|
||
import { toggleText } from './main.js'; | ||
import MusicMixer from './lib/MusicMixer.js'; | ||
|
||
/* Web only; loading after interaction with page */ | ||
let mixer; | ||
let ambienceTrack; | ||
function loadMixer() { | ||
mixer = new MusicMixer(); | ||
ambienceTrack = mixer.newTrackGroup('ambience'); | ||
ambienceTrack.volume(0.5); | ||
|
||
ambienceTrack | ||
.newTrack('storm', 'audio/Storm2.ogg') | ||
.loop(true, 772_453, 772_453 + 2_233_599) | ||
.volume(0.5); | ||
|
||
ambienceTrack | ||
.newTrack('rain', 'audio/River.ogg') | ||
.loop(true, 31, 31 + 353_589) | ||
.volume(0.5); | ||
|
||
ambienceTrack | ||
.newTrack('wildlife', 'audio/Night.ogg') | ||
.loop(true, 572_933, 572_933 + 4_101_063) | ||
.volume(0.5); | ||
|
||
ambienceTrack | ||
.newTrack('cave', 'audio/Drips.ogg') | ||
.loop(true, 10, 10 + 544_625) | ||
.volume(0.5); | ||
} | ||
|
||
/* Button functions */ | ||
|
||
function toggleTrack(self) { | ||
const name = self.getAttribute('data-track'); | ||
const playing = self.getAttribute('data-playing') == 'true'; | ||
const track = ambienceTrack.track(name); | ||
if (track) { | ||
if (playing) { | ||
track.getActiveSource().onended = null; | ||
track.stop({ duration: 2 }); | ||
self.setAttribute('data-playing', 'false'); | ||
toggleText(self); | ||
} else { | ||
track.start({ duration: 2 }); | ||
self.setAttribute('data-playing', 'true'); | ||
toggleText(self); | ||
track.getActiveSource().onended = () => { | ||
if (self.getAttribute('data-playing') == 'true') { | ||
self.setAttribute('data-playing', 'false'); | ||
toggleText(self); | ||
} | ||
}; | ||
} | ||
} | ||
} | ||
|
||
function changeVolume(name, volume) { | ||
if (name == 'ambience') { | ||
ambienceTrack.volume(volume); | ||
return; | ||
} | ||
|
||
const track = ambienceTrack.track(name); | ||
if (track) { | ||
track.volume(volume); | ||
} | ||
} | ||
|
||
/* Web only; bind functions to global context */ | ||
|
||
window.loadMixer = loadMixer; | ||
window.toggleTrack = toggleTrack; | ||
window.changeVolume = changeVolume; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters