aboutsummaryrefslogtreecommitdiff
path: root/include/AudioPlayer.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'include/AudioPlayer.hpp')
-rw-r--r--include/AudioPlayer.hpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/include/AudioPlayer.hpp b/include/AudioPlayer.hpp
new file mode 100644
index 0000000..22c3be8
--- /dev/null
+++ b/include/AudioPlayer.hpp
@@ -0,0 +1,22 @@
+#pragma once
+
+#include <thread>
+
+namespace gsr {
+ // Only plays raw stereo PCM audio in 48000hz in s16le format.
+ // Use this command to convert an audio file (input.wav) to a format playable by this class (output.pcm):
+ // ffmpeg -i input.wav -f s16le -acodec pcm_s16le -ar 48000 output.pcm
+ class AudioPlayer {
+ public:
+ AudioPlayer() = default;
+ ~AudioPlayer();
+ AudioPlayer(const AudioPlayer&) = delete;
+ AudioPlayer& operator=(const AudioPlayer&) = delete;
+
+ bool play(const char *filepath);
+ private:
+ std::thread thread;
+ bool stop_playing_audio = false;
+ int audio_file_fd = -1;
+ };
+} \ No newline at end of file