Sound card from MP3 player module(s)

A place for discussing battery-electric locomotives, whether they're diesel, steam or even electric outline
Post Reply
User avatar
ge_rik
Administrator
Administrator
Posts: 6497
Joined: Sun Oct 25, 2009 10:20 pm
Location: Cheshire
Contact:

Sound card from MP3 player module(s)

Post by ge_rik » Thu Feb 28, 2019 12:56 pm

This is a continuation of a discussion started on another thread:
https://gardenrails.org/forum/viewtopic ... 15#p144949

I'm thinking of playing around with an MP3 module to see if I can use it to produce digitised sounds for, initially, a diesel loco. I already have some form in playing around with MP3s - https://gardenrails.org/forum/viewtopic ... 37&t=10095

And Tom has alerted me to a neat little MP3 module which can be used with Arduino - https://www.dfrobot.com/wiki/index.php/ ... KU:DFR0299

The difficulty I had with using MP3 files on my railmotor was having a 1 second silent pause when changing from one track to another. So, I'm wondering whether there's some way of playing another sound (eg a horn, or a miscellaneous piece of engine noise) to mask the change-over.

All very tentative at the moment, but it's the sort of thing I like tinkering with.

If anyone has any bright ideas or knows of someone who's already trodden this path, then please contribute.

Rik
------------------------
Peckforton Light Railway - Blog Facebook Youtube

User avatar
tom_tom_go
Driver
Driver
Posts: 4824
Joined: Wed Feb 23, 2011 3:08 am
Location: Kent, UK
Contact:

Re: Sound card from MP3 player module(s)

Post by tom_tom_go » Thu Feb 28, 2019 1:39 pm

Hi Rik,

I am interested in this project and as I already own an Arduino I could do some testing before you commit to buy.

The area that requires thought is getting the sounds to play when you want them (I am thinking when the motor current is a certain voltage the sound changes?)

In your post about the MP3 build did you try wav files? I can convert files if you need help.

There are plenty of sketches of code to play audio files that's the easy bit.

User avatar
ge_rik
Administrator
Administrator
Posts: 6497
Joined: Sun Oct 25, 2009 10:20 pm
Location: Cheshire
Contact:

Re: Sound card from MP3 player module(s)

Post by ge_rik » Thu Feb 28, 2019 6:24 pm

tom_tom_go wrote: Thu Feb 28, 2019 1:39 pm Hi Rik,

I am interested in this project and as I already own an Arduino I could do some testing before you commit to buy.

The area that requires thought is getting the sounds to play when you want them (I am thinking when the motor current is a certain voltage the sound changes?)

In your post about the MP3 build did you try wav files? I can convert files if you need help.

There are plenty of sketches of code to play audio files that's the easy bit.
Hi Tom
I tried wav files on the original mp3 player but it didn't recognise them. I use Audacity for editing sound files which can export in a range of formats.

I'm planning to draw on Greg's experiences with Picaxe to help work out how to test for changes in voltages when determining which sounds to play. There's some useful examples on his website.

Rik
------------------------
Peckforton Light Railway - Blog Facebook Youtube

User avatar
gregh
Trainee Driver
Trainee Driver
Posts: 566
Joined: Sun Apr 01, 2018 5:44 am
Location: Sydney, Australia
Contact:

Re: Sound card from MP3 player module(s)

Post by gregh » Sat Mar 30, 2019 12:23 am

Thanks to Tom for the link to the mini MP3 players. I raided the piggybank and paid 4 aussie dollars for two of them. (You need a TF / mini SD card too, so another couple of dollars!)

The whole thing is 20mm square and looks like this:
DF mp3 mini player composite.jpg
DF mp3 mini player composite.jpg (57.79 KiB) Viewed 3736 times

It includes an amplifier to drive a speaker too. It runs from 3.3 to 5.5Vdc and takes about 18mA (@5V) when not playing a sound.

I was initially interested when I found that they could be used stand alone, just using switches and resistors to trigger up to 14 different sound files. I thought maybe some sounds like a diesel horn or shovelling coal, could be triggered from RC outputs?

I found that I could easily get them to work in that ‘switch’ circuit, called Adkey mode.
See data sheet here for the circuit: https://www.dfrobot.com/wiki/index.php ... KU:DFR0299

Note that ‘segment’ on the circuit diag means file.
The sound files are stored on the TF card but since sound files are pretty small, the number you could store on even an 8 GB card would be enormous. You can use either MP3 or WAV files. (I did have one wav file that didn’t work – I think it was too low resolution at 8kbps)

The 'order' of the files called segments 1 to 14 is determined by the order in which you copy the sound files onto the TF card. The first one copied to the card will be segment 1. This is something to do with the FAT32 file system – I no understand.
I found a problem that if I copied a number of files all at once - I suspect it couldn't tell which one was 'first' etc. So I recommend copying one file at a time onto the TF card, with a few seconds between each one. The drawback to this is that if you ever want to change a file and reload it onto the TF card, it and all other files will have changed number and your switches will play the wrong files.
If the relevant switch 'K7 to K20' is closed to 0V momentarily, the segment is played once and then stops. If the switch is held low for 1 second or more (or continuously), the sound file loops when finished - ie it starts again WITH NO AUDIBLE PAUSE BETWEEN !


