| 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 | * $Logfile: /DescentIII/Main/streamaudio/streamaudio.cpp $ |
| 21 | * $Revision: 1.1.1.1 $ |
| 22 | * $Date: 2000/04/18 00:00:49 $ |
| 23 | * $Author: icculus $ |
| 24 | * |
| 25 | * Interface for streaming audio, compressed or not |
| 26 | * |
| 27 | * $Log: streamaudio.cpp,v $ |
| 28 | * Revision 1.1.1.1 2000/04/18 00:00:49 icculus |
| 29 | * initial checkin |
| 30 | * |
| 31 | * |
| 32 | * 44 9/29/99 5:13p Jeff |
| 33 | * Linux now has real stream audio |
| 34 | * |
| 35 | * 43 7/28/99 2:04p Kevin |
| 36 | * Macintosh Changes |
| 37 | * |
| 38 | * 41 5/17/99 1:56p Ardussi |
| 39 | * changed to compile on Mac |
| 40 | * |
| 41 | * 40 5/10/99 9:22p Samir |
| 42 | * added code to allow for certain streams to be specified to start on |
| 43 | * next sound frame. |
| 44 | * |
| 45 | * 39 4/29/99 3:03p Samir |
| 46 | * took out mprintfs and if we're opening an opened stream, close it and |
| 47 | * continue. |
| 48 | * |
| 49 | * 38 4/17/99 5:58a Jeff |
| 50 | * Changes for linux |
| 51 | * |
| 52 | * 37 4/14/99 1:48a Jeff |
| 53 | * fixed case mismatched #includes |
| 54 | * |
| 55 | * 36 4/10/99 5:09p Samir |
| 56 | * beginning to add prioritization of sounds code. currently non |
| 57 | * functional, but allows me to change all calls to Play3dSound so that I |
| 58 | * can test later. |
| 59 | * |
| 60 | * 35 3/22/99 5:12p Samir |
| 61 | * on shutdown, CLOSE any open streams. |
| 62 | * |
| 63 | * 34 3/17/99 4:22p Samir |
| 64 | * made pause and resume for streams work. |
| 65 | * |
| 66 | * 33 3/09/99 6:40p Jeff |
| 67 | * put try/catch around StreamPlay |
| 68 | * |
| 69 | * 32 3/04/99 6:38p Samir |
| 70 | * Saved stream state per frame. |
| 71 | * |
| 72 | * 31 3/03/99 5:08p Samir |
| 73 | * added slew of debug code: hopefully the library will be revamped after |
| 74 | * OEM. |
| 75 | * |
| 76 | * 30 3/01/99 8:11p Samir |
| 77 | * fixed bug when audio stream was playing while sound system shutdown. |
| 78 | * |
| 79 | * 29 2/28/99 6:35p Samir |
| 80 | * fixed streaming bugs for very small samples. |
| 81 | * |
| 82 | * 28 2/28/99 5:11p Nate |
| 83 | * added playcount. |
| 84 | * |
| 85 | * 27 2/27/99 6:52p Samir |
| 86 | * added function to get current loop count |
| 87 | * |
| 88 | * 26 2/26/99 8:34p Samir |
| 89 | * may have fixed problem with really small streams. |
| 90 | * |
| 91 | * 25 2/26/99 5:31p Samir |
| 92 | * |
| 93 | * 24 2/25/99 9:20p Kevin |
| 94 | * Semi fix for music in DS |
| 95 | * |
| 96 | * 23 2/17/99 8:35p Samir |
| 97 | * use m_streamdone to determine whether play should reset the stream or |
| 98 | * not. |
| 99 | * |
| 100 | * 22 12/13/98 6:50p Samir |
| 101 | * fixed problems with looping and next.switching sync. |
| 102 | * |
| 103 | * 21 12/11/98 5:25p Samir |
| 104 | * took out debug messages. |
| 105 | * |
| 106 | * 20 12/11/98 5:20p Samir |
| 107 | * perhaps prevent unused buffers from playing. |
| 108 | * |
| 109 | * 19 12/11/98 3:27p Samir |
| 110 | * add debug code. |
| 111 | * |
| 112 | * 18 12/10/98 7:12p Samir |
| 113 | * fixed some bugs in file/playback buffer sequencing with new system. |
| 114 | * |
| 115 | * 17 12/10/98 10:11a Samir |
| 116 | * newer streaming audio library. |
| 117 | * |
| 118 | * 11 11/20/98 5:20p Samir |
| 119 | * correcting a lot of errors in AudioStream::Next |
| 120 | * |
| 121 | * 10 11/13/98 4:03p Nate |
| 122 | * took out volume stuff from high level sound lib |
| 123 | * |
| 124 | * 9 11/13/98 2:25p Samir |
| 125 | * added 'next' stream processing. |
| 126 | * |
| 127 | * 9 11/13/98 10:48a Samir |
| 128 | * added 'next' stream capability. |
| 129 | * |
| 130 | * 8 10/23/98 7:04p Samir |
| 131 | * |
| 132 | * 7 10/23/98 6:45p Matt |
| 133 | * Scale the streaming audio volume by the master volume. |
| 134 | * |
| 135 | * 6 8/10/98 5:54p Samir |
| 136 | * added looping streams and soft measure stopping. |
| 137 | * |
| 138 | * 5 7/30/98 4:35p Dan |
| 139 | * more error checking. |
| 140 | * |
| 141 | * 4 7/30/98 10:57a Sean |
| 142 | * if no sound, then don't do anything. |
| 143 | * |
| 144 | * 3 7/24/98 5:18p Samir |
| 145 | * use OSFArchive for stream file operations now. |
| 146 | * |
| 147 | * 2 7/09/98 8:36p Samir |
| 148 | * fully implemented redo of Stream interface. |
| 149 | * |
| 150 | * 1 7/09/98 6:48p Samir |
| 151 | * |
| 152 | * MOVED FROM MAIN PROJECT |
| 153 | * |
| 154 | * 10 6/29/98 4:15p Chris |
| 155 | * Streaming audio works |
| 156 | * |
| 157 | * 9 6/24/98 5:00p Jeff |
| 158 | * set filehandle to null on close, short circuit read data if file handle |
| 159 | * is NULL |
| 160 | * |
| 161 | * 8 6/24/98 4:41p Jeff |
| 162 | * will kill the stream is the sound is killed |
| 163 | * |
| 164 | * |
| 165 | * $NoKeywords: $ |
| 166 | */ |
| 167 | |
| 168 | #include <cstdlib> |
| 169 | #include <cstring> |
| 170 | |
| 171 | #include "adecode.h"cxx . . $ `<file>/AudioEncode/adecode.h`/ |
| 172 | #include "cfile.h"cxx . . $ `<file>/cfile/cfile.h`/ |
| 173 | #include "ddio.h"cxx . . $ `<file>/ddio/ddio.h`/ |
| 174 | #include "Macros.h"cxx . . $ `<file>/lib/Macros.h`/ |
| 175 | #include "mem.h"cxx . . $ `<file>/mem/mem.h`/ |
| 176 | #include "pserror.h"cxx . . $ `<file>/misc/pserror.h`/ |
| 177 | #include "streamaudio.h"cxx . . $ `<file>/stream_audio/streamaudio.h`/ |
| 178 | |
| 179 | #define LOGFILEcxx . . $ `stream_audio/streamaudio.cpp:179:9`!(_s) |
| 180 | // this stream is for everyone (used by the StreamPlay interface) |
| 181 | static AudioStreamcxx . . $ AudioStream# User_audio_streamcxx . . $ User_audio_stream.; |
| 182 | llsSystemcxx . . $ llsSystem# *AudioStreamcxx . . $ AudioStream#::m_ll_sndsyscxx . . $ AudioStream#m_ll_sndsys. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 183 | AudioStreamcxx . . $ AudioStream# *AudioStreamcxx . . $ AudioStream#::m_streamscxx . . $ AudioStream#m_streams.[STRM_LIMITcxx . . $ `stream_audio/streamaudio.h:217:9`!]; |
| 184 | int AudioStreamcxx . . $ AudioStream#::m_thisidcxx . . $ AudioStream#m_thisid. = -1; |
| 185 | #define SAMPLES_PER_STREAM_SHORT_BUFcxx . . $ `stream_audio/streamaudio.cpp:185:9`! 22050 |
| 186 | #define SAMPLES_PER_STREAM_BUFcxx . . $ `stream_audio/streamaudio.cpp:186:9`! 44100 |
| 187 | // sets the low-level sound object |
| 188 | void AudioStreamcxx . . $ AudioStream#::InitSystemcxx . . $ AudioStream#InitSystem(81c6c6b1aaadc380).(llsSystemcxx . . $ llsSystem# *sndsys) { |
| 189 | int i; |
| 190 | AudioStreamcxx . . $ AudioStream#::m_ll_sndsyscxx . . $ AudioStream#m_ll_sndsys. = sndsys; |
| 191 | // reserve sound slots for streams, they should never get replaced, and always should be played. |
| 192 | for (i = 0; i < STRM_LIMITcxx . . $ `stream_audio/streamaudio.h:217:9`!; i++) { |
| 193 | AudioStreamcxx . . $ AudioStream#::m_streamscxx . . $ AudioStream#m_streams.[i] = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 194 | } |
| 195 | } |
| 196 | // shutdsown |
| 197 | void AudioStreamcxx . . $ AudioStream#::Shutdowncxx . . $ AudioStream#Shutdown(49f6e7a06ebc5aa8).() { |
| 198 | if (AudioStreamcxx . . $ AudioStream#::m_ll_sndsyscxx . . $ AudioStream#m_ll_sndsys.) { |
| 199 | int i; |
| 200 | // stop all streams. |
| 201 | for (i = 0; i < STRM_LIMITcxx . . $ `stream_audio/streamaudio.h:217:9`!; i++) { |
| 202 | if (AudioStreamcxx . . $ AudioStream#::m_streamscxx . . $ AudioStream#m_streams.[i]) { |
| 203 | AudioStreamcxx . . $ AudioStream#::m_streamscxx . . $ AudioStream#m_streams.[i]->Closecxx . . $ AudioStream#Close(49f6e7a06ebc5aa8).(); |
| 204 | AudioStreamcxx . . $ AudioStream#::m_streamscxx . . $ AudioStream#m_streams.[i] = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 205 | } |
| 206 | } |
| 207 | AudioStreamcxx . . $ AudioStream#::m_ll_sndsyscxx . . $ AudioStream#m_ll_sndsys. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 208 | } |
| 209 | } |
| 210 | // allocates a stream slot for a stream |
| 211 | bool AudioStreamcxx . . $ AudioStream#::ActivateStreamcxx . . $ AudioStream#ActivateStream(321490c9ed9e4edf).(AudioStreamcxx . . $ AudioStream# *stream) { |
| 212 | int i; |
| 213 | for (i = 0; i < STRM_LIMITcxx . . $ `stream_audio/streamaudio.h:217:9`!; i++) { |
| 214 | if (AudioStreamcxx . . $ AudioStream#::m_streamscxx . . $ AudioStream#m_streams.[i] == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) { |
| 215 | AudioStreamcxx . . $ AudioStream#::m_streamscxx . . $ AudioStream#m_streams.[i] = stream; |
| 216 | stream->m_streamindexcxx . . $ AudioStream#m_streamindex. = i; |
| 217 | return true; |
| 218 | } |
| 219 | } |
| 220 | mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "STRMAUD: AudioStream queue filled!\n"); |
| 221 | return false; |
| 222 | } |
| 223 | void AudioStreamcxx . . $ AudioStream#::DeactivateStreamcxx . . $ AudioStream#DeactivateStream(d2c77b78bb8a70f0).(AudioStreamcxx . . $ AudioStream# *stream) { |
| 224 | if (stream->m_streamindexcxx . . $ AudioStream#m_streamindex. > -1) { |
| 225 | AudioStreamcxx . . $ AudioStream#::m_streamscxx . . $ AudioStream#m_streams.[stream->m_streamindexcxx . . $ AudioStream#m_streamindex.] = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 226 | stream->m_streamindexcxx . . $ AudioStream#m_streamindex. = -1; |
| 227 | } |
| 228 | } |
| 229 | // called by application to allow stream playback |
| 230 | void AudioStreamcxx . . $ AudioStream#::Framecxx . . $ AudioStream#Frame(49f6e7a06ebc5aa8).() { |
| 231 | int t; |
| 232 | float time = timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!(); |
| 233 | if (!m_ll_sndsyscxx . . $ AudioStream#m_ll_sndsys.) |
| 234 | return; |
| 235 | for (t = 0; t < STRM_LIMITcxx . . $ `stream_audio/streamaudio.h:217:9`!; t++) { |
| 236 | if (AudioStreamcxx . . $ AudioStream#::m_streamscxx . . $ AudioStream#m_streams.[t]) { |
| 237 | AudioStreamcxx . . $ AudioStream# *strm = AudioStreamcxx . . $ AudioStream#::m_streamscxx . . $ AudioStream#m_streams.[t]; |
| 238 | if (strm->m_laststatecxx . . $ AudioStream#m_laststate. != strm->m_statecxx . . $ AudioStream#m_state.) { |
| 239 | LOGFILEcxx . . $ `stream_audio/streamaudio.cpp:179:9`!((_logfp, "STRM[%d]:frame_state=%d\n", strm->m_curid, strm->m_state)); |
| 240 | } |
| 241 | if (strm->m_statecxx . . $ AudioStream#m_state. == STRM_PLAYINGcxx . . $ `stream_audio/streamaudio.h:219:9`!) { |
| 242 | // see if the sound is still playing if it isn't then kill it (also if no more loops) |
| 243 | strm->m_measure_timercxx . . $ AudioStream#m_measure_timer. += (time - strm->m_last_frametimecxx . . $ AudioStream#m_last_frametime.); |
| 244 | if (strm->m_measure_timercxx . . $ AudioStream#m_measure_timer. >= strm->m_measure_timecxx . . $ AudioStream#m_measure_time.) { |
| 245 | strm->m_curmeasurecxx . . $ AudioStream#m_curmeasure.++; |
| 246 | } |
| 247 | strm->m_last_frametimecxx . . $ AudioStream#m_last_frametime. = time; |
| 248 | if (strm->m_statecxx . . $ AudioStream#m_state. == STRM_PLAYINGcxx . . $ `stream_audio/streamaudio.h:219:9`!) |
| 249 | strm->UpdateDatacxx . . $ AudioStream#UpdateData(49f6e7a06ebc5aa8).(); |
| 250 | } else if (strm->m_statecxx . . $ AudioStream#m_state. == STRM_STOPPINGcxx . . $ `stream_audio/streamaudio.h:221:9`!) { |
| 251 | if (!AudioStreamcxx . . $ AudioStream#::m_ll_sndsyscxx . . $ AudioStream#m_ll_sndsys.->IsSoundInstancePlayingcxx . . $ llsSystem#IsSoundInstancePlaying(83c267b20bac841a).(strm->m_llshandlecxx . . $ AudioStream#m_llshandle.)) { |
| 252 | strm->Stopcxx . . $ AudioStream#Stop(87564e930d06994).(); |
| 253 | // mprintf(0, "STRM[%d]: Stopped!\n", strm->m_curid); |
| 254 | LOGFILEcxx . . $ `stream_audio/streamaudio.cpp:179:9`!((_logfp, "STRM[%d]: Stopped!\n", strm->m_curid)); |
| 255 | if (CHECK_FLAGcxx . . $ `lib/Macros.h:63:9`!(strm->m_flags, STRM_OPNF_ONETIMEcxx . . $ `stream_audio/streamaudio.h:225:9`!)) { |
| 256 | strm->Closecxx . . $ AudioStream#Close(49f6e7a06ebc5aa8).(); |
| 257 | } |
| 258 | strm->m_readaheadcxx . . $ AudioStream#m_readahead. = false; |
| 259 | } |
| 260 | } else if (strm->m_statecxx . . $ AudioStream#m_state. == STRM_INVALIDcxx . . $ `stream_audio/streamaudio.h:223:9`!) { |
| 261 | strm->DeactivateStreamcxx . . $ AudioStream#DeactivateStream(d2c77b78bb8a70f0).(strm); |
| 262 | } else if (strm->m_start_on_framecxx . . $ AudioStream#m_start_on_frame.) { |
| 263 | strm->m_llshandlecxx . . $ AudioStream#m_llshandle. = m_ll_sndsyscxx . . $ AudioStream#m_ll_sndsys.->PlayStreamcxx . . $ llsSystem#PlayStream(c3f562479373c168).(&strm->m_playinfocxx . . $ AudioStream#m_playinfo.); |
| 264 | if (strm->m_llshandlecxx . . $ AudioStream#m_llshandle. > -1) { |
| 265 | // for one buffer samples, prepare to stop now so that the one and only one buffer gets called. |
| 266 | // looped one buffer samples dont do this though... |
| 267 | if (strm->m_nbufscxx . . $ AudioStream#m_nbufs. == 1 && !strm->m_start_on_frame_loopedcxx . . $ AudioStream#m_start_on_frame_looped.) { |
| 268 | strm->m_statecxx . . $ AudioStream#m_state. = STRM_STOPPINGcxx . . $ `stream_audio/streamaudio.h:221:9`!; |
| 269 | } else { |
| 270 | strm->m_statecxx . . $ AudioStream#m_state. = STRM_PLAYINGcxx . . $ `stream_audio/streamaudio.h:219:9`!; |
| 271 | } |
| 272 | } |
| 273 | strm->m_start_on_framecxx . . $ AudioStream#m_start_on_frame. = false; |
| 274 | strm->m_start_on_frame_loopedcxx . . $ AudioStream#m_start_on_frame_looped. = false; |
| 275 | } |
| 276 | strm->m_laststatecxx . . $ AudioStream#m_laststate. = strm->m_statecxx . . $ AudioStream#m_state.; |
| 277 | } |
| 278 | } |
| 279 | } |
| 280 | // called to pause all streams. |
| 281 | void AudioStreamcxx . . $ AudioStream#::PauseAllcxx . . $ AudioStream#PauseAll(49f6e7a06ebc5aa8).() { |
| 282 | int t; |
| 283 | for (t = 0; t < STRM_LIMITcxx . . $ `stream_audio/streamaudio.h:217:9`!; t++) { |
| 284 | if (AudioStreamcxx . . $ AudioStream#::m_streamscxx . . $ AudioStream#m_streams.[t]) { |
| 285 | AudioStreamcxx . . $ AudioStream#::m_streamscxx . . $ AudioStream#m_streams.[t]->Pausecxx . . $ AudioStream#Pause(49f6e7a06ebc5aa8).(); |
| 286 | } |
| 287 | } |
| 288 | } |
| 289 | void AudioStreamcxx . . $ AudioStream#::ResumeAllcxx . . $ AudioStream#ResumeAll(49f6e7a06ebc5aa8).() { |
| 290 | int t; |
| 291 | for (t = 0; t < STRM_LIMITcxx . . $ `stream_audio/streamaudio.h:217:9`!; t++) { |
| 292 | if (AudioStreamcxx . . $ AudioStream#::m_streamscxx . . $ AudioStream#m_streams.[t]) { |
| 293 | AudioStreamcxx . . $ AudioStream#::m_streamscxx . . $ AudioStream#m_streams.[t]->Resumecxx . . $ AudioStream#Resume(49f6e7a06ebc5aa8).(); |
| 294 | } |
| 295 | } |
| 296 | } |
| 297 | // AudioStream object Interface |
| 298 | // allows dynamic playing of streams |
| 299 | AudioStreamcxx . . $ AudioStream#::AudioStreamcxx . . $ AudioStream#AudioStream(49f6e7a06ebc5aa8).() { |
| 300 | m_decodercxx . . $ AudioStream#m_decoder. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; // audio decomp object |
| 301 | m_llshandlecxx . . $ AudioStream#m_llshandle. = -1; // snd system handle |
| 302 | m_sbufidxcxx . . $ AudioStream#m_sbufidx. = 0; // stream position markers for synching. |
| 303 | m_fbufidxcxx . . $ AudioStream#m_fbufidx. = 0; |
| 304 | m_flagscxx . . $ AudioStream#m_flags. = 0; |
| 305 | m_statecxx . . $ AudioStream#m_state. = STRM_INVALIDcxx . . $ `stream_audio/streamaudio.h:223:9`!; |
| 306 | m_streamindexcxx . . $ AudioStream#m_streamindex. = -1; |
| 307 | m_curmeasurecxx . . $ AudioStream#m_curmeasure. = -1; |
| 308 | m_stopnextmeasurecxx . . $ AudioStream#m_stopnextmeasure. = false; |
| 309 | m_stopflagcxx . . $ AudioStream#m_stopflag. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 310 | m_bytesleftcxx . . $ AudioStream#m_bytesleft. = 0; |
| 311 | m_readahead_finished_loopcxx . . $ AudioStream#m_readahead_finished_loop. = false; |
| 312 | m_playcountcxx . . $ AudioStream#m_playcount. = 0; |
| 313 | m_curidcxx . . $ AudioStream#m_curid. = -1; |
| 314 | m_nbufscxx . . $ AudioStream#m_nbufs. = 0; |
| 315 | m_start_on_framecxx . . $ AudioStream#m_start_on_frame. = false; |
| 316 | } |
| 317 | AudioStreamcxx . . $ AudioStream#::~cxx . . $ AudioStream#`~AudioStream`(ced63f7c635d850d).AudioStreamcxx . . $ AudioStream#() { AudioStreamcxx . . $ AudioStream#::Closecxx . . $ AudioStream#Close(49f6e7a06ebc5aa8).(); } |
| 318 | // sets flags for playback (STRM_OPNF_XXX) |
| 319 | void AudioStreamcxx . . $ AudioStream#::SetFlagscxx . . $ AudioStream#SetFlags(d4f767463ce0a6b3).(int flags) { m_flagscxx . . $ AudioStream#m_flags. = flags; } |
| 320 | void AudioStreamcxx . . $ AudioStream#::SetLoopCountcxx . . $ AudioStream#SetLoopCount(d4f767463ce0a6b3).(int loop_count) { |
| 321 | // if loop_count = 0, then m_loopcount= -1, infinite; |
| 322 | // if loop_count = 1, then m_loopcount=0, no looping, etc. |
| 323 | m_loopcountcxx . . $ AudioStream#m_loopcount. = loop_count - 1; |
| 324 | } |
| 325 | int AudioStreamcxx . . $ AudioStream#::GetLoopCountcxx . . $ AudioStream#GetLoopCount(455f465bc33b4cdf).() const { |
| 326 | // if loop_count = 0, then m_loopcount= -1, infinite; |
| 327 | // if loop_count = 1, then m_loopcount=0, no looping, etc. |
| 328 | return m_loopcountcxx . . $ AudioStream#m_loopcount. + 1; |
| 329 | } |
| 330 | void AudioStreamcxx . . $ AudioStream#::SetVolumecxx . . $ AudioStream#SetVolume(9364e6e7bff7660).(float vol) { |
| 331 | m_volumecxx . . $ AudioStream#m_volume. = vol; |
| 332 | if (m_ll_sndsyscxx . . $ AudioStream#m_ll_sndsys.) { |
| 333 | if (m_llshandlecxx . . $ AudioStream#m_llshandle. < 0) |
| 334 | return; |
| 335 | m_ll_sndsyscxx . . $ AudioStream#m_ll_sndsys.->AdjustSoundcxx . . $ llsSystem#AdjustSound(96ebaef3518743f8).(m_llshandlecxx . . $ AudioStream#m_llshandle., vol, 0.0f, m_playinfocxx . . $ AudioStream#m_playinfo..samples_per_22khz_samplecxx . . $ play_information#samples_per_22khz_sample. * 22050); |
| 336 | } |
| 337 | } |
| 338 | float AudioStreamcxx . . $ AudioStream#::GetVolumecxx . . $ AudioStream#GetVolume(9b8c9e39889c762c).() { return m_volumecxx . . $ AudioStream#m_volume.; } |
| 339 | // flags specify what type of stream it is. |
| 340 | bool AudioStreamcxx . . $ AudioStream#::Opencxx . . $ AudioStream#Open(2551bed5d6fc04f6).(const char *filename, int open_flags) { |
| 341 | // don't open a stream that's already open, or bogus filename |
| 342 | if (m_statecxx . . $ AudioStream#m_state. != STRM_INVALIDcxx . . $ `stream_audio/streamaudio.h:223:9`!) { |
| 343 | AudioStreamcxx . . $ AudioStream#::Closecxx . . $ AudioStream#Close(49f6e7a06ebc5aa8).(); |
| 344 | // Int3(); |
| 345 | // return false; |
| 346 | } |
| 347 | if (m_archivecxx . . $ AudioStream#m_archive..Openedcxx . . $ OSFArchive#Opened(50ce9a9e25b4a850).() || !filename) |
| 348 | return false; |
| 349 | if (!m_ll_sndsyscxx . . $ AudioStream#m_ll_sndsys.) |
| 350 | return false; |
| 351 | m_statecxx . . $ AudioStream#m_state. = STRM_INVALIDcxx . . $ `stream_audio/streamaudio.h:223:9`!; |
| 352 | m_streamindexcxx . . $ AudioStream#m_streamindex. = -1; |
| 353 | m_flagscxx . . $ AudioStream#m_flags. = open_flags; |
| 354 | m_curmeasurecxx . . $ AudioStream#m_curmeasure. = 0; |
| 355 | m_volumecxx . . $ AudioStream#m_volume. = 1.0f; |
| 356 | m_bufsizecxx . . $ AudioStream#m_bufsize. = SAMPLES_PER_STREAM_BUFcxx . . $ `stream_audio/streamaudio.cpp:186:9`! * 4; |
| 357 | m_measure_timercxx . . $ AudioStream#m_measure_timer. = 0.0f; |
| 358 | m_measure_timecxx . . $ AudioStream#m_measure_time. = 0.0f; |
| 359 | m_last_frametimecxx . . $ AudioStream#m_last_frametime. = 0.0f; |
| 360 | m_readahead_finished_loopcxx . . $ AudioStream#m_readahead_finished_loop. = false; |
| 361 | m_curidcxx . . $ AudioStream#m_curid. = -1; |
| 362 | m_nbufscxx . . $ AudioStream#m_nbufs. = 0; |
| 363 | m_start_on_framecxx . . $ AudioStream#m_start_on_frame. = m_start_on_frame_loopedcxx . . $ AudioStream#m_start_on_frame_looped. = false; |
| 364 | // open up stream file |
| 365 | if (m_archivecxx . . $ AudioStream#m_archive..Opencxx . . $ OSFArchive#Open(e96b1cf346ae2c6).(filename)) { |
| 366 | int i; |
| 367 | int nbufs; |
| 368 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(m_archive.StreamType() == OSF_DIGITAL_STRMcxx . . $ `stream_audio/streamaudio.h:159:9`!); |
| 369 | m_thisidcxx . . $ AudioStream#m_thisid.++; |
| 370 | m_curidcxx . . $ AudioStream#m_curid. = m_thisidcxx . . $ AudioStream#m_thisid.; |
| 371 | |
| 372 | for (i = 0; i < STRM_BUFCOUNTcxx . . $ `stream_audio/streamaudio.h:215:9`!; i++) { |
| 373 | m_buffercxx . . $ AudioStream#m_buffer.[i].flagscxx . . $ AudioStream#$anonymous_type_1#flags. = 0; |
| 374 | m_buffercxx . . $ AudioStream#m_buffer.[i].nbytescxx . . $ AudioStream#$anonymous_type_1#nbytes. = 0; |
| 375 | m_buffercxx . . $ AudioStream#m_buffer.[i].datacxx . . $ AudioStream#$anonymous_type_1#data. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 376 | m_buffercxx . . $ AudioStream#m_buffer.[i].idcxx . . $ AudioStream#$anonymous_type_1#id. = -1; // marks stream buffer to be allocated. |
| 377 | } |
| 378 | // gradual streams don't readahead yet. |
| 379 | nbufs = CHECK_FLAGcxx . . $ `lib/Macros.h:63:9`!(m_flags, STRM_OPNF_GRADUALcxx . . $ `stream_audio/streamaudio.h:226:9`!) ? 1 : STRM_BUFCOUNTcxx . . $ `stream_audio/streamaudio.h:215:9`!; |
| 380 | |
| 381 | if (!AudioStreamcxx . . $ AudioStream#::ReopenDigitalStreamcxx . . $ AudioStream#ReopenDigitalStream(355a5c9433db0802).(0, nbufs)) { |
| 382 | return false; |
| 383 | } |
| 384 | AudioStreamcxx . . $ AudioStream#::SetLoopCountcxx . . $ AudioStream#SetLoopCount(d4f767463ce0a6b3).(1); |
| 385 | m_laststatecxx . . $ AudioStream#m_laststate. = m_statecxx . . $ AudioStream#m_state.; |
| 386 | m_statecxx . . $ AudioStream#m_state. = STRM_STOPPEDcxx . . $ `stream_audio/streamaudio.h:218:9`!; |
| 387 | return true; |
| 388 | } |
| 389 | return false; |
| 390 | } |
| 391 | // deallocates all stream buffers and decoder. |
| 392 | void AudioStreamcxx . . $ AudioStream#::Closecxx . . $ AudioStream#Close(49f6e7a06ebc5aa8).() { |
| 393 | int i; |
| 394 | if (m_archivecxx . . $ AudioStream#m_archive..Openedcxx . . $ OSFArchive#Opened(50ce9a9e25b4a850).()) { |
| 395 | // stop the stream, close the archive, close the decoder. |
| 396 | AudioStreamcxx . . $ AudioStream#::Stopcxx . . $ AudioStream#Stop(87564e930d06994).(); |
| 397 | m_archivecxx . . $ AudioStream#m_archive..Closecxx . . $ OSFArchive#Close(49f6e7a06ebc5aa8).(); |
| 398 | m_curidcxx . . $ AudioStream#m_curid. = -1; |
| 399 | // free streaming buffers and decoder if we need to. |
| 400 | for (i = 0; i < STRM_BUFCOUNTcxx . . $ `stream_audio/streamaudio.h:215:9`!; i++) { |
| 401 | if (m_buffercxx . . $ AudioStream#m_buffer.[i].datacxx . . $ AudioStream#$anonymous_type_1#data.) { |
| 402 | mem_freecxx . . $ `mem/mem.h:80:9`!(m_buffer[i].data); |
| 403 | m_buffercxx . . $ AudioStream#m_buffer.[i].datacxx . . $ AudioStream#$anonymous_type_1#data. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 404 | m_buffercxx . . $ AudioStream#m_buffer.[i].nbytescxx . . $ AudioStream#$anonymous_type_1#nbytes. = 0; |
| 405 | m_buffercxx . . $ AudioStream#m_buffer.[i].flagscxx . . $ AudioStream#$anonymous_type_1#flags. = 0; |
| 406 | m_buffercxx . . $ AudioStream#m_buffer.[i].idcxx . . $ AudioStream#$anonymous_type_1#id. = -1; |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | if (m_decodercxx . . $ AudioStream#m_decoder.) { |
| 411 | delete m_decodercxx . . $ AudioStream#m_decoder.; |
| 412 | m_decodercxx . . $ AudioStream#m_decoder. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 413 | } |
| 414 | } |
| 415 | m_playcountcxx . . $ AudioStream#m_playcount. = 0; |
| 416 | m_nbufscxx . . $ AudioStream#m_nbufs. = 0; |
| 417 | m_statecxx . . $ AudioStream#m_state. = STRM_INVALIDcxx . . $ `stream_audio/streamaudio.h:223:9`!; |
| 418 | } |
| 419 | // has stream finished with its readahead of current loop? |
| 420 | bool AudioStreamcxx . . $ AudioStream#::ReadAheadFinishedLoopcxx . . $ AudioStream#ReadAheadFinishedLoop(c9857a73d68e59ba).() { |
| 421 | if (m_readahead_finished_loopcxx . . $ AudioStream#m_readahead_finished_loop.) { |
| 422 | m_readahead_finished_loopcxx . . $ AudioStream#m_readahead_finished_loop. = false; |
| 423 | return true; |
| 424 | } |
| 425 | return false; |
| 426 | } |
| 427 | // are we still reading from disk? |
| 428 | bool AudioStreamcxx . . $ AudioStream#::ReadAheadcxx . . $ AudioStream#ReadAhead(c9857a73d68e59ba).() { return m_readaheadcxx . . $ AudioStream#m_readahead.; } |
| 429 | bool AudioStreamcxx . . $ AudioStream#::IsReadycxx . . $ AudioStream#IsReady(c9857a73d68e59ba).() { |
| 430 | if (m_statecxx . . $ AudioStream#m_state. == STRM_STOPPEDcxx . . $ `stream_audio/streamaudio.h:218:9`!) { |
| 431 | if (!m_readaheadcxx . . $ AudioStream#m_readahead. || m_fbufidxcxx . . $ AudioStream#m_fbufidx. == (STRM_BUFCOUNTcxx . . $ `stream_audio/streamaudio.h:215:9`! - 1)) { |
| 432 | return true; |
| 433 | } |
| 434 | } |
| 435 | return false; |
| 436 | } |
| 437 | ////////////////////////////////////////////////////////////////////////////// |
| 438 | bool AudioStreamcxx . . $ AudioStream#::ReopenDigitalStreamcxx . . $ AudioStream#ReopenDigitalStream(355a5c9433db0802).(uint8_tcxx . . $ uint8_t# fbufidx, int nbufs) { |
| 439 | const tOSFDigiHdrcxx . . $ tOSFDigiHdr# *digihdr = (const tOSFDigiHdrcxx . . $ tOSFDigiHdr# *)m_archivecxx . . $ AudioStream#m_archive..StreamHeadercxx . . $ OSFArchive#StreamHeader(3a8ef3fdc6e817ef).(); |
| 440 | |
| 441 | m_bytesleftcxx . . $ AudioStream#m_bytesleft. = m_archivecxx . . $ AudioStream#m_archive..StreamLengthcxx . . $ OSFArchive#StreamLength(ddd8539a2fcdd4ce).(); |
| 442 | m_readaheadcxx . . $ AudioStream#m_readahead. = false; |
| 443 | |
| 444 | // free current decoder. |
| 445 | if (m_decodercxx . . $ AudioStream#m_decoder.) { |
| 446 | delete m_decodercxx . . $ AudioStream#m_decoder.; |
| 447 | m_decodercxx . . $ AudioStream#m_decoder. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 448 | } |
| 449 | |
| 450 | // instatiate decompression facility or use raw source data |
| 451 | uint32_tcxx . . $ uint32_t# sample_count = 0; |
| 452 | uint32_tcxx . . $ uint32_t# channels = 0; |
| 453 | if (m_archivecxx . . $ AudioStream#m_archive..StreamCompcxx . . $ OSFArchive#StreamComp(bd807b21b9713a30).() == OSF_DIGIACM_STRMcxx . . $ `stream_audio/streamaudio.h:162:9`!) { |
| 454 | uint32_tcxx . . $ uint32_t# sample_rate; |
| 455 | m_decodercxx . . $ AudioStream#m_decoder. = AudioDecodercxx . . $ AudioDecoder/::CreateDecodercxx . . $ AudioDecoder/CreateDecoder(8b054913a2e04880).(ADecodeFileReadcxx . . $ ADecodeFileRead(42dc92c764946a43)., this, channels, sample_rate, sample_count); |
| 456 | if (!m_decodercxx . . $ AudioStream#m_decoder.) { |
| 457 | delete m_decodercxx . . $ AudioStream#m_decoder.; |
| 458 | m_decodercxx . . $ AudioStream#m_decoder. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 459 | return false; |
| 460 | } |
| 461 | } else { |
| 462 | return false; |
| 463 | } |
| 464 | |
| 465 | // convert bufsize to true bufsize (bufsize = samples per measure for now.) |
| 466 | int bytesize, granularity; |
| 467 | switch (m_archivecxx . . $ AudioStream#m_archive..StreamFormatcxx . . $ OSFArchive#StreamFormat(bd807b21b9713a30).()) { |
| 468 | case SAF_8BIT_Mcxx . . $ `stream_audio/streamaudio.h:169:9`!: |
| 469 | granularity = 1; |
| 470 | break; |
| 471 | case SAF_8BIT_Scxx . . $ `stream_audio/streamaudio.h:170:9`!: |
| 472 | granularity = 2; |
| 473 | bytesize = digihdr->measurecxx . . $ tOSFDigiHdr#measure. << 1; |
| 474 | break; |
| 475 | case SAF_16BIT_Mcxx . . $ `stream_audio/streamaudio.h:171:9`!: |
| 476 | granularity = 2; |
| 477 | bytesize = digihdr->measurecxx . . $ tOSFDigiHdr#measure. << 1; |
| 478 | break; |
| 479 | case SAF_16BIT_Scxx . . $ `stream_audio/streamaudio.h:172:9`!: |
| 480 | granularity = 4; |
| 481 | bytesize = digihdr->measurecxx . . $ tOSFDigiHdr#measure. << 2; |
| 482 | break; |
| 483 | } |
| 484 | |
| 485 | // bufsize is bytes per measure. now scale according to memory requirements. |
| 486 | // clear out buffer list |
| 487 | if (channels == 0 || channels > 2) { |
| 488 | // weird, faulty osf |
| 489 | mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "STRM[%d]: Illegal OSF (no channels?): %d.\n", m_curid, channels); |
| 490 | LOGFILEcxx . . $ `stream_audio/streamaudio.cpp:179:9`!((_logfp, "STRM[%d]: Illegal OSF (no channels?): %d.\n", m_curid, channels)); |
| 491 | return false; |
| 492 | } |
| 493 | |
| 494 | int32_t bytes_per_buf = (SAMPLES_PER_STREAM_BUFcxx . . $ `stream_audio/streamaudio.cpp:186:9`! * granularity); |
| 495 | int32_t filelen = (sample_count / channels) * granularity; |
| 496 | int nbuffers = filelen / bytes_per_buf; |
| 497 | if (nbuffers >= 0 && nbuffers <= 1) { |
| 498 | if (filelen > 0) { |
| 499 | bytes_per_buf = (SAMPLES_PER_STREAM_SHORT_BUFcxx . . $ `stream_audio/streamaudio.cpp:185:9`! * granularity); |
| 500 | nbuffers = filelen / bytes_per_buf; |
| 501 | if (nbuffers == 0) |
| 502 | nbuffers = 1; |
| 503 | } else { |
| 504 | mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "STRM[%d]: Bad stream length %d\n", m_curid, filelen); |
| 505 | LOGFILEcxx . . $ `stream_audio/streamaudio.cpp:179:9`!((_logfp, "STRM[%d]: Bad stream length %d\n", m_curid, filelen)); |
| 506 | return false; |
| 507 | } |
| 508 | } |
| 509 | m_playbytestotalcxx . . $ AudioStream#m_playbytestotal. = filelen; |
| 510 | m_playbytesleftcxx . . $ AudioStream#m_playbytesleft. = filelen; |
| 511 | m_fbufidxcxx . . $ AudioStream#m_fbufidx. = fbufidx; |
| 512 | m_sbufidxcxx . . $ AudioStream#m_sbufidx. = 0; |
| 513 | // Get the file size, and figure out an ideal buffer size |
| 514 | // so our looping sounds don't have an odd silence in the middle |
| 515 | m_measure_timecxx . . $ AudioStream#m_measure_time. = (digihdr->measurecxx . . $ tOSFDigiHdr#measure. / 22050.0f); |
| 516 | m_bufsizecxx . . $ AudioStream#m_bufsize. = (filelen / nbuffers); |
| 517 | // figure out if we still need to be 4-byte aligned. |
| 518 | granularity = granularity >> 1; |
| 519 | if (granularity) { |
| 520 | if (m_bufsizecxx . . $ AudioStream#m_bufsize. % 4) { |
| 521 | m_bufsizecxx . . $ AudioStream#m_bufsize. = m_bufsizecxx . . $ AudioStream#m_bufsize. + (4 - (m_bufsizecxx . . $ AudioStream#m_bufsize. % 4)); |
| 522 | if (m_bufsizecxx . . $ AudioStream#m_bufsize. % 4) { |
| 523 | Int3cxx . . $ `misc/pserror.h:247:9`!(); |
| 524 | } |
| 525 | } |
| 526 | } |
| 527 | // mprintf(0,"STRM[%d]: Using buffer size of %d\n",m_curid, m_bufsize); |
| 528 | LOGFILEcxx . . $ `stream_audio/streamaudio.cpp:179:9`!((_logfp, "STRM[%d]: Using buffer size of %d\n", m_curid, m_bufsize)); |
| 529 | // mark stream as not done. |
| 530 | m_readaheadcxx . . $ AudioStream#m_readahead. = true; |
| 531 | m_readahead_finished_loopcxx . . $ AudioStream#m_readahead_finished_loop. = false; |
| 532 | if (!nbufs) { |
| 533 | // dont set m_readahead, because readahead only told this function whether it was going to do |
| 534 | // the read of buffers now, or let UpdateData do it later. |
| 535 | return true; |
| 536 | } |
| 537 | // fill buffers. |
| 538 | nbufs--; |
| 539 | while (!CHECK_FLAGcxx . . $ `lib/Macros.h:63:9`!(m_buffer[m_fbufidx].flags, STRM_BUFF_USEDcxx . . $ `stream_audio/streamaudio.h:230:9`!) && nbufs >= 0 && m_readaheadcxx . . $ AudioStream#m_readahead.) { |
| 540 | // if our stream's current id does not match the streaming buffer's id, then we need to reallocate |
| 541 | // the stream buffer with the new memory size |
| 542 | if (m_buffercxx . . $ AudioStream#m_buffer.[m_fbufidxcxx . . $ AudioStream#m_fbufidx.].idcxx . . $ AudioStream#$anonymous_type_1#id. != (int)m_curidcxx . . $ AudioStream#m_curid.) { |
| 543 | if (m_buffercxx . . $ AudioStream#m_buffer.[m_fbufidxcxx . . $ AudioStream#m_fbufidx.].datacxx . . $ AudioStream#$anonymous_type_1#data.) { |
| 544 | mem_freecxx . . $ `mem/mem.h:80:9`!(m_buffer[m_fbufidx].data); |
| 545 | } |
| 546 | m_buffercxx . . $ AudioStream#m_buffer.[m_fbufidxcxx . . $ AudioStream#m_fbufidx.].datacxx . . $ AudioStream#$anonymous_type_1#data. = (uint8_tcxx . . $ uint8_t# *)mem_malloccxx . . $ `mem/mem.h:79:9`!(m_bufsize); |
| 547 | } |
| 548 | m_buffercxx . . $ AudioStream#m_buffer.[m_fbufidxcxx . . $ AudioStream#m_fbufidx.].nbytescxx . . $ AudioStream#$anonymous_type_1#nbytes. = AudioStreamcxx . . $ AudioStream#::ReadFileDatacxx . . $ AudioStream#ReadFileData(9b79fb6aee4c0440).(m_fbufidxcxx . . $ AudioStream#m_fbufidx., m_bufsizecxx . . $ AudioStream#m_bufsize.); |
| 549 | m_buffercxx . . $ AudioStream#m_buffer.[m_fbufidxcxx . . $ AudioStream#m_fbufidx.].flagscxx . . $ AudioStream#$anonymous_type_1#flags. = 0; |
| 550 | m_buffercxx . . $ AudioStream#m_buffer.[m_fbufidxcxx . . $ AudioStream#m_fbufidx.].flagscxx . . $ AudioStream#$anonymous_type_1#flags. |= STRM_BUFF_USEDcxx . . $ `stream_audio/streamaudio.h:230:9`!; |
| 551 | m_buffercxx . . $ AudioStream#m_buffer.[m_fbufidxcxx . . $ AudioStream#m_fbufidx.].idcxx . . $ AudioStream#$anonymous_type_1#id. = m_thisidcxx . . $ AudioStream#m_thisid.; |
| 552 | m_playbytesleftcxx . . $ AudioStream#m_playbytesleft. -= m_buffercxx . . $ AudioStream#m_buffer.[m_fbufidxcxx . . $ AudioStream#m_fbufidx.].nbytescxx . . $ AudioStream#$anonymous_type_1#nbytes.; |
| 553 | // mprintf(0, "[%d]:pbytesleft=%d\n", m_curid, m_playbytesleft); |
| 554 | LOGFILEcxx . . $ `stream_audio/streamaudio.cpp:179:9`!((_logfp, "[%d]:pbytesleft=%d\n", m_curid, m_playbytesleft)); |
| 555 | if (m_playbytesleftcxx . . $ AudioStream#m_playbytesleft. <= (m_bufsizecxx . . $ AudioStream#m_bufsize. / 4)) { |
| 556 | // mprintf(0, "STRM[%d]: ", m_curid); |
| 557 | if (m_buffercxx . . $ AudioStream#m_buffer.[m_fbufidxcxx . . $ AudioStream#m_fbufidx.].nbytescxx . . $ AudioStream#$anonymous_type_1#nbytes. == 0) { |
| 558 | memset(m_buffercxx . . $ AudioStream#m_buffer.[m_fbufidxcxx . . $ AudioStream#m_fbufidx.].datacxx . . $ AudioStream#$anonymous_type_1#data., 0, 4); |
| 559 | m_buffercxx . . $ AudioStream#m_buffer.[m_fbufidxcxx . . $ AudioStream#m_fbufidx.].nbytescxx . . $ AudioStream#$anonymous_type_1#nbytes. = 4; |
| 560 | mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "making empty buffer and"); |
| 561 | } |
| 562 | // mprintf(0, "TERMINAL buffer.\n"); |
| 563 | LOGFILEcxx . . $ `stream_audio/streamaudio.cpp:179:9`!((_logfp, "STRM[%d] TERMINAL buffer. ", m_curid)); |
| 564 | m_buffercxx . . $ AudioStream#m_buffer.[m_fbufidxcxx . . $ AudioStream#m_fbufidx.].flagscxx . . $ AudioStream#$anonymous_type_1#flags. |= STRM_BUFF_TERMINALcxx . . $ `stream_audio/streamaudio.h:231:9`!; |
| 565 | m_readaheadcxx . . $ AudioStream#m_readahead. = false; |
| 566 | m_readahead_finished_loopcxx . . $ AudioStream#m_readahead_finished_loop. = true; |
| 567 | } |
| 568 | m_nbufscxx . . $ AudioStream#m_nbufs.++; |
| 569 | //@@ if (m_buffer[m_fbufidx].nbytes < m_bufsize || m_bytesleft == 0) { |
| 570 | //@@ if (m_buffer[m_fbufidx].nbytes == 0) { |
| 571 | //@@ memset(m_buffer[m_fbufidx].data, 0, 4); |
| 572 | //@@ m_buffer[m_fbufidx].nbytes = 4; |
| 573 | //@@ } |
| 574 | //@@ m_buffer[m_fbufidx].flags |= STRM_BUFF_TERMINAL; |
| 575 | //@@ m_readahead = false; |
| 576 | //@@ m_readahead_finished_loop = true; |
| 577 | //@@ } |
| 578 | m_fbufidxcxx . . $ AudioStream#m_fbufidx. = (m_fbufidxcxx . . $ AudioStream#m_fbufidx. + 1) % STRM_BUFCOUNTcxx . . $ `stream_audio/streamaudio.h:215:9`!; |
| 579 | } |
| 580 | // readjust file buffer index down so that it matches the CURRENT file index, not the next one. |
| 581 | if (m_fbufidxcxx . . $ AudioStream#m_fbufidx. == 0) |
| 582 | m_fbufidxcxx . . $ AudioStream#m_fbufidx. = STRM_BUFCOUNTcxx . . $ `stream_audio/streamaudio.h:215:9`! - 1; |
| 583 | else |
| 584 | m_fbufidxcxx . . $ AudioStream#m_fbufidx.--; |
| 585 | return true; |
| 586 | } |
| 587 | /////////////////////////////////////////////////////////////////////////////// |
| 588 | // plays a stream |
| 589 | bool AudioStreamcxx . . $ AudioStream#::Playcxx . . $ AudioStream#Play(efaadfb7dc14930a).(bool start_on_frame) { |
| 590 | // call low level stream manager. - samir |
| 591 | int sflag = SIF_STREAMING_16_Mcxx . . $ `sndlib/ssl_lib.h:385:9`!, i; |
| 592 | bool looped = false; |
| 593 | if (m_statecxx . . $ AudioStream#m_state. == STRM_INVALIDcxx . . $ `stream_audio/streamaudio.h:223:9`!) { |
| 594 | #ifdef WIN32 |
| 595 | Int3(); |
| 596 | #endif |
| 597 | return false; |
| 598 | } |
| 599 | // play stream if there's room to. |
| 600 | if (!ActivateStreamcxx . . $ AudioStream#ActivateStream(321490c9ed9e4edf).(this)) |
| 601 | return false; |
| 602 | switch (m_archivecxx . . $ AudioStream#m_archive..StreamFormatcxx . . $ OSFArchive#StreamFormat(bd807b21b9713a30).()) { |
| 603 | case SAF_8BIT_Mcxx . . $ `stream_audio/streamaudio.h:169:9`!: |
| 604 | sflag = SIF_STREAMING_8_Mcxx . . $ `sndlib/ssl_lib.h:384:9`!; |
| 605 | break; |
| 606 | case SAF_8BIT_Scxx . . $ `stream_audio/streamaudio.h:170:9`!: |
| 607 | sflag = SIF_STREAMING_8_Scxx . . $ `sndlib/ssl_lib.h:386:9`!; |
| 608 | break; |
| 609 | case SAF_16BIT_Mcxx . . $ `stream_audio/streamaudio.h:171:9`!: |
| 610 | sflag = SIF_STREAMING_16_Mcxx . . $ `sndlib/ssl_lib.h:385:9`!; |
| 611 | break; |
| 612 | case SAF_16BIT_Scxx . . $ `stream_audio/streamaudio.h:172:9`!: |
| 613 | sflag = SIF_STREAMING_16_Scxx . . $ `sndlib/ssl_lib.h:387:9`!; |
| 614 | break; |
| 615 | default: |
| 616 | Int3cxx . . $ `misc/pserror.h:247:9`!(); |
| 617 | return false; |
| 618 | } |
| 619 | // reset soft stopping. |
| 620 | m_stopnextmeasurecxx . . $ AudioStream#m_stopnextmeasure. = false; |
| 621 | m_curmeasurecxx . . $ AudioStream#m_curmeasure. = 0; |
| 622 | m_stopflagcxx . . $ AudioStream#m_stopflag. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 623 | if (m_statecxx . . $ AudioStream#m_state. != STRM_STOPPEDcxx . . $ `stream_audio/streamaudio.h:218:9`!) { |
| 624 | AudioStreamcxx . . $ AudioStream#::Stopcxx . . $ AudioStream#Stop(87564e930d06994).(); |
| 625 | } |
| 626 | if (m_playcountcxx . . $ AudioStream#m_playcount. > 0) { |
| 627 | AudioStreamcxx . . $ AudioStream#::Resetcxx . . $ AudioStream#Reset(49f6e7a06ebc5aa8).(); |
| 628 | } |
| 629 | m_playcountcxx . . $ AudioStream#m_playcount.++; |
| 630 | m_measure_timercxx . . $ AudioStream#m_measure_timer. = 0.0f; |
| 631 | m_last_frametimecxx . . $ AudioStream#m_last_frametime. = timer_GetTimecxx . . $ `ddio/ddio.h:236:9`!(); |
| 632 | // check for terminal and if loopcount != 0 then specify terminal as looping |
| 633 | if (m_loopcountcxx . . $ AudioStream#m_loopcount. != 0) { |
| 634 | for (i = 0; i < STRM_BUFCOUNTcxx . . $ `stream_audio/streamaudio.h:215:9`!; i++) { |
| 635 | if (CHECK_FLAGcxx . . $ `lib/Macros.h:63:9`!(m_buffer[i].flags, STRM_BUFF_USEDcxx . . $ `stream_audio/streamaudio.h:230:9`!)) { |
| 636 | if (CHECK_FLAGcxx . . $ `lib/Macros.h:63:9`!(m_buffer[i].flags, STRM_BUFF_TERMINALcxx . . $ `stream_audio/streamaudio.h:231:9`!)) { |
| 637 | if (m_loopcountcxx . . $ AudioStream#m_loopcount. == -1) { |
| 638 | m_buffercxx . . $ AudioStream#m_buffer.[m_fbufidxcxx . . $ AudioStream#m_fbufidx.].flagscxx . . $ AudioStream#$anonymous_type_1#flags. |= STRM_BUFF_LOOPENDcxx . . $ `stream_audio/streamaudio.h:232:9`!; |
| 639 | looped = true; |
| 640 | AudioStreamcxx . . $ AudioStream#::Resetcxx . . $ AudioStream#Reset(49f6e7a06ebc5aa8).(); |
| 641 | } else if (m_loopcountcxx . . $ AudioStream#m_loopcount. > 0) { |
| 642 | m_buffercxx . . $ AudioStream#m_buffer.[m_fbufidxcxx . . $ AudioStream#m_fbufidx.].flagscxx . . $ AudioStream#$anonymous_type_1#flags. |= STRM_BUFF_LOOPENDcxx . . $ `stream_audio/streamaudio.h:232:9`!; |
| 643 | looped = true; |
| 644 | AudioStreamcxx . . $ AudioStream#::Resetcxx . . $ AudioStream#Reset(49f6e7a06ebc5aa8).(); |
| 645 | m_loopcountcxx . . $ AudioStream#m_loopcount.--; |
| 646 | } |
| 647 | m_readahead_finished_loopcxx . . $ AudioStream#m_readahead_finished_loop. = true; |
| 648 | } |
| 649 | } |
| 650 | } |
| 651 | } |
| 652 | // if (m_curid == 3) Int3(); |
| 653 | // invoke low level sound system. |
| 654 | memset(&m_playinfocxx . . $ AudioStream#m_playinfo., 0, sizeof(m_playinfocxx . . $ AudioStream#m_playinfo.)); |
| 655 | m_playinfocxx . . $ AudioStream#m_playinfo..samples_per_22khz_samplecxx . . $ play_information#samples_per_22khz_sample. = 1.0; |
| 656 | m_playinfocxx . . $ AudioStream#m_playinfo..sample_skip_intervalcxx . . $ play_information#sample_skip_interval. = 0; |
| 657 | m_playinfocxx . . $ AudioStream#m_playinfo..m_stream_cbackcxx . . $ play_information#m_stream_cback. = AudioStreamCBcxx . . $ AudioStreamCB(9326456ed2624211).; |
| 658 | m_playinfocxx . . $ AudioStream#m_playinfo..m_stream_datacxx . . $ play_information#m_stream_data. = m_buffercxx . . $ AudioStream#m_buffer.[m_sbufidxcxx . . $ AudioStream#m_sbufidx.].datacxx . . $ AudioStream#$anonymous_type_1#data.; |
| 659 | m_playinfocxx . . $ AudioStream#m_playinfo..m_stream_formatcxx . . $ play_information#m_stream_format. = sflag; |
| 660 | m_playinfocxx . . $ AudioStream#m_playinfo..m_stream_sizecxx . . $ play_information#m_stream_size. = m_buffercxx . . $ AudioStream#m_buffer.[m_sbufidxcxx . . $ AudioStream#m_sbufidx.].nbytescxx . . $ AudioStream#$anonymous_type_1#nbytes.; |
| 661 | m_playinfocxx . . $ AudioStream#m_playinfo..m_stream_handlecxx . . $ play_information#m_stream_handle. = m_streamindexcxx . . $ AudioStream#m_streamindex.; |
| 662 | m_playinfocxx . . $ AudioStream#m_playinfo..m_stream_bufsizecxx . . $ play_information#m_stream_bufsize. = m_bufsizecxx . . $ AudioStream#m_bufsize.; |
| 663 | m_playinfocxx . . $ AudioStream#m_playinfo..user_datacxx . . $ play_information#user_data. = this; |
| 664 | m_playinfocxx . . $ AudioStream#m_playinfo..left_volumecxx . . $ play_information#left_volume. = m_playinfocxx . . $ AudioStream#m_playinfo..right_volumecxx . . $ play_information#right_volume. = m_volumecxx . . $ AudioStream#m_volume.; |
| 665 | m_playinfocxx . . $ AudioStream#m_playinfo..prioritycxx . . $ play_information#priority. = SND_PRIORITY_CRITICALcxx . . $ `sndlib/ssl_lib.h:281:9`!; // this stream must play. |
| 666 | m_start_on_framecxx . . $ AudioStream#m_start_on_frame. = start_on_frame; |
| 667 | m_start_on_frame_loopedcxx . . $ AudioStream#m_start_on_frame_looped. = looped; |
| 668 | if (!m_start_on_framecxx . . $ AudioStream#m_start_on_frame.) { |
| 669 | m_llshandlecxx . . $ AudioStream#m_llshandle. = m_ll_sndsyscxx . . $ AudioStream#m_ll_sndsys.->PlayStreamcxx . . $ llsSystem#PlayStream(c3f562479373c168).(&m_playinfocxx . . $ AudioStream#m_playinfo.); |
| 670 | if (m_llshandlecxx . . $ AudioStream#m_llshandle. > -1) { |
| 671 | // for one buffer samples, prepare to stop now so that the one and only one buffer gets called. |
| 672 | // looped one buffer samples dont do this though... |
| 673 | if (m_nbufscxx . . $ AudioStream#m_nbufs. == 1 && !looped) { |
| 674 | m_statecxx . . $ AudioStream#m_state. = STRM_STOPPINGcxx . . $ `stream_audio/streamaudio.h:221:9`!; |
| 675 | } else { |
| 676 | m_statecxx . . $ AudioStream#m_state. = STRM_PLAYINGcxx . . $ `stream_audio/streamaudio.h:219:9`!; |
| 677 | } |
| 678 | return true; |
| 679 | } else { |
| 680 | mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "STRMAUD:Eh? this should be reserved??\n"); |
| 681 | Int3cxx . . $ `misc/pserror.h:247:9`!(); |
| 682 | } |
| 683 | } |
| 684 | return true; |
| 685 | } |
| 686 | // pauses a stream |
| 687 | void AudioStreamcxx . . $ AudioStream#::Pausecxx . . $ AudioStream#Pause(49f6e7a06ebc5aa8).() { |
| 688 | if (m_statecxx . . $ AudioStream#m_state. != STRM_PLAYINGcxx . . $ `stream_audio/streamaudio.h:219:9`!) { |
| 689 | return; |
| 690 | } |
| 691 | m_statecxx . . $ AudioStream#m_state. = STRM_PAUSEDcxx . . $ `stream_audio/streamaudio.h:220:9`!; |
| 692 | m_ll_sndsyscxx . . $ AudioStream#m_ll_sndsys.->PauseSoundcxx . . $ llsSystem#PauseSound(d4f767463ce0a6b3).(m_llshandlecxx . . $ AudioStream#m_llshandle.); |
| 693 | // mprintf(0, "Paused stream (%d)\n", m_llshandle); |
| 694 | } |
| 695 | // pauses a stream |
| 696 | void AudioStreamcxx . . $ AudioStream#::Resumecxx . . $ AudioStream#Resume(49f6e7a06ebc5aa8).() { |
| 697 | if (m_statecxx . . $ AudioStream#m_state. != STRM_PAUSEDcxx . . $ `stream_audio/streamaudio.h:220:9`!) { |
| 698 | return; |
| 699 | } |
| 700 | m_ll_sndsyscxx . . $ AudioStream#m_ll_sndsys.->ResumeSoundcxx . . $ llsSystem#ResumeSound(d4f767463ce0a6b3).(m_llshandlecxx . . $ AudioStream#m_llshandle.); |
| 701 | m_statecxx . . $ AudioStream#m_state. = STRM_PLAYINGcxx . . $ `stream_audio/streamaudio.h:219:9`!; |
| 702 | // mprintf(0, "Resumed stream (%d)\n", m_llshandle); |
| 703 | } |
| 704 | // causes a rewind to start of stream, if on_measure is true, stop occurs when measure ends |
| 705 | void AudioStreamcxx . . $ AudioStream#::Stopcxx . . $ AudioStream#Stop(87564e930d06994).(bool on_measure, int *stop_flag) { |
| 706 | if (!m_ll_sndsyscxx . . $ AudioStream#m_ll_sndsys.) { |
| 707 | return; |
| 708 | } |
| 709 | m_start_on_framecxx . . $ AudioStream#m_start_on_frame. = false; |
| 710 | if (m_statecxx . . $ AudioStream#m_state. == STRM_INVALIDcxx . . $ `stream_audio/streamaudio.h:223:9`!) { |
| 711 | if (stop_flag) { |
| 712 | *stop_flag = true; |
| 713 | } |
| 714 | return; |
| 715 | } |
| 716 | if (m_statecxx . . $ AudioStream#m_state. != STRM_STOPPEDcxx . . $ `stream_audio/streamaudio.h:218:9`!) { |
| 717 | if (!on_measure) { |
| 718 | if (m_statecxx . . $ AudioStream#m_state. == STRM_PLAYINGcxx . . $ `stream_audio/streamaudio.h:219:9`! || m_statecxx . . $ AudioStream#m_state. == STRM_PAUSEDcxx . . $ `stream_audio/streamaudio.h:220:9`! || m_statecxx . . $ AudioStream#m_state. == STRM_STOPPINGcxx . . $ `stream_audio/streamaudio.h:221:9`!) { |
| 719 | m_ll_sndsyscxx . . $ AudioStream#m_ll_sndsys.->StopSoundcxx . . $ llsSystem#StopSound(9633529ce3c4ff50).(m_llshandlecxx . . $ AudioStream#m_llshandle., SKT_STOP_IMMEDIATELYcxx . . $ `sndlib/ssl_lib.h:406:9`!); |
| 720 | m_statecxx . . $ AudioStream#m_state. = STRM_STOPPEDcxx . . $ `stream_audio/streamaudio.h:218:9`!; |
| 721 | m_readaheadcxx . . $ AudioStream#m_readahead. = m_readahead_finished_loopcxx . . $ AudioStream#m_readahead_finished_loop. = true; |
| 722 | DeactivateStreamcxx . . $ AudioStream#DeactivateStream(d2c77b78bb8a70f0).(this); |
| 723 | m_llshandlecxx . . $ AudioStream#m_llshandle. = -1; |
| 724 | m_curmeasurecxx . . $ AudioStream#m_curmeasure. = 0; |
| 725 | } |
| 726 | } else { |
| 727 | // handle soft stopping. |
| 728 | m_stopflagcxx . . $ AudioStream#m_stopflag. = stop_flag; |
| 729 | if (m_stopflagcxx . . $ AudioStream#m_stopflag.) { |
| 730 | *m_stopflagcxx . . $ AudioStream#m_stopflag. = false; |
| 731 | } |
| 732 | m_stopnextmeasurecxx . . $ AudioStream#m_stopnextmeasure. = on_measure; |
| 733 | } |
| 734 | } else { |
| 735 | DeactivateStreamcxx . . $ AudioStream#DeactivateStream(d2c77b78bb8a70f0).(this); |
| 736 | m_llshandlecxx . . $ AudioStream#m_llshandle. = -1; |
| 737 | m_curmeasurecxx . . $ AudioStream#m_curmeasure. = 0; |
| 738 | if (m_stopflagcxx . . $ AudioStream#m_stopflag.) { |
| 739 | *m_stopflagcxx . . $ AudioStream#m_stopflag. = true; |
| 740 | } |
| 741 | } |
| 742 | } |
| 743 | // performs a clean stop and play when switching to next stream |
| 744 | void AudioStreamcxx . . $ AudioStream#::Resetcxx . . $ AudioStream#Reset(49f6e7a06ebc5aa8).() { |
| 745 | m_archivecxx . . $ AudioStream#m_archive..Rewindcxx . . $ OSFArchive#Rewind(49f6e7a06ebc5aa8).(); |
| 746 | m_bytesleftcxx . . $ AudioStream#m_bytesleft. = m_archivecxx . . $ AudioStream#m_archive..StreamLengthcxx . . $ OSFArchive#StreamLength(ddd8539a2fcdd4ce).(); |
| 747 | m_curmeasurecxx . . $ AudioStream#m_curmeasure. = 0; |
| 748 | m_readaheadcxx . . $ AudioStream#m_readahead. = true; |
| 749 | m_playbytesleftcxx . . $ AudioStream#m_playbytesleft. = m_playbytestotalcxx . . $ AudioStream#m_playbytestotal.; |
| 750 | if (m_decodercxx . . $ AudioStream#m_decoder.) { |
| 751 | delete m_decodercxx . . $ AudioStream#m_decoder.; |
| 752 | |
| 753 | uint32_tcxx . . $ uint32_t# channels; |
| 754 | uint32_tcxx . . $ uint32_t# sample_rate; |
| 755 | uint32_tcxx . . $ uint32_t# sample_count; |
| 756 | m_decodercxx . . $ AudioStream#m_decoder. = AudioDecodercxx . . $ AudioDecoder/::CreateDecodercxx . . $ AudioDecoder/CreateDecoder(8b054913a2e04880).(ADecodeFileReadcxx . . $ ADecodeFileRead(42dc92c764946a43)., this, channels, sample_rate, sample_count); |
| 757 | } |
| 758 | } |
| 759 | ////////////////////////////////////////////////////////////////////////////// |
| 760 | // invoked by AudioStreamCB. |
| 761 | #pragma optimize("", off) |
| 762 | void *AudioStreamcxx . . $ AudioStream#::StreamCallbackcxx . . $ AudioStream#StreamCallback(5b9d5e032d1f146d).(int *size) { |
| 763 | uint8_tcxx . . $ uint8_t# nextbuffer = (m_sbufidxcxx . . $ AudioStream#m_sbufidx. + 1) % STRM_BUFCOUNTcxx . . $ `stream_audio/streamaudio.h:215:9`!; |
| 764 | void *data = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 765 | // we're not done yet. |
| 766 | // adjust sound buffer to the next buffer |
| 767 | if (m_statecxx . . $ AudioStream#m_state. == STRM_STOPPINGcxx . . $ `stream_audio/streamaudio.h:221:9`! || m_statecxx . . $ AudioStream#m_state. == STRM_STOPPEDcxx . . $ `stream_audio/streamaudio.h:218:9`!) { |
| 768 | if (m_statecxx . . $ AudioStream#m_state. == STRM_STOPPEDcxx . . $ `stream_audio/streamaudio.h:218:9`!) { |
| 769 | // mprintf(0, "STRM[%d]: Callback entered while stopping! Force stop.\n", m_curid); |
| 770 | LOGFILEcxx . . $ `stream_audio/streamaudio.cpp:179:9`!((_logfp, "STRM[%d]: Callback entered while stopping! Force stop.\n", m_curid)); |
| 771 | } else { |
| 772 | // mprintf(0, "STRM[%d]: Stopping softly\n", m_curid); |
| 773 | LOGFILEcxx . . $ `stream_audio/streamaudio.cpp:179:9`!((_logfp, "STRM[%d]: Stopping softly\n", m_curid)); |
| 774 | // if (m_curid == 3) Int3(); |
| 775 | } |
| 776 | // mark played buffer as unused. |
| 777 | m_buffercxx . . $ AudioStream#m_buffer.[m_sbufidxcxx . . $ AudioStream#m_sbufidx.].flagscxx . . $ AudioStream#$anonymous_type_1#flags. = 0; |
| 778 | m_buffercxx . . $ AudioStream#m_buffer.[m_sbufidxcxx . . $ AudioStream#m_sbufidx.].nbytescxx . . $ AudioStream#$anonymous_type_1#nbytes. = 0; |
| 779 | *size = 0; |
| 780 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 781 | } |
| 782 | if (!CHECK_FLAGcxx . . $ `lib/Macros.h:63:9`!(m_buffer[nextbuffer].flags, STRM_BUFF_USEDcxx . . $ `stream_audio/streamaudio.h:230:9`!)) { |
| 783 | // mprintf(0, "STRM[%d]: Playing onetime buffer?\n",m_curid); |
| 784 | LOGFILEcxx . . $ `stream_audio/streamaudio.cpp:179:9`!((_logfp, "STRM[%d]: Playing onetime buffer?\n", m_curid)); |
| 785 | m_statecxx . . $ AudioStream#m_state. = STRM_STOPPEDcxx . . $ `stream_audio/streamaudio.h:218:9`!; |
| 786 | *size = 0; |
| 787 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 788 | //@@ mprintf(0, "STRMAUD: Repeating last buffer.\n"); |
| 789 | //@@ data = (void *)m_buffer[m_sbufidx].data; |
| 790 | //@@ *size = m_buffer[m_sbufidx].nbytes; |
| 791 | //@@ return data; |
| 792 | } |
| 793 | // mark played buffer as unused. |
| 794 | m_buffercxx . . $ AudioStream#m_buffer.[m_sbufidxcxx . . $ AudioStream#m_sbufidx.].flagscxx . . $ AudioStream#$anonymous_type_1#flags. = 0; |
| 795 | m_buffercxx . . $ AudioStream#m_buffer.[m_sbufidxcxx . . $ AudioStream#m_sbufidx.].nbytescxx . . $ AudioStream#$anonymous_type_1#nbytes. = 0; |
| 796 | m_sbufidxcxx . . $ AudioStream#m_sbufidx. = nextbuffer; |
| 797 | // ASSERT(CHECK_FLAG(m_buffer[m_sbufidx].flags, STRM_BUFF_USED)); |
| 798 | // mprintf(0,"%c",m_sbufidx+'A'); |
| 799 | // increment measure count if we've entered a new measure. |
| 800 | // if stop measure has been flagged, don't return new valid data. |
| 801 | // make sure and lock mutex, because we're modifying these contents when the caller could |
| 802 | // do the same. |
| 803 | // if we reached the last buffer in an opened stream, and we're not switching prepare to stop |
| 804 | // if we are switching, release the switch lock and continue |
| 805 | // otherwise just continue. |
| 806 | data = (void *)m_buffercxx . . $ AudioStream#m_buffer.[m_sbufidxcxx . . $ AudioStream#m_sbufidx.].datacxx . . $ AudioStream#$anonymous_type_1#data.; |
| 807 | *size = m_buffercxx . . $ AudioStream#m_buffer.[m_sbufidxcxx . . $ AudioStream#m_sbufidx.].nbytescxx . . $ AudioStream#$anonymous_type_1#nbytes.; |
| 808 | // ASSERT((*size) > 0); |
| 809 | if (CHECK_FLAGcxx . . $ `lib/Macros.h:63:9`!(m_buffer[m_sbufidx].flags, STRM_BUFF_TERMINALcxx . . $ `stream_audio/streamaudio.h:231:9`!)) { |
| 810 | // mprintf(0, "STRMAUD: reached end of stream (%d bytes).\n", (*size)); |
| 811 | if (!CHECK_FLAGcxx . . $ `lib/Macros.h:63:9`!(m_buffer[m_sbufidx].flags, STRM_BUFF_LOOPENDcxx . . $ `stream_audio/streamaudio.h:232:9`!)) { |
| 812 | m_statecxx . . $ AudioStream#m_state. = STRM_STOPPINGcxx . . $ `stream_audio/streamaudio.h:221:9`!; |
| 813 | } |
| 814 | if (m_stopnextmeasurecxx . . $ AudioStream#m_stopnextmeasure.) { |
| 815 | m_statecxx . . $ AudioStream#m_state. = STRM_STOPPINGcxx . . $ `stream_audio/streamaudio.h:221:9`!; |
| 816 | } |
| 817 | // mprintf(0, "STRM[%d]: Start stopping softly\n", m_curid); |
| 818 | LOGFILEcxx . . $ `stream_audio/streamaudio.cpp:179:9`!((_logfp, "STRM[%d]: Start stopping softly\n", m_curid)); |
| 819 | // *done = true; |
| 820 | } |
| 821 | if ((*size) == 0) { |
| 822 | // *done = true; |
| 823 | // mprintf(0, "STRM[%d]: Used buffer has 0 bytes!\n", m_curid); |
| 824 | LOGFILEcxx . . $ `stream_audio/streamaudio.cpp:179:9`!((_logfp, "STRM[%d]: Used buffer has 0 bytes!\n", m_curid)); |
| 825 | m_statecxx . . $ AudioStream#m_state. = STRM_STOPPINGcxx . . $ `stream_audio/streamaudio.h:221:9`!; |
| 826 | data = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 827 | } |
| 828 | return data; |
| 829 | } |
| 830 | #pragma optimize("", on) |
| 831 | // reads in decompressed raw data. |
| 832 | int AudioStreamcxx . . $ AudioStream#::ReadFileDatacxx . . $ AudioStream#ReadFileData(9b79fb6aee4c0440).(int buf, int len) { |
| 833 | if (!m_archivecxx . . $ AudioStream#m_archive..Openedcxx . . $ OSFArchive#Opened(50ce9a9e25b4a850).()) |
| 834 | return 0; |
| 835 | |
| 836 | if (m_decodercxx . . $ AudioStream#m_decoder.) { |
| 837 | // We have a compressed stream |
| 838 | return m_decodercxx . . $ AudioStream#m_decoder.->Readcxx . . $ AudioDecoder/IAudioDecoder#Read(35feec062aeef876).(m_buffercxx . . $ AudioStream#m_buffer.[buf].datacxx . . $ AudioStream#$anonymous_type_1#data., len); |
| 839 | } |
| 840 | |
| 841 | // We have a non-compressed stream |
| 842 | if (len > m_bytesleftcxx . . $ AudioStream#m_bytesleft.) { |
| 843 | len = m_bytesleftcxx . . $ AudioStream#m_bytesleft.; |
| 844 | m_bytesleftcxx . . $ AudioStream#m_bytesleft. = 0; |
| 845 | } else { |
| 846 | m_bytesleftcxx . . $ AudioStream#m_bytesleft. -= len; |
| 847 | } |
| 848 | |
| 849 | return m_archivecxx . . $ AudioStream#m_archive..Readcxx . . $ OSFArchive#Read(7405b416d0535413).(m_buffercxx . . $ AudioStream#m_buffer.[buf].datacxx . . $ AudioStream#$anonymous_type_1#data., len); |
| 850 | } |
| 851 | // TURN OFF OPTIMIZATIONS HERE. Placement of instructions is VERY IMPORTANT here. synched with StreamCallback, |
| 852 | // which also has optimizations off. |
| 853 | #pragma optimize("", off) |
| 854 | // updates file buffers |
| 855 | void AudioStreamcxx . . $ AudioStream#::UpdateDatacxx . . $ AudioStream#UpdateData(49f6e7a06ebc5aa8).() { |
| 856 | int nextbuffer = ((m_fbufidxcxx . . $ AudioStream#m_fbufidx. + 1) % STRM_BUFCOUNTcxx . . $ `stream_audio/streamaudio.h:215:9`!); |
| 857 | // check if are on a measure boundary for current stream. if so, then check if we have a next request pending |
| 858 | if (CHECK_FLAGcxx . . $ `lib/Macros.h:63:9`!(m_buffer[nextbuffer].flags, STRM_BUFF_USEDcxx . . $ `stream_audio/streamaudio.h:230:9`!)) { |
| 859 | return; |
| 860 | } |
| 861 | // quit out if we can. |
| 862 | if (nextbuffer == m_sbufidxcxx . . $ AudioStream#m_sbufidx.) { |
| 863 | return; |
| 864 | } |
| 865 | // do read! |
| 866 | // READ DATA INTO BUFFER. UPDATE BYTES LEFT PER MEASURE, ETC. |
| 867 | if (m_readaheadcxx . . $ AudioStream#m_readahead.) { |
| 868 | // ok update the next buffer with data |
| 869 | m_fbufidxcxx . . $ AudioStream#m_fbufidx. = nextbuffer; |
| 870 | // mprintf(0,"%c",m_fbufidx+'a'); |
| 871 | // if our stream's current id does not match the streaming buffer's id, then we need to reallocate |
| 872 | // the stream buffer with the new memory size |
| 873 | if (m_buffercxx . . $ AudioStream#m_buffer.[m_fbufidxcxx . . $ AudioStream#m_fbufidx.].idcxx . . $ AudioStream#$anonymous_type_1#id. != (int)m_curidcxx . . $ AudioStream#m_curid.) { |
| 874 | if (m_buffercxx . . $ AudioStream#m_buffer.[m_fbufidxcxx . . $ AudioStream#m_fbufidx.].datacxx . . $ AudioStream#$anonymous_type_1#data.) { |
| 875 | mem_freecxx . . $ `mem/mem.h:80:9`!(m_buffer[m_fbufidx].data); |
| 876 | } |
| 877 | m_buffercxx . . $ AudioStream#m_buffer.[m_fbufidxcxx . . $ AudioStream#m_fbufidx.].datacxx . . $ AudioStream#$anonymous_type_1#data. = (uint8_tcxx . . $ uint8_t# *)mem_malloccxx . . $ `mem/mem.h:79:9`!(m_bufsize); |
| 878 | } |
| 879 | m_buffercxx . . $ AudioStream#m_buffer.[m_fbufidxcxx . . $ AudioStream#m_fbufidx.].nbytescxx . . $ AudioStream#$anonymous_type_1#nbytes. = AudioStreamcxx . . $ AudioStream#::ReadFileDatacxx . . $ AudioStream#ReadFileData(9b79fb6aee4c0440).(m_fbufidxcxx . . $ AudioStream#m_fbufidx., m_bufsizecxx . . $ AudioStream#m_bufsize.); |
| 880 | m_buffercxx . . $ AudioStream#m_buffer.[m_fbufidxcxx . . $ AudioStream#m_fbufidx.].flagscxx . . $ AudioStream#$anonymous_type_1#flags. = 0; |
| 881 | m_buffercxx . . $ AudioStream#m_buffer.[m_fbufidxcxx . . $ AudioStream#m_fbufidx.].flagscxx . . $ AudioStream#$anonymous_type_1#flags. |= STRM_BUFF_USEDcxx . . $ `stream_audio/streamaudio.h:230:9`!; |
| 882 | m_buffercxx . . $ AudioStream#m_buffer.[m_fbufidxcxx . . $ AudioStream#m_fbufidx.].idcxx . . $ AudioStream#$anonymous_type_1#id. = (int)m_curidcxx . . $ AudioStream#m_curid.; |
| 883 | m_playbytesleftcxx . . $ AudioStream#m_playbytesleft. -= m_buffercxx . . $ AudioStream#m_buffer.[m_fbufidxcxx . . $ AudioStream#m_fbufidx.].nbytescxx . . $ AudioStream#$anonymous_type_1#nbytes.; |
| 884 | // mprintf(0, "[%d]:pbytesleft=%d\n", m_curid, m_playbytesleft); |
| 885 | LOGFILEcxx . . $ `stream_audio/streamaudio.cpp:179:9`!((_logfp, "[%d]:pbytesleft=%d\n", m_curid, m_playbytesleft)); |
| 886 | if (m_playbytesleftcxx . . $ AudioStream#m_playbytesleft. <= (m_bufsizecxx . . $ AudioStream#m_bufsize. / 4)) { |
| 887 | // mprintf(0, "STRM[%d]: ", m_curid); |
| 888 | if (m_buffercxx . . $ AudioStream#m_buffer.[m_fbufidxcxx . . $ AudioStream#m_fbufidx.].nbytescxx . . $ AudioStream#$anonymous_type_1#nbytes. == 0) { |
| 889 | memset(m_buffercxx . . $ AudioStream#m_buffer.[m_fbufidxcxx . . $ AudioStream#m_fbufidx.].datacxx . . $ AudioStream#$anonymous_type_1#data., 0, 4); |
| 890 | m_buffercxx . . $ AudioStream#m_buffer.[m_fbufidxcxx . . $ AudioStream#m_fbufidx.].nbytescxx . . $ AudioStream#$anonymous_type_1#nbytes. = 4; |
| 891 | mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "making empty buffer and"); |
| 892 | } |
| 893 | // mprintf(0, "TERMINAL buffer.\n"); |
| 894 | LOGFILEcxx . . $ `stream_audio/streamaudio.cpp:179:9`!((_logfp, "STRM[%d]: TERMINAL buffer.\n", m_curid)); |
| 895 | m_buffercxx . . $ AudioStream#m_buffer.[m_fbufidxcxx . . $ AudioStream#m_fbufidx.].flagscxx . . $ AudioStream#$anonymous_type_1#flags. |= STRM_BUFF_TERMINALcxx . . $ `stream_audio/streamaudio.h:231:9`!; |
| 896 | m_readaheadcxx . . $ AudioStream#m_readahead. = false; |
| 897 | m_readahead_finished_loopcxx . . $ AudioStream#m_readahead_finished_loop. = true; |
| 898 | } |
| 899 | // looping? |
| 900 | if (CHECK_FLAGcxx . . $ `lib/Macros.h:63:9`!(m_buffer[m_fbufidx].flags, STRM_BUFF_TERMINALcxx . . $ `stream_audio/streamaudio.h:231:9`!)) { |
| 901 | if (m_loopcountcxx . . $ AudioStream#m_loopcount. == -1) { |
| 902 | m_buffercxx . . $ AudioStream#m_buffer.[m_fbufidxcxx . . $ AudioStream#m_fbufidx.].flagscxx . . $ AudioStream#$anonymous_type_1#flags. |= STRM_BUFF_LOOPENDcxx . . $ `stream_audio/streamaudio.h:232:9`!; |
| 903 | AudioStreamcxx . . $ AudioStream#::Resetcxx . . $ AudioStream#Reset(49f6e7a06ebc5aa8).(); |
| 904 | } else if (m_loopcountcxx . . $ AudioStream#m_loopcount. > 0) { |
| 905 | m_buffercxx . . $ AudioStream#m_buffer.[m_fbufidxcxx . . $ AudioStream#m_fbufidx.].flagscxx . . $ AudioStream#$anonymous_type_1#flags. |= STRM_BUFF_LOOPENDcxx . . $ `stream_audio/streamaudio.h:232:9`!; |
| 906 | AudioStreamcxx . . $ AudioStream#::Resetcxx . . $ AudioStream#Reset(49f6e7a06ebc5aa8).(); |
| 907 | m_loopcountcxx . . $ AudioStream#m_loopcount.--; |
| 908 | } |
| 909 | m_readahead_finished_loopcxx . . $ AudioStream#m_readahead_finished_loop. = true; |
| 910 | } |
| 911 | } |
| 912 | } |
| 913 | |
| 914 | #pragma optimize("", on) |
| 915 | /////////////////////////////////////////////////////////////////////////////// |
| 916 | // decoder |
| 917 | int ADecodeFileReadcxx . . $ ADecodeFileRead(42dc92c764946a43).(void *data, void *buf, unsigned qty) { |
| 918 | AudioStreamcxx . . $ AudioStream# *stream = (AudioStreamcxx . . $ AudioStream# *)data; |
| 919 | int iqty = (int)qty; |
| 920 | |
| 921 | if (iqty > stream->m_bytesleftcxx . . $ AudioStream#m_bytesleft.) { |
| 922 | iqty = stream->m_bytesleftcxx . . $ AudioStream#m_bytesleft.; |
| 923 | stream->m_bytesleftcxx . . $ AudioStream#m_bytesleft. = 0; |
| 924 | } else { |
| 925 | stream->m_bytesleftcxx . . $ AudioStream#m_bytesleft. -= iqty; |
| 926 | } |
| 927 | |
| 928 | return stream->m_archivecxx . . $ AudioStream#m_archive..Readcxx . . $ OSFArchive#Read(7405b416d0535413).((uint8_tcxx . . $ uint8_t# *)buf, iqty); |
| 929 | } |
| 930 | |
| 931 | // Router for stream callbacks. |
| 932 | // Invoked by sound system |
| 933 | void *AudioStreamCBcxx . . $ AudioStreamCB(9326456ed2624211).(void *user_data, int handle, int *size) { |
| 934 | AudioStreamcxx . . $ AudioStream# *stream = (AudioStreamcxx . . $ AudioStream# *)user_data; |
| 935 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(stream); |
| 936 | ASSERTcxx . . $ `misc/pserror.h:246:9`!(stream->m_streamindex == handle); |
| 937 | return stream->StreamCallbackcxx . . $ AudioStream#StreamCallback(5b9d5e032d1f146d).(size); |
| 938 | } |
| 939 | static float Stream_volumecxx . . $ Stream_volume. = 1.0f; |
| 940 | static float Stream_master_volumecxx . . $ Stream_master_volume. = 1.0f; |
| 941 | void StreamVolumecxx . . $ StreamVolume(9364e6e7bff7660).(float master_volume) { |
| 942 | Stream_master_volumecxx . . $ Stream_master_volume. = master_volume; |
| 943 | User_audio_streamcxx . . $ User_audio_stream..SetVolumecxx . . $ AudioStream#SetVolume(9364e6e7bff7660).(Stream_volumecxx . . $ Stream_volume. * master_volume); |
| 944 | } |
| 945 | // these functions are the 'simplified' stream interface from Jeff (most of this code is from Jeff) |
| 946 | int StreamPlaycxx . . $ StreamPlay(d157d8952ffc14b5).(const char *filename, float volume, int flags) { |
| 947 | int retval = -1; |
| 948 | try { |
| 949 | flags = 0; |
| 950 | User_audio_streamcxx . . $ User_audio_stream..Closecxx . . $ AudioStream#Close(49f6e7a06ebc5aa8).(); |
| 951 | User_audio_streamcxx . . $ User_audio_stream..Opencxx . . $ AudioStream#Open(2551bed5d6fc04f6).(filename, STRM_OPNF_ONETIMEcxx . . $ `stream_audio/streamaudio.h:225:9`!); |
| 952 | Stream_volumecxx . . $ Stream_volume. = volume; |
| 953 | User_audio_streamcxx . . $ User_audio_stream..SetVolumecxx . . $ AudioStream#SetVolume(9364e6e7bff7660).(Stream_volumecxx . . $ Stream_volume. * Stream_master_volumecxx . . $ Stream_master_volume.); |
| 954 | User_audio_streamcxx . . $ User_audio_stream..Playcxx . . $ AudioStream#Play(efaadfb7dc14930a).(true); // start this stream on the next frame. |
| 955 | retval = User_audio_streamcxx . . $ User_audio_stream..m_streamindexcxx . . $ AudioStream#m_streamindex.; |
| 956 | } catch (...) { |
| 957 | return -1; |
| 958 | } |
| 959 | return retval; |
| 960 | } |
| 961 | void StreamStopcxx . . $ StreamStop(d4f767463ce0a6b3).(int handle) { |
| 962 | if (handle > -1) { |
| 963 | if (AudioStreamcxx . . $ AudioStream#::m_streamscxx . . $ AudioStream#m_streams.[handle]) |
| 964 | AudioStreamcxx . . $ AudioStream#::m_streamscxx . . $ AudioStream#m_streams.[handle]->Stopcxx . . $ AudioStream#Stop(87564e930d06994).(); |
| 965 | } |
| 966 | User_audio_streamcxx . . $ User_audio_stream..Closecxx . . $ AudioStream#Close(49f6e7a06ebc5aa8).(); |
| 967 | } |
| 968 | int StreamGetSoundHandlecxx . . $ StreamGetSoundHandle(7864480464b09eea).(int handle) { |
| 969 | if (handle > -1) { |
| 970 | if (AudioStreamcxx . . $ AudioStream#::m_streamscxx . . $ AudioStream#m_streams.[handle]) |
| 971 | return AudioStreamcxx . . $ AudioStream#::m_streamscxx . . $ AudioStream#m_streams.[handle]->GetSoundHandlecxx . . $ AudioStream#GetSoundHandle(455f465bc33b4cdf).(); |
| 972 | else |
| 973 | return -1; |
| 974 | } |
| 975 | return -1; |
| 976 | } |