Skip to navigation

Revs on the BBC Micro

The engine sounds

Creating a realistic three-tone engine sound

The engine sound is a key part of the driving experience in Revs; it helps you gauge the rev count without taking your eyes off the road. To get a reasonably realistic sound out of the BBC Micro's sound system, the game produces a three-part engine sound, using two tones and a sprinkling of white noise.

Let's see what's involved in making the engine sound, as well as the game's other noises.

The engine sound routine
------------------------

The engine sound is generated by the MakeDrivingSounds routine, which is called twice during the main driving loop. (I'm not sure why it's called twice, as reducing this to one call doesn't seem to affect the sound, but it might be to prevent the sounds from stuttering when the main loop is busier than normal; this, however, is a guess.)

The engine sound is made up of three parts:

  • Engine exhaust on sound channel 0
  • Engine tone 1 on sound channel 1
  • Engine tone 2 on sound channel 2

Channel 0 is the BBC Micro's noise channel, so the exhaust is a kind of "putter-putter" white-noise sound. The tones on channel 1 and 2 get higher with higher rev counts, with tone 2 sounding for the whole range of engine speeds from idling and up, and tone 1 only kicking in at higher revs. The exhaust sound dies off at higher revs, when the engine is working at high efficiency. The two tones are separated by a pitch of 28, with tone 1 lower than tone 2.

The engine sounds depend on the value of the soundRevTarget variable, which is set to revCount + 25 as part of the engine calculations in the driving model (where revCount is the current rev count, as shown on the rev counter). The soundRevCount variable moves towards the value of soundRevTarget in steps of 1 on each call of the MakeDrivingSounds routine, so the engine sound is constantly trying to match the target in soundRevTarget, pitching up or down in small steps where necessary.

Note that the sound routines aren't responsible for the throbbing of the engine that you can hear when the engine is idling; that's added by the ThrobRevsNoTorque routine, which alters the rev count in a random manner to simulate the idling sound. The sound routine also doesn't affect the rev count itself, it just makes the correct sound depending on the current value of soundRevCount.

This is how the engine sounds are generated, depending on the value of soundRevCount:

  • If soundRevCount < 28:
    • The engine is off (revCount < 3)
    • The rev counter hand is resting on the pin at 8 o'clock (i.e. the minimum)
    • Stop all engine-related sounds
  • If 28 <= soundRevCount < 64:
    • The engine is idling (3 <= revCount < 39)
    • When the engine is idling, soundRevCount drops below 28 every now and then, so the engine sound cuts out as if it is misfiring, but generally it stays just above 28
    • The rev counter hand is between 8 o'clock and 9 o'clock
    • Make the sound of the engine exhaust
    • Silence engine tone 1
    • Silence engine tone 2
  • If 64 <= soundRevCount < 92:
    • The engine is revving up (39 <= revCount < 67)
    • The rev counter hand is between 9 o'clock and 11 o'clock
    • Make the sound of the engine exhaust
    • Silence engine tone 1
    • Set the pitch of engine tone 2 to soundRevCount - 64 (which in the range 0 to 27)
    • Make the sound of engine tone 2
  • If soundRevCount >= 92:
    • The engine is revved up (revCount >= 67)
    • The rev counter hand is past 11 o'clock
    • Do not make the sound of the engine exhaust
    • Set the pitch of engine tone 1 to soundRevCount - 92 (which in the range 0 and up)
    • Make the sound of engine tone 1
    • Set the pitch of engine tone 2 to soundRevCount - 64 (which in the range 28 and up)
    • Make the sound of engine tone 2

Note that in the above, the clock-face times are rounded to the nearest hour, to keep things simple. For example, in the last section, both tones kick in when the rev counter passes 3.5 minutes to 12, which is actually a little way after 11 o'clock.

Making the sounds
-----------------

The MakeDrivingSounds is responsible for deciding which engine sounds to make, but the sounds themselves are made by the MakeSound routine, which makes all the different sounds in the game.

There are five different sounds in Revs that are generated by the MakeSound routine:

  • Sound #0: Engine exhaust (channel 0)
  • Sound #1: Engine tone 1 (channel 1)
  • Sound #2: Engine tone 2 (channel 2)
  • Sound #3: Tyre squeal (channel 3)
  • Sound #4: Crash/contact (channel 0)

These are all implemented by OSWORD sound commands that are defined in the soundData table. We've already talked about the first three, and sound #4 is another simple tone that uses the noise channel to make the sound of a crash, or contact with another car or the verge.

Sound #3 is a more complex sound than the others, and is the only one to use a sound envelope, which generates the sound of the tyres squealing. The envelope data is defined in the envelopeData table.

The sound system buffers the sounds in each channel by noting which channels are in use via the soundBuffer table. This enables individual sound channels to be flushed by the FlushSoundBuffer routine, or all four channels to be flushed by the FlushSoundBuffers routine. As an example, this is useful when calculating the tyre forces in the ApplyTyresAndSkids routine, where we stop the tyres from squealing as soon as we leave the track, or if the driving model is no longer marking the tyres as skidding.

So the sounds in Revs might be fairly basic, but there's no doubt that the tyre squeals and engine sounds are important contributors to the feeling of driving the car. I mean, it wouldn't be Revs without revs, right?