Showing posts with label Loco No 10 - Sam and Jo. Show all posts
Showing posts with label Loco No 10 - Sam and Jo. Show all posts

Friday, November 06, 2015

Creating an MP3 sound sytem

Introduction

As part of my ongoing investigations into sound systems, I thought I would have a go at 'modifying' a self-contained USB MP3 player to provide a sound system for my Ford(ish) Railmotor.

 It turned out to be a relatively straightforward conversion requiring very few additional components - a voltage regulator to provide the power and the sound files which were mostly downloaded from the internet.

Pros
  • Relatively cheap - mine cost about £5.00 a couple of years ago. I notice there are several variants of this still available on eBay for around £6.50. I paid for some of my sound files (around $10), but it could have been done with free sound files or my own recordings
  • Comes complete with micro SD slot, amplifier, loudspeaker, battery and case (even includes a built-in FM radio)
  • Loud enough to be heard across the garden
  • Easily adaptable
  • Plays 'real' sound files to produce quite high quality sound
  • Plays very long sound files (a 1Gb SD card could hold around 18 hours of sound effects)
  • You can make and play your own tailor-made sound effects
Cons
  • There is about a pause of about 1 second when switching between tracks
  • Requires a little bit of time and effort to make the modifications to the player and the edit your own sound files
  • Not much else, really
I control my player remotely from my Deltang Tx22 transmitter through a Deltang Rx61b receiver, though any receiver which provides outputs from the direction switch (Channel 3) could be used.

Dismantling the MP3 Player

 At first, I couldn't see how the gadget fitted together, but after reading an article by Mike Jeffries in the December 2014 edition of the Garden Rail magazine in which he dismantled a similar sound system, I realised it wasn't too difficult.

The base was prised off with a small flat-bladed screwdriver.

It was held in place by some sort of silicone-based glue which was still quite gummy, but with some gentle persuasion, it became detached. At the same time the plug for the speaker disconnected itself from the socket.

The wires to the battery were snipped off. I wanted to be able to remember which wire was attached whereas there was nothing printed on the circuit board indicating how the battery should be connected.

The two screws holding the circuit board to the base were removed.

The lithium-ion battery was glued to the underside of the speaker and needed a fair bit of leverage to become free .......

In the end, I sliced the plastic sleeve and removed the battery from it as I was anxious not to damage the battery case.

 The speaker grille was prised away from the case, bringing the speaker with it. Again, this was held in place with silicone-based adhesive.


Connecting the circuit board to the receiver

 The switches which enable the user to move forwards and backwards through the MP3 files on the card were held in place on the circuit board with a large blob of hot-glue.

This needed to be very carefully cut away to avoid damaging the board or the delicate contacts on the back of the switches. 

 Scrutiny of the board revealed that the left hand contacts (viewed from the back) on the switches were connected to ground (ie the negative side of the battery), so leads were carefully soldered to the contacts on the right of the 'next' and 'previous' switches using the thinnest wire I could lay my hands-on.

To check that these wires would act as triggers to move forwards and back through the tracks on the SD card, the board was wired up to the speaker and a 4.5v battery. The ends of the flying leads were then touched on to the negative terminal of the battery and, reassuringly, the player moved back and forth through the tracks.

Powering the MP3 player

 The MP3 player runs off 5v and as the loco is powered by a 12v battery I needed to find a way of powering it. As there is plenty of space in the railbus I could easily have added another 4.5v or 5v battery pack and linked the negative leads of the two battery packs to ensure the 0v logic signals would still work. However, I like to keep things simple when it comes to recharging and so decided it would be easier to make a voltage regulator circuit using an LM7805 voltage regulator. There is plenty of guidance on the internet for making this circuit - eg http://www.learningaboutelectronics.com/Articles/How-to-connect-a-voltage-regulator-in-a-circuit.

Mine was mounted on a small piece of stripboard and covered with some clear heatshrink sleeving as the mounting plate of the regulator is 'live'.

I decided not to clamp the regulator to a heatsink, even though the regulator did run quite hot when I wired everything up and turned the sound up to full power. To reduce the current draw, I replaced the 4 ohm speaker which was supplied with the MP3 player with a small 8 ohm speaker. The voltage regulator still gets warm but now not alarmingly so.

Tailoring the receiver output pads on the receiver

 The receiver installed in my railbus is an Rx61b (v603) as it was installed a couple of years ago. The programming information for this older version of the Rx is still there in detail on the Deltang website, and so I could see from the chart for the Rx61b-22-v603, that pads 4 and 5 provide 3.3v outputs in response to Channel 3 (the direction switch on Deltang transmitters).

Item

Setting Details
P1 output

Servo
Bind button (Ch5)

