How to add audio to arduino

I am using the adafruit tcs34725 color sensor with the 'arduino uno elegoo r3. I have successfully programmed the arduino and adafruit sensor to detect and report the colors red, blue, and green.

As the next step, I need to connect a speaker and write a program to play an 'mp3' file based on the color detected.

I am planning to use the speaker in the following link.

I am looking for help with updating my c++ program to selectively play 'mp3' music files based on the color detected by the sensor. I would appreciate if someone can share any sample c++ source code, documentation or guidance related to the same.

Get a [u]audio shield[/u] (sound module).

These boards have memory for the audio files, a clock for the digital audio, a DAC, and the required firmware to read & play an audio file. Some have a built-in MP3 decoder. So, the sound module does all of the work and the Arduino simply acts as a "controller".

Also look for one that can directly drive a speaker. Some audio boards/modules put-out a line-level signal that goes into an amplifier, or there are some that can only drive headphones.

Decoding mp3's is completely beyond an Uno, a separate mp3 file player would be needed(*). Low datarate
raw audio can be played, however, as you only have to fetch it from a memory device like an SDcard.

(*)mp3's require decent DSP capability, 8 bit microcontrollers don't have anything like that.

Thanks much for the response. If the Ardurino can play 'wav' files, it would get my project done. The instructions for playing the 'wav' files seem to be available at https://www.instructables.com/id/Audio-Playback-From-SD-Card-With-Arduino/.

  1. Any feedback on what the 'Fritzing' file, available for download in the article, might be for?
  2. Library SimpleSDAudio points to a web link with 'c plus plus' files available for download. Which files are at this location are the actual library files required to play 'wav' file?
  3. What location should the library files be stored on the Ardurino to make the sample code in the web link above work?

That’s pretty impressive. 8 bit is only the amplitude so the dynamic range is limited. 32khz sampling is sufficient for voice I don’t see the need for stereo. This looks like it could be my next project.

It’s memory intensive. Says it takes 1.3k RAM to run. Doesn’t look like it supports. File library so it wouldn’t work for your purpose of calling up different recordings for the different colors. Try TMRpcm. Google it

That's pretty impressive. 8 bit is only the amplitude so the dynamic range is limited. 32khz sampling is sufficient for voice

Sampling at that rate is is way over the top for speech.
8 bits 8KHz https://youtu.be/WShVFcrFpwU

Instructables are normally crap, only read them if you can spot the inevitable errors. Most are written by people with little grasp of electronics. Your questions show what a crap it was.

Any feedback on what the 'Fritzing' file, available for download in the article, might be for?

Fritzing is crap also, as is using solderless bread board.

What location should the library files be stored on the Ardurino

https://www.arduino.cc/en/Guide/Libraries

Grumpy_Mike:
Sampling at that rate is is way over the top for speech.
8 bits 8KHz

Thanks for sharing and that's pretty cool.

Sorry Mike, I disagree... especially if you want it to be clear and not sound like an old phone. 8kHz means that you will capture up to 4k (Nyquist therom). It will be understandable but will sound muffled. It not only has to do with being able to hear the frequencies but also the overtones which affect the fundamental tones. The video you posted sounds good enough to understand but sounds muffled because of the missing overtones.

I'm used to recording at 24 bit, 96kHz audio using Apogee converters. There's a subtle difference between it and 16bit 44kHz which theoretically should include all audible frequencies. When you put it up on mastering quality monitors you can hear huge differences.

Having said that it's still cool! I'm impressed at what this little processor can do!

8kHz means that you will capture up to 4k (Nyquist therom).

Do you think I don't know that?

I did my PhD research into digital sound compression back in the mid 70's when you had to build everything out of logic bits as there were no micros around fast enough. I researched delta adaptive PWM and built a system that did this. It was a rack mounted system having over 100 digital ICs.

I'm used to recording at 24 bit, 96kHz audio using Apogee converters.

Today you are a bit spoiled, I don't buy into the gold plated mains connector crap of audiophiles. :slight_smile:
And while no doubt you could tell a subtle difference, I doubt if you can on a 1" speaker unmounted. You see back in my youth you couldn't just throw speed and resolution at a problem, you had to think about things. I spent quite some time experimenting with sample speed v sample resolution and I was not surprised with what I could get from an Arduino. :slight_smile:

