Layering Ambient Sound in Twine Chapbook

I’m attempting to manually layer ambient sound in the Chapbook format, but I’m having some trouble. The page in the chapbook guide tells you that regular ambient sound should look like this:

sound.ambient.forest.url: 'forest.mp3'
sound.ambient.forest.description: 'midday forest sounds'
--
{ambient sound: 'forest'}

It's a beautiful day.

and that the code to control the sound manually and play more than one ambient sound simultaneously looks like this:

sound.ambient.forest.playing: true
sound.ambient.rain.playing: true
--
You walk outside.

However, I’m having trouble figuring out how these two things work together practically. Do you put them on the same page? Do you repeat the first one twice, once for each audio clip? Or am I misunderstanding completely and they’re not meant to both occur at the same time? For example, some variations I have tried:

sound.ambient.like_real_people.url: 'https://www.dropbox.com/s/e7yh98lklr1bevs/like_real_people.mp3?dl=1'
sound.ambient.like_real_people.description: 'Slow acoustic music begins to play...'

sound.ambient.roomandfan.url: 'https://www.dropbox.com/s/f38fd1kmktys8ct/roomandfan.mp3?dl=1'
sound.ambient.roomandfan.description: 'A fan whirs in the background'
--
Text

and then on the next passage

sound.ambient.like_real_people.playing: true
sound.ambient.roomandfan.playing: true
--
{ambient sound: 'like_real_people', volume: 0.2}
{ambient sound: 'like_real_people', volume: 0.5}

Text

I have also tried them on the same page:

sound.ambient.like_real_people.url: 'https://www.dropbox.com/s/e7yh98lklr1bevs/like_real_people.mp3?dl=1'
sound.ambient.like_real_people.description: 'slow acoustic music begins to play...'

sound.ambient.roomandfan.url: 'https://www.dropbox.com/s/f38fd1kmktys8ct/roomandfan.mp3?dl=1'
sound.ambient.roomandfan.description: 'A fan whirs in the background'

sound.ambient.like_real_people.playing: true
sound.ambient.roomandfan.playing: true

--
{ambient sound: 'like_real_people', volume: 0.2}
{ambient sound: 'roomandfan', volume: 0.5}

Text

and

sound.ambient.like_real_people.url: 'https://www.dropbox.com/s/e7yh98lklr1bevs/like_real_people.mp3?dl=1'
sound.ambient.like_real_people.playing: true
sound.ambient.like_real_people.description: 'slow acoustic music begins to play...'

sound.ambient.roomandfan.url: 'https://www.dropbox.com/s/f38fd1kmktys8ct/roomandfan.mp3?dl=1'
sound.ambient.roomandfan.playing: true
sound.ambient.roomandfan.description: 'A fan whirs in the background'
--
{ambient sound: 'like_real_people', volume: 0.2}
{ambient sound: 'roomandfan', volume: 0.5}

Text

This is my first significant project with Twine and I am by no means a coder, so I feel like I’m probably missing something really basic haha. However, if anyone knows if this is possible and if so how to do it, I would really appreciate your insight!

Twine Version: 2.5.1.0
Story Format: Chapbook 1.2.2

1 Like

The documentation for Audio in Chapbook says:

  • There can only be one ambient sound playing at a time under normal circumstances.

However, you can have multiple “sound effects” so you could technically layer those. The only issue I believe is ambient sound is expected to be longer and plays from a file and sound effects are read-in and might cause a loading delay if they are long sounds. (Someone correct me if I’m wrong.)

So you could make the forest ambient and then have a moderate-sized rain sound effect playing over it. I don’t know if sound effects can naturally loop.

If you insert multiple different sound effects in a single passage, they will play simultaneously. If you insert a sound effect in another passage the player reaches while the effect is stil playing, the second insert will have no effect.

If you need to play a sound effect repeatedly, define it multiple times. You can assign the entire object to save time. For example:

sound.effect.explosion.url: 'boom.mp3'
sound.effect.explosion.description: 'a large explosion'
sound.effect.explosion2: sound.effect.explosion
--
The timer reads 0:00...

{sound effect: 'explosion'}

This is one reason I switched to Sugarcube where I have frequently by mistake had two music-tracks happening simultaneously when I neglected to stop one.

In Sugarcube everything is just audio and preloads and loops if you tell it to. This is code from my WIP:

\<<audio "waltzmoderato" volume .3 play>><<audio "ethernight" pause>><<set $ether to false>>
\<<audio "lobbyambience" fadeto 0>>

This simultaneously pauses one music selection without losing the place in the music, sets another to play immediately at 30% volume (from the beginning if it stopped or from wherever it was paused if not at the beginning), and fades out the “lobby ambience” track gradually.