Home › Forums › Sparkfun MP3 Shield Library Support Forum › Adding an LED..
Tagged: Audio Monitoring
- This topic has 14 replies, 2 voices, and was last updated 8 years, 5 months ago by Michael P. Flaga.
-
AuthorPosts
-
March 21, 2016 at 11:25 am #3498AnonymousInactive
Hi there-
I had one other question about the v1053 shield.. I’m trying to patch the audio back into the Arudino, to control an LED. For some reason, this code isn’t working, though..any ideas?
#include <SPI.h>
#include <SdFat.h>
#include <SdFatUtil.h>
#include <SFEMP3Shield.h>SdFat sd;
SFEMP3Shield MP3player;byte result;
const int ledPin = 9;
int sensorPin = 1;
int sensorValue = 0;void setup() {
Serial.begin(115200);
result = sd.begin(SD_SEL, SPI_FULL_SPEED);
result = MP3player.begin();
MP3player.setVolume(20, 20);
randomSeed (millis()); // set a more random seed for the random function
Serial.println(“Hello”);
pinMode(ledPin, OUTPUT);
}
void loop() {
int brightness;
MP3player.playTrack(random(5)); // range of tracks to randomly play.
while (MP3player.isPlaying());
{sensorValue = analogRead(sensorPin);
Serial.println(sensorValue);
analogWrite(ledPin, sensorValue);
}
MP3player.stopTrack();// stop track
}
March 21, 2016 at 8:11 pm #3499Michael P. FlagaMemberI do not believe it may be as simple and straight forward as your attempt may be.
First electrically you don’t say what the schematic of it is. Note that the signal is AC and can be very small ranging from milli volts to 1vpp peak to peak. Note sure if you are isolating it through a cap. I believe that will need to be done, somewhere. The output amplifer of the 1053 is not isolated. And that will make it +/-. the minus will likely need to be clip the negative. So the ac signal will range from zero to positive peak, with a max of +1vp.
the above code should likely map to rescale the analog input to the output scale.
Also note about the Analog output; that it is really a duty cycle of a pulse. so if the signal was max of 1 vp, then that would be one fifth of the cycle. and noting even at max the signal is sinusoidal and only about a small portion is near peak.
The other aspect of concern is your update rate. there is no delay between samples and updates of the analog-write. So your code is constantly re-writing the duty cycle, way more time then an actual cycle. I believe the default cycle is around 490 hertz ish. So you may re-writing it hundreds of times per cycle. And that may be freaking it out. Not sure. Just a guess.
I would pass the audio input through a cap and low pass filter it. As to smooth/average out the audio energy and then sample that at 2 or 10 per second and then map (aka re-scale) that to a range that was visibly pleasing.
March 21, 2016 at 9:30 pm #3500AnonymousInactiveElectrically, I’m using this basic arrangement for the LED: https://www.arduino.cc/en/uploads/Tutorial/ExampleCircuit_sch.png
From there, I’m hardwiring the output of the shield (right channel) to the Analog Input (sensorPin) through 1 uF cap.
Is there a recommended way to do the rescaling of volt-to-PWM? What about slowing the sampling rate? I’m not sure I know how to do these procedures. I’m sorry for the newbie questions, I’m sure this is a huge waste of time for you – but I know you are helping out of the goodness of your heart and I appreciate it a great deal. I’m still learning.
March 22, 2016 at 10:27 am #3501Michael P. FlagaMemberI would recommend starting with the first code shown at
https://learn.adafruit.com/adafruit-microphone-amplifier-breakout/measuring-sound-levels
The 2nd code is the same but has extra code for a matrix display. But look at that to. As it should store it for time.
Also note that the 1053 and this library has a feature for measuring the transmitted power level at any time, called VUmeter.
setVUmeter’s enable. then occasionally poll the getVUlevel and use this to replace the analogread data. Scale the output of the getVUlevel and then send it to analogwrite.
There are set and get VU examples in both MP3Shield_Library_Demo.ino and FilePlayer.ino
March 22, 2016 at 11:54 am #3502AnonymousInactiveThank you, Mr. Flaga.. I’m still a little confused about the difference between “getVUlevel” and “getVUmeter” and how to properly implement them in this code.. shouldn’t something like this work?
void loop() {
MP3player.playTrack(random(5)); // range of tracks to randomly play.
while (MP3player.isPlaying());
{MP3player.setVUmeter(1);
Serial.println(MP3player.getVUmeter());
}MP3player.stopTrack();// stop track
}
March 28, 2016 at 1:28 pm #3507AnonymousInactivehi there-
i’m trying to simplify the code, just to get the getVUmeter reading in the “while” loop….but i’m just getting a bunch of garbled text and then a stream of zeroes. any ideas?
#include <SPI.h>
#include <SdFat.h>
#include <SdFatUtil.h>
#include <SFEMP3Shield.h>
SdFat sd;
SFEMP3Shield MP3player;
byte result;
void setup() {
Serial.begin(115200);
result = sd.begin(SD_SEL, SPI_FULL_SPEED);
result = MP3player.begin();
MP3player.setVolume(20, 20);
randomSeed (millis()); // set a more random seed for the random function
Serial.println(“Hello”);
}
void loop() {
MP3player.playTrack(random(5)); // range of tracks to randomly play.
while (MP3player.isPlaying()){
Serial.println(MP3player.getVUmeter());
}
MP3player.stopTrack();// stop track
}
March 28, 2016 at 2:00 pm #3508AnonymousInactiveThere may be a larger problem – the demo code did not seem be reading the VU meter either…
March 28, 2016 at 2:50 pm #3509Michael P. FlagaMemberNot sure about it not working. Honestly has been over a year since I last fired it up. I recall testing it before committing it. hmm. It may require the DSP patches, as I see it is a read of SCI_AICTRL3 . a register in the DSP and those are affected by the patches.
about “getVUlevel” and “getVUmeter”. The later basically reads back if it is enabled. where getVUlevel returns the actual VU level on the line. note in the demo code it enables it with
MP3player.setVUmeter(1);
then polls it
vu.word = MP3player.getVUlevel();
notice that it returns a word and the union splits that into a Left and Right for the print.
- This reply was modified 8 years, 5 months ago by Michael P. Flaga.
March 28, 2016 at 3:08 pm #3511Michael P. FlagaMemberI see right there in my documentation of the code at http://mpflaga.github.io/Sparkfun-MP3-Player-Shield-Arduino-Library/class_s_f_e_m_p3_shield.html#aed2dc5833ab0fa71c2994cf89e598f35
get current measured VU Meter
Returns the calculated peak sample values from both channels in 3 dB increaments through. Where the high byte represent the left channel, and the low bytes the right channel.
Values from 0 to 31 are valid for both channels.
Warning :This feature is only available with patches that support VU meter.
So I suspect that there are two issues. 1) need the patches and 2) use getVUlevel.
Hope that helps.
March 28, 2016 at 4:59 pm #3512AnonymousInactiveAh..so, I need a certain kind of patch to also be loaded on the SD card, in order for the VU to work? Then I need to use VSLoadUserCode? What kind of patch is this? I’m sorry that I’m confused..
March 28, 2016 at 5:06 pm #3513Michael P. FlagaMemberPlease see step #2 in the documentation at http://mpflaga.github.io/Sparkfun-MP3-Player-Shield-Arduino-Library/#Installation
The plugin patches are located in the repo at: https://github.com/mpflaga/Sparkfun-MP3-Player-Shield-Arduino-Library/tree/master/plugins
The libraries initializing code of the VS1053 looks optionally for the “patches.053” in the root of the SdCard. If not found it issues a warning and moves on, as it is not needed for basic functions.
March 30, 2016 at 10:35 am #3514AnonymousInactiveAh, I think I see now. Is there anywhere that gives the specifications of the output signal from the 1053 shield? I’m having trouble finding out what sort of bias I’m dealing with or what the p-to-p values are.
March 30, 2016 at 11:21 am #3515Michael P. FlagaMemberExtrace from http://www.vlsi.fi/fileadmin/software/VS10XX/vs1053b-patches.pdf
Where the below documentation is from the current patch from their website and is more recent patch. That I have not converted to the SFEMP3 file binary format. So the library has the old version. There is a vs_plg_to_bin.pl in the repo for creating new binary files from their patches.
VU Meter
SCI_STATUS bit 9 enables VU meter, which calculates a leaking peak sample value from both channels and returns the values in 1 dB resolution through SCI_AICTRL3. The high 8 bits represent the left channel, the low 8 bits the right channel.
Note that the following has changed from the previous release.
Values from 0 to 96 are valid for both channels. 0 means no sound, 96 is highest level. In practise the highest value will be 95, the signal is probably clipping if you get 96.
The calculation does not take the volume setting into account.
The VU meter takes about 0.6MHz of processing power with 48 kHz samplerate.
_______
from wikipedia i read:
<span style=”color: #252525; font-family: sans-serif; font-size: 14px; line-height: 22.4px;”>0 VU is equal to +4 [dBu], or 1.228 </span>volts<span style=”color: #252525; font-family: sans-serif; font-size: 14px; line-height: 22.4px;”> </span>RMS<span style=”color: #252525; font-family: sans-serif; font-size: 14px; line-height: 22.4px;”> across a 600</span>ohm<span style=”color: #252525; font-family: sans-serif; font-size: 14px; line-height: 22.4px;”> </span>load<span style=”color: #252525; font-family: sans-serif; font-size: 14px; line-height: 22.4px;”>, or about 2.5 milliWatts</span>
March 30, 2016 at 2:40 pm #3516AnonymousInactiveSorry, I meant voltage-wise, what are the maximum values for the signal?
I’m looking at the output of the VS1053 in a scope right now and it only seems to be operating at about +/- 0.2v.
March 30, 2016 at 5:10 pm #3517Michael P. FlagaMembernot much of an expert on audio signals. I believe LINE is typically 1V peak to peak. So +/- 0.2 equal 0.4Vpp. ruffly half. And then noting that the output of the VS1053 is not LINE, but a driver for low impedance speakers. either 8 or 16 Ohm. And think is some kind of D type amplifier.
If you need more power I recall documenting somewhere in the github doc an API to change to mono and add the currents of both the outputs into one channel. Someone did this for a stuffed toy. So it would appear to be more current based then voltage.
-
AuthorPosts
- You must be logged in to reply to this topic.