Debian Codegraph @

sndlib/sdlsound.h

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
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 __LINUX_DD_SOUND_H_
20 #define __LINUX_DD_SOUND_H_
21
22 #include <SDL_audio.h>
23
24 #include "ssl_lib.h"
25 #include "mixer.h"
26
27 class sound_buffer_info;
28
29 void lnxsound_SetError(int code);
30 void lnxsound_ErrorText(const char *fmt, ...);
31 inline void sb_adjust_properties_2d(sound_buffer_info *sb, float f_volume, float f_pan, uint16_t frequency);
32
33 class emulated_listener {
34 public:
35 matrix orient;
36 vector position;
37 vector velocity;
38 };
39
40 class lnxsound : public llsSystem {
41 // Public functions
42 public:
43 lnxsound();
44 ~lnxsound();
45
46 // may be called before init (must be to be valid, the card passed here will be initialized in InitSoundLib)
47 void SetSoundCard(const char *name) override;
48 void PauseSound(int sound_uid) override;
49 void ResumeSound(int sound_uid) override;
50 // set special parameters for the 3d environment.
51 // of strcuture passed, you must set the appropriate 'flags' value for values you wish to modify
52 void SetEnvironmentValues(const t3dEnvironmentValues *env) override;
53
54 // get special parameters for the 3d environment.
55 // of strcuture passed, you must set the appropriate 'flags' value for values you wish to modify
56 void GetEnvironmentValues(t3dEnvironmentValues *env) override;
57
58 // enable special parameters for the 3d environment.
59 // of strcuture passed, you must set the appropriate 'flags' value for values you wish to modify
60 void SetEnvironmentToggles(const t3dEnvironmentToggles *env) override;
61
62 // get states of special parameters for the 3d environment.
63 // of strcuture passed, you must set the appropriate 'flags' value for values you wish to modify
64 void GetEnvironmentToggles(t3dEnvironmentToggles *env) override;
65
66 // Starts the sound library, maybe have it send back some information -- 3d support?
67 int InitSoundLib(char mixer_type, oeApplication *sos, uint8_t max_sounds_played) override;
68 // Cleans up after the Sound Library
69 void DestroySoundLib() override;
70
71 // Locks and unlocks sounds (used when changing play_info data)
72 bool LockSound(int sound_uid) override;
73 bool UnlockSound(int sound_uid) override;
74
75 bool SetSoundQuality(char quality) override;
76 char GetSoundQuality() override;
77 bool SetSoundMixer(char mixer_type) override;
78 char GetSoundMixer() override;
79
80 // Plays a 2d sound
81 int PlaySound2d(play_information *play_info, int sound_index, float volume, float pan, bool f_looped) override;
82 int PlayStream(play_information *play_info) override;
83
84 void SetListener(pos_state *cur_pos) override;
85 int PlaySound3d(play_information *play_info, int sound_index, pos_state *cur_pos, float master_volume,
86 bool f_looped, float reverb = 0.5f) override;
87 void AdjustSound(int sound_uid, float f_volume, float f_pan, uint16_t frequency) override;
88 void AdjustSound(int sound_uid, pos_state *cur_pos, float adjusted_volume, float reverb = 0.5f) override;
89
90 void StopAllSounds() override;
91
92 // Checks if a sound is playing (removes finished sound);
93 bool IsSoundInstancePlaying(int sound_uid) override;
94 int IsSoundPlaying(int sound_index) override;
95
96 // virtual void AdjustSound(int sound_uid, play_information *play_info) = 0;
97
98 // Stops 2d and 3d sounds
99 void StopSound(int sound_uid, uint8_t f_immediately = SKT_STOP_IMMEDIATELY) override;
100
101 // Pause all sounds/resume all sounds
102 void PauseSounds() override;
103 void ResumeSounds() override;
104 bool CheckAndForceSoundDataAlloc(int sound_file_index) override;
105
106 // Begin sound frame
107 void SoundStartFrame() override;
108
109 // End sound frame
110 void SoundEndFrame() override;
111
112 // returns the error string.
113 virtual const char *GetErrorStr() const;
114
115 // environmental sound interface
116 // volume modifier (0-1), damping(0-1), 1 = complete, 0 = none
117 // decay 0.1 to 100 seconds, how long it takes for a sound to die.
118 bool SetGlobalReverbProperties(float volume, float damping, float decay) override;
119
120 bool GetDeviceSettings(SDL_AudioDeviceID *sound_device, uint32_t *freq, uint32_t *bit_depth,
121 uint32_t *channels) const;
122
123 friend void lnxsound_SetError(int code);
124 friend void lnxsound_ErrorText(const char *fmt, ...);
125 friend inline void sb_adjust_properties_2d(sound_buffer_info *sb, float f_volume, float f_pan, uint16_t frequency);
126
127 protected:
128 #ifdef _DEBUG
129 int16_t FindFreeSoundSlot(int sound_index, float volume, int priority);
130 #else
131 int16_t FindFreeSoundSlot(float volume, int priority);
132 #endif
133 // This function limits the number of sounds cached to 255(8bits) and 256 bit is for invalid channel
134 // The purpose is to create unique signatures for each sound played (and allow for
135 // the slot_number to be quickly determined)
136 inline int MakeUniqueId(int sound_slot) const;
137 static inline int ValidateUniqueId(int sound_uid);
138
139 // Sound System Error Handler.
140 void CheckForErrors() override;
141
142 void StartStreaming();
143 void EndStreaming();
144
145 int m_primary_frequency; // Set to the primary buffers frequency -- cmphack
146 int m_primary_alignment;
147
148 SDL_AudioDeviceID sound_device;
149 bool in_at_exit;
150 bool m_in_sound_frame;
151 bool m_pending_actions;
152 char m_sound_quality;
153 float m_cache_stress_timer;
154 float m_timer_last_frametime;
155
156 int m_total_sounds_played;
157 int m_cur_sounds_played;
158
159 emulated_listener m_emulated_listener;
160
161 // Sam 6/29 - Added support for SDL
162 software_mixer m_mixer;
163 };
164
165 #endif