1 2 #ifndef AUDIO_STREAM_H 3 #define AUDIO_STREAM_H 4 5 #include <stdint.h> 6 7 // NUMBUFFERS is a number of buffers cyclically used for each stream. 8 // Double is enough, but we use quad for further stability, because 9 // OGG codec seems to be very sensitive to buffering. 10 11 #define TR_AUDIO_STREAM_NUMBUFFERS 4 12 13 // MAP_SIZE is similar to sound map size, but it is used to mark 14 // already played audiotracks. Note that audiotracks CAN play several 15 // times, if they were consequently called with increasing activation 16 // flags (e.g., at first we call it with 00001 flag, then with 00101, 17 // and so on). If all activation flags were set, including only once 18 // flag, audiotrack won't play anymore. 19 20 #define TR_AUDIO_STREAM_MAP_SIZE 256 21 22 // Stream loading method describes the way audiotracks are loaded. 23 // There are either seperate OGG files, single CDAUDIO.WAD file or 24 // seperate ADPCM WAV files. 25 // You can add extra types with implementation of extra audio codecs, 26 // only thing to do is to add corresponding stream and load routines 27 // into class' private section. 28 29 enum TR_AUDIO_STREAM_METHOD 30 { 31 TR_AUDIO_STREAM_METHOD_OGG, // OGG files. Used in TR1-2 (replaces CD audio). 32 TR_AUDIO_STREAM_METHOD_WAD, // WAD file. Used in TR3. 33 TR_AUDIO_STREAM_METHOD_WAV, // WAV files. Used in TR4-5. 34 TR_AUDIO_STREAM_METHOD_LASTINDEX 35 }; 36 37 // Crossfades for different track types are also different, 38 // since background ones tend to blend in smoothly, while one-shot 39 // tracks should be switched fastly. 40 41 #define TR_AUDIO_STREAM_CROSSFADE_ONESHOT (60.0f / 0.3f) 42 #define TR_AUDIO_STREAM_CROSSFADE_BACKGROUND (60.0f / 2.0f) 43 #define TR_AUDIO_STREAM_CROSSFADE_CHAT (60.0f / 0.1f) 44 45 // Damp coefficient specifies target volume level on a tracks 46 // that are being silenced (background music). The larger it is, the bigger 47 // silencing is. 48 49 #define TR_AUDIO_STREAM_DAMP_LEVEL 0.6f 50 51 // Damp fade speed is used when dampable track is either being 52 // damped or un-damped. 53 54 #define TR_AUDIO_STREAM_DAMP_SPEED (GAME_LOGIC_REFRESH_INTERVAL / 1.0f) 55 56 57 // Main stream track struct is used to create multi-channel soundtrack player, 58 // which differs from classic TR scheme, where each new soundtrack interrupted 59 // previous one. With flexible class handling, we now can implement multitrack 60 // player with automatic channel and crossfade management. 61 62 #define TR_AUDIO_STREAM_STOPPED (0) 63 #define TR_AUDIO_STREAM_PLAYING (1) 64 #define TR_AUDIO_STREAM_PAUSED (2) 65 #define TR_AUDIO_STREAM_STOPPING (3) 66 67 struct stream_internal_s; 68 69 typedef struct stream_track_s 70 { 71 int32_t track; 72 uint16_t type; // Either BACKGROUND, ONESHOT or CHAT. 73 uint16_t state; 74 uint32_t linked_buffers; 75 uint32_t buffer_offset; 76 float current_volume; // Stream volume, considering fades. 77 struct stream_internal_s *internal; 78 }stream_track_t, *stream_track_p; 79 80 81 void StreamTrack_Init(stream_track_p s); 82 void StreamTrack_Clear(stream_track_p s); 83 void StreamTrack_SetEffects(stream_track_p s, int value); 84 int StreamTrack_Play(stream_track_p s); 85 int StreamTrack_Stop(stream_track_p s); 86 int StreamTrack_Pause(stream_track_p s); 87 int StreamTrack_CheckForEnd(stream_track_p s); 88 89 int StreamTrack_IsNeedUpdateBuffer(stream_track_p s); 90 int StreamTrack_UpdateBuffer(stream_track_p s, uint8_t *buff, size_t size, int sample_bitsize, int channels, int frequency); 91 int StreamTrack_UpdateState(stream_track_p s, float time, float volume); 92 93 94 #endif // AUDIO_STREAM_H 95