2 * $Logfile: /Freespace2/code/Sound/AudioStr.cpp $
7 * Routines to stream large WAV files from disk
10 * Revision 1.1 2002/05/03 03:28:10 root
14 * 5 9/14/99 1:32a Jimb
15 * Commented out Int3() that was hanging Jim's machine. Happens before
16 * sm2-07 command brief.
18 * 4 7/14/99 12:09p Jefff
19 * Make sure we're not servicing a bogus audiostream. Check for "used"
20 * after the critical section lock.
22 * 3 12/17/98 4:01p Andsager
23 * up wavedata buffer size to 180000 to allow stereo 16b/22KHz streaming
25 * 2 10/07/98 10:53a Dave
28 * 1 10/07/98 10:51a Dave
30 * 53 6/28/98 6:35p Lawrance
31 * move re-entrancy semaphore into audiostream class
33 * 52 5/24/98 4:42p Dan
34 * AL: Fix several bugs related to pausing and enabling/disabling event
37 * 51 5/21/98 11:57a Lawrance
38 * fix potential bug with transitions for music when in packfiles
40 * 50 5/15/98 9:09p Lawrance
41 * The last of the multi-threading fixes
43 * 49 5/15/98 7:57p Duncan
44 * AL: Fix race condition with music streaming
46 * 48 5/15/98 10:13a Lawrance
47 * remove unused audiostream member
49 * 47 5/14/98 5:45p Lawrance2
50 * Put critical section around audiostream destroying
52 * 46 5/12/98 5:40p Lawrance
53 * Add critical section code to the service buffer call.. since it is
54 * possible to release buffers while in this call
56 * 45 5/10/98 3:49p Sandeep
57 * Fix problem with having the audio streaming while trying to close down
60 * 44 4/30/98 4:53p John
61 * Restructured and cleaned up cfile code. Added capability to read off
62 * of CD-ROM drive and out of multiple pack files.
64 * 43 4/26/98 3:30a Lawrance
65 * Fix a couple of potential bugs
67 * 42 4/21/98 10:18a Dan
69 * 41 4/17/98 6:59a John
70 * Changed code the used 'new' and 'delete' to use 'malloc' and 'free'
71 * instead. Had to manually can constructors/destructors.
73 * 40 4/13/98 10:18a John
76 * 39 4/13/98 10:16a John
77 * Switched gettime back to timer_get_milliseconds, which is now thread
80 * 38 4/12/98 11:08p Lawrance
81 * switch back to using gettime() in separate threads
83 * 37 4/12/98 5:31p Lawrance
84 * use timer_get_milliseconds() instead of gettime()
86 * 36 4/06/98 12:36a Lawrance
87 * Ensure all non-music ADPCM files get decompressed to 8 bit.
89 * 35 4/03/98 4:56p Lawrance
90 * Upu the max audio streams to 30
92 * 34 3/31/98 4:50p Dan
93 * AL: Clean up all audio streams if necessary in
94 * event_music_level_close()
96 * 33 3/23/98 4:12p Lawrance
97 * Fix subtle bug with looping and fading out songs
99 * 32 2/18/98 5:49p Lawrance
100 * Even if the ADPCM codec is unavailable, allow game to continue.
102 * 31 2/15/98 4:43p Lawrance
103 * work on real-time voice
105 * 30 1/19/98 11:37p Lawrance
106 * Fixing Optimization build warnings
108 * 29 1/17/98 4:41p Lawrance
109 * Fix problem with multiple audio streams using the same buffers
111 * 28 1/16/98 11:49a Lawrance
112 * Use own internal timer for fading.
114 * 27 12/28/97 12:43p John
115 * Put in support for reading archive files; Made missionload use the
116 * cf_get_file_list function. Moved demos directory out of data tree.
118 * 26 12/27/97 8:08p Lawrance
119 * If an audiostream doesn't exists, it can't be playing
121 * 25 12/18/97 3:30p Lawrance
122 * Fix bug that sometimes caused music with no volume to not get stopped
125 * 24 12/17/97 10:17p Allender
126 * redid streadming code to use mmio* functions instead of cf* functions.
127 * Our functions are not reentrant!
129 * 23 12/10/97 10:04p Lawrance
130 * modify what happens in Audio_stream constructor
132 * 22 12/09/97 6:14p Lawrance
135 * 21 12/08/97 6:21p Lawrance
136 * fix problems with signaling that end-of-file has been reached
138 * 20 12/05/97 10:50a Lawrance
139 * improve how silence bytes are written on transitions
141 * 19 12/04/97 5:35p Lawrance
142 * fix bug that may have caused errors when writing silence
144 * 18 11/28/97 2:09p Lawrance
145 * Overhaul how ADPCM conversion works... use much less memory... safer
148 * 17 10/03/97 8:24a Lawrance
149 * When unpausing, be sure to retain looping status
151 * 16 9/24/97 5:30p Lawrance
152 * fix bug that was messing up streaming of 8 bit audio
154 * 15 9/18/97 10:31p Lawrance
155 * add functions to pause and unpause all audio streams
157 * 14 9/09/97 3:39p Sandeep
158 * warning level 4 bugs
169 #include <mmsystem.h>
173 #include "audiostr.h"
174 #include "cfile.h" // needed for cf_get_path
176 #include "sound.h" /* for Snd_sram */
182 #define SUCCESS TRUE // Error returns for all member functions
183 #define FAILURE FALSE
186 typedef BOOL (*TIMERCALLBACK)(DWORD);
188 #define BIGBUF_SIZE 180000 // This can be reduced to 88200 once we don't use any stereo
189 //#define BIGBUF_SIZE 88300 // This can be reduced to 88200 once we don't use any stereo
190 unsigned char *Wavedata_load_buffer = NULL; // buffer used for cueing audiostreams
191 unsigned char *Wavedata_service_buffer = NULL; // buffer used for servicing audiostreams
193 CRITICAL_SECTION Global_service_lock;
195 #define COMPRESSED_BUFFER_SIZE 88300
196 unsigned char *Compressed_buffer = NULL; // Used to load in compressed data during a cueing interval
197 unsigned char *Compressed_service_buffer = NULL; // Used to read in compressed data during a service interval
199 #define AS_HIGHEST_MAX 999999999 // max uncompressed filesize supported is 999 meg
205 // Wrapper class for Windows multimedia timer services. Provides
206 // both periodic and one-shot events. User must supply callback
207 // for periodic events.
213 void constructor(void);
214 void destructor(void);
215 BOOL Create (UINT nPeriod, UINT nRes, DWORD dwUser, TIMERCALLBACK pfnCallback);
217 static void CALLBACK TimeProc(UINT uID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2);
218 TIMERCALLBACK m_pfnCallback;
230 // WAV file class (read-only).
243 BOOL Open (LPSTR pszFilename);
245 int Read (BYTE * pbDest, UINT cbSize, int service=1);
246 UINT GetNumBytesRemaining (void) { return (m_nDataSize - m_nBytesPlayed); }
247 UINT GetUncompressedAvgDataRate (void) { return (m_nUncompressedAvgDataRate); }
248 UINT GetDataSize (void) { return (m_nDataSize); }
249 UINT GetNumBytesPlayed (void) { return (m_nBytesPlayed); }
250 BYTE GetSilenceData (void);
251 WAVEFORMATEX m_wfmt; // format of wave file used by Direct Sound
252 WAVEFORMATEX * m_pwfmt_original; // foramt of wave file from actual wave source
253 UINT m_total_uncompressed_bytes_read;
254 UINT m_max_uncompressed_bytes_to_read;
255 UINT m_bits_per_sample_uncompressed;
258 UINT m_data_offset; // number of bytes to actual wave data
259 int m_data_bytes_left;
262 UINT m_wave_format; // format of wave source (ie WAVE_FORMAT_PCM, WAVE_FORMAT_ADPCM)
263 UINT m_nBlockAlign; // wave data block alignment spec
264 UINT m_nUncompressedAvgDataRate; // average wave data rate
265 UINT m_nDataSize; // size of data chunk
266 UINT m_nBytesPlayed; // offset into data chunk
267 BOOL m_abort_next_read;
269 HACMSTREAM m_hStream;
271 WAVEFORMATEX m_wfxDest;
276 // AudioStreamServices
278 // DirectSound apportions services on a per-window basis to allow
279 // sound from background windows to be muted. The AudioStreamServices
280 // class encapsulates the initialization of DirectSound services.
282 // Each window that wants to create AudioStream objects must
283 // first create and initialize an AudioStreamServices object.
284 // All AudioStream objects must be destroyed before the associated
285 // AudioStreamServices object is destroyed.
286 class AudioStreamServices
289 void Constructor(void);
291 LPDIRECTSOUND GetPDS (void) { return m_pds; }
299 // Audio stream interface class for playing WAV files using DirectSound.
300 // Users of this class must create AudioStreamServices object before
301 // creating an AudioStream object.
317 BOOL Create (LPSTR pszFilename, AudioStreamServices * pass);
319 void Play (long volume, int looping);
320 int Is_Playing(){ return(m_fPlaying); }
321 int Is_Paused(){ return(m_bIsPaused); }
322 int Is_Past_Limit() { return m_bPastLimit; }
323 void Stop (int paused=0);
324 void Stop_and_Rewind (void);
325 void Fade_and_Destroy (void);
326 void Fade_and_Stop(void);
327 void Set_Volume(long vol);
330 void Set_Byte_Cutoff(unsigned int num_bytes_cutoff);
331 void Set_Default_Volume(long converted_volume) { m_lDefaultVolume = converted_volume; }
332 long Get_Default_Volume() { return m_lDefaultVolume; }
333 unsigned int Get_Bytes_Committed(void);
334 int Is_looping() { return m_bLooping; }
337 UINT m_bits_per_sample_uncompressed;
341 BOOL WriteWaveData (UINT cbSize, UINT* num_bytes_written,int service=1);
342 BOOL WriteSilence (UINT cbSize);
343 DWORD GetMaxWriteSize (void);
344 BOOL ServiceBuffer (void);
345 static BOOL TimerCallback (DWORD dwUser);
347 AudioStreamServices * m_pass; // ptr to AudioStreamServices object
348 LPDIRECTSOUNDBUFFER m_pdsb; // ptr to Direct Sound buffer
349 WaveFile * m_pwavefile; // ptr to WaveFile object
350 Timer m_timer; // ptr to Timer object
351 BOOL m_fCued; // semaphore (stream cued)
352 BOOL m_fPlaying; // semaphore (stream playing)
353 DSBUFFERDESC m_dsbd; // Direct Sound buffer description
354 LONG m_lInService; // reentrancy semaphore
355 UINT m_cbBufOffset; // last write position
356 UINT m_nBufLength; // length of sound buffer in msec
357 UINT m_cbBufSize; // size of sound buffer in bytes
358 UINT m_nBufService; // service interval in msec
359 UINT m_nTimeStarted; // time (in system time) playback started
361 BOOL m_bLooping; // whether or not to loop playback
362 BOOL m_bFade; // fade out music
363 BOOL m_bDestroy_when_faded;
364 LONG m_lVolume; // volume of stream ( 0 -> -10 000 )
365 LONG m_lCutoffVolume;
366 BOOL m_bIsPaused; // stream is stopped, but not rewinded
367 UINT m_silence_written; // number of bytes of silence written to buffer
368 UINT m_bReadingDone; // no more bytes to be read from disk, still have remaining buffer to play
369 DWORD m_fade_timer_id; // timestamp so we know when to start fade
370 DWORD m_finished_id; // timestamp so we know when we've played #bytes required
371 BOOL m_bPastLimit; // flag to show we've played past the number of bytes requred
372 LONG m_lDefaultVolume;
375 CRITICAL_SECTION write_lock;
379 // AudioStreamServices class implementation
381 ////////////////////////////////////////////////////////////
384 void AudioStreamServices::Constructor(void)
386 // Initialize member data
389 // It would seem to make sense to initialize DirectSound here,
390 // but because there could be an error, it's best done in a
391 // separate member function, ::Initialize.
395 extern LPDIRECTSOUND pDirectSound; // From Sound.cpp
399 BOOL AudioStreamServices::Initialize ()
402 BOOL fRtn = SUCCESS; // assume success
405 m_pds = pDirectSound;
414 // AudioStream class implementation
416 ////////////////////////////////////////////////////////////
418 // The following constants are the defaults for our streaming buffer operation.
419 const UINT DefBufferLength = 2000; // default buffer length in msec
420 const UINT DefBufferServiceInterval = 250; // default buffer service interval in msec
423 AudioStream::AudioStream (void)
425 InitializeCriticalSection( &write_lock );
430 AudioStream::~AudioStream (void)
432 DeleteCriticalSection( &write_lock );
436 void AudioStream::Init_Data ()
442 m_bPastLimit = FALSE;
444 m_bDestroy_when_faded = FALSE;
446 m_lCutoffVolume = -10000;
448 m_silence_written = 0;
449 m_bReadingDone = FALSE;
453 m_fPlaying = m_fCued = FALSE;
454 m_lInService = FALSE;
456 m_nBufLength = DefBufferLength;
458 m_nBufService = DefBufferServiceInterval;
463 BOOL AudioStream::Create (LPSTR pszFilename, AudioStreamServices * pass)
465 BOOL fRtn = SUCCESS; // assume success
473 if (pszFilename && m_pass) {
474 // Create a new WaveFile object
476 m_pwavefile = (WaveFile *)malloc(sizeof(WaveFile));
483 m_pwavefile->m_bits_per_sample_uncompressed = m_bits_per_sample_uncompressed;
484 if (m_pwavefile->Open (pszFilename)) {
485 // Calculate sound buffer size in bytes
486 // Buffer size is average data rate times length of buffer
487 // No need for buffer to be larger than wave data though
488 m_cbBufSize = (m_pwavefile->GetUncompressedAvgDataRate () * m_nBufLength) / 1000;
489 nprintf(("SOUND", "SOUND => Stream buffer created using %d bytes\n", m_cbBufSize));
490 // m_cbBufSize = (m_cbBufSize > m_pwavefile->GetDataSize ()) ? m_pwavefile->GetDataSize () : m_cbBufSize;
492 //nprintf(("Sound", "SOUND => average data rate = %d\n\r", m_pwavefile->GetUncompressedAvgDataRate ()));
493 //nprintf(("Sound", "SOUND => m_cbBufSize = %d\n\r", m_cbBufSize));
495 // Create sound buffer
497 memset (&m_dsbd, 0, sizeof (DSBUFFERDESC));
498 m_dsbd.dwSize = sizeof (DSBUFFERDESC);
499 m_dsbd.dwBufferBytes = m_cbBufSize;
500 m_dsbd.lpwfxFormat = &m_pwavefile->m_wfmt;
501 m_dsbd.dwFlags = DSBCAPS_STATIC | DSBCAPS_CTRLPAN | DSBCAPS_CTRLVOLUME | DSBCAPS_LOCSOFTWARE;
503 hr = (m_pass->GetPDS ())->CreateSoundBuffer (&m_dsbd, &m_pdsb, NULL);
507 Snd_sram += m_cbBufSize;
510 // Error, unable to create DirectSound buffer
511 nprintf(("Sound", "SOUND => Error, unable to create DirectSound buffer\n\r"));
512 if (hr == DSERR_BADFORMAT) {
513 nprintf(("Sound", "SOUND => Bad format (probably ADPCM)\n\r"));
520 // Error opening file
521 nprintf(("SOUND", "SOUND => Failed to open wave file: %s\n\r", pszFilename));
522 m_pwavefile->Close();
529 // Error, unable to create WaveFile object
530 nprintf(("Sound", "SOUND => Failed to create WaveFile object %s\n\r", pszFilename));
535 // Error, passed invalid parms
544 BOOL AudioStream::Destroy (void)
548 EnterCriticalSection(&write_lock);
553 // Release DirectSound buffer
557 Snd_sram -= m_cbBufSize;
560 // Delete WaveFile object
562 m_pwavefile->Close();
569 LeaveCriticalSection(&write_lock);
576 // Writes wave data to sound buffer. This is a helper method used by Create and
577 // ServiceBuffer; it's not exposed to users of the AudioStream class.
578 BOOL AudioStream::WriteWaveData (UINT size, UINT *num_bytes_written, int service)
581 LPBYTE lpbuf1 = NULL;
582 LPBYTE lpbuf2 = NULL;
585 DWORD dwbyteswritten1 = 0;
586 DWORD dwbyteswritten2 = 0;
588 unsigned char *uncompressed_wave_data;
590 *num_bytes_written = 0;
592 if ( size == 0 || m_bReadingDone ) {
596 if ( !m_pdsb || !m_pwavefile ) {
601 EnterCriticalSection(&Global_service_lock);
605 uncompressed_wave_data = Wavedata_service_buffer;
607 uncompressed_wave_data = Wavedata_load_buffer;
610 int num_bytes_read = 0;
612 // Lock the sound buffer
613 hr = m_pdsb->Lock (m_cbBufOffset, size, (void**)(&lpbuf1), &dwsize1, (void**)(&lpbuf2), &dwsize2, 0);
615 // Write data to sound buffer. Because the sound buffer is circular, we may have to
616 // do two write operations if locked portion of buffer wraps around to start of buffer.
619 num_bytes_read = m_pwavefile->Read(uncompressed_wave_data, dwsize1+dwsize2,service);
620 if ( num_bytes_read == -1 ) {
621 // means nothing left to read!
626 if ( num_bytes_read > 0 ) {
627 if ( (unsigned int)num_bytes_read > dwsize1 ) {
628 dwbyteswritten1 = dwsize1;
629 dwbyteswritten2 = num_bytes_read - dwsize1;
631 memcpy(lpbuf1, uncompressed_wave_data, dwsize1);
633 memcpy(lpbuf2, uncompressed_wave_data+dwsize1, num_bytes_read-dwsize1);
635 dwbyteswritten1 = num_bytes_read;
637 memcpy(lpbuf1, uncompressed_wave_data, num_bytes_read);
641 // Update our buffer offset and unlock sound buffer
642 m_cbBufOffset = (m_cbBufOffset + dwbyteswritten1 + dwbyteswritten2) % m_cbBufSize;
643 *num_bytes_written = dwbyteswritten1 + dwbyteswritten2;
644 m_pdsb->Unlock (lpbuf1, dwsize1, lpbuf2, dwsize2);
647 // Error locking sound buffer
648 nprintf(("SOUND", "SOUND ==> Error, unable to lock sound buffer in AudioStr\n"));
653 LeaveCriticalSection(&Global_service_lock);
662 // Writes silence to sound buffer. This is a helper method used by
663 // ServiceBuffer; it's not exposed to users of the AudioStream class.
664 BOOL AudioStream::WriteSilence (UINT size)
667 LPBYTE lpbuf1 = NULL;
668 LPBYTE lpbuf2 = NULL;
671 DWORD dwbyteswritten1 = 0;
672 DWORD dwbyteswritten2 = 0;
675 // Lock the sound buffer
676 hr = m_pdsb->Lock (m_cbBufOffset, size, (void**)(&lpbuf1), &dwsize1, (void**)(&lpbuf2), &dwsize2, 0);
679 // Get silence data for this file format. Although word sizes vary for different
680 // wave file formats, ::Lock will always return pointers on word boundaries.
681 // Because silence data for 16-bit PCM formats is 0x0000 or 0x00000000, we can
682 // get away with writing bytes and ignoring word size here.
683 BYTE bSilence = m_pwavefile->GetSilenceData ();
685 // Write silence to sound buffer. Because the sound buffer is circular, we may have to
686 // do two write operations if locked portion of buffer wraps around to start of buffer.
687 memset (lpbuf1, bSilence, dwsize1);
688 dwbyteswritten1 = dwsize1;
690 // Second write required?
692 memset (lpbuf2, bSilence, dwsize2);
693 dwbyteswritten2 = dwsize2;
696 // Update our buffer offset and unlock sound buffer
697 m_cbBufOffset = (m_cbBufOffset + dwbyteswritten1 + dwbyteswritten2) % m_cbBufSize;
698 // m_pdsb->Unlock (lpbuf1, dwbyteswritten1, lpbuf2, dwbyteswritten2);
699 m_pdsb->Unlock (lpbuf1, dwsize1, lpbuf2, dwsize2);
702 // Error locking sound buffer
703 nprintf(("SOUND", "SOUND ==> Error, unable to lock sound buffer in AudioStr\n"));
713 // Helper function to calculate max size of sound buffer write operation, i.e. how much
714 // free space there is in buffer.
715 DWORD AudioStream::GetMaxWriteSize (void)
717 DWORD dwWriteCursor, dwPlayCursor, dwMaxSize;
719 // Get current play position
720 if (m_pdsb->GetCurrentPosition (&dwPlayCursor, &dwWriteCursor) == DS_OK) {
721 if (m_cbBufOffset <= dwPlayCursor) {
722 // Our write position trails play cursor
723 dwMaxSize = dwPlayCursor - m_cbBufOffset;
726 else {// (m_cbBufOffset > dw7Cursor)
727 // Play cursor has wrapped
728 dwMaxSize = m_cbBufSize - m_cbBufOffset + dwPlayCursor;
732 // GetCurrentPosition call failed
737 // nprintf(("Alan","Max write size: %d\n", dwMaxSize));
744 // Routine to service buffer requests initiated by periodic timer.
746 // Returns TRUE if buffer serviced normally; otherwise returns FALSE.
747 #define FADE_VOLUME_INTERVAL 400 // 100 == 1db
748 #define VOLUME_ATTENUATION_BEFORE_CUTOFF 3000 // 12db
749 BOOL AudioStream::ServiceBuffer (void)
754 if ( status != ASF_USED )
757 EnterCriticalSection(&write_lock);
759 // status may have changed, so lets check once again
760 if ( status != ASF_USED ){
761 LeaveCriticalSection(&write_lock);
765 // Check for reentrance
766 if (InterlockedExchange (&m_lInService, TRUE) == FALSE) {
767 if ( m_bFade == TRUE ) {
768 if ( m_lCutoffVolume == -10000 ) {
770 // nprintf(("Alan","Volume is: %d\n",vol));
771 m_lCutoffVolume = max(vol - VOLUME_ATTENUATION_BEFORE_CUTOFF, -10000);
775 vol = vol - FADE_VOLUME_INTERVAL; // decrease by 1db
776 // nprintf(("Alan","Volume is now: %d\n",vol));
779 // nprintf(("Sound","SOUND => Volume for stream sound is %d\n",vol));
780 // nprintf(("Alan","Cuttoff Volume is: %d\n",m_lCutoffVolume));
781 if ( vol < m_lCutoffVolume ) {
783 m_lCutoffVolume = -10000;
784 if ( m_bDestroy_when_faded == TRUE ) {
785 LeaveCriticalSection(&write_lock);
787 // Reset reentrancy semaphore
788 InterlockedExchange (&m_lInService, FALSE);
793 // Reset reentrancy semaphore
794 LeaveCriticalSection(&write_lock);
795 InterlockedExchange (&m_lInService, FALSE);
801 // All of sound not played yet, send more data to buffer
802 DWORD dwFreeSpace = GetMaxWriteSize ();
804 // Determine free space in sound buffer
807 // Some wave data remains, but not enough to fill free space
808 // Send wave data to buffer, fill remainder of free space with silence
809 uint num_bytes_written;
811 if (WriteWaveData (dwFreeSpace, &num_bytes_written) == SUCCESS) {
812 // nprintf(("Alan","Num bytes written: %d\n", num_bytes_written));
814 if ( m_pwavefile->m_total_uncompressed_bytes_read >= m_pwavefile->m_max_uncompressed_bytes_to_read ) {
815 m_fade_timer_id = timer_get_milliseconds() + 1700; // start fading 1.7 seconds from now
816 m_finished_id = timer_get_milliseconds() + 2000; // 2 seconds left to play out buffer
817 m_pwavefile->m_max_uncompressed_bytes_to_read = AS_HIGHEST_MAX;
820 if ( (m_fade_timer_id>0) && ((uint)timer_get_milliseconds() > m_fade_timer_id) ) {
825 if ( (m_finished_id>0) && ((uint)timer_get_milliseconds() > m_finished_id) ) {
830 if ( (num_bytes_written < dwFreeSpace) && m_bReadingDone ) {
831 int num_bytes_silence;
832 num_bytes_silence = dwFreeSpace - num_bytes_written;
834 if ( num_bytes_silence > 0 ) {
836 m_silence_written += num_bytes_silence;
837 if (WriteSilence (num_bytes_silence) == FAILURE) {
842 if ( m_silence_written >= m_cbBufSize ) {
843 m_silence_written = 0;
845 if ( m_bDestroy_when_faded == TRUE ) {
846 LeaveCriticalSection(&write_lock);
848 // Reset reentrancy semaphore
849 InterlockedExchange (&m_lInService, FALSE);
853 // All of sound has played, stop playback or loop again
854 if ( m_bLooping && !m_bFade) {
855 Play(m_lVolume, m_bLooping);
865 // Error writing wave data
871 // Reset reentrancy semaphore
872 InterlockedExchange (&m_lInService, FALSE);
874 // Service routine reentered. Do nothing, just return
878 LeaveCriticalSection(&write_lock);
883 void AudioStream::Cue (void)
885 UINT num_bytes_written;
891 m_bPastLimit = FALSE;
893 m_lCutoffVolume = -10000;
895 m_bDestroy_when_faded = FALSE;
900 // Reset file ptr, etc
903 // Reset DirectSound buffer
904 m_pdsb->SetCurrentPosition (0);
906 // Fill buffer with wave data
907 WriteWaveData (m_cbBufSize, &num_bytes_written,0);
915 void AudioStream::Play (long volume, int looping)
920 if ( m_bIsPaused == FALSE)
924 // Cue for playback if necessary
934 // Begin DirectSound playback
935 HRESULT hr = m_pdsb->Play (0, 0, DSBPLAY_LOOPING);
937 m_nTimeStarted = timer_get_milliseconds();
939 // Kick off timer to service buffer
940 m_timer.constructor();
942 m_timer.Create (m_nBufService, m_nBufService, DWORD (this), TimerCallback);
944 // Playback begun, no longer cued
949 // If the buffer was lost, try to restore it
950 if ( hr == DSERR_BUFFERLOST ) {
951 hr = m_pdsb->Restore();
953 hr = m_pdsb->Play (0, 0, DSBPLAY_LOOPING);
956 nprintf(("Sound", "Sound => Lost a buffer, tried restoring but got %s\n", get_DSERR_text(hr) ));
957 Int3(); // get Alan, he wants to see this
962 nprintf(("Sound", "Sound => Play failed with return value %s\n", get_DSERR_text(hr) ));
968 // Timer callback for Timer object created by ::Play method.
969 BOOL AudioStream::TimerCallback (DWORD dwUser)
971 // dwUser contains ptr to AudioStream object
972 AudioStream * pas = (AudioStream *) dwUser;
974 return (pas->ServiceBuffer ());
977 void AudioStream::Set_Byte_Cutoff(unsigned int byte_cutoff)
979 if ( m_pwavefile == NULL )
982 m_pwavefile->m_max_uncompressed_bytes_to_read = byte_cutoff;
985 unsigned int AudioStream::Get_Bytes_Committed(void)
987 if ( m_pwavefile == NULL )
990 return m_pwavefile->m_total_uncompressed_bytes_read;
995 void AudioStream::Fade_and_Destroy (void)
998 m_bDestroy_when_faded = TRUE;
1002 void AudioStream::Fade_and_Stop (void)
1005 m_bDestroy_when_faded = FALSE;
1010 void AudioStream::Stop(int paused)
1013 // Stop DirectSound playback
1016 m_bIsPaused = paused;
1018 // Delete Timer object
1019 m_timer.destructor();
1024 void AudioStream::Stop_and_Rewind (void)
1027 // Stop DirectSound playback
1030 // Delete Timer object
1031 m_timer.destructor();
1036 m_fCued = FALSE; // this will cause wave file to start from beginning
1037 m_bReadingDone = FALSE;
1041 void AudioStream::Set_Volume(long vol)
1049 Assert( vol >= -10000 && vol <= 0 );
1050 h_result = m_pdsb->SetVolume(vol);
1052 if ( h_result != DS_OK )
1053 nprintf(("Sound","SOUND => SetVolume() failed with code '%s'\n", get_DSERR_text(h_result) ));
1058 long AudioStream::Get_Volume()
1064 void Timer::constructor(void)
1071 void Timer::destructor(void)
1074 timeKillEvent (m_nIDTimer);
1081 BOOL Timer::Create (UINT nPeriod, UINT nRes, DWORD dwUser, TIMERCALLBACK pfnCallback)
1083 BOOL bRtn = SUCCESS; // assume success
1085 Assert(pfnCallback);
1086 Assert(nPeriod > 10);
1087 Assert(nPeriod >= nRes);
1089 m_nPeriod = nPeriod;
1092 m_pfnCallback = pfnCallback;
1094 if ((m_nIDTimer = timeSetEvent (m_nPeriod, m_nRes, TimeProc, (DWORD) this, TIME_PERIODIC)) == NULL) {
1102 // Timer proc for multimedia timer callback set with timeSetTime().
1104 // Calls procedure specified when Timer object was created. The
1105 // dwUser parameter contains "this" pointer for associated Timer object.
1107 void CALLBACK Timer::TimeProc(UINT uID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2)
1109 // dwUser contains ptr to Timer object
1110 Timer * ptimer = (Timer *) dwUser;
1112 // Call user-specified callback and pass back user specified data
1113 (ptimer->m_pfnCallback) (ptimer->m_dwUser);
1117 // WaveFile class implementation
1119 ////////////////////////////////////////////////////////////
1122 void WaveFile::Init(void)
1124 // Init data members
1127 m_pwfmt_original = NULL;
1129 m_nUncompressedAvgDataRate = 0;
1132 m_total_uncompressed_bytes_read = 0;
1133 m_max_uncompressed_bytes_to_read = AS_HIGHEST_MAX;
1136 m_abort_next_read = FALSE;
1140 void WaveFile::Close(void)
1143 if (m_pwfmt_original) {
1144 free(m_pwfmt_original);
1145 m_pwfmt_original = NULL;
1148 if ( m_hStream_open ) {
1149 ACM_stream_close((void*)m_hStream);
1156 mmioClose( cfp, 0 );
1163 BOOL WaveFile::Open (LPSTR pszFilename)
1167 BOOL fRtn = SUCCESS; // assume success
1168 PCMWAVEFORMAT pcmwf;
1169 char fullpath[_MAX_PATH];
1171 m_total_uncompressed_bytes_read = 0;
1172 m_max_uncompressed_bytes_to_read = AS_HIGHEST_MAX;
1174 int FileSize, FileOffset;
1176 if ( !cf_find_file_location(pszFilename, CF_TYPE_ANY, fullpath, &FileSize, &FileOffset )) {
1180 cfp = mmioOpen(fullpath, NULL, MMIO_ALLOCBUF | MMIO_READ);
1181 if ( cfp == NULL ) {
1185 // Skip the "RIFF" tag and file size (8 bytes)
1186 // Skip the "WAVE" tag (4 bytes)
1187 mmioSeek( cfp, 12+FileOffset, SEEK_SET );
1189 // Now read RIFF tags until the end of file
1190 uint tag, size, next_chunk;
1192 while(done == FALSE) {
1193 if ( mmioRead(cfp, (char *)&tag, sizeof(uint)) != sizeof(uint) )
1196 if ( mmioRead(cfp, (char *)&size, sizeof(uint)) != sizeof(uint) )
1199 next_chunk = mmioSeek( cfp, 0, SEEK_CUR );
1203 case 0x20746d66: // The 'fmt ' tag
1204 mmioRead( cfp, (char *)&pcmwf, sizeof(PCMWAVEFORMAT) );
1205 if ( pcmwf.wf.wFormatTag != WAVE_FORMAT_PCM ) {
1206 mmioRead( cfp, (char *)&cbExtra, sizeof(short) );
1209 // Allocate memory for WAVEFORMATEX structure + extra bytes
1210 if ( (m_pwfmt_original = (WAVEFORMATEX *) malloc ( sizeof(WAVEFORMATEX)+cbExtra )) != NULL ){
1211 Assert(m_pwfmt_original != NULL);
1212 // Copy bytes from temporary format structure
1213 memcpy (m_pwfmt_original, &pcmwf, sizeof(pcmwf));
1214 m_pwfmt_original->cbSize = cbExtra;
1216 // Read those extra bytes, append to WAVEFORMATEX structure
1218 mmioRead( cfp, (char *)((ubyte *)(m_pwfmt_original) + sizeof(WAVEFORMATEX)), cbExtra );
1222 Int3(); // malloc failed
1227 case 0x61746164: // the 'data' tag
1228 m_nDataSize = size; // This is size of data chunk. Compressed if ADPCM.
1229 m_data_bytes_left = size;
1230 m_data_offset = mmioSeek( cfp, 0, SEEK_CUR);
1234 default: // unknown, skip it
1238 mmioSeek( cfp, next_chunk, SEEK_SET );
1241 // At this stage, examine source format, and set up WAVEFORATEX structure for DirectSound.
1242 // Since DirectSound only supports PCM, force this structure to be PCM compliant. We will
1243 // need to convert data on the fly later if our souce is not PCM
1244 switch ( m_pwfmt_original->wFormatTag ) {
1245 case WAVE_FORMAT_PCM:
1246 m_wave_format = WAVE_FORMAT_PCM;
1247 m_wfmt.wBitsPerSample = m_pwfmt_original->wBitsPerSample;
1250 case WAVE_FORMAT_ADPCM:
1251 m_wave_format = WAVE_FORMAT_ADPCM;
1252 m_wfmt.wBitsPerSample = 16;
1256 nprintf(("SOUND", "SOUND => Not supporting %d format for playing wave files\n"));
1263 // Set up the WAVEFORMATEX structure to have the right PCM characteristics
1264 m_wfmt.wFormatTag = WAVE_FORMAT_PCM;
1265 m_wfmt.nChannels = m_pwfmt_original->nChannels;
1266 m_wfmt.nSamplesPerSec = m_pwfmt_original->nSamplesPerSec;
1268 m_wfmt.nBlockAlign = (unsigned short)(( m_wfmt.nChannels * m_wfmt.wBitsPerSample ) / 8);
1269 m_wfmt.nAvgBytesPerSec = m_wfmt.nBlockAlign * m_wfmt.nSamplesPerSec;
1271 // Init some member data from format chunk
1272 m_nBlockAlign = m_pwfmt_original->nBlockAlign;
1273 m_nUncompressedAvgDataRate = m_wfmt.nAvgBytesPerSec;
1275 // Cue for streaming
1282 // Handle all errors here
1283 nprintf(("SOUND","SOUND ==> Could not open wave file %s for streaming\n",pszFilename));
1288 mmioClose( cfp, 0 );
1291 if (m_pwfmt_original)
1293 free(m_pwfmt_original);
1294 m_pwfmt_original = NULL;
1304 // Set the file pointer to the start of wave data
1306 BOOL WaveFile::Cue (void)
1308 BOOL fRtn = SUCCESS; // assume success
1311 m_total_uncompressed_bytes_read = 0;
1312 m_max_uncompressed_bytes_to_read = AS_HIGHEST_MAX;
1314 rval = mmioSeek( cfp, m_data_offset, SEEK_SET );
1319 m_data_bytes_left = m_nDataSize;
1320 m_abort_next_read = FALSE;
1328 // Returns number of bytes actually read.
1330 // Returns -1 if there is nothing more to be read. This function can return 0, since
1331 // sometimes the amount of bytes requested is too small for the ACM decompression to
1332 // locate a suitable block
1333 int WaveFile::Read(BYTE *pbDest, UINT cbSize, int service)
1335 unsigned char *dest_buf=NULL, *uncompressed_wave_data;
1336 int rc, uncompressed_bytes_written;
1337 unsigned int src_bytes_used, convert_len, num_bytes_desired=0, num_bytes_read;
1339 // nprintf(("Alan","Reqeusted: %d\n", cbSize));
1343 uncompressed_wave_data = Wavedata_service_buffer;
1345 uncompressed_wave_data = Wavedata_load_buffer;
1348 switch ( m_wave_format ) {
1349 case WAVE_FORMAT_PCM:
1350 num_bytes_desired = cbSize;
1354 case WAVE_FORMAT_ADPCM:
1355 if ( !m_hStream_open ) {
1356 if ( !ACM_stream_open(m_pwfmt_original, &m_wfxDest, (void**)&m_hStream), m_bits_per_sample_uncompressed ) {
1363 num_bytes_desired = cbSize;
1366 dest_buf = Compressed_service_buffer;
1368 dest_buf = Compressed_buffer;
1371 if ( num_bytes_desired <= 0 ) {
1372 num_bytes_desired = 0;
1373 // nprintf(("Alan","No bytes required for ADPCM time interval\n"));
1375 num_bytes_desired = ACM_query_source_size((void*)m_hStream, cbSize);
1376 // nprintf(("Alan","Num bytes desired: %d\n", num_bytes_desired));
1381 nprintf(("SOUND", "SOUND => Not supporting %d format for playing wave files\n"));
1391 // read data from disk
1392 if ( m_data_bytes_left <= 0 ) {
1394 uncompressed_bytes_written = 0;
1398 if ( m_data_bytes_left > 0 && num_bytes_desired > 0 ) {
1401 if ( num_bytes_desired <= (unsigned int)m_data_bytes_left ) {
1402 num_bytes_read = num_bytes_desired;
1405 num_bytes_read = m_data_bytes_left;
1408 actual_read = mmioRead( cfp, (char *)dest_buf, num_bytes_read );
1409 if ( (actual_read <= 0) || (m_abort_next_read) ) {
1411 uncompressed_bytes_written = 0;
1415 if ( num_bytes_desired >= (unsigned int)m_data_bytes_left ) {
1416 m_abort_next_read = 1;
1419 num_bytes_read = actual_read;
1422 // convert data if necessary, to PCM
1423 if ( m_wave_format == WAVE_FORMAT_ADPCM ) {
1424 if ( num_bytes_read > 0 ) {
1425 rc = ACM_convert((void*)m_hStream, dest_buf, num_bytes_read, uncompressed_wave_data, BIGBUF_SIZE, &convert_len, &src_bytes_used);
1429 if ( convert_len == 0 ) {
1434 Assert(src_bytes_used <= num_bytes_read);
1435 if ( src_bytes_used < num_bytes_read ) {
1436 // seek back file pointer to reposition before unused source data
1437 mmioSeek(cfp, src_bytes_used - num_bytes_read, SEEK_CUR);
1440 // Adjust number of bytes left
1441 m_data_bytes_left -= src_bytes_used;
1442 m_nBytesPlayed += src_bytes_used;
1443 uncompressed_bytes_written = convert_len;
1445 // Successful read, keep running total of number of data bytes read
1449 // Successful read, keep running total of number of data bytes read
1450 // Adjust number of bytes left
1451 m_data_bytes_left -= num_bytes_read;
1452 m_nBytesPlayed += num_bytes_read;
1453 uncompressed_bytes_written = num_bytes_read;
1459 uncompressed_bytes_written = 0;
1462 m_total_uncompressed_bytes_read += uncompressed_bytes_written;
1463 // nprintf(("Alan","Read: %d\n", uncompressed_bytes_written));
1464 return (uncompressed_bytes_written);
1470 // Returns 8 bits of data representing silence for the Wave file format.
1472 // Since we are dealing only with PCM format, we can fudge a bit and take
1473 // advantage of the fact that for all PCM formats, silence can be represented
1474 // by a single byte, repeated to make up the proper word size. The actual size
1475 // of a word of wave data depends on the format:
1477 // PCM Format Word Size Silence Data
1478 // 8-bit mono 1 byte 0x80
1479 // 8-bit stereo 2 bytes 0x8080
1480 // 16-bit mono 2 bytes 0x0000
1481 // 16-bit stereo 4 bytes 0x00000000
1483 BYTE WaveFile::GetSilenceData (void)
1485 BYTE bSilenceData = 0;
1487 // Silence data depends on format of Wave file
1488 if (m_pwfmt_original) {
1489 if (m_wfmt.wBitsPerSample == 8) {
1490 // For 8-bit formats (unsigned, 0 to 255)
1491 // Packed DWORD = 0x80808080;
1492 bSilenceData = 0x80;
1494 else if (m_wfmt.wBitsPerSample == 16) {
1495 // For 16-bit formats (signed, -32768 to 32767)
1496 // Packed DWORD = 0x00000000;
1497 bSilenceData = 0x00;
1507 return (bSilenceData);
1510 int Audiostream_inited = 0;
1511 AudioStreamServices * m_pass = NULL; // ptr to AudioStreamServices object
1513 #define MAX_AUDIO_STREAMS 30
1514 AudioStream Audio_streams[MAX_AUDIO_STREAMS];
1516 void audiostream_init()
1520 if ( Audiostream_inited == 1 )
1523 if ( !ACM_is_inited() ) {
1527 // Create and initialize AudioStreamServices object.
1528 // This must be done once and only once for each window that uses
1529 // streaming services.
1530 m_pass = (AudioStreamServices *)malloc(sizeof(AudioStreamServices));
1533 m_pass->Constructor();
1534 m_pass->Initialize();
1536 if ( !pDirectSound ) {
1541 // Allocate memory for the buffer which holds the uncompressed wave data that is streamed from the
1542 // disk during a load/cue
1543 if ( Wavedata_load_buffer == NULL ) {
1544 Wavedata_load_buffer = (unsigned char*)malloc(BIGBUF_SIZE);
1545 Assert(Wavedata_load_buffer != NULL);
1548 // Allocate memory for the buffer which holds the uncompressed wave data that is streamed from the
1549 // disk during a service interval
1550 if ( Wavedata_service_buffer == NULL ) {
1551 Wavedata_service_buffer = (unsigned char*)malloc(BIGBUF_SIZE);
1552 Assert(Wavedata_service_buffer != NULL);
1555 // Allocate memory for the buffer which holds the compressed wave data that is read from the hard disk
1556 if ( Compressed_buffer == NULL ) {
1557 Compressed_buffer = (unsigned char*)malloc(COMPRESSED_BUFFER_SIZE);
1558 Assert(Compressed_buffer != NULL);
1561 if ( Compressed_service_buffer == NULL ) {
1562 Compressed_service_buffer = (unsigned char*)malloc(COMPRESSED_BUFFER_SIZE);
1563 Assert(Compressed_service_buffer != NULL);
1566 for ( i = 0; i < MAX_AUDIO_STREAMS; i++ ) {
1567 Audio_streams[i].Init_Data();
1568 Audio_streams[i].status = ASF_FREE;
1569 Audio_streams[i].type = ASF_NONE;
1572 InitializeCriticalSection( &Global_service_lock );
1574 Audiostream_inited = 1;
1577 // Close down the audiostream system. Must call audiostream_init() before any audiostream functions can
1579 void audiostream_close()
1582 if ( Audiostream_inited == 0 )
1585 for ( i = 0; i < MAX_AUDIO_STREAMS; i++ ) {
1586 if ( Audio_streams[i].status == ASF_USED ) {
1587 Audio_streams[i].status = ASF_FREE;
1588 Audio_streams[i].Destroy();
1592 // Destroy AudioStreamServices object
1598 // free global buffers
1599 if ( Wavedata_load_buffer ) {
1600 free(Wavedata_load_buffer);
1601 Wavedata_load_buffer = NULL;
1604 if ( Wavedata_service_buffer ) {
1605 free(Wavedata_service_buffer);
1606 Wavedata_service_buffer = NULL;
1609 if ( Compressed_buffer ) {
1610 free(Compressed_buffer);
1611 Compressed_buffer = NULL;
1614 if ( Compressed_service_buffer ) {
1615 free(Compressed_service_buffer);
1616 Compressed_service_buffer = NULL;
1619 DeleteCriticalSection( &Global_service_lock );
1621 Audiostream_inited = 0;
1624 // Open a digital sound file for streaming
1626 // input: filename => disk filename of sound file
1627 // type => what type of audio stream do we want to open:
1632 // returns: success => handle to identify streaming sound
1634 int audiostream_open( char * filename, int type )
1637 if (!Audiostream_inited || !snd_is_inited())
1640 for ( i = 0; i < MAX_AUDIO_STREAMS; i++ ) {
1641 if ( Audio_streams[i].status == ASF_FREE ) {
1642 Audio_streams[i].status = ASF_USED;
1643 Audio_streams[i].type = type;
1648 if ( i == MAX_AUDIO_STREAMS ) {
1649 nprintf(("Sound", "SOUND => No more audio streams available!\n"));
1656 Audio_streams[i].m_bits_per_sample_uncompressed = 8;
1658 case ASF_EVENTMUSIC:
1659 Audio_streams[i].m_bits_per_sample_uncompressed = 16;
1666 rc = Audio_streams[i].Create(filename, m_pass);
1668 Audio_streams[i].status = ASF_FREE;
1676 void audiostream_close_file(int i, int fade)
1678 if (!Audiostream_inited)
1684 Assert( i >= 0 && i < MAX_AUDIO_STREAMS );
1686 if ( Audio_streams[i].status == ASF_USED ) {
1687 if ( fade == TRUE ) {
1688 Audio_streams[i].Fade_and_Destroy();
1691 Audio_streams[i].Destroy();
1696 void audiostream_close_all(int fade)
1700 for ( i = 0; i < MAX_AUDIO_STREAMS; i++ ) {
1701 if ( Audio_streams[i].status == ASF_FREE )
1704 audiostream_close_file(i, fade);
1708 extern int ds_convert_volume(float volume);
1710 void audiostream_play(int i, float volume, int looping)
1712 if (!Audiostream_inited)
1718 Assert(looping >= 0);
1719 Assert( i >= 0 && i < MAX_AUDIO_STREAMS );
1721 // convert from 0->1 to -10000->0 for volume
1722 int converted_volume;
1723 if ( volume == -1 ) {
1724 converted_volume = Audio_streams[i].Get_Default_Volume();
1727 Assert(volume >= 0.0f && volume <= 1.0f );
1728 converted_volume = ds_convert_volume(volume);
1731 Assert( Audio_streams[i].status == ASF_USED );
1732 Audio_streams[i].Set_Default_Volume(converted_volume);
1733 Audio_streams[i].Play(converted_volume, looping);
1736 void audiostream_stop(int i, int rewind, int paused)
1738 if (!Audiostream_inited) return;
1743 Assert( i >= 0 && i < MAX_AUDIO_STREAMS );
1744 Assert( Audio_streams[i].status == ASF_USED );
1747 Audio_streams[i].Stop_and_Rewind();
1749 Audio_streams[i].Stop(paused);
1752 int audiostream_is_playing(int i)
1757 Assert( i >= 0 && i < MAX_AUDIO_STREAMS );
1758 if ( Audio_streams[i].status != ASF_USED )
1761 return Audio_streams[i].Is_Playing();
1765 void audiostream_set_volume_all(float volume, int type)
1769 for ( i = 0; i < MAX_AUDIO_STREAMS; i++ ) {
1770 if ( Audio_streams[i].status == ASF_FREE )
1773 if ( Audio_streams[i].type == type ) {
1774 int converted_volume;
1775 converted_volume = ds_convert_volume(volume);
1776 Audio_streams[i].Set_Volume(converted_volume);
1782 void audiostream_set_volume(int i, float volume)
1787 Assert( i >= 0 && i < MAX_AUDIO_STREAMS );
1788 Assert( volume >= 0 && volume <= 1);
1790 if ( Audio_streams[i].status == ASF_FREE )
1793 int converted_volume;
1794 converted_volume = ds_convert_volume(volume);
1795 Audio_streams[i].Set_Volume(converted_volume);
1799 int audiostream_is_paused(int i)
1804 Assert( i >= 0 && i < MAX_AUDIO_STREAMS );
1805 if ( Audio_streams[i].status == ASF_FREE )
1809 is_paused = Audio_streams[i].Is_Paused();
1814 void audiostream_set_byte_cutoff(int i, unsigned int cutoff)
1819 Assert( i >= 0 && i < MAX_AUDIO_STREAMS );
1820 Assert( cutoff > 0 );
1822 if ( Audio_streams[i].status == ASF_FREE )
1825 Audio_streams[i].Set_Byte_Cutoff(cutoff);
1829 unsigned int audiostream_get_bytes_committed(int i)
1834 Assert( i >= 0 && i < MAX_AUDIO_STREAMS );
1836 if ( Audio_streams[i].status == ASF_FREE )
1839 unsigned int num_bytes_committed;
1840 num_bytes_committed = Audio_streams[i].Get_Bytes_Committed();
1841 return num_bytes_committed;
1844 int audiostream_done_reading(int i)
1849 Assert( i >= 0 && i < MAX_AUDIO_STREAMS );
1851 if ( Audio_streams[i].status == ASF_FREE )
1855 done_reading = Audio_streams[i].Is_Past_Limit();
1856 return done_reading;
1860 int audiostream_is_inited()
1862 return Audiostream_inited;
1865 // pause a single audio stream, indentified by handle i.
1866 void audiostream_pause(int i)
1871 Assert( i >= 0 && i < MAX_AUDIO_STREAMS );
1872 if ( Audio_streams[i].status == ASF_FREE )
1875 if ( audiostream_is_playing(i) == TRUE ) {
1876 audiostream_stop(i, 0, 1);
1880 // pause all audio streams that are currently playing.
1881 void audiostream_pause_all()
1885 for ( i = 0; i < MAX_AUDIO_STREAMS; i++ ) {
1886 if ( Audio_streams[i].status == ASF_FREE )
1889 audiostream_pause(i);
1893 // unpause the audio stream identified by handle i.
1894 void audiostream_unpause(int i)
1901 Assert( i >= 0 && i < MAX_AUDIO_STREAMS );
1902 if ( Audio_streams[i].status == ASF_FREE )
1905 if ( audiostream_is_paused(i) == TRUE ) {
1906 is_looping = Audio_streams[i].Is_looping();
1907 audiostream_play(i, -1.0f, is_looping);
1911 // unpause all audio streams that are currently paused
1912 void audiostream_unpause_all()
1916 for ( i = 0; i < MAX_AUDIO_STREAMS; i++ ) {
1917 if ( Audio_streams[i].status == ASF_FREE )
1920 audiostream_unpause(i);