is audio actually digital?

so my arduino can play mp3 after all!?!

i just want to see if i can input a music file and just echo it back out another pin, would this code work?

int PININ=5;
int PINOUT=6;
setup()
{
     pinMode(PININ,INPUT);
     pinMode(PINOUT,OUTPUT);
}


void loop()
{
     int OUT= analogRead(PININ);

     analogWrite(PINOUT,OUT);

}

Will the code work - no
Is audio digital - no
Can an Arduino play an MP3 file - no

so my arduino can play mp3 after all

Complete non sequitur

The Arduino's "analog" output is PWM, and the default is rather low-frequency PWM. The Arduino does not have a true digital-to-analog converter (DAC). You can get "sound", but if you want to play music files with reasonable quality PWM won't cut it.

The analog-to-digital converter (ADC) is a true ADC and it can read PCM. (Your waveform diagram shows PCM, which is normal for digital audio.)

The ADC input is 10-bits. The PWM output is 8-bits.

The Arduino can't handle negative voltages, so for audio (which is AC) you have to bias the input (and filter the bias from the output).

MP3 isn't PCM either... It has to be decoded to PCM before being sent to the DAC.

Bottom line: To play MP3s, you need an MP3 shield with a MP3 decoder and a DAC.

To get good quality audio you need to add a DAC.

If you are going read audio into the Arduino, you only have 10-bits of resolution unless you use an external ADC.

Normally, you should have a known sample rate and a low-pass filter before the ADC to prevent aliasing. (A low-pass filter following the DAC is standard too, although you can usually get by without it if the sample rate is above the audio range where you can't hear it or the related harmonics.)

The Arduino's "analog" output is PWM,

wouldnt pwm imply the input signal be switching on/off at a particular voltage? ie digital

the arduino can't output true analog but it can output varying voltage levels so the arduino should be capable of pcm shouldnt it?

and the default is rather low-frequency PWM.

If you are going read audio into the Arduino, you only have 10-bits of resolution

questions: does the outputting rate also correspond to the set baud rate in the ide (usually 9600bps)?

10 bits of resolution meaning average number of sampling points per sin wave? and again, how is analogRead() a pwm sample point, it should be a pcm sample point no?

questions: does the outputting rate also correspond to the set baud rate in the ide (usually 9600bps)?

Answer: no.

10 bits of resolution meaning average number of sampling points per sin wave?

Answer: no; the question doesn't make sense.

how is analogRead() a pwm sample point, it should be a pcm sample point no?

Answer: no; the question doesn't make sense.

wouldnt pwm imply the input signal be switching on/off at a particular voltage? ie digital

Yes. PWM is digital. [u]This page[/u] shows how PWM works... If you "flash" and LED on & off fast enough, you won't see the flashing but it will look dim.

AT 50% PWM the average current will be half and it will look the same as if you reduced the continuous "analog" current in half.

This can work for audio too. Class D amplifiers use PWM. But, while you can't see an led blinking at 490Hz, you can hear 490Hz. So, class D amplifiers use a much higher frequency (maybe 100kHz or more). With a PWM frequency that's much-higher than the audio frequency, you can filter-out the PWM without filtering-out the audio.

the arduino can't output true analog but it can output varying voltage levels...

No it cannot. It puts-out only 0v and 5V (approximately). A DAC can put-out 1VDC, but the Arduino cannot.

With the Arduino at 20% PWM, you have 1V average. You can low-pass filter the PWM to get constant 1VDC. But since the Arduino's default PWM is 490Hz, around the middle of the audio range, you can't filter-out the PWM pulses without also filtering-out (most of) the audio too.

10 bits of resolution meaning average number of sampling points per sin wave? and again, how is analogRead() a pwm sample point, it should be a pcm sample point no?

10-bits is the amplitude (or "height") resolution. A sample is represented in 2-dimensions of amplitude and time.

The time-resolution is defined as the sample rate (Hz or Samples-per-second). As you may know, CDs have a sample rate of 44.1kHz.

With 10-bits you "count" to 11 1111 1111 in binary, which is 1023 in decimal. As you may also know, CDs use 16-bit signed integers (-32,768 to +32,767 when converted to decimal).

The Audacity website has a nice [u]introduction to digital audio[/u] (normal PCM). It shows how the waveform is digitized/sampled, and how you can"connect the dots" and filter (smooth) to reproduce the analog waveform.

You should check out Open Music Labs article on PWM and Audio, they also have a great little example technically do what you want to do:

Hope that helps!