Interesting, I am endeavouring to perform a similar task (although mine will output to an LCD panel.....mebby) and was wondering where to put the calibration for +0dB. Doing it in software seems the sensible option as it offers the most flexibility.
Cant wait for my hardware to arrive, its kind of frustrating developing even simple test code without something to test it against
See, I did not get to the point with the Db calibration. The reason I did not is due to the math function and the way you would have to use a logarithmic scale for that voltage. If you get any further on that, let me know.
Vpp would have to be calculated from the data, the cutoffs depend on the signal type, if its line level it "should" be 1.0 Vpp at 0dB most European audio kit goes uo to +6dB (around 2.2V) and US kit usually hangs around the +4dB level or 1.7Vpp.
Obviously amplified levels such as those from a typical MP3 players headphone output can go wherever the hell the manufacturer wants (but mostly top out at 4v). Conversely Mic inputs are waaaaay lower.
What could happen is to rectify and smooth the input to the Vpp pins and leave the signal as merely rectified, combining the two. But I think that's an unnecessary over complication.
One thing I have seen mentioned but haven't looked at yet is resetting the voltage range that represents 0-1023 samples.
I can generate a known 1Vpp 1K tone and use that to calibrate my inputs either within software or with a preamp circuit of some description.
Thankfully subjective audio quality is irrelevant, its power I intend to measure so the input stage can be reallllly cheap and nasty Or The Easy Way - http://www.electronics-tutorials.ws/diode/diode_6.html as I like to call it. The forward voltage drop will need to be addressed though.
#include <LCD4Bit_fast.h>
LCD4Bit_fast lcd = LCD4Bit_fast(2);
void setup() {
lcd.init(); //Inits the LCD
}
void loop() {
//int i=(analogRead(1)/64); //readin Analog 1 (Left) calibrate for screen
//int j=(analogRead(2)/64); //readin Analog 2 (Right) calibrate for screen
int i=random(2,14); //simulated input
int j=i+(random(-2,2)); //simulated input
int x=0;
int y=0;
lcd.clear();
lcd.commandWrite(0x80+11); //Place cursor at row 1 col 0 and add i to the col
lcd.printIn("|"); //fill character with ]
lcd.commandWrite(0xC0+11); //Place cursor at row 1 col 0 and add i to the col
lcd.printIn("|"); //fill character with ]
while (x <= i)
{
lcd.commandWrite(0x80+x); //Place cursor at row 1 col 0 and add x to the col
if (x > 11)
{
lcd.print(255);
}
else
{
lcd.printIn("="); //fill character with white
}
x++;
}
while (y <= j)
{
lcd.commandWrite(0xC0+y); //Place cursor at row 2 col 0 and add y to the col
if (y > 11)
{
lcd.print(255);
}
else
{
lcd.printIn("="); //fill character with white
}
y++;
}
delay(120);
}