Dedicated MP3 player - Page 1
Forum section: electronics / general

author: PerranOak
author_rank: Frequent Contributor
timestamp: July 08, 2019, 09:51:59 am
content: I would like to build a simple MP3 player that plays one tune over and over - "white noise" (or rather, the sea or something) to help a youngster to sleep ... don't ask(!)Changing the tune is not the biggest issue - it is ok to change it via a programmer, etc. i.e. no need for SD card or whatever. It would only need to run ear buds so no speakers. Quality is not a big deal either.Does anyone know of an example circuit/code I could try please.

author: OwO
author_rank: Super Contributor
timestamp: July 08, 2019, 11:10:30 am
content: If the waveform is repetitive and not very long you can simply use a MCU with sufficient flash (e.g. stm32 blue pill) and a resistor DAC. This is the cheapest option.Otherwise there is the DFplayer (requires separate MCU and SD card).Is there a reason an off the shelf consumer mp3 player won't do?

author: PerranOak
author_rank: Frequent Contributor
timestamp: July 08, 2019, 11:52:27 am
content: Cheers. I've never written software to do this though.No, no reason, just thought it would be interesting to make one.

author: SiliconWizard
author_rank: Super Contributor
timestamp: July 08, 2019, 01:55:16 pm
content: Obviously the easiest and shortest (and probably cheapest as well) option would be to buy a cheap MP3 player (that you could probably get for a few bucks). Prepare whatever audio sequence you wish with an audio editor, make it long enough, store it in the player. Done.Now if you still really want to build it yourself, look up "mcu wav player" or something like this. You'll find examples for various MCUs. Since you're probably going to deal with repetitive sequences, you'll only need a few seconds of audio, and loop. And you won't need any MP3 decoding. Just be aware that for this kind of application, it has been shown that such a repetitive sequence (similar to white noise/"waves" sounds/...) should be at least between 5s and 10s before looping (don't remember exactly), because any sequence shorter than this can be identified by the brain as repetitive (anything longer won't sound "repetitive") and will tend to get annoying to the listener instead of being soothing.

author: PerranOak
author_rank: Frequent Contributor
timestamp: July 08, 2019, 02:33:21 pm
content: Brilliant! Thanks very much.

author: SiliconWizard
author_rank: Super Contributor
timestamp: July 08, 2019, 03:12:29 pm
content: Note that if you're OK with white-noise only, you could consider generating it on the fly, thus requiring very little memory compared to storing several seconds of audio samples, and as long as your generator is decent, you wouldn't have a problem with periodicity, at least not on a few seconds scale. White noise is basically random noise. Just don't use the standard rand() function for this, as most standard implementations are relatively poor in terms of "randomness". I've implemented one of Knuth's pseudo-random generators to generate white noise in past projects, and it turned out pretty good. ("The Art of Computer Programming, D. Knuth, Volume 2.) Even a small MCU would have enough CPU power to do this in real time @44.1kHz or so.

author: Sal Ammoniac
author_rank: Super Contributor
timestamp: July 08, 2019, 03:38:50 pm
content: Is this intended as a learning exercise? If not, then there are many "sleep sound" devices out there that play sounds of the sea, rain, babbling brooks, etc. I've seen them for $19 here in the States.

author: PerranOak
author_rank: Frequent Contributor
timestamp: July 08, 2019, 03:40:35 pm
content: SiliconWizard:That does sound interesting but I've, now, been "instructed" that it has to be the sea!Sal Ammoniac:Yes, it's to learn while creating something useful.

author: SiliconWizard
author_rank: Super Contributor
timestamp: July 08, 2019, 04:16:19 pm
content: If writing that completely from scratch on an MCU sounds intimidating, or if getting enough sample memory without having to handle an external SD card or Flash chip is not possible, you could also consider using a VS1053. It pretty much contains everything you need (including an headphones driver), supports several audio formats, and can be further controlled by an MCU if you want.http://www.vlsi.fi/en/products/vs1053.htmlYou could consider this board to begin with:https://www.adafruit.com/product/1381(yes it's a bit of "cheating", but you could start with this, and then maybe design your own board later on...)