Slow-motion servo for coupling
Press bind button to open coupling
Release bind button to close coupling

P2 output

Front Light
(auto)

Led needs current limiting resistor

P3 output

Rear Light
(auto)

Led needs current limiting resistor

P4 output On/Off
Direction switch (Ch3)

Item being switched needs current limiting resistor
Switch right for ON (center/left OFF)

P5 output On/Off
Direction switch (Ch3)

Item being switched needs current limiting resistor
Switch left for ON (center/right OFF)

P6 output On/Off
Bind button (Ch5)

Item being switched needs current limiting resistor
ON while button pressed, OFF when released (momentary)

P7 output On/Off
Bind button (Ch5)

Item being switched needs current limiting resistor
Toggle ON/OFF each time button is pressed (latching)

P8 output IR4

Battery voltage telemetry
Infrared led needs current limiting resistor

I was already using Pads 2 and 3 for direction lighting and Pad 4 to turn on and off the interior lighting, and so I needed to find another way of turning the lighting on and off. Normally, I would use the bind button (Ch 5) for the loco whistle or horn but decided I could manage without the horn if I included it in the sound files for the engine sound (see below). I therefore soldered wires to Pads 4, 5 and 7. The outputs from pads 4 and 5 could be used to move back and forward through the tracks on the SD card (provided I inverted the outputs from 3.3v to 0v) and the output from Pad 7 could be used (without modification) to operate the interior lighting.


To invert the outputs from Pads 4 and 5, I made up a couple of transistor inverter circuits with a 2N3904 transistor and a couple of resistors (See How I trigger soundcards with a Deltang receiver.)

The two transistors, together with the four resistors, were mounted on a small piece of Veroboard as I found that the legs of the transistors were a little fragile.

The output leads were connected to the push button leads on the MP3 player and the inputs connected to pads 4 and 5 on the receiver.


All that was needed now was to find or create the sound files needed for the railbus.

Creating the sound files

After some experimentation, I decided I could simulate all the situations needed for the railbus with five sound files:
  1. 20 minutes of silence
  2. Engine start and idle (for 20 minutes)
  3. Horn, gear grind and acceleration through the gears to running speed ( for 20 mins)
  4. Decelerate, brake squeal and idle (for 20 mins)
  5. Engine shut down
I decided to include 20 minutes of silence as there will be times when the railbus is stationary before I get around to turning it off manually. Also, I didn't have a spare switch or channel on my Tx22 transmitter which I could use to switch the MP3 player on and off remotely.

From 'silence', I could then advance to the 'engine start and idle file' using the direction switch. When ready, I could then advance to 'the acceleration and running file'. The distance between my stations is such that I would never need to run the bus for more than ten minutes and so a leeway of 20 minutes running sound would be fine. The bus tends to run at a fairly consistent, slowish, speed and so there seemed little need to vary the speed of the running sound by a great deal. Approaching stations, I could then advance to 'the decelerate, brake and idle file' and leave the railbus on idle for as long as necessary. Using the direction switch I could therefore either move to the next 'engine stop file' which would automatically advance round to the first 'silence' file when it stopped playing, or I could move back to the previous file and go through the acceleration and running sequence again.

For more information on how I created the sound files see How I used Audacity to create sound files for my Ford(ish) railmotor.

The Railmotor in action

Once everything had been wired-up and tested, the speaker was put into a small sound chamber made from some 2mm thick larch veneer. This, together with the circuit board was mounted in the roof of the railbus power car (suitably insulated from accidental contact with the lighting bus bars).

Of course, after all this work, the railbus required some extensive testing.

I'm considering ways in which I could overcome the 1-second pause when I change tracks. It might be possible to program a Picaxe microcontroller to trigger some sound on another soundboard for a second or so to mask the silence (e.g. a horn, a backfire or even a chunk of miscellaneous engine sound).


I am happy to live with the hiccup in the sound for now - after all, I run my railway mostly for my own pleasure and am mostly the only audience for my operational sessions. When I make videos (such as the one about the test run above), I can easily shoot the video to avoid the pauses or them edit out.
 

Further developments (August 20026) 

I can't believe this was originally posted over ten years ago, but I have finally sorted out the 1-second pause when moving from one track to another. This involved replacing the MP3 player circuit board with a much smaller DF Player Mini module.


 This marvellous little gadget does everything the old MP3 Player did and more. It includes an inbuilt audio amplifier thus allowing it to be connected directly to the speaker in the railbus and it also has similar inputs to allow the receiver to move forwards and backwards through the tracks stored on the Micro SD Card.

 VCC is the +ve voltage input (3.2 - 5v) and so required no changes to the output from the voltage regulator. Either of the GND pins can be used as the -ve connection.
 
