Skip to content

Commit

Permalink
feat: Apply configured audio file volume to played music and sound (#43)
Browse files Browse the repository at this point in the history
* Apply originally configured volume to played sound.

* Apply configured volume level for music.

* Document an example of changing volume per file
  • Loading branch information
jornvandebeek committed Mar 23, 2023
1 parent 41881df commit 63b56ca
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions demo-template/public/data/audio.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ files:
click:
src: audio/click.ogg
game_start:
volume: 0.9
src: audio/game_start.ogg
failure:
src: audio/failure.ogg
Expand Down
5 changes: 4 additions & 1 deletion docs/features/audio.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ description: This guide explains how to use the audio features of narrat to play

The `play` function plays audio, either music or sounds.

To use the `play` function, the game needs to have audio files loaded by adding them to the config file:
To use the `play` function, the game needs to have audio files loaded by adding them to the audio config file, usually located at `data/audio.yaml`:

```yaml
files:
Expand All @@ -22,6 +22,7 @@ files:
click:
src: audio/click.ogg
game_start:
volume: 0.9
src: audio/game_start.ogg
failure:
src: audio/failure.ogg
Expand All @@ -36,6 +37,8 @@ audioTriggers:
onSkillCheckFailure: failure
```
The path of the audio configuration yaml can be changed in the base `config.yaml`:

```yaml
audio: data/audio.yaml
```
Expand Down
1 change: 1 addition & 0 deletions packages/narrat/examples/games/default/data/audio.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ files:
click:
src: audio/click.ogg
game_start:
volume: 0.9
src: audio/game_start.ogg
failure:
src: audio/failure.ogg
Expand Down
1 change: 1 addition & 0 deletions packages/narrat/examples/games/demo/data/audio.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ files:
click:
src: audio/click.ogg
game_start:
volume: 0.9
src: audio/game_start.ogg
failure:
src: audio/failure.ogg
Expand Down
4 changes: 2 additions & 2 deletions packages/narrat/src/stores/audio-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,14 @@ export const useAudio = defineStore('audio', {
// newAudio.volume(0.5, newId);
newAudio.fade(
0,
this.modeVolume(mode),
this.modeVolume(mode) * newAudio.volume(),
audioConfig().options.musicFadeInTime * 1000,
newId,
);
}
} else if (mode === 'sound') {
const newId = newAudio.play();
newAudio.volume(this.modeVolume(mode), newId);
newAudio.volume(this.modeVolume(mode) * newAudio.volume(), newId);
this.setAudioChannel(mode, channelIndex, {
audio,
howlerId: newId,
Expand Down

0 comments on commit 63b56ca

Please sign in to comment.