Author Topic: Dedicated MP3 player  (Read 4481 times)

0 Members and 1 Guest are viewing this topic.

Offline PerranOakTopic starter

  • Frequent Contributor
  • **
  • Posts: 548
  • Country: gb
Dedicated MP3 player
« on: July 08, 2019, 09:51:59 am »
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.
You can release yourself but the only way to go is down!
RJD
 

Offline OwO

  • Super Contributor
  • ***
  • Posts: 1250
  • Country: cn
  • RF Engineer.
Re: Dedicated MP3 player
« Reply #1 on: July 08, 2019, 11:10:30 am »
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?
Email: OwOwOwOwO123@outlook.com
 

Offline PerranOakTopic starter

  • Frequent Contributor
  • **
  • Posts: 548
  • Country: gb
Re: Dedicated MP3 player
« Reply #2 on: July 08, 2019, 11:52:27 am »
Cheers. I've never written software to do this though.

No, no reason, just thought it would be interesting to make one.
You can release yourself but the only way to go is down!
RJD
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14309
  • Country: fr
Re: Dedicated MP3 player
« Reply #3 on: July 08, 2019, 01:55:16 pm »
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.
« Last Edit: July 08, 2019, 01:57:34 pm by SiliconWizard »
 
The following users thanked this post: PerranOak

Offline PerranOakTopic starter

  • Frequent Contributor
  • **
  • Posts: 548
  • Country: gb
Re: Dedicated MP3 player
« Reply #4 on: July 08, 2019, 02:33:21 pm »
Brilliant! Thanks very much.
You can release yourself but the only way to go is down!
RJD
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14309
  • Country: fr
Re: Dedicated MP3 player
« Reply #5 on: July 08, 2019, 03:12:29 pm »
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.
 

Offline Sal Ammoniac

  • Super Contributor
  • ***
  • Posts: 1663
  • Country: us
Re: Dedicated MP3 player
« Reply #6 on: July 08, 2019, 03:38:50 pm »
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.
Complexity is the number-one enemy of high-quality code.
 

Offline PerranOakTopic starter

  • Frequent Contributor
  • **
  • Posts: 548
  • Country: gb
Re: Dedicated MP3 player
« Reply #7 on: July 08, 2019, 03:40:35 pm »
SiliconWizard:
That does sound interesting but I've, now, been "instructed" that it has to be the sea!  :palm:

Sal Ammoniac:
Yes, it's to learn while creating something useful.
You can release yourself but the only way to go is down!
RJD
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14309
  • Country: fr
Re: Dedicated MP3 player
« Reply #8 on: July 08, 2019, 04:16:19 pm »
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.html

You 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...)
 

Offline Muttley Snickers

  • Supporter
  • ****
  • Posts: 2334
  • Country: au
  • Cursed: 679 times
Re: Dedicated MP3 player
« Reply #9 on: July 08, 2019, 04:40:18 pm »
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.


 

Offline Sal Ammoniac

  • Super Contributor
  • ***
  • Posts: 1663
  • Country: us
Re: Dedicated MP3 player
« Reply #10 on: July 08, 2019, 05:18:25 pm »
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.

There are MCUs that have true random number generators implemented in hardware that would be ideal for this application.
Complexity is the number-one enemy of high-quality code.
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14309
  • Country: fr
Re: Dedicated MP3 player
« Reply #11 on: July 08, 2019, 07:46:49 pm »
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.

There are MCUs that have true random number generators implemented in hardware that would be ideal for this application.

Oh yeah, true.
 

Offline lucazader

  • Regular Contributor
  • *
  • Posts: 221
  • Country: au
Re: Dedicated MP3 player
« Reply #12 on: July 08, 2019, 08:35:49 pm »
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.
 

Offline Mr. Scram

  • Super Contributor
  • ***
  • Posts: 9810
  • Country: 00
  • Display aficionado
Re: Dedicated MP3 player
« Reply #13 on: July 08, 2019, 08:41:29 pm »
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.
 

Offline NiHaoMike

  • Super Contributor
  • ***
  • Posts: 8973
  • Country: us
  • "Don't turn it on - Take it apart!"
    • Facebook Page
Re: Dedicated MP3 player
« Reply #14 on: July 09, 2019, 07:02:31 pm »
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".
It'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.
Cryptocurrency has taught me to love math and at the same time be baffled by it.

Cryptocurrency lesson 0: Altcoins and Bitcoin are not the same thing.
 

Offline MT

  • Super Contributor
  • ***
  • Posts: 1616
  • Country: aq
Re: Dedicated MP3 player
« Reply #15 on: July 09, 2019, 08:28:32 pm »
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.

What 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.


« Last Edit: July 09, 2019, 08:38:53 pm by MT »
 

Offline Jan Audio

  • Frequent Contributor
  • **
  • Posts: 820
  • Country: nl
Re: Dedicated MP3 player
« Reply #16 on: July 11, 2019, 01:57:10 pm »
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.
 

Offline PerranOakTopic starter

  • Frequent Contributor
  • **
  • Posts: 548
  • Country: gb
Re: Dedicated MP3 player
« Reply #17 on: July 11, 2019, 05:03:54 pm »
Cheers all.
You can release yourself but the only way to go is down!
RJD
 

Offline Mr. Scram

  • Super Contributor
  • ***
  • Posts: 9810
  • Country: 00
  • Display aficionado
Re: Dedicated MP3 player
« Reply #18 on: July 11, 2019, 05:45:02 pm »
What 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.

Some loathe ASMR with enthusiasm.
 


Offline NiHaoMike

  • Super Contributor
  • ***
  • Posts: 8973
  • Country: us
  • "Don't turn it on - Take it apart!"
    • Facebook Page
Re: Dedicated MP3 player
« Reply #20 on: July 12, 2019, 02:03:48 am »
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.
Adding 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.
Cryptocurrency has taught me to love math and at the same time be baffled by it.

Cryptocurrency lesson 0: Altcoins and Bitcoin are not the same thing.
 

Offline Mr. Scram

  • Super Contributor
  • ***
  • Posts: 9810
  • Country: 00
  • Display aficionado
Re: Dedicated MP3 player
« Reply #21 on: July 12, 2019, 02:25:50 am »
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.
 

Offline NiHaoMike

  • Super Contributor
  • ***
  • Posts: 8973
  • Country: us
  • "Don't turn it on - Take it apart!"
    • Facebook Page
Re: Dedicated MP3 player
« Reply #22 on: July 12, 2019, 05:07:29 am »
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.
Cryptocurrency has taught me to love math and at the same time be baffled by it.

Cryptocurrency lesson 0: Altcoins and Bitcoin are not the same thing.
 

Offline PerranOakTopic starter

  • Frequent Contributor
  • **
  • Posts: 548
  • Country: gb
Re: Dedicated MP3 player
« Reply #23 on: July 16, 2019, 04:35:49 pm »
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 128Mbit
Organisation 32M x 4 bit, 64M x 2 bit, 128M x 1 bit

Does 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.
You can release yourself but the only way to go is down!
RJD
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14309
  • Country: fr
Re: Dedicated MP3 player
« Reply #24 on: July 16, 2019, 05:29:00 pm »
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).

« Last Edit: July 16, 2019, 05:40:59 pm by SiliconWizard »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf