Debian Codegraph @

libmve/movie_sound.h

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Descent Developers
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #ifndef LIBMVE_MOVIE_SOUND_H_
20 #define LIBMVE_MOVIE_SOUND_H_
21
22 #include <SDL_audio.h>
23
24 #include "sound_interface.h"
25
26 namespace D3 {
27
28 /// Implementation class for sound device used on movie playback.
29 class MovieSoundDevice : ISoundDevice {
30 private:
31 SDL_AudioDeviceID m_device_id = 0;
32 uint16_t m_sample_size = 0;
33
34 public:
35 /**
36 * Initialize sound device
37 * @param sample_rate sample rate in Hz (22050, 44100...)
38 * @param sample_size sample size (8, 16)
39 * @param channels count of channels (1 for mono, 2 for stereo)
40 * @param buf_size buffer size for SDL audio device
41 * @param is_compressed mark stream as compressed (on streaming will be used decompression functions)
42 */
43 MovieSoundDevice(int sample_rate, uint16_t sample_size, uint8_t channels, uint32_t buf_size, bool is_compressed);
44 ~MovieSoundDevice();
45
46 /**
47 * Check if sound device is properly initialized
48 * @return true on success
49 */
50 [[nodiscard]] bool IsInitialized() const { return m_device_id > 0; }
51
52 /**
53 * Fill internal audio stream to be played
54 * @param stream source buffer
55 * @param len length of source buffer
56 */
57 void FillBuffer(char *stream, int len) const;
58
59 /**
60 * Get sample size
61 * @return 2 (for 16 bit), 1 (for 8 bit)
62 */
63 [[nodiscard]] uint16_t GetSampleSize() const { return m_sample_size; };
64
65 void Play() override;
66 void Stop() override;
67 void Lock() override;
68 void Unlock() override;
69
70 using ISoundDevice::IsCompressed;
71
72 };
73
74 }
75
76 #endif // LIBMVE_MOVIE_SOUND_H_