Debian Codegraph @

sndlib/ds3dlib_internal.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 --- HISTORICAL COMMENTS FOLLOW ---
19
20 * $Source: $
21 * $Revision: 9 $
22 * $Author: Samir $
23 * $Date: 8/23/99 5:29p $
24 *
25 * Win32 Sound Library Internal Header.
26 *
27 * $Log: /DescentIII/Main/dd_sndlib/ds3dlib_internal.h $
28 *
29 * 9 8/23/99 5:29p Samir
30 * incremental EAX 2.0 checkin
31 *
32 * 8 5/03/99 3:12a Samir
33 * fixed up aureal so it works (a little slow though...)
34 *
35 * 7 4/29/99 3:01p Samir
36 * added code for direct sound mixers only (and function for Aureal
37 * really) that will use direct sound looping for simple loops.
38 *
39 * 6 4/22/99 10:33p Samir
40 * modifications so that DirectSound mixers use one thread for all looping
41 * and streaming sounds. It worked without crashing for about twenty
42 * minutes of playing from level 1 to level 2 of D3. We'll see.
43 *
44 * 5 4/13/99 4:09p Samir
45 * more priority stuff.
46 *
47 * 4 4/12/99 7:14p Samir
48 * prioritization code added.
49 *
50 * 3 4/10/99 5:08p Samir
51 * took out obsolete data from play_information structure that should save
52 * around 70 bytes per instance.
53 *
54 * 2 4/06/99 8:29p Samir
55 * added error check system.
56 *
57 * 1 4/06/99 8:16p Samir
58 * Initial rev.
59 *
60 */
61
62 #ifndef DS3DLIB_INTERNAL_H
63 #define DS3DLIB_INTERNAL_H
64
65 #include <windows.h>
66 #include <mmsystem.h>
67
68 #include "win/directx/dsound.h"
69 #include "ssl_lib.h"
70
71 class win_llsSystem;
72
73 struct DSLOOPSTREAM {
74 uint8_t method; // method 0 for streamed method, 1 for emulated method
75 uint8_t playing;
76 uint8_t please_close;
77
78 union // dependant on method.
79 {
80 uint8_t close_on_next;
81 int8_t loop_step; // method 1, = 0 for start loop, 1 = mid loop, 2 = end loop.
82 };
83
84 union // dependant on method.
85 {
86 DWORD bytes_left;
87 float loop_timer; // method 1, time spent in current loop step
88 };
89
90 char *current_position; // used for streamed method
91 HANDLE hEvent; // used for event notification.
92 DWORD half_buffer_point;
93 DWORD last_half;
94 int num_written;
95 uint8_t time_slice;
96 bool kill_me;
97 bool f_sample_16bit;
98 char silence_byte;
99 };
100
101 struct DSSTREAM {
102 // These 2 pointers are the same on good sound cards
103 LPDIRECTSOUNDBUFFER m_lp_primary_buffer; // pointer to the primary sound buffer
104 LPDIRECTSOUNDBUFFER m_lp_looping_buffer; // pointer to the looping sound buffer
105 bool m_f_secondary_looping;
106
107 int BufferSize; // Size of the primary buffer
108
109 int MaxWriteSamples;
110 int MaxWriteBytes;
111
112 uintptr_t thread_handle;
113 // unsigned thread_id;
114 volatile bool thread_request_kill;
115 volatile bool thread_alive;
116
117 // Updating state variables
118 int NextWritePos; // Last bit position we wrote sound data to
119 int LastPlayPos; // Last bit position that the play pointer was recorded at
120
121 };
122
123 struct tPSBInfo {
124 float volume;
125 union {
126 float pan;
127 pos_state *cur_pos;
128 };
129 float reverb;
130 uint16_t freq;
131 uint16_t priority;
132 bool looping;
133 };
134
135 // Sound item info (cache list)
136 class sound_buffer_info {
137 public:
138 sound_buffer_info() {
139 m_status = SSF_UNUSED;
140 m_sound_buffer = NULL;
141 m_sound_buffer_3d = NULL;
142 s = NULL;
143 }
144
145 play_information *play_info;
146
147 int m_sound_index; // Index of sound
148 int m_unique_id; // Unique id for the currently playing sample
149
150 // Not needed by the software mixer
151 volatile DSLOOPSTREAM *s; // Streaming info for a looping sample
152 union {
153 LPDIRECTSOUNDBUFFER m_sound_buffer; // May be a pointer to a 2d or 3d sound buffer
154 void *m_snd_obj; // used for non direct sound systems.
155 };
156 LPDIRECTSOUND3DBUFFER m_sound_buffer_3d; // Used for 3d interface
157 LPKSPROPERTYSET m_lpksps; // used mainly for EAX 2.0 but is a direct sound object.
158
159 int16_t m_mixer_type; // aureal, ds3d, ds_8?
160 int16_t m_buffer_type; // Buffer type 2d or 3d
161
162 char *sample_data;
163 int sample_length; // used for storage purposes.
164
165 bool stereo;
166 int8_t bps;
167 uint8_t m_status; // Sound status
168 uint8_t pad;
169
170 float m_volume; // kept for priority.
171 };
172
173 // stop a sound buffer.
174 void sb_stop_buffer(sound_buffer_info *sb);
175
176 // frees a sound buffer.
177 void sb_free_buffer(sound_buffer_info *sb);
178
179 // load data into sound buffer
180 bool sb_load_buffer(sound_buffer_info *sb, void *sample_data, int length);
181
182 // update current position of sound buffer
183 int sb_get_current_position(sound_buffer_info *sb, uint32_t *writep);
184
185 // locks a sound buffer
186 bool sb_lock_buffer(sound_buffer_info *sb, uint32_t dwWriteCursor, uint32_t dwWriteBytes, void **lplpvAudioPtr1,
187 uint32_t *lpdwAudioBytes1, void **lplpvAudioPtr2, uint32_t *lpdwAudioBytes2);
188
189 // unlocks an allocated sound buffer
190 bool sb_unlock_buffer(sound_buffer_info *sb, void *ptr1, uint32_t len1, void *ptr2, uint32_t len2);
191
192 // this will initialize the looping thread
193 bool sb_loop_thread_init(win_llsSystem *lls);
194
195 // kill looped thread
196 void sb_loop_thread_kill();
197
198 // initializes a loop for the loop thread.
199 bool sb_loop_element_init(sound_buffer_info *sb, char *sample_ptr, int sound_length, int buffer_size);
200
201 // initialize streaming audio.
202 bool sb_stream_element_init(sound_buffer_info *sb, char *sample_ptr, int sound_length, int buffer_size);
203
204 // these work on both loops and streams.
205 void sb_loop_element_kill(sound_buffer_info *sb);
206 void sb_loop_element_wait_until_dead(sound_buffer_info *sb);
207
208 // these work on buffered streams only
209 void sb_stream_element_kill(sound_buffer_info *sb);
210 void sb_stream_buffered_update(sound_buffer_info *sb);
211
212 // used for buffered loops.
213 char *sb_get_loop_info(const sound_buffer_info *sb, int *loop_byte_start, int *loop_byte_end, bool *is_16_bit);
214 char *sb_get_loop_step_info(const sound_buffer_info *sb, int step, bool is16bit, int *length);
215 void sb_buffered_loop_step(win_llsSystem *lls, sound_buffer_info *sb, int force_next_step = -2);
216
217 #include "ds3dlib.h"
218 #include "ddsndgeometry.h"
219
220 #endif