sound.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*
  2. Copyright (C) 1996-1997 Id Software, Inc.
  3. This program is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU General Public License
  5. as published by the Free Software Foundation; either version 2
  6. of the License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. See the GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. */
  15. // sound.h -- client sound i/o functions
  16. #ifndef __SOUND__
  17. #define __SOUND__
  18. #define DEFAULT_SOUND_PACKET_VOLUME 255
  19. #define DEFAULT_SOUND_PACKET_ATTENUATION 1.0
  20. // !!! if this is changed, it much be changed in asm_i386.h too !!!
  21. typedef struct
  22. {
  23. int left;
  24. int right;
  25. } portable_samplepair_t;
  26. typedef struct sfx_s
  27. {
  28. char name[MAX_QPATH];
  29. cache_user_t cache;
  30. } sfx_t;
  31. // !!! if this is changed, it much be changed in asm_i386.h too !!!
  32. typedef struct
  33. {
  34. int length;
  35. int loopstart;
  36. int speed;
  37. int width;
  38. int stereo;
  39. byte data[1]; // variable sized
  40. } sfxcache_t;
  41. typedef struct
  42. {
  43. qboolean gamealive;
  44. qboolean soundalive;
  45. qboolean splitbuffer;
  46. int channels;
  47. int samples; // mono samples in buffer
  48. int submission_chunk; // don't mix less than this #
  49. int samplepos; // in mono samples
  50. int samplebits;
  51. int speed;
  52. unsigned char *buffer;
  53. } dma_t;
  54. // !!! if this is changed, it much be changed in asm_i386.h too !!!
  55. typedef struct
  56. {
  57. sfx_t *sfx; // sfx number
  58. int leftvol; // 0-255 volume
  59. int rightvol; // 0-255 volume
  60. int end; // end time in global paintsamples
  61. int pos; // sample position in sfx
  62. int looping; // where to loop, -1 = no looping
  63. int entnum; // to allow overriding a specific sound
  64. int entchannel; //
  65. vec3_t origin; // origin of sound effect
  66. vec_t dist_mult; // distance multiplier (attenuation/clipK)
  67. int master_vol; // 0-255 master volume
  68. } channel_t;
  69. typedef struct
  70. {
  71. int rate;
  72. int width;
  73. int channels;
  74. int loopstart;
  75. int samples;
  76. int dataofs; // chunk starts this many bytes from file start
  77. } wavinfo_t;
  78. void S_Init (void);
  79. void S_Startup (void);
  80. void S_Shutdown (void);
  81. void S_StartSound (int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol, float attenuation);
  82. void S_StaticSound (sfx_t *sfx, vec3_t origin, float vol, float attenuation);
  83. void S_StopSound (int entnum, int entchannel);
  84. void S_StopAllSounds(qboolean clear);
  85. void S_ClearBuffer (void);
  86. void S_Update (vec3_t origin, vec3_t v_forward, vec3_t v_right, vec3_t v_up);
  87. void S_ExtraUpdate (void);
  88. sfx_t *S_PrecacheSound (char *sample);
  89. void S_TouchSound (char *sample);
  90. void S_ClearPrecache (void);
  91. void S_BeginPrecaching (void);
  92. void S_EndPrecaching (void);
  93. void S_PaintChannels(int endtime);
  94. void S_InitPaintChannels (void);
  95. // picks a channel based on priorities, empty slots, number of channels
  96. channel_t *SND_PickChannel(int entnum, int entchannel);
  97. // spatializes a channel
  98. void SND_Spatialize(channel_t *ch);
  99. // initializes cycling through a DMA buffer and returns information on it
  100. qboolean SNDDMA_Init(void);
  101. // gets the current DMA position
  102. int SNDDMA_GetDMAPos(void);
  103. // shutdown the DMA xfer.
  104. void SNDDMA_Shutdown(void);
  105. // ====================================================================
  106. // User-setable variables
  107. // ====================================================================
  108. #define MAX_CHANNELS 128
  109. #define MAX_DYNAMIC_CHANNELS 8
  110. extern channel_t channels[MAX_CHANNELS];
  111. // 0 to MAX_DYNAMIC_CHANNELS-1 = normal entity sounds
  112. // MAX_DYNAMIC_CHANNELS to MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS -1 = water, etc
  113. // MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS to total_channels = static sounds
  114. extern int total_channels;
  115. //
  116. // Fake dma is a synchronous faking of the DMA progress used for
  117. // isolating performance in the renderer. The fakedma_updates is
  118. // number of times S_Update() is called per second.
  119. //
  120. extern qboolean fakedma;
  121. extern int fakedma_updates;
  122. extern int paintedtime;
  123. extern vec3_t listener_origin;
  124. extern vec3_t listener_forward;
  125. extern vec3_t listener_right;
  126. extern vec3_t listener_up;
  127. extern volatile dma_t *shm;
  128. extern volatile dma_t sn;
  129. extern vec_t sound_nominal_clip_dist;
  130. extern cvar_t loadas8bit;
  131. extern cvar_t bgmvolume;
  132. extern cvar_t volume;
  133. extern qboolean snd_initialized;
  134. extern int snd_blocked;
  135. void S_LocalSound (char *s);
  136. sfxcache_t *S_LoadSound (sfx_t *s);
  137. wavinfo_t GetWavinfo (char *name, byte *wav, int wavlength);
  138. void SND_InitScaletable (void);
  139. void SNDDMA_Submit(void);
  140. void S_AmbientOff (void);
  141. void S_AmbientOn (void);
  142. #endif