More P2 Eval/Audio questions
I'm very interested in audio programming for the P2. Specifically, I'd like to build a synthesizer, including a sampler & realtime effects processor.
To start this process, I found the "headphones.spin2" file in the Propeller Tool's Examples folder, and this seems like a perfect place to start. It plays a single frequency note through each speaker, using very little code, so it's a great learning platform.
So I edited the file and set the note frequency to 30 Hz and the volume to $7FF. It played a nice 30Hz note, but it sounded like there's some background hissing, so I hooked up my oscilloscope to see what the wave actually looked like.
I thought this was rather odd - Sure, it's 30Hz, but it seems to be built of a higher frequency carrier wave, thats "thicker" at the top and thinner at the bottom. This seems very strange. When I zoomed in on that, I saw:
I'm a n00b regarding electronics & oscilloscope usage, so I may have my scope set up incorrectly, but this seems odd. It also seems odd that the wave isn't balanced from top to bottom, from the first image you see that it goes to +140mV but only -90mV. Why the imbalance? And is the carrier oscillation ringing in the circuit, or is it part of the ADC output?
The probe was connected to the left headphone pin on the AV board, not the raw output of the P2 chip, so it is after the capacitor.
I also have some questions about the headphones.spin2 program.
- It uses setse1 & waitse1, but I can't find a clear doc explaining what these instructions actually do in this case. I find mention of the commands, but not enough info to understand what
setse1 #%001<<6+leftis actually doing, or what
waitse1is actually waiting for.
- The f1 & f2 vars are initialized like this:
f1 long round(freq1 * 65536.0 * 65536.0 *256.0 /float(clkfreq_)). It's been a while since I did any fixed point math, but am I correct in assuming this is dividing a circle into 256 elements and converting it to FXP for the cordic rotation calc?
- Is it possible to get high quality, low noise audio output from the P2 ADC pins? Do I need to add something to achieve this, like larger capacitors?
- The bottom of the file mentions PWM dither. Is this using PWM? Is that how DAC is accomplished? Is that the carrier frequency we're seeing here?