]> git.sesse.net Git - nageru/blobdiff - alsa_output.cpp
Write 1.4.0 changelog.
[nageru] / alsa_output.cpp
index a3d17a2088ca0a49ad9ababfa118363150a07147..7dd10244b094d83b9f93c65af0b8e87dc4e5a5c6 100644 (file)
@@ -1,5 +1,9 @@
 #include "alsa_output.h"
 
+#include <alsa/asoundlib.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
 #include <vector>
 
 using namespace std;
@@ -17,7 +21,7 @@ void die_on_error(const char *func_name, int err)
 }  // namespace
 
 ALSAOutput::ALSAOutput(int sample_rate, int num_channels)
-       : num_channels(num_channels)
+       : sample_rate(sample_rate), num_channels(num_channels)
 {
        die_on_error("snd_pcm_open()", snd_pcm_open(&pcm_handle, "default", SND_PCM_STREAM_PLAYBACK, 0));
 
@@ -79,7 +83,8 @@ try_again:
                if (ret == 0) {
                        if (buffer.size() >= period_size * num_channels * 8) {
                                // OK, almost 100 ms. Giving up.
-                               fprintf(stderr, "warning: ALSA overrun, dropping some audio\n");
+                               fprintf(stderr, "warning: ALSA overrun, dropping some audio (%d ms)\n",
+                                       int(buffer.size() * 1000 / (num_channels * sample_rate)));
                                buffer.clear();
                        }
                } else if (ret > 0) {