1 /*****************************************************************************
2  * Copyright (c) 2014-2020 OpenRCT2 developers
3  *
4  * For a complete list of all authors, please refer to contributors.md
5  * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
6  *
7  * OpenRCT2 is licensed under the GNU General Public License version 3.
8  *****************************************************************************/
9 
10 #pragma once
11 
12 #include "../common.h"
13 #include "../core/IStream.hpp"
14 
15 #include <memory>
16 
17 #define MIXER_VOLUME_MAX 128
18 #define MIXER_LOOP_NONE 0
19 #define MIXER_LOOP_INFINITE (-1)
20 
21 namespace OpenRCT2::Audio
22 {
23     enum class SoundId : uint8_t;
24 
25     enum class MixerGroup : int32_t
26     {
27         Sound,
28         RideMusic,
29         TitleMusic,
30     };
31 
32     struct IAudioSource;
33     struct IAudioChannel;
34 
35     /**
36      * Provides an audio stream by mixing multiple audio channels together.
37      */
38     struct IAudioMixer
39     {
40         virtual ~IAudioMixer() = default;
41 
42         virtual void Init(const char* device) abstract;
43         virtual void Close() abstract;
44         virtual void Lock() abstract;
45         virtual void Unlock() abstract;
46         virtual IAudioChannel* Play(IAudioSource* source, int32_t loop, bool deleteondone, bool deletesourceondone) abstract;
47         virtual void Stop(IAudioChannel* channel) abstract;
48         virtual bool LoadMusic(size_t pathid) abstract;
49         virtual void SetVolume(float volume) abstract;
50 
51         virtual IAudioSource* GetSoundSource(SoundId id) abstract;
52         virtual IAudioSource* GetMusicSource(int32_t id) abstract;
53     };
54 } // namespace OpenRCT2::Audio
55 
56 #ifndef DSBPAN_LEFT
57 #    define DSBPAN_LEFT (-10000)
58 #endif
59 #ifndef DSBPAN_RIGHT
60 #    define DSBPAN_RIGHT 10000
61 #endif
62 
63 void Mixer_Init(const char* device);
64 void* Mixer_Play_Effect(
65     OpenRCT2::Audio::SoundId id, int32_t loop, int32_t volume, float pan, double rate, int32_t deleteondone);
66 void Mixer_Stop_Channel(void* channel);
67 void Mixer_Channel_Volume(void* channel, int32_t volume);
68 void Mixer_Channel_Pan(void* channel, float pan);
69 void Mixer_Channel_Rate(void* channel, double rate);
70 int32_t Mixer_Channel_IsPlaying(void* channel);
71 uint64_t Mixer_Channel_GetOffset(void* channel);
72 int32_t Mixer_Channel_SetOffset(void* channel, uint64_t offset);
73 void Mixer_Channel_SetGroup(void* channel, OpenRCT2::Audio::MixerGroup group);
74 void* Mixer_Play_Music(int32_t pathId, int32_t loop, int32_t streaming);
75 void* Mixer_Play_Music(const char* path, int32_t loop);
76 void* Mixer_Play_Music(std::unique_ptr<OpenRCT2::IStream> stream, int32_t loop);
77 void Mixer_SetVolume(float volume);
78 
79 int32_t DStoMixerVolume(int32_t volume);
80 float DStoMixerPan(int32_t pan);
81 double DStoMixerRate(int32_t frequency);
82