Author Topic: Dedicated MP3 player  (Read 4559 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: 14481
  • 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: 14481
  • 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: 1673
  • 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: 14481
  • 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: 2341
  • 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: 1673
  • 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: 14481
  • 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: 9019
  • 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: 9019
  • 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: 9019
  • 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: 14481
  • 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 »
 

Offline RadioNerd

  • Contributor
  • Posts: 42
  • Country: ch
Re: Dedicated MP3 player
« Reply #25 on: July 17, 2019, 05:35:49 am »
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
 

Offline Canis Dirus Leidy

  • Regular Contributor
  • *
  • Posts: 214
  • Country: ru
Re: Dedicated MP3 player
« Reply #26 on: July 17, 2019, 08:32:17 pm »
 

Offline PerranOakTopic starter

  • Frequent Contributor
  • **
  • Posts: 548
  • Country: gb
Re: Dedicated MP3 player
« Reply #27 on: July 18, 2019, 04:00:00 pm »
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 years  :palm:

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

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14481
  • Country: fr
Re: Dedicated MP3 player
« Reply #28 on: July 18, 2019, 04:33:51 pm »
I guess then that WAV files have 8 bits to the byte?

Well, 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.


 

Offline NiHaoMike

  • Super Contributor
  • ***
  • Posts: 9019
  • Country: us
  • "Don't turn it on - Take it apart!"
    • Facebook Page
Re: Dedicated MP3 player
« Reply #29 on: July 19, 2019, 05:00:18 am »
Perform a spectral analysis on the file and then make a noise generator with very similar spectral characteristics.
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 #30 on: July 19, 2019, 12:47:51 pm »
As I need to use the file as given (thanks anyway NiHaoMike) I'll try-out the RAW option; I already have Audacity. Cheers.
You can release yourself but the only way to go is down!
RJD
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14481
  • Country: fr
Re: Dedicated MP3 player
« Reply #31 on: July 19, 2019, 12:58:10 pm »
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).
 

Offline NiHaoMike

  • Super Contributor
  • ***
  • Posts: 9019
  • Country: us
  • "Don't turn it on - Take it apart!"
    • Facebook Page
Re: Dedicated MP3 player
« Reply #32 on: July 19, 2019, 01:25:10 pm »
As I need to use the file as given (thanks anyway NiHaoMike) I'll try-out the RAW option; I already have Audacity. Cheers.
Except 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?)
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 #33 on: July 19, 2019, 08:49:11 pm »
Quote from: Mr. Scram
Some loathe ASMR with enthusiasm.

Some enjoy ASMR, some enjoy the silence, some both. Milage varies! :-//
 

Offline Old Printer

  • Frequent Contributor
  • **
  • Posts: 747
  • Country: us
Re: Dedicated MP3 player
« Reply #34 on: July 21, 2019, 06:42:33 pm »
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.
 

Offline @rt

  • Super Contributor
  • ***
  • Posts: 1059
Re: Dedicated MP3 player
« Reply #35 on: July 22, 2019, 03:15:16 am »
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.
 

Offline luiHS

  • Frequent Contributor
  • **
  • Posts: 592
  • Country: es
Re: Dedicated MP3 player
« Reply #36 on: August 05, 2019, 07:18:45 pm »


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
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf