User Tools

Site Tools


* Back to WiRocs Description See also Uploading Sound Files

The WiRocS Sound System

The "S" in WiRocS stands for sounds. The code uses the EarlePhilhower Audio Library to give the ability to play two independent Wav files simultaneously.

The capability was first developed for use with the Mobile decoder variant, where it is used to produce Chuff sounds that are speed linked to the loco speed. But it also has sound effects, such as a bell and whistles, and a Wav file that plays "Please stand clear of the platform". These sound files are stored as 11Khz .Wav files in an internal "SPIFFS" memory on the Esp. The ESP 8266 has 3Mb possible storage.

I have used this with both an external DAC, but more often with the Single Transistor drive for sound "NoDAC". Earle added a "mixer" capability to his code at my request, so that I could play "chuffs" simultaneously with "sound effects". The results are remarkable. Video illustrating Sound Effects.


I prefer to use the "noDAC" audio option. Using this with the ESP8266, the Sound output is driven by the Serial {Rx} Input.
This just needs three components. A transistor, a resistor and a loudspeaker. A 1-10K ohm resistor is connected from the audio output pin (Rx on the ESP8266) to the base of an NPN transistor, whose collector is connected to the loudspeaker.
The other Speaker connection is to 5V.
This arrangement "squeaks" when the board is programmed, but gives remarkably good sounds, and does not use up any of the 8/16 I/O.
On the ESP32 version, the Transistor base is connected to pin #22.

Sounds in Stationary Mode

I have used the filenames F1-F9 for the sound effects triggered by functions 1-9 in the loco version of WiRocS. But these same files can also be played by the "stationary" WiRocS nodes, and respond to addresses 101 to 109.

To play sound effect 108 (A guards whistle) set up a push button accessory on Rocview. Set it as "pushbutton" in the 'General' tab, and in the 'Interface' tab, set the "Bus" to the RoocNode number of the WiRocS node you wish to play the sound. Then set the address to 108. Make sure the track plan is set to "operate", press the button and the node will whistle. Sound F9 (triggered by address 109) in the default set of sounds is a Platform Announcement "Please stand clear of the platform".

Unfortunately, in stationary mode I only allow a single file to be played at a time, but there is no technical reason why the code could not be modified to play two files simultaneously, in the same way that the Loco plays chuffs on one output channel, and sound effect on the other.

(For my reference, the file selection for stationary sound effects is in lines 1260 in RocSubs.h it could easily be modified to work with more sound effects or different filenames.)

Standard 'LOCO' setup

The standard loco setup has F9 as a Chuffs on/off toggle, and F1-F8 play various sound effects. F1 is an "Ivor the engine" tune. Chuffs play a sequence of chuff wav files in sequence. I have cut some samples up so that a full revolution of the wheel gives the four distinct phased sounds. As the train speeds up, the code truncates the playing sound and plays the next part in sequence. This works reasonably well until the sounds get merged. At this point the code can switch to a "one wav per revolution" version of the code, that I try to be generally just a sound without noticeable chuffing. The Chuff code also works with three phase sounds. I have made three "chuff sounds". Fenchurch and BBCH are cut from videos of a Terrier loco at slow speed. Ivor is an attempt to get the Shffff Teeee Puffff three phase sound of Ivor the engine. (not very successful). For multi phase sounds, each wav chuff part must be named ending with a 1,2,3 or 4. The code then plays these in sequence. If "4" is missing, it assumes it is 3 phase sound and adjusts.
You can switch between two set sounds by using F10, which sets the "ALternateSounds" boolean.

The choice of which sounds to play and at what point they switch to the faster sounds is set at compile in the main .ino file, line 574 or thereabouts.
if (TimeToChuff(LoopTimer)){

  if (!AlternateSounds()){\\
        Chuff("/Fenchurch","/Fench",35);}// 35 is the approximate Mph to switch to the alternate "/Fench.wav single wav per rev sound \\  

There are a number of CV[] parameters that are essential to get good sounds:

  • CV[47] is a "gear ratio to set the timing of the chuffs to the speed. (Chuff_wav_period=(CV[47]*inv_Speed)/(WavsPerRevolution*48);)
  • CV[100] (max 127) is an overall Volume control
  • CV[101] is the individual control for F1
  • CV[102 .. 108] Individual controls for F2-F8
  • CV[110] is the volume for the Chuff sounds
  • CV[111] is the volume for a brake squeal that turns on when the loco is slowed down to stop.

When a board with the sounds enabled is first switched on, it plays F6 and F3 to set its self up. This can be changed at {Chuff.cpp, line 182}. But you must have some selected file played , as it sets up stuff so other files can play later.

users/dagnall53/sound_system.txt · Last modified: 2019/03/17 19:10 by dagnall53