So I have a MIDI synth I'm working on, and it's all working nicely, except for one thing.
When the arduino receives any type of MIDI message (and I would assume any serial message in general), I get a small click on the audio output I have set up. It's really not manageable, since doing things like turning a pitchbend wheel causes an audible buzz.
here's a little soundclip of the synth while I turn the mod and pitchbend wheel on my keyboard:
http://soundcloud.com/beefinator-2/arduino-synth-weirdnessAbout halfway through, I turn up the gain so the buzzing is more audible. But the first half, that's at the same recording gain as when I play a couple notes, so you can see how relatively loud it is compared to the actual notes.
I'm using an MCP4822 DAC, but that's irrelevant, because I had this same issue a while ago when I used filtered PWM to generate an analog output.
I have in the program an interrupt routine that runs at 22KHz to update the DAC.
I would guess that the clicking has something to do with the serial reception interrupt, but I don't see how it would affect anything. My routine is not reentrant, so it can't be that the serial interrupt is firing midway through my interrupt. The DAC is completely updated by the time my routine is done, and the chip has an internal buffer, so the problem can't be the Serial interrupt slightly delaying my interrupt.
I looked through the Serial source code, the MIDI library code, and the atmega328 datasheet to try to figure out what's going on, but I couldn't find any solutions. From what I understand, the SPI and USART are independent on the chip, so that's not an issue.
I dunno.
The sketch is attached; any ideas on something I'm missing?