On advanced audio effects on a layout

The easiest and, seemingly, most widespread DIY way to add audio effects to a layout is with the help of MP3 module with microSD card slot. These cheap modules play mp3 files from uSD card and Next/Play/Stop controls are provided by GPIO pins, so you can control them with buttons or Arduino. They also come with UART so that Arduinos can get a list of files on the card and select the file to be played.

However, this functionality is often not sufficient for advanced sound effects. In particular, 2 features would be very useful for a layout, but are not possible with a MP3 module:

  1. Mixing of several audio tracks together.

  2. Gapless playback of several consecutive sounds. This feature can be used to create looping playback and transition one sound to another.

With these capabilities, we can implement, for example, locomotive engine sound:

  • Start of an engine

  • Run with idle engine sound for indefinite duration,

  • Transition to 1st gear,

  • Run with 1st gear indefinitely,

  • Mix with a coupler sound,

  • Mix with horn,

  • …​ and so on

Or, for example, we can play ocean waves sound in loop and mix it with occasional seagulls and wooden screeching.

Or we can play a campfire sound with occasional forest birds, owls, wolf howl.

ESP8266Audio Library

The library is located here: https://github.com/earlephilhower/ESP8266Audio and it allows you to write a program that will itself read audio data from a defined source, mix and/or process it, and send it to an audio device. Despite the name, it can run on ESP8266, ESP32 and RP2040 MCUs.

It can decode WAV data, in addition to MP3, AAC, MIDI, MOD, and can read files from the firmware itself, internal flash, SD card and even internet. It can send data to an I2S amplifier or to a single-transistor amplifier circuit, which is probably enough for our needs.

For the purposes of a diorama layout, WAV data and internal flash (or SD card) is enough.

The library allows to play several sources simultaneously, setting volume for each source independently.

Sounds as state machines

The idea is that a simple continous sound has a beginning portion, middle portion looping continously and ending portion:

%3 Silence Silence Entry Entry Silence->Entry Command to start sound Check1 Effect still on? Entry->Check1 Loop Loop Check1->Loop Yes Exit Exit Check1->Exit No Check2 Effect still on? Loop->Check2:nw Check2->Loop Yes Check2->Exit No Exit->Silence

Simplified state machine diagram of this can look like this:

%3 Silence Silence Entry sound Entry sound Silence->Entry sound Loop sound Loop sound Entry sound->Loop sound Exit sound Exit sound Entry sound->Exit sound Loop sound:nw->Loop sound:sw Loop sound->Exit sound Exit sound->Silence

A more advanced continous sound effect can be represented by a more complex state diagram. Here is a simplified diagram of a 2-gear diesel engine. The transitions are controled by current locomotive speed.

%3 Silence Silence Startup Startup Silence->Startup Idle Idle Startup->Idle Idle->Idle Idle to 1st gear Idle to 1st gear Idle->Idle to 1st gear Cutoff Cutoff Idle->Cutoff 1st gear 1st gear Idle to 1st gear->1st gear Cutoff->Silence 1st gear->1st gear 1st to 2nd gear 1st to 2nd gear 1st gear->1st to 2nd gear 1st gear to idle 1st gear to idle 1st gear->1st gear to idle 2nd gear 2nd gear 1st to 2nd gear->2nd gear 1st gear to idle->Idle 2nd gear->2nd gear 2nd to 1st gear 2nd to 1st gear 2nd gear->2nd to 1st gear 2nd to 1st gear->1st gear

Locomotive decoders with sound (such as ESU LokSound) play sounds in a similar fashion, and their sound editors allow users to edit the state diagram and respective samples.

So, we can implement this in code of our MCU and make it play different sounds for each state and move through states according to some input, and we’ll get realistic continous sounds.

2024

Updates

The 3D printable files for RC truck are published!. The link is on project page, and for convenience also here:

Moving on to RC transmitter

I’ve created a page for the development of the transmitter. Expect updates there. So far I’ve created a breadboard prototype that is able to c...

Updates on the projects

There were no updates for a long time due to my vacation, but finally here are some.

Crane updates

The crane mechanics is close to completion

Casting solder into resin-printed molds

Last time I tried to pur solder into a hand-cut cardboard "mold". The result was as inaccurate as one would expect. My attempts to smooth it out with epoxy...

Experiments with cast solder

In portal crane project the hook has to be as heavy as possible, otherwise the threads will not be tightened enough and will skip all the time (and will l...

Motor board for portal crane

For some time I’ve wanted to develop a PCB again. Last time I did that was around 2021, when I made LocoNet-equipped decoder and command station for...

Slip ring ideas, two of them

The functional crane model I’m working on requires a slip ring to rotate superstructure. Currently this is implemented as a 3D-printed casing for bron...

Back to Top ↑

2023

A gondola wagon, now with cargo

Making cargo for a gondola ended up being longer than printing the gondola itself. I had some sticks and branches lying around, that I cut to length and g...

Project: Flatcar series 13-401

A new project: Flatcar series 13-401. A model of a flat wagon, which is widespread in USSR, Russia and other 1520mm guage countries.

Another tank container assembled

less than 1 minute read

I’ve assembled, primed, sanded and painted second container variant (frame2). Here are the pictures (along with frame1 variant). New variant is in red.

Another tank container

This week I’ve added one more tank into my tank container collection, codename frame2. It turned out to be much more complicated that previous design...

Introducing project: a tank container collection

less than 1 minute read

This week I’ve reworked my older tank container into a collection of different options, so they add some variety to the layout. For now, there are 2 ...

Back to Top ↑