author: Muttley Snickers
author_rank: Unknown
timestamp: July 08, 2019, 04:40:18 pm
content: I would keep this one as simple as possible otherwise you could be just adding to the nightmares. As others have stated, a basic MP3 player or better still a digital audio recorder would be easy to use and very flexible, they are also extremely affordable as well.With a digital audio recorder or even your mobile phone you could just record the audio from an existing youtube video or similar and if you need more material CityPedia has plenty of other good stuff on youtube as well, some even have seagulls in the mix.

author: Sal Ammoniac
author_rank: Super Contributor
timestamp: July 08, 2019, 05:18:25 pm
content: Quote from: SiliconWizard on July 08, 2019, 03:12:29 pmThere are MCUs that have true random number generators implemented in hardware that would be ideal for this application.

author: SiliconWizard
author_rank: Super Contributor
timestamp: July 08, 2019, 07:46:49 pm
content: Quote from: Sal Ammoniac on July 08, 2019, 05:18:25 pmOh yeah, true.

author: lucazader
author_rank: Regular Contributor
timestamp: July 08, 2019, 08:35:49 pm
content: Quite a few of the STM32 range include an RNG generator in hardware (https://www.st.com/resource/en/application_note/dm00073853.pdf)I think most of the newer G0 and G4 ranges have this, as well as the F7 and H7, and at least some of the F4's and F2's. dont think it is on the F0, F1 or F3's however.

author: Mr. Scram
author_rank: Super Contributor
timestamp: July 08, 2019, 08:41:29 pm
content: Quote from: Muttley Snickers on July 08, 2019, 04:40:18 pm

author: NiHaoMike
author_rank: Super Contributor
timestamp: July 09, 2019, 07:02:31 pm
content: Quote from: SiliconWizard on July 08, 2019, 03:12:29 pmIt's a white noise generator, not a cryptographic key generator. Speaking of crypto, incrementing a counter and encrypting each output or repeatedly looping a value through a hash function is a good way to make a very good PRNG. (I have done the latter in various test software I have written - nicely satisfies the requirement to be random but repeatable on demand.) I would say those are overkill for this purpose, however - a simple 32 bit LFSR will do the trick.The most straightforward way to generate white noise, of course, is to amplify a noise source like a transistor in reverse breakdown. Or use a fan and get the extra benefit of a bit of airflow that's really nice during the summer.

author: MT
author_rank: Super Contributor
timestamp: July 09, 2019, 08:28:32 pm
content: Quote from: PerranOak on July 08, 2019, 09:51:59 amWhat you looking for are ASMR, video web search it, repeating white noise are torture, you have to try numerous ASMR sounds to find the right one for your kid.Some enjoy sea surf, other thunder and rain, some like bubble pop and klick, some, ear licking, some enjoy a drousy MaineCoon and long nails clattering, there are thousands to chose from.

author: Jan Audio
author_rank: Frequent Contributor
timestamp: July 11, 2019, 01:57:10 pm
content: Take a transistor to generate noise.9volt with 100K into the emitter, base + collector to 0 volt.Add amplifier with transistor or opamp.Very simple and better.

author: PerranOak
author_rank: Frequent Contributor
timestamp: July 11, 2019, 05:03:54 pm
content: Cheers all.

author: Mr. Scram
author_rank: Super Contributor
timestamp: July 11, 2019, 05:45:02 pm
content: Quote from: MT on July 09, 2019, 08:28:32 pmSome loathe ASMR with enthusiasm.

author: Warhawk
author_rank: Frequent Contributor
timestamp: July 11, 2019, 09:08:11 pm
content: Isn't this what you want?https://www.ebay.de/itm/TF-Card-U-Disk-Mini-MP3-Player-Audio-Voice-Modul-Arduino-DFPlayer-Tafel-AIP/382737685871?hash=item591cf19d6f:g:uewAAOSwP6pbtdXJ

author: NiHaoMike
author_rank: Super Contributor
timestamp: July 12, 2019, 02:03:48 am
content: Quote from: Jan Audio on July 11, 2019, 01:57:10 pmAdding a second transistor to buffer the one used as a noise source significantly increases the output. I once used it in the 7400 logic competition.The output of the noise source is digitized with a crude one bit ADC and scrambled with a small LFSR to remove frequency bias in order to allow it to pass randomness tests. Then a counter drives a circuit to gate the signal to make valid RS232 characters.

author: Mr. Scram
author_rank: Super Contributor
timestamp: July 12, 2019, 02:25:50 am
content: This isn't a cryptographic application, it's generating sound. People who care about the true random nature of their sound are to be avoided at all costs. You could generate a sine and simulate literal waves of noise.

author: NiHaoMike
author_rank: Super Contributor
timestamp: July 12, 2019, 05:07:29 am
content: Indeed, I tried connecting a small speaker to the RNG and didn't notice much difference between the input and output of the scrambler. The frequency bias must be at higher frequencies that are irrelevant for audio.To adapt (vastly simplify) the circuit for use as a white noise generator, connect the 470n capacitor to a potentiometer then to a small audio amplifier like a LM386. The charge pump booster is not necessary if there's a supply voltage of at least 12V available. If reducing power use is important such as if battery operation is desired, use a small class D amplifier and the charge pump should be able to piggyback off the amplifier as it will be switching even without an input signal.

author: PerranOak
author_rank: Frequent Contributor
timestamp: July 16, 2019, 04:35:49 pm
content: To get the file I've been given (!) on a memory chip I'd need 70Mb.I was looking at memory and found serial flash memory but it has a description that I don't get:Memory Size 128MbitOrganisation 32M x 4 bit, 64M x 2 bit, 128M x 1 bitDoes it really mean "bit" not "byte"?If so, how do I know how many bits are in a byte of the file I have: it's just a regular WAV file?Cheers.

author: SiliconWizard
author_rank: Super Contributor
timestamp: July 16, 2019, 05:29:00 pm
content: I suppose you mean 70MBytes for the file. "Byte" is more commonly abbreviated as "B" and not "b". "b" is usually for "bits", so try not to mix them up.A 128Mbit memory chip can hold 16MBytes of data. Nothing more. Larger flash chips will tend to come in BGA packages almost exclusively, so I don't know whether you'd be comfortable with this, but I suspect not. (Eg, a 128Mbyte one:https://www.digikey.com/product-detail/en/micron-technology-inc/MT29F1G08ABAEAH4-E-TR/557-1657-1-ND/6207195)I've just found this though: IS37SML01G1-MLI, a 1GBit (128Mbytes) flash memory chip in a SOIC16 package (available on Mouser), so that would probably be the easiest path for you.You could also go for an SD-card instead. There are libraries out there to deal with them. That would probably still be a bit more difficult to integrate from the firmware POV, and if your MCU is not fast enough, reading from it on the fly may even not be fast enough to feed an audio DAC; OTOH, writing files to the card would obviously be much easier than writing to a flash chip (you will need to implement that in your device instead, or use an external spi flash programmer).

author: RadioNerd
author_rank: Regular Contributor
timestamp: July 17, 2019, 05:35:49 am
content: Just as a side note: Ocean wave sound is actually much closer to 1/f noise rather than white noise.pure white noise is not very relaxing in my opinion

author: Canis Dirus Leidy
author_rank: Regular Contributor
timestamp: July 17, 2019, 08:32:17 pm
content: Quote from: PerranOak on July 08, 2019, 09:51:59 amIf you want to do it thehard wayoldskool:Simulator of the rain noiseSimulator of the surf soundCombined surf sound/pink noise generatorSimulator of the campfire sound

author: PerranOak
author_rank: Frequent Contributor
timestamp: July 18, 2019, 04:00:00 pm
content: Thanks guys but I really have to use the WAV file supplied by SWMBO.SiliconWizard thank you for searching that out - you are spot-on about the BGAs! I've been using a lowercase "b" for yearsSo, flash memory is ideal for this then? I really want to do it with memory rather than SD or anything like that.I guess then that WAV files have 8 bits to the byte?What I'd really like to do is to write all the code from scratch, if this is achievable, but I don't even know how to "inspect"/"edit" a WAV file so that I could copy the data!

author: SiliconWizard
author_rank: Super Contributor
timestamp: July 18, 2019, 04:33:51 pm
content: Quote from: PerranOak on July 18, 2019, 04:00:00 pmWell, yes!A WAV file has a RIFF structure. If you don't want to write a WAV file parser, which is not that difficult (but still, if you really want to write a DECENT one, just skipping a supposed fixed header is NOT the way to go IMO, so I wouldn't personally do that AND thus I will warn you that writing a correct parser is not completely trivial. A WAV file can contain many additional chunks than just a header and the audio samples), I would suggest you choose a fixed sample rate, and write the audio data as raw samples in the memory chip, along with just the number of samples. Many audio editors can save a WAV file as RAW data. I think that would be the easiest path for you. Audacity can export audio as a RAW file with various sample encoding options, such as 16-bit signed or 24-bit signed integers.

author: NiHaoMike
author_rank: Super Contributor
timestamp: July 19, 2019, 05:00:18 am
content: Perform a spectral analysis on the file and then make a noise generator with very similar spectral characteristics.

author: PerranOak
author_rank: Frequent Contributor
timestamp: July 19, 2019, 12:47:51 pm
content: As I need to use the file as given (thanks anyway NiHaoMike) I'll try-out the RAW option; I already have Audacity. Cheers.

author: SiliconWizard
author_rank: Super Contributor
timestamp: July 19, 2019, 12:58:10 pm
content: I think that will be the simpler option really if you don't want to have to deal with file formats, SD cards and filesystems, and using a flash chip this way will be much easier to understand and easier to get something working in real-time. And if your intent is not to develop a full-blown audio player, but a dedicated one as I understood it, that's perfectly fine. Of course just keep in mind that changing the audio content will require a "maintenance" and the user won't be able to do it themselves, which is not necessarily a problem here. (Note that it could still be implemented later on if you're using an MCU that supports USB, but that would obviously require more work...)In Audacity just use Export / Export Audio, select "other formats", then "RAW (headerless)" for the header, and then the encoding you want for the samples (ideally the same format as what you'll directly send to the DAC).

author: NiHaoMike
author_rank: Super Contributor
timestamp: July 19, 2019, 01:25:10 pm
content: Quote from: PerranOak on July 19, 2019, 12:47:51 pmExcept you are still using the file - you're using it as a reference for what the output should be like. Would it be OK to post at least a short clip of the file? That should give us ideas on how to generate the output or downsample it to reduce storage requirements. (E.g. can it be truncated to 8 bit 22kHz without too much quality loss? Can a short piece of it be looped without introducing a noticeable discontinuity where it restarts?)

author: MT
author_rank: Super Contributor
timestamp: July 19, 2019, 08:49:11 pm
content: Quote from: Mr. ScramSome enjoy ASMR, some enjoy the silence, some both. Milage varies!

author: Old Printer
author_rank: Frequent Contributor
timestamp: July 21, 2019, 06:42:33 pm
content: I know this does not address the OP's dilemma, or the spirit of the project, but as someone who really needs a constant background noise to sleep I will offer this. There is an app for that, of course. It's called Rain Rain, and I have it on all of my Ios devices. I travel a bit, and after getting searched at TSA too many times for an odd looking electronic device in my carry-on, I tried it. Many sounds to choose from and a low drain overnight on the battery if you are not on a charger.

author: @rt
author_rank: Super Contributor
timestamp: July 22, 2019, 03:15:16 am
content: The MP3 player chips from VLSI Solutions (ie. VS1003B) are designed to be used with microcontrollers that provide GUI, and move data from SD card to the chip, etc.but they also have a minimal mode set by holding a pin in a particular state so that a simple MP3 player can be constructed with no programming.That requires the chip (or module/shield), SD card, and crystal. The resulting player will just go play whatever MP3 files are at the root of the card.But yeah, given that you can get an eBay USB MP3 player under $10AU, I’d not bother for the problem as I understand it.

author: luiHS
author_rank: Frequent Contributor
timestamp: August 05, 2019, 07:18:45 pm
content: Teensy Audio Library, and a Kinetis microcontroller, is all you need to make your own audio player. I have built some Kinetis-based sound players for machines that needed custom sounds, activated from a main processor, connected by serial port, and they worked very well.It is a cheap solution, and you have total control, you can modify the software to work as you want, without dependencies of proprietary chips like those of VLSI, and others of the Chinese.https://www.pjrc.com/teensy/td_libs_Audio.html