Connecting the IO_1 pin to Ground plays the previous track (short press) or decreases the volume (long press) and connecting the IO_2 pin to ground plays the next track (short press) or increases the volume (long press). So, it was simply a case of removing the old MP3 player circuit board and replacing it with the DF Player Mini module using the existing wiring connections.
 
 
 


How I used Audacity to create sound files for my Ford(ish) railbus

Introduction

Having just modified a cheap USB MP3 Player to enable a Deltang receiver to trigger movement from file to file (see How I modified an MP3 Player to provide sound for my railbus), I needed to create some appropriate sound files to use with it.

I decided that I needed five sound files:
  1. 20 min of silence (when the railbus was stationary with no engine running)
  2. Engine start-up and idle (for 20 minutes)
  3. Horn, gears and acceleration through the gears before running sound (for 20 mins)
  4. Deceleration, brake squeal and idle (for 20 mins)
  5. Engine stop
I figured that I could move forward and back through these files using the direction switch on my Deltang Tx22 transmitter to cover all eventualities under which the railbus might operate.

Locating suitable sound files

The internet is a wonderful place. I searched for appropriate sound files of antiquated Ford motor vehicles which I could use. Initially, I searched for Model T Ford sounds as I had previously used some of these to dub sounds on to a video of the railbus in action (see A Day in the Life of Peckforton Station).

 These sounds had been suitable for lineside shots, with the railbus moving towards and away from the camera, but I needed engine sounds which were more constant.

Eventually, I managed to track down the sound of a Model A Ford on the StockMusic.com website. For a modest sum (just under $10), I was equipped with the sound of a car running past, the car starting, idling and stopping, and the sound of a car horn.

I was now ready to start editing in Audacity, which is a free open-source sound editing program available from SourceForge. To demonstrate the editing processes involved in producing the sound files, I'll show you how I produced the most complicated one - the third file with the horn, gear change and acceleration to running speed.

The first step was to start up Audacity and then open the downloaded file containing the idling engine sound. The engine start and engine stop sections of the file were highlighted and then deleted, leaving just the sound of the idling engine.

Part of the engine sound was highlighted and then Adjustable fade ... was selected from the Effects menu

 The opening volume was set to 100% and the closing volume was set to 200%. You may need to experiment with these values to suit the sound file you are working with.

 Once the rising effect of the volume was checked, the same section was highlighted once more and the Sliding Time Scale/Pitch Shift tool was selected from the Effects menu.

 The initial tempo change was set to 0 and the final tempo change was set to 200%. Again this final value was determined by experimentation. After some checking I decided the pitch needed to be changed as well to give a rising pitch to the engine as it increased in speed. The final pitch shift was set to 100%.

 The effect was tested to check the settings sounded satisfactory.

 The edited section of sound was highlighted, copied and pasted into the sound track and another section of the original idling sound was edited to give a slightly different and shorter section of rising sound, which was copied and pasted again to give the effect of working through four gears.

I decided the sound would be enhanced with the addition of the gearbox whining in the background. I tracked down the video of a vintage bus on the internet and extracted the sound using another piece of free software - Any Video Converter.

Once a suitable section of whining gearbox was found it was imported into the Audacity .......

.... where it opened as a new track

The short section of whine was copied and pasted a few times....

 The section of whine sound before the rising engine sound was highlighted and then, using the Amplify tool from the Effects menu, its volume was reduced to zero (there would be no gearbox whine while the railbus is stationary).

A section about twice as long as the rising engine sound was highlighted and amplified, rising from 0 to 400% using the Adjustable fade tool from the Effects menu (again some experimentation was necessary to find the most appropriate value).

The tempo and pitch of the same section was edited with the Sliding Time Scale/Pitch Shift tool from the Effects menu. The tempo was changed from 0 to 200, and the pitch from 0 to 100%.

The effect was applied again and copied and pasted to match the other sections of the engine sound track.

After some tweaking and adjustment, the sound of a grating gearbox (found on a free sound effects website - https://www.freesound.org/ ) was then imported and copied and pasted on to a new track to occur at appropriate places alongside the engine and gearbox sounds.

Finally, the sound of the Ford's klaxon horn was imported and added on a track near the start of the recording.

 A similar approach was used to create the other files needed (ie start and idle, decelerate and idle, idle and engine stop). These were exported from Audacity as MP3s and then transferred, one at a time (to ensure they appeared in the correct order) on to the micro SD card.

The SD card was then installed into the MP3 player on the railbus and tested to ensure everything worked as intended.

As you can see, there is a 1 second pause when moving from one track to another. I may look into the possibility of using a recordable sound module triggered by a Picaxe chip to mask this pause, but for now I am happy to live with the pause - my imagination disguises the gap in sound and when making videos of the railbus, I can edit out the pauses.