But having ‘mastered’ the Serial method, I abandoned it ! I realised that I couldn’t trigger enough files by RC switches. Maybe it would be useful for lineside sounds, but that’s it.

Since I am a Picaxe aficionado, I proceeded to look at the data sheet for the ‘Serial mode’ of operation. This is where you use a Picaxe (or Arduino) to send short serial commands to the mini MP3 player to select which track will play. Unfortunately since the method was designed for ‘real’ mp3 players it was very complicated at first look, sending messages back and forth between the picaxe and player. And I later found that the data sheet linked above, was not complete!
This was probably the reason when years ago I ‘looked at’ these things, that I gave up.

But I found it really is very simple if you have a little picaxe knowledge. All you need is one wire , with a 1k resistor, from the picaxe to the player’s ‘Rx’ terminal to send commands to the player.

In this mode the TF card MUST have a folder called /MP3 with the sound files in it AND each file must have 4-numerals at the start of the filename, and can be followed by further alpha characters if required. These are ignored and the 4 digit number is all that is used to address the file.
Eg 0001- startengine.mp3
Commands include “play track number xx’, ‘play and loop track yy’, increase or decrease volume in 30 steps.
A full listing of commands is here, starting on page 17:
http://www.picaxe.com/docs/spe035.pdf


Unfortunately, when you send a command to play another file, while one is playing, there is an audible sound gap. Maybe ¼ to ½ sec – there, but scarcely noticeable.
But if the file is in ‘loop’ mode there is NO gap when it goes from the end back to the start,

I have tested a program that could be used for a diesel loco sound. I had 5 files:
0001 engine starting.mp3, plays at power on to picaxe, then plays
0002-engine idling.wav, plays and loops over and over until picaxe detects a speed/motor volts increase, then plays
0003-engine notching.mp3, then plays
0004-engine running fast.mp3, plays and loops until voltage decreases, then plays idling again.
If idles for more than some time period, play
0005-engine shutting down.mp3.

All very promising. Might do a video soon.

As this forum is probably not that interested in picaxe programming, I’ll finish here. If you want more programming details, ask here or via PM.
Greg from downunder.
The Sandstone & Termite's website: https://members.optusnet.com.au/satr/satr.htm

User avatar
ge_rik
Administrator
Administrator
Posts: 6497
Joined: Sun Oct 25, 2009 10:20 pm
Location: Cheshire
Contact:

Re: Sound card from MP3 player module(s)

Post by ge_rik » Sat Mar 30, 2019 8:53 am

Sounds interesting, Greg (sorry about the pun). What's really intriguing is that a sound file can be looped without a gap - a problem which has plagued my attempts to use 'real' sounds up to now. Also, sounds promising that the tracks can be switched relatively simply with Picaxe commands.

Is the volume from the unit workable, or will it need amplifying?

Rik
------------------------
Peckforton Light Railway - Blog Facebook Youtube

User avatar
gregh
Trainee Driver
Trainee Driver
Posts: 566
Joined: Sun Apr 01, 2018 5:44 am
Location: Sydney, Australia
Contact:

Re: Sound card from MP3 player module(s)

Post by gregh » Mon Apr 01, 2019 4:04 am

The Oily Rag wrote: Sat Mar 30, 2019 9:20 am I will be following with interest and I will try to read that other thread linked in OP. For me its just the amplification side. My home brewed RC railcar horn could do with some extra volume and I did try with a Maplins single chip amplifier kit I had by me. It didn't work and I have not really looked elsewhere so this is opportune indeed for me.
Thanks
regards
Ian
I was surprised by the volume I got with my initial tests using a tiny 8ohm, 40mmx 20mm speaker in no enclosure. I can't do a test in a loco with my picaxe test setup.
Here's video I put together using an old computer speaker, with comparisons to the tiny one.
Tests done with a few diesel sound files under the control of a picaxe, to show a loco engine starting up, idling, notching up and running at speed, an a horn.
I doubt you'd get quite as much volume in a loco as the computer speaker gives.



Re your statement about volume with amplifier kit. I use the 8pin LM386 amplifiers and they are usually easy to use. Maybe I can help.
Greg from downunder.
The Sandstone & Termite's website: https://members.optusnet.com.au/satr/satr.htm

User avatar
ge_rik
Administrator
Administrator
Posts: 6497
Joined: Sun Oct 25, 2009 10:20 pm
Location: Cheshire
Contact:

Re: Sound card from MP3 player module(s)

Post by ge_rik » Mon Apr 01, 2019 8:23 am

That sounds quite healthy with a decent speaker. The quality is pretty good too. I've got a couple of these, so must have a play (when current projects are done).

Rik
------------------------
Peckforton Light Railway - Blog Facebook Youtube

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests