Debian Codegraph @

libmve/movie_sound.cpp

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 #include <functional>
20 #include "movie_sound.h"
21
22 namespace D3 {
23
24 MovieSoundDevice::MovieSoundDevice(int sample_rate, uint16_t sample_size, uint8_t channels, uint32_t buf_size,
25 bool is_compressed) {
26 SDL_AudioFormat format = (sample_size == 2) ? AUDIO_S16LSB : AUDIO_U8;
27 SDL_AudioSpec spec;
28 spec.freq = sample_rate;
29 spec.format = format;
30 spec.channels = channels;
31 spec.size = buf_size;
32 spec.callback = nullptr;
33 spec.userdata = this;
34
35 m_device_id = SDL_OpenAudioDevice(nullptr, 0, &spec, nullptr, 0);
36 m_is_compressed = is_compressed;
37 m_sample_size = sample_size;
38 };
39
40 MovieSoundDevice::~MovieSoundDevice() {
41 if (m_device_id > 0) {
42 SDL_CloseAudioDevice(m_device_id);
43 m_device_id = 0;
44 }
45 }
46
47 void MovieSoundDevice::FillBuffer(char *stream, int len) const {
48 SDL_QueueAudio(m_device_id, stream, len);
49 };
50
51 void MovieSoundDevice::Play() { SDL_PauseAudioDevice(m_device_id, 0); }
52
53 void MovieSoundDevice::Stop() { SDL_PauseAudioDevice(m_device_id, 1); }
54
55 void MovieSoundDevice::Lock() { SDL_LockAudioDevice(m_device_id); }
56
57 void MovieSoundDevice::Unlock() { SDL_UnlockAudioDevice(m_device_id); }
58
59 } // namespace D3