title: ALSA PCM Non-Blocking Capture Producing Static
body: <p>Whenever I construct a non-blocking PCM capture stream in ALSA, I sometimes get garbage samples back when I call snd_pcm_readi() (meaning data gets populated, and I'm told I've just read N samples, but only M are valid, the rest is just garbage). This tells me that the samples aren't actually ready, so I don't understand why ALSA would even return them.</p>
  
  <p>For those who have the ALSA-provided <code>latency</code> tool lying around someplace, I can reproduce this static by running <code>latency -P &lt;playback-device&gt; -C &lt;capture-device&gt; -r 48000</code>. ALSA begins normalizing around a roundtrip time of 16ms for me, but it just <em>sounds</em> atrocious.</p>
  
  <p>I was able to capture some of the bad data, and I loaded it up in Audacity for visualization:
  <a href="https://drive.google.com/file/d/0B-1aumGKQcQTcUJoZzIwRWhYSFE/view?usp=sharing" rel="nofollow">https://drive.google.com/file/d/0B-1aumGKQcQTcUJoZzIwRWhYSFE/view?usp=sharing</a></p>
  
  <p>It looks like the internal buffer occasionally is sending me more data than it actually captured, and I end up either reading old PCM data from the internal ring buffer, or (at the very beginning) a bunch of zeros.</p>
  
  <p>Can anyone help me understand what is going on?</p>
  
  <p>In case it helps:</p>
  
  <ul>
  <li>Hardware: Samson Meteor Mic (USB-Audio, USB Mixer) [Though, it even happens with my built-in microphone]</li>
  <li>ALSA version: Advanced Linux Sound Architecture Driver Version k4.4.0-28-generic.</li>
  <li>apt-cache policy (installed alsa-lib version): 1.1.0-0ubuntu1</li>
  </ul>
  
  <p>EDIT:
  I got a vote to close as off-topic, which I disagree with... I feel the API is not acting in accordance with what the documentation says, and don't understand <em>why</em>. I've rephrased the question to perhaps make it a little more clear, but if it still appears to be off-topic, please let me know why so I can either correct it or close it myself.</p>