If the Arduino is anything like a PIC µC then you have no hope of sampling at 44KHz. Most simple µC have quite a slow sampling rate (like 100's of samples per second).
If you want faster then you'd be looking at using something like a dsPIC which has an actual audio grade ADC in it, or use an audio ADC externally that can send I²S data to a µC that is fast enough to respond to it.
I have done some similar work recently while designing a digitally controlled amp.
I had the output of the first stage of the amp going into an analog input on the controlling PIC to then control a bargraph of LEDs for a simple VU meter.
For an output from a PC soundcard you're probably looking at around 1 to 2 volts voltage swing. For my system I wasn't too fussed about frequency and such - just pure peak amplitude - so I passed the signal through a small shottky diode first to trim off the negative voltages. This simplified my design a whole lot.
I am also designing a small frequency analyzer at the moment, and am looking at having selectable op-amp based band-pass filters based around this design: http://www.wa4dsy.net/robot/bandpass-filter-calc which so far has given quite good results. I am varying some of the resistor values by a combination of digital pots and analog multiplexers.
I would certainly recommend at least protecting your analog input(s) with op-amps to limit the maximum voltage they get - just in case. You don't want a voltage spike blowing up your Arduino now do you? Easier to replace a blown op-amp.
And as for a signal for testing? There are many free signal generators for the PC available for download if you do a little google for them. They will let you select waveform, frequency, amplitude, phase, etc. Even allow summing of waveforms to give new waveforms if you're lucky.
You can even use your PC soundcard as a rudimentary scope as well with the right software and a small home-made probe. There is software and designs around for this too on the net.
Oh, and remember to isolate different stages / voltage levels with capacitors in the audio signal. As a rule of thumb, if I am changing PSU voltage levels, I always introduce a capacitor to isolate the stages. So, I had one on the input signal, one on the stage 1 -> stage 2 (+/-5V to +/-12V power supply), one on the stage 1 -> analog input, and one again on the output. It pays to take no chances with stray DC offsets wandering into the wrong part of the circuit.
I took a quick look at the Arduino SPI library and couldn't find the attachInterrupt() function. I assume that you're using an extended library of some sort and I'll make the assumption that it works although I would like to see how it's implemented underneath.
A couple things that I saw:
- This compiles?
if (pos < sizeof buf)
- it probably needs to be if (pos < sizeof(buf))
In the sample code on the forum, he has a key line right here that you're missing in your slave code:
// turn on interrupts
SPCR |= _BV(SPIE);
Without this your receive interrupt probably won't fire. I also don't see where global interrupts are being enabled although I have no idea if Arduino takes care of that for you under the hood. I also haven't bothered to look up what any of those registers mean, I'm trying my best to go by memory of AVR's SPI registers.
Best Answer
Setup input amplifier so that the audio waveform is clipped into a square wave. Then feed this into a pin and use one of the frequency measurement libraries, such as this: http://interface.khm.de/index.php/lab/experiments/frequency-measurement-library/