Audio input distortion

I have a problem with distortion on the audio input in the AudioIOCallback class. When I analyse what is being read, it is clear that occasional input frames are being repeated, which is what is creating the noise. I've trapped this in the code by checking for non-zero subsequent frames that are sample-for-sample identical, and the classes at the native audio device IO level show this problem. I see the same behaviour in Windows and OSX. What I've tried up to now is:

  • checking if there are device errors : there are'nt;
  • checking if something is overwriting the buffers along the way : also negative;
  • stripping the audio callback to a bare minimum and seeing if this helps : no dice;
  • enabling memory boundary checking on OSX : no result

This is starting to drive me crazy frown. Three things may also be relevant:

- if I look at the audio input the basic audio is being preserved (i.e. there are no extra frames being added) but a frame is being overwritten. The weird thing is that I would expect frame x to be overwritten by frame x -1, which would be caused by some silly bug with a persistant buffer, but in fact what is happening is that frame x is being overwritten by frame x +1.

- The program has a metronome sound which is optionally merged into the output stream in the callback. The actual sound is in a memory resource and is read via a WavAudioFormat as a MemoryInputStream. The problem only happens when the metronome is enabled (and then not always), but persists when it is disabled (I've checked that the extra code is not executed when disabled, that's ok)

- This may be irrelevant, but occasionaly the program initialises fine, but the audio callback isn't called. None of the start routines return an error and the callback is registered in the AudioManager. Opening the program's control panel reinitialises the device and everything works fine.

As I said, this behaviour is present in OSX and Windows, and is the same in Windows with ASIO, DirectSound and WASAPI.

I don't expect that anyone could give a soution based on the above, but I would appreciate  (a) some sort of approach to help debug this or (b) someone who has experienced something similar.

Update for anyone with a similor problem. The problem went away when I changes the metronomen to use it's won audio callback. Still - if anyone has thoughts in how this dan occupy in the first place ...