Looping a sound file for background music?

Hello again,

I need help looping a sound file so that the sound plays the entire time you are in a room. I can play a sound during an event, like when play begins, but cannot find any method of making it loop so it keeps playing.

Also is there an event for entering a room? So I can say something like:

When you enter the Control Room: Play the Sound of mySound.

Thanks again :slight_smile:

Jeremy

I don’t know about looping sound, but for triggering on entering a room, you can say

After going to the Control Room: Play the Sound of mySound.
Chapter 7.13 has some more detailed examples.

I think you need to track down the Damusix extension for looping. Unfortunately it’s not yet easy to get as far as I know (maybe someone here can help? I know some folks have been testing it).

Look up Eliuk Blau (the author) at caad.es/eliukblau/index.html for his email address.

Thanks for the tips :slight_smile:

I did find a small I6 code snippet that was posted elsewhere by Eliuk Blau and seemed to be part of a I6 Damusix extension, but just the looping and stop functions:
http://rec.arts.int-fiction.free-usenet.eu/Simple-Sounds-in-I7_T23205391_S1

[code]{code} <- change back to square brackets

Include (-
[ SoundPlayExt sound channel loop;
if (channel == 1 or 2) {
if (channel == 1) { channel = gg_backgroundchan; }
else { channel = gg_foregroundchan; }
}
else { “ERROR: Bad channel (1 or 2, no others).”; }
!------------------------------------------------------------------------
if (glk_gestalt(gestalt_Sound,0) && glk_gestalt
(gestalt_SoundMusic,0)) {
glk_schannel_play_ext(channel,sound,loop,0);
}
else { “Sound feature is unsuportted by your interpreter.”; }
];

[ SoundStopExt channel;
if (channel == 1 or 2) {
if (channel == 1) { channel = gg_backgroundchan; }
else { channel = gg_foregroundchan; }
}
else { “ERROR: Bad channel (1 or 2, no others).”; }
!------------------------------------------------------------------------
if (glk_gestalt(gestalt_Sound,0) && glk_gestalt
(gestalt_SoundMusic,0)) {
glk_schannel_stop(channel);
}
else { “Sound feature is unsuportted by your interpreter.”; }
];
-).

To sound-play (SND - sound-name) in channel (CHN - number):
(- SoundPlayExt({SND},{CHN},1); -)

To sound-play (SND - sound-name) in channel (CHN - number) with loop:
(- SoundPlayExt({SND},{CHN},-1); -)

To sound-stop channel (CHN - number):
(- SoundStopExt({CHN}); -)

{/code}[/code]

Then

[code]Sound of Music is the file “music.ogg”.

sound-play the sound of Music in channel 1 with loop.[/code]

Compiles OK, but no sound :frowning:. Ill have to familiarize myself with the glk/glux? stuff to see why its not working for me.

You can’t get sounds to repeat without a little Inform 6 work. However, not much is required, as nearly all of it is already available in the Standard Rules. From the 6E72 Standard Rules, we have

To play (SFX - sound name), one time only (documented at ph_playsf): (- PlaySound(ResourceIDsOfSounds-->{SFX}, {phrase options}); -).
PlaySound is defined in the I6 template layer, in “Extensions/Reserved/Figures.i6t”:

[ PlaySound resource_ID one_time; if (resource_ID == 0) return; ! The "silence" non-sound effect if ((one_time) && (ResourceUsageFlags->resource_ID)) return; ResourceUsageFlags->resource_ID = true; VM_SoundEffect(resource_ID); ];
Finally, VM_SoundEffect is defined in the same layer, in the file “Extensions/Reserved/Glulx.i6t”:

[ VM_SoundEffect resource_ID; if (glk_gestalt(gestalt_Sound, 0)) { glk_schannel_play(gg_foregroundchan, resource_ID); } else { print "[Sound effect number ", resource_ID, " here.]^"; } ];
That “glk_schannel_play()” call is a Glk call that makes the sound actually play: what we need to do is to create a new action that ends up making a slightly different Glk call to “glk_schannel_play_ext()”, as that call does allow repeats.

Something like the following should work (not tested, but you get the idea):

[code]To loopplay (SFX - sound name):
(- PlaySoundLoop(ResourceIDsOfSounds–>{SFX}); -).

(-
[ PlaySoundLoop resource_ID;
if (resource_ID == 0) return;
ResourceUsageFlags->resource_ID = true;
if (glk_gestalt(gestalt_Sound, 0)) {
glk_schannel_play_ext(gg_foregroundchan, resource_ID, -1, 0);
}
];
-)
[/code]
It’s that “-1” in the “glk_schannel_play_ext()” call that makes the sound repeat.

Incidentally, recent I7 builds introduced the need for that “ResourceIDsOfSounds–>{SFX}” bit of logic to get the resource identifier of sounds and pictures: I suspect that that is why that old code from Eliuk no longer works.

1 Like

Thanks DavidK! It worked great!

Just had to add an Include before that second part and it worked as is :slight_smile:

But now that Ive tried it Im not sure I like having a background sound looping all the time. After testing it I got tired of it after a minute or so. I think Ill limit it to one or 2 rooms, like an engine room with a low background, then as some point we lose power and that noise is gone… Also defiantly have to program in some user commands to turn it off and on.

Thanks again

Jeremy