| 1 | /* |
| 2 | * LegacyClonk |
| 3 | * |
| 4 | * Copyright (c) 2017-2021, The LegacyClonk Team and contributors |
| 5 | * |
| 6 | * Distributed under the terms of the ISC license; see accompanying file |
| 7 | * "COPYING" for details. |
| 8 | * |
| 9 | * "Clonk" is a registered trademark of Matthes Bender, used with permission. |
| 10 | * See accompanying file "TRADEMARK" for details. |
| 11 | * |
| 12 | * To redistribute this file separately, substitute the full license texts |
| 13 | * for the above references. |
| 14 | */ |
| 15 | |
| 16 | // Interfaces for music and sound playback handling |
| 17 | |
| 18 | #pragma once |
| 19 | |
| 20 | #include "C4Log.h" |
| 21 | #include "Standard.h" |
| 22 | |
| 23 | #include <cstddef> |
| 24 | #include <cstdint> |
| 25 | |
| 26 | class C4AudioSystem |
| 27 | { |
| 28 | protected: |
| 29 | C4AudioSystem() = default; |
| 30 | |
| 31 | public: |
| 32 | C4AudioSystem(const C4AudioSystem &) = delete; |
| 33 | C4AudioSystem(C4AudioSystem &&) = delete; |
| 34 | virtual ~C4AudioSystem() = default; |
| 35 | C4AudioSystem &operator=(const C4AudioSystem &) = delete; |
| 36 | |
| 37 | static C4AudioSystem *NewInstance(int maxChannels, bool preferLinearResampling); |
| 38 | |
| 39 | class MusicFile; |
| 40 | class SoundFile; |
| 41 | |
| 42 | virtual void FadeOutMusic(std::int32_t ms) = 0; |
| 43 | virtual bool IsMusicPlaying() const = 0; |
| 44 | // Plays music file. If supported by audio library, playback starts paused. |
| 45 | virtual void PlayMusic(const MusicFile *const music, bool loop) = 0; |
| 46 | // Range: 0.0f through 1.0f |
| 47 | virtual void SetMusicVolume(float volume) = 0; |
| 48 | virtual void StopMusic() = 0; |
| 49 | virtual void UnpauseMusic() = 0; |
| 50 | |
| 51 | class MusicFile |
| 52 | { |
| 53 | protected: |
| 54 | MusicFile() = default; |
| 55 | |
| 56 | public: |
| 57 | MusicFile(const MusicFile &) = delete; |
| 58 | MusicFile(MusicFile &&) = default; |
| 59 | virtual ~MusicFile() = default; |
| 60 | MusicFile &operator=(const MusicFile &) = delete; |
| 61 | }; |
| 62 | |
| 63 | virtual MusicFile *CreateMusicFile(const void *buf, std::size_t size) = 0; |
| 64 | |
| 65 | class SoundChannel |
| 66 | { |
| 67 | protected: |
| 68 | SoundChannel() = default; |
| 69 | |
| 70 | public: |
| 71 | // Plays sound file. If supported by audio library, playback starts paused. |
| 72 | SoundChannel(const SoundChannel &) = delete; |
| 73 | SoundChannel(SoundChannel &&) = delete; |
| 74 | virtual ~SoundChannel() = default; |
| 75 | SoundChannel &operator=(const SoundChannel &) = delete; |
| 76 | |
| 77 | virtual bool IsPlaying() const = 0; |
| 78 | virtual void SetPosition(std::uint32_t ms) = 0; |
| 79 | // volume range: 0.0f through 1.0f; pan range: -1.0f through 1.0f |
| 80 | virtual void SetVolumeAndPan(float volume, float pan) = 0; |
| 81 | virtual void Unpause() = 0; |
| 82 | }; |
| 83 | |
| 84 | virtual SoundChannel *CreateSoundChannel(const SoundFile *const sound, bool loop) = 0; |
| 85 | |
| 86 | class SoundFile |
| 87 | { |
| 88 | protected: |
| 89 | SoundFile() = default; |
| 90 | |
| 91 | public: |
| 92 | SoundFile(const SoundFile &) = delete; |
| 93 | SoundFile(SoundFile &&) = delete; |
| 94 | virtual ~SoundFile() = default; |
| 95 | SoundFile &operator=(const SoundFile &) = delete; |
| 96 | |
| 97 | virtual std::uint32_t GetDuration() const = 0; |
| 98 | }; |
| 99 | |
| 100 | virtual SoundFile *CreateSoundFile(const void *buf, std::size_t size) = 0; |
| 101 | |
| 102 | public: |
| 103 | static constexpr auto MaxChannels = 1024; |
| 104 | }; |
| 105 | |
| 106 | C4LOGGERCONFIG_NAME_TYPE(C4AudioSystem); |
| 107 | |