That's very cool Mike. I still love analog compression. I have LA2A (optical tube with an actual light bulb to trigger tube compression) and 1172 (solid state) as my main compressors.

Theoretically tape had better frequency response than digital does.

Yeah we are a bit spoiled but that's what they want when folks go into to lay down tracks. For my little projects I could really care less about fidelity... I'm not an audiophile, I have a masters in composition and have produced, recorded, engineered, built recording studio... .blah blah.

what was the purpose of the you digital compression???

what was the purpose of the you digital compression?

Well CDs had just come out so it was an attempt to save space and therefore make them play longer.

While the theory had been postulated a few years before little in the way of practical work had been done. I actually made a system and also made a machine to acquire the statics of sample changes and effective weighting of the samples.

The Wikipedia entry for this says:-

Adaptive delta modulation (ADM) was first published by Dr. John E. Abate (AT&T Bell Laboratories Fellow) in his doctoral thesis at NJ Institute Of Technology in 1968. ADM was later selected as the standard for all NASA communications between mission control and space-craft.

Adaptive delta modulation or Continuously variable slope delta modulation (CVSD) is a modification of DM in which the step size is not fixed. Rather, when several consecutive bits have the same direction value, the encoder and decoder assume that slope overload is occurring, and the step size becomes progressively larger.

Otherwise, the step size becomes gradually smaller over time. ADM reduces slope error, at the expense of increasing quantizing error. This error can be reduced by using a low-pass filter. ADM provides robust performance in the presence of bit errors meaning error detection and correction are not typically used in an ADM radio design, it is this very useful technique that allows for adaptive-delta-modulation.

This bit however is not exactly correct:-

when several consecutive bits have the same direction value, the encoder and decoder assume that slope overload is occurring, and the step size becomes progressively larger.

The decision to increase the bit weighting was taken on the size of the delta. When it reached a threshold the weighting was increased. So lots of experiments to determine thresholds and sample sizes against listening quality.

A pure mathematical analysis while giving a figure for distortion does not represent how annoying it sounds. So I listened repeatedly to two recordings - Schubert's Trout quintet, my supervisor's choice and Six Wives of Henry 8 - Rick Wakeman , my choice.

Grumpy_Mike:
A pure mathematical analysis while giving a figure for distortion does not represent how annoying it sounds. So I listened repeatedly to two recordings - Schubert's Trout quintet, my supervisor's choice and Six Wives of Henry 8 - Rick Wakeman , my choice.

Thank you for all the pioneering work modern digital compression is incredible.... curse you for having Ads figure out mass compression ugh...

I thought maybe you worked with Dolby for noise reduction.

That would be annoying. 24 bit is so nice when you get the higher dynamic range.

I can't keep listening to recordings like that any more. My ears start to bleed.

There are two completely different sorts of compression being discussed here I suspect, data compression
and audio level compresssion - they are not the same thing at all.

MarkT:
There are two completely different sorts of compression being discussed here I suspect, data compression
and audio level compresssion - they are not the same thing at all.

YES! I just realized that... what Grumps is talking about is data compression. Cool stuff... I've read about low bit rate compression that can actually outperform higher ones. I think Vorbis was one of them. But they all have some strengths and weaknesses.

Getting back to actual sound, studios now use 24 bit/192kHz. I believe this has to do with processing which requires the details and the incredible advances in computers and hard drives.

32kHz recording and playback will give you a fairly realistic audio if you can spare the RAM and resources. If we can apply good data compression we would get better quality sound for less.

wolframore:
Getting back to actual sound, studios now use 24 bit/192kHz. I believe this has to do with processing which requires the details and the incredible advances in computers and hard drives.

High sample rates make anti-aliasing filters far easier to implement and facilitates easier rate-conversion -
and the wide dynamic range means not having to optimize levels all over the shop till the final mixdown.

In a DAW you'd never limit sample rates or depths until necessary. Its not as if 192kSPS or 384kSPS is
actually fast to a modern processor spec'd in gigaflops.

Where you actually hear the difference is when you start to model filters, delays and reverbs... you still want good signal level for the noise floor. But dynamic range is almost impossible to add back later if you need it.

It's possible to record at 96kHz and master at 192kHz due to the additonal processing involved. Then do final mix at 96kHz for DVD with surround sound.