Audio loopback application, issue: increasing latency... (WaveForm Audio API) RRS feed

  • Question

  • I've wrote a simple audio loopback application which records voice from a mic and continuously send it to the speakers.

    I'm using 1 thread capturing audio and another thread playing audio. That is, KISS solution.
    Between these 2 threads there is a FIFO buffer (circular buffer, i've used it for years, it has been tested rigidly). I use a critical section to synchronize mutual exclusion access to this buffer.

    Record >>> AudioInputThread(producer) >>> buffer >>> AudioOutputThread(consumer) >>> Playback

    I'm esperiencing an increasing latency, infact the buffer in the middle seem to increase its content gradually. The mittle buffer has 100 slots, and the occupied waiting slots are increasing slowly, increasing latency.
    I've checked line by line with thread timers, and my threads are not wasting any time.
    The CPU usage during execution is below 2% constantly. This means that my threads are waiting for data to copy from/to buffers about all the time.

    It seem to that playback is slower than recording. why?
    I'm recording 8000 sample/s at 16 bit each on 1 channel = 16 kbyte/s audio incoming. Outgoing audio has the same waveformat. Why the middle buffer is increasing, the producer is faster than the cosumer? why?

    I've tried to sleep(some time) the audioinputthread if the middle buffer increases a lot. It doesn't stop increasing until i put a sleep(200) inside producer thread. But this makes audio bluttering... beacouse i'm losing live audio recording.

    I could post the code if you need.
    Thank you.
    Sunday, March 18, 2007 7:02 AM


  • Try posting your question on the pro-audio development forum: http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=351&SiteID=1

    Just a thought off the top of my head (this might be completely wrong, though): Your mic and your audio card may have device clocks that run at almost-but-not-exactly the same speed.  They might be off by up to a couple percentage points.  An audio card that plays back slightly slower than the capture device captures might account for a gradually-growing buffer in between.

    Monday, March 26, 2007 7:28 PM