Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1 | pmbaty | 1 | /* |
| 2 | * Portions of this file are copyright Rebirth contributors and licensed as |
||
| 3 | * described in COPYING.txt. |
||
| 4 | * Portions of this file are copyright Parallax Software and licensed |
||
| 5 | * according to the Parallax license below. |
||
| 6 | * See COPYING.txt for license details. |
||
| 7 | |||
| 8 | THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX |
||
| 9 | SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO |
||
| 10 | END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A |
||
| 11 | ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS |
||
| 12 | IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS |
||
| 13 | SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE |
||
| 14 | FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE |
||
| 15 | CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS |
||
| 16 | AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE. |
||
| 17 | COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. |
||
| 18 | */ |
||
| 19 | |||
| 20 | /* |
||
| 21 | * |
||
| 22 | * Include file for sound hardware. |
||
| 23 | * |
||
| 24 | */ |
||
| 25 | |||
| 26 | #pragma once |
||
| 27 | |||
| 28 | #include <SDL_version.h> |
||
| 29 | #include <type_traits> |
||
| 30 | #include "pstypes.h" |
||
| 31 | #include "vecmat.h" |
||
| 32 | |||
| 33 | #ifdef __cplusplus |
||
| 34 | #include "dxxsconf.h" |
||
| 35 | #include "dsx-ns.h" |
||
| 36 | #include "fwd-object.h" |
||
| 37 | #include "fwd-segment.h" |
||
| 38 | #include <utility> |
||
| 39 | |||
| 40 | #ifdef dsx |
||
| 41 | namespace dcx { |
||
| 42 | |||
| 43 | struct sound_object; |
||
| 44 | extern int digi_volume; |
||
| 45 | |||
| 46 | } |
||
| 47 | namespace dsx { |
||
| 48 | struct digi_sound |
||
| 49 | { |
||
| 50 | int bits; |
||
| 51 | int freq; |
||
| 52 | int length; |
||
| 53 | uint8_t * data; |
||
| 54 | }; |
||
| 55 | |||
| 56 | extern int digi_get_settings(); |
||
| 57 | extern int digi_init(); |
||
| 58 | #ifndef RELEASE |
||
| 59 | extern void digi_reset(); |
||
| 60 | #endif |
||
| 61 | extern void digi_close(); |
||
| 62 | |||
| 63 | // Volume is max at F1_0. |
||
| 64 | extern void digi_play_sample( int sndnum, fix max_volume ); |
||
| 65 | extern void digi_play_sample_once( int sndnum, fix max_volume ); |
||
| 66 | #if defined(DXX_BUILD_DESCENT_I) || defined(DXX_BUILD_DESCENT_II) |
||
| 67 | enum class sound_stack : uint8_t |
||
| 68 | { |
||
| 69 | allow_stacking, |
||
| 70 | cancel_previous, |
||
| 71 | }; |
||
| 72 | void digi_link_sound_to_object(unsigned soundnum, vcobjptridx_t objnum, uint8_t forever, fix max_volume, sound_stack once); |
||
| 73 | void digi_kill_sound_linked_to_segment(vmsegidx_t segnum, unsigned sidenum, int soundnum); |
||
| 74 | void digi_link_sound_to_pos(unsigned soundnum, vcsegptridx_t segnum, unsigned sidenum, const vms_vector &pos, int forever, fix max_volume); |
||
| 75 | // Same as above, but you pass the max distance sound can be heard. The old way uses f1_0*256 for max_distance. |
||
| 76 | void digi_link_sound_to_object2(unsigned soundnum, vcobjptridx_t objnum, uint8_t forever, fix max_volume, sound_stack once, vm_distance max_distance); |
||
| 77 | void digi_link_sound_to_object3(unsigned soundnum, vcobjptridx_t objnum, uint8_t forever, fix max_volume, sound_stack once, vm_distance max_distance, int loop_start, int loop_end); |
||
| 78 | void digi_kill_sound_linked_to_object(vcobjptridx_t); |
||
| 79 | #endif |
||
| 80 | |||
| 81 | void digi_play_sample_3d(int soundno, int angle, int volume); // Volume from 0-0x7fff |
||
| 82 | |||
| 83 | extern void digi_init_sounds(); |
||
| 84 | extern void digi_sync_sounds(); |
||
| 85 | |||
| 86 | extern void digi_set_digi_volume( int dvolume ); |
||
| 87 | |||
| 88 | extern void digi_pause_digi_sounds(); |
||
| 89 | extern void digi_resume_digi_sounds(); |
||
| 90 | |||
| 91 | extern int digi_xlat_sound(int soundno); |
||
| 92 | |||
| 93 | extern void digi_stop_sound( int channel ); |
||
| 94 | |||
| 95 | // Volume 0-F1_0 |
||
| 96 | constexpr sound_object *sound_object_none = nullptr; |
||
| 97 | int digi_start_sound(short soundnum, fix volume, int pan, int looping, int loop_start, int loop_end, sound_object *); |
||
| 98 | |||
| 99 | // Stops all sounds that are playing |
||
| 100 | void digi_stop_all_channels(); |
||
| 101 | |||
| 102 | void digi_stop_digi_sounds(); |
||
| 103 | |||
| 104 | extern void digi_end_sound( int channel ); |
||
| 105 | extern void digi_set_channel_pan( int channel, int pan ); |
||
| 106 | extern void digi_set_channel_volume( int channel, int volume ); |
||
| 107 | extern int digi_is_channel_playing(int channel); |
||
| 108 | |||
| 109 | extern void digi_play_sample_looping( int soundno, fix max_volume,int loop_start, int loop_end ); |
||
| 110 | extern void digi_change_looping_volume( fix volume ); |
||
| 111 | extern void digi_stop_looping_sound(); |
||
| 112 | |||
| 113 | // Plays a queued voice sound. |
||
| 114 | extern void digi_start_sound_queued( short soundnum, fix volume ); |
||
| 115 | |||
| 116 | // Following declarations are for the runtime switching system |
||
| 117 | |||
| 118 | #define SAMPLE_RATE_11K 11025 |
||
| 119 | #define SAMPLE_RATE_22K 22050 |
||
| 120 | #define SAMPLE_RATE_44K 44100 |
||
| 121 | |||
| 122 | #define SDLMIXER_SYSTEM 1 |
||
| 123 | #define SDLAUDIO_SYSTEM 2 |
||
| 124 | |||
| 125 | #define MUSIC_TYPE_NONE 0 |
||
| 126 | #define MUSIC_TYPE_BUILTIN 1 |
||
| 127 | #if DXX_USE_SDL_REDBOOK_AUDIO |
||
| 128 | #define MUSIC_TYPE_REDBOOK 2 |
||
| 129 | #endif |
||
| 130 | #define MUSIC_TYPE_CUSTOM 3 |
||
| 131 | |||
| 132 | #define SOUND_MAX_VOLUME F1_0 / 2 |
||
| 133 | |||
| 134 | #if defined(DXX_BUILD_DESCENT_I) |
||
| 135 | extern int digi_sample_rate; |
||
| 136 | #endif |
||
| 137 | extern int Dont_start_sound_objects; |
||
| 138 | extern int SoundQ_channel; |
||
| 139 | void digi_select_system(); |
||
| 140 | |||
| 141 | #ifdef _WIN32 |
||
| 142 | // Windows native-MIDI stuff. |
||
| 143 | void digi_win32_set_midi_volume( int mvolume ); |
||
| 144 | int digi_win32_play_midi_song(const char * filename, int loop ); |
||
| 145 | void digi_win32_pause_midi_song(); |
||
| 146 | void digi_win32_resume_midi_song(); |
||
| 147 | void digi_win32_stop_midi_song(); |
||
| 148 | #endif |
||
| 149 | void digi_end_soundobj(sound_object &); |
||
| 150 | void SoundQ_end(); |
||
| 151 | #ifndef NDEBUG |
||
| 152 | int verify_sound_channel_free( int channel ); |
||
| 153 | #endif |
||
| 154 | |||
| 155 | } |
||
| 156 | |||
| 157 | namespace dcx { |
||
| 158 | |||
| 159 | class RAIIdigi_sound |
||
| 160 | { |
||
| 161 | static constexpr auto invalid_channel = std::integral_constant<int, -1>{}; |
||
| 162 | int channel = invalid_channel; |
||
| 163 | static void stop(int channel) |
||
| 164 | { |
||
| 165 | if (channel != invalid_channel) |
||
| 166 | digi_stop_sound(channel); |
||
| 167 | } |
||
| 168 | public: |
||
| 169 | ~RAIIdigi_sound() |
||
| 170 | { |
||
| 171 | stop(channel); |
||
| 172 | } |
||
| 173 | void reset(int c = invalid_channel) |
||
| 174 | { |
||
| 175 | stop(std::exchange(channel, c)); |
||
| 176 | } |
||
| 177 | operator int() const = delete; |
||
| 178 | explicit operator bool() const |
||
| 179 | { |
||
| 180 | return channel != invalid_channel; |
||
| 181 | } |
||
| 182 | }; |
||
| 183 | |||
| 184 | } |
||
| 185 | #endif |
||
| 186 | #endif |