OpenMoHAA 0.82.0
Loading...
Searching...
No Matches
snd_openal_new.h
1/*
2===========================================================================
3Copyright (C) 2024 the OpenMoHAA team
4
5This file is part of OpenMoHAA source code.
6
7OpenMoHAA source code is free software; you can redistribute it
8and/or modify it under the terms of the GNU General Public License as
9published by the Free Software Foundation; either version 2 of the License,
10or (at your option) any later version.
11
12OpenMoHAA source code is distributed in the hope that it will be
13useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with OpenMoHAA source code; if not, write to the Free Software
19Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20===========================================================================
21*/
22
23#pragma once
24
25#include "qal.h"
26
27#undef OPENAL
28
29typedef int S32;
30typedef unsigned int U32;
31
32#define MAX_STREAM_BUFFERS 16
33#define MAX_BUFFER_SAMPLES 16384
34
35typedef enum {
36 FADE_NONE,
37 FADE_IN,
38 FADE_OUT
39} fade_t;
40
41typedef struct {
42 vec3_t vOrigin;
43 vec3_t vRelativeOrigin;
44 vec3_t vVelocity;
45
46 sfx_t *pSfx;
47 qboolean bPlaying;
48
49 int iChannel;
50 float fVolume;
51 float fPitch;
52
53 int iStartTime;
54 qboolean bInUse;
55 qboolean bCombine;
56
57 float fBaseVolume;
58 float fMinDist;
59 float fMaxDist;
60 int iFlags;
62
64 sfx_t *pSfx;
65 int iEntNum;
66 int iEntChannel;
67 vec3_t vOrigin;
68
69 float fVolume;
70 int iBaseRate;
71 float fNewPitchMult;
72 float fMinDist;
73 float fMaxDist;
74
75 int iStartTime;
76 int iTime;
77 int iEndTime;
78 int iFlags;
79 int iPausedOffset;
80
81 int song_number;
82
83 fade_t fading;
84 int fade_time;
85 int fade_start_time;
86
87 ALuint source;
88 ALuint buffer;
89 ALubyte *bufferdata;
90
91public:
92 void play();
93 virtual void stop();
94 void pause();
95
96 void set_no_3d();
97 void set_3d();
98 void set_no_virtualization();
99 void set_virtualization();
100
101 void set_gain(float gain);
102 void set_velocity(float v0, float v1, float v2);
103 void set_position(float v0, float v1, float v2);
104
105 bool is_free();
106 bool is_paused();
107 bool is_playing();
108
109 void force_free();
110 virtual bool set_sfx(sfx_t *pSfx);
111
112 void start_sample();
113 void stop_sample();
114 void resume_sample();
115 void end_sample();
116
117 void set_sample_pan(S32 pan);
118 void set_sample_playback_rate(S32 pan);
119 S32 sample_playback_rate();
120
121 S32 sample_volume();
122 virtual U32 sample_offset();
123 U32 sample_ms_offset();
124 U32 sample_loop_count();
125 virtual void set_sample_offset(U32 offset);
126 void set_sample_ms_offset(U32 offset);
127 virtual void set_sample_loop_count(S32 count);
128 void set_sample_loop_block(S32 start_offset, S32 end_offset);
129
130 U32 sample_status();
131
132public:
133 virtual void update();
134
135 virtual U32 buffer_frequency() const;
136};
137
138struct openal_channel_two_d_stream : public openal_channel {
139private:
140 char fileName[64];
141 void *streamHandle;
142 unsigned int buffers[MAX_STREAM_BUFFERS];
143 unsigned int currentBuf;
144 unsigned int sampleLoopCount;
145 unsigned int sampleLooped;
146 unsigned int streamNextOffset;
147 bool streaming;
148
149public:
150 openal_channel_two_d_stream();
151 ~openal_channel_two_d_stream();
152
153 void stop() override;
154 bool set_sfx(sfx_t *pSfx) override;
155 void set_sample_loop_count(S32 count) override;
156 void update() override;
157 U32 sample_offset() override;
158 void set_sample_offset(U32 offset) override;
159
160 bool queue_stream(const char *fileName);
161
162protected:
163 U32 buffer_frequency() const override;
164
165private:
166 void clear_stream();
167
168 unsigned int getQueueLength() const;
169 unsigned int getCurrentStreamPosition() const;
170 unsigned int getBitsPerSample() const;
171};
172
174
175};
176
178 openal_channel chan_3D[MAX_SOUNDSYSTEM_CHANNELS_3D];
179 openal_channel chan_2D[MAX_SOUNDSYSTEM_CHANNELS_2D];
180 openal_channel_two_d_stream chan_2D_stream[MAX_SOUNDSYSTEM_CHANNELS_2D_STREAM];
181 openal_channel_two_d_stream chan_song[MAX_SOUNDSYSTEM_SONGS];
183 openal_channel_two_d_stream chan_trig_music;
185
186 // Pointers to channels
187 openal_channel *channel[MAX_SOUNDSYSTEM_CHANNELS];
188
189 openal_loop_sound_t loop_sounds[MAX_SOUNDSYSTEM_LOOP_SOUNDS];
190
191 openal_channel movieChannel;
192 sfx_t movieSFX;
193
194 char tm_filename[MAX_RES_NAME];
195 int tm_loopcount;
196};
197
198#ifdef __cplusplus
199extern "C" {
200#endif
201
202 qboolean S_OPENAL_Init();
203 void S_OPENAL_Shutdown();
204 void S_OPENAL_StartSound(
205 const vec3_t vOrigin,
206 int iEntNum,
207 int iEntChannel,
208 sfxHandle_t sfxHandle,
209 float fVolume,
210 float fMinDist,
211 float fPitch,
212 float fMaxDist,
213 qboolean bStreamed
214 );
215 void S_OPENAL_AddLoopingSound(
216 const vec3_t vOrigin,
217 const vec3_t vVelocity,
218 sfxHandle_t sfxHandle,
219 float fVolume,
220 float fMinDist,
221 float fMaxDist,
222 float fPitch,
223 int iFlags
224 );
225 void S_OPENAL_ClearLoopingSounds();
226 void S_OPENAL_StopSound(int iEntNum, int iEntChannel);
227 void S_OPENAL_StopAllSounds(qboolean bStopMusic);
228 void S_OPENAL_Respatialize(int iEntNum, const vec3_t vHeadPos, const vec3_t vAxis[3]);
229 void S_OPENAL_SetReverb(int iType, float fLevel);
230 void S_OPENAL_Update();
231
232 const char *S_OPENAL_GetMusicFilename();
233 int S_OPENAL_GetMusicLoopCount();
234 unsigned int S_OPENAL_GetMusicOffset();
235
236#ifdef __cplusplus
237}
238#endif
Definition snd_openal_new.h:138
Definition snd_openal_new.h:63
Definition snd_openal_new.h:177
Definition snd_openal_new.h:41
Definition snd_openal_new.h:173