]> git.sesse.net Git - nageru/blobdiff - nageru/alsa_output.cpp
Fix a Clang 19 warning.
[nageru] / nageru / alsa_output.cpp
index 7dd10244b094d83b9f93c65af0b8e87dc4e5a5c6..21143e8fa4bd619f667f6b047fe34d4b95d69c41 100644 (file)
@@ -1,6 +1,8 @@
 #include "alsa_output.h"
 
 #include <alsa/asoundlib.h>
+#include <alsa/error.h>
+#include <alsa/pcm.h>
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -14,7 +16,7 @@ void die_on_error(const char *func_name, int err)
 {
        if (err < 0) {
                fprintf(stderr, "%s: %s\n", func_name, snd_strerror(err));
-               exit(1);
+               abort();
        }
 }
 
@@ -34,12 +36,12 @@ ALSAOutput::ALSAOutput(int sample_rate, int num_channels)
        die_on_error("snd_pcm_hw_params_set_rate()", snd_pcm_hw_params_set_rate(pcm_handle, hw_params, sample_rate, 0));
        die_on_error("snd_pcm_hw_params_set_channels", snd_pcm_hw_params_set_channels(pcm_handle, hw_params, num_channels));
 
-       // Fragment size of 512 samples. (A frame at 60 fps/48 kHz is 800 samples.)
-       // We ask for 16 such periods (~170 ms buffer).
-       unsigned int num_periods = 16;
+       // Fragment size of 2048 samples. (A frame at 60 fps/48 kHz is 800 samples.)
+       // We ask for 4 such periods (~170 ms buffer).
+       unsigned int num_periods = 4;
        int dir = 0;
        die_on_error("snd_pcm_hw_params_set_periods_near()", snd_pcm_hw_params_set_periods_near(pcm_handle, hw_params, &num_periods, &dir));
-       period_size = 512;
+       period_size = 2048;
        dir = 0;
        die_on_error("snd_pcm_hw_params_set_period_size_near()", snd_pcm_hw_params_set_period_size_near(pcm_handle, hw_params, &period_size, &dir));
        die_on_error("snd_pcm_hw_params()", snd_pcm_hw_params(pcm_handle, hw_params));
@@ -74,7 +76,7 @@ try_again:
                ret = 0;
        } else if (ret < 0) {
                fprintf(stderr, "error: snd_pcm_writei() returned '%s'\n", snd_strerror(ret));
-               exit(1);
+               abort();
        } else if (ret > 0) {
                buffer.erase(buffer.begin(), buffer.begin() + ret * num_channels);
        }