An author's reference for Bisquixe, a tool for adding audiovisual content to Inform projects (update: linking to external files)

Working with Sound

To implement sound in an Inform game is to walk a barely worn path. This is not because sound adds nothing to parser games! Indeed, authors have used sound and music to great effect.

One challenge is that sound is temporal. We experience it as something in motion, but parser games almost always wait for the player’s input. There can be a disconnect between atemporal play and temporal sensory information.

A sound effect can afford a “jump scare” effect, coming as it might seem out of nowhere. Because so few parser games use sound effects, we do not always expect them. Consider, for instance, a hypothetical game that is silent for 60 minutes of play before playing a loud, crashing sound. It would be unkind to put a player through such a thing.

These are design challenges that should not discourage the use of sound altogether. Everything in an Inform game presents a design challenge! The question this reference must answer is this: how can they be implemented?

Documentation review

Inform’s documentation has little to say about sounds. If we have used images with Inform, we will find the process familiar. First, we declare our sound files. Just as we do with images, our sentence associates a sound name with a file name.

sound goldberg is the file "11_Goldberg_Variation_8.ogg".

Our sound name must begin with the word “sound”. While an IDE may not be too strict regarding file types, Inform’s release machinery will only permit the following file extensions: .ogg, .midi, .mod, and .aiff.

Here, a problem arises. Safari on iOS will only support .mp3 format with Bisquixe. A workaround will be discussed later, but it is always worth asking if the author intends to support mobile web browsers. Whatever the author decides, authors should be aware that .mp3 support will require extra steps.

Once the sound name is associated with a file, authors can play it during the course of any rule. The phrase begins with play:

before jumping:
	play sound goldberg;

Using Daniel Stelzer’s Music extension

We can add more features via Daniel Stelzer’s “Music” extension.

include music by daniel stelzer.

Not all of features of Music are supported by Bisquixe.

  • loop [sound name]: supported; play a sound in a loop.
  • stop [sound name]: supported; immediately end playback of a sound.
  • fade (see extension for details): somewhat supported; timer behavior sometimes feels off.
  • crossfade and introduce: does not work at all and will likely crash Bisquixe. Do not use.

Using Bisquixe and working around problems

At this point—this is not completely necessary—I recommend editing the Simple Multimedia Effects extension to permit multiple file types. Search the extension for the to upload-audio definition:

To upload-audio (Temp - a text) with internal name (Temp1 - a sound name):
	let tempid be the Glulx resource ID of Temp1;
	let tempname be "[temp].mp3";
	add-audio tempname with id tempid;

and replace it with this code:

To upload-audio (Temp - a text) with internal name (Temp1 - a sound name):
	let tempid be the Glulx resource ID of Temp1;
[	let tempname be "[temp].mp3";]
	let tempname be "[temp]";
	add-audio tempname with id tempid;

While authors should be aware of iOS support and file formats, making this change will leave the question of iOS browser support in their hands.

Just as is the case with image files, Inform will strip all sound files from our project. We can run ifsitegen if we like, but that won’t be enough. Why? We will discuss this further in a discussion about interpreters and portability, but, for now, it is enough to point out that Quixe, the interpreter upon which Bisquixe is built, does not support sound in any way. Without using Bisquixe-specific code and features, our web page will have no means of handling sound resources and code.

In fact, using ifsitegen.py to restore sound files to our project without corresponding Bisquixe code will likely crash the interpreter. That being so, our next step whether we run ifsitegen.py or not will be to associate each sound file with the appropriate Glulx resource ID. This is the required format, using an upload-audio phrase:

	upload-audio "[file name]"  with internal name sound [sound name];

So long as a sounds folder containing all of our named sound files exists within the release directory, our audio files should play correctly.

Supporting “unsupported” file formats

Since our Bisquixe project is accessing external sound files through a browser window, Inform’s internal support requirements do not always apply. In fact, they can be overcome at will:

  • Declare a sound file within inform to generate a sound name and Glulx resource ID
  • Maintain an external directory of sound files for our game to access
  • Use Bisquixe to associate the project’s sound name and Glulx resource ID with our files, .mp3 or otherwise.

To get an mp3 into our Bisquixe project, in other words, we need to declare a supported file name. The file isn’t really important, as we just need a valid sound name to work from. We can get away with this, for instance:

sound dog is the file "0004086.ogg".

when play begins:
	upload-audio "blargh.mp3" with internal name sound dog;

In order to release our project, we need a file named 0004086.ogg in our /Materials/Sounds directory. For our project to play sound dog in a browser, we need a file named blargh.mp3 in the /Release/Sounds directory.

This is a lot to take in! A combination of factors (variable platform support, Quixe sound support, Inform’s file format requirements) set before us a complex and hard-to-traverse landscape. This is entirely understandable. Many games featuring music and sound are authored in Vorple, a more sohpisticated multimedia option for Inform authors. Some authors are able to write their own sound extensions. As for the rest of us: sound seldom comes up, as a search of intfiction.org will confirm. In the absence of ongoing technical discussion, it is hard to know what authors and readers seek.

This is all to say that, through no one’s fault or neglect, many of sound’s edges go unsanded. Authors hoping to make heavy use of sound and music in their Inform projects will likely require both courage and curiosity. These challenges also mean that works using sound and music stand out all the more, and that their successes are impressive indeed.

Blockquote