sound.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. // !!! if this is changed, it much be changed in asm_i386.h too !!!
  19. typedef struct
  20. {
  21. int left;
  22. int right;
  23. } portable_samplepair_t;
  24. typedef struct sfx_s
  25. {
  26. char name[MAX_QPATH];
  27. cache_user_t cache;
  28. } sfx_t;
  29. // !!! if this is changed, it much be changed in asm_i386.h too !!!
  30. typedef struct
  31. {
  32. int length;
  33. int loopstart;
  34. int speed;
  35. int width;
  36. int stereo;
  37. byte data[1]; // variable sized
  38. } sfxcache_t;
  39. typedef struct
  40. {
  41. qboolean gamealive;
  42. qboolean soundalive;
  43. qboolean splitbuffer;
  44. int channels;
  45. int samples; // mono samples in buffer
  46. int submission_chunk; // don't mix less than this #
  47. int samplepos; // in mono samples
  48. int samplebits;
  49. int speed;
  50. unsigned char *buffer;
  51. } dma_t;
  52. // !!! if this is changed, it much be changed in asm_i386.h too !!!
  53. typedef struct
  54. {
  55. sfx_t *sfx; // sfx number
  56. int leftvol; // 0-255 volume
  57. int rightvol; // 0-255 volume
  58. int end; // end time in global paintsamples
  59. int pos; // sample position in sfx
  60. int looping; // where to loop, -1 = no looping
  61. int entnum; // to allow overriding a specific sound
  62. int entchannel; //
  63. vec3_t origin; // origin of sound effect
  64. vec_t dist_mult; // distance multiplier (attenuation/clipK)
  65. int master_vol; // 0-255 master volume
  66. } channel_t;
  67. typedef struct
  68. {
  69. int rate;
  70. int width;
  71. int channels;
  72. int loopstart;
  73. int samples;
  74. int dataofs; // chunk starts this many bytes from file start
  75. } wavinfo_t;
  76. void S_Init (void);
  77. void S_Startup (void);
  78. void S_Shutdown (void);
  79. void S_StartSound (int entnum, int entchannel, sfx_t *sfx, vec3_t origin, float fvol, float attenuation);
  80. void S_StaticSound (sfx_t *sfx, vec3_t origin, float vol, float attenuation);
  81. void S_StopSound (int entnum, int entchannel);
  82. void S_StopAllSounds(qboolean clear);
  83. void S_ClearBuffer (void);
  84. void S_Update (vec3_t origin, vec3_t v_forward, vec3_t v_right, vec3_t v_up);
  85. void S_ExtraUpdate (void);
  86. sfx_t *S_PrecacheSound (char *sample);
  87. void S_TouchSound (char *sample);
  88. void S_ClearPrecache (void);
  89. void S_BeginPrecaching (void);
  90. void S_EndPrecaching (void);
  91. void S_PaintChannels(int endtime);
  92. void S_InitPaintChannels (void);
  93. // picks a channel based on priorities, empty slots, number of channels
  94. channel_t *SND_PickChannel(int entnum, int entchannel);
  95. // spatializes a channel
  96. void SND_Spatialize(channel_t *ch);
  97. // initializes cycling through a DMA buffer and returns information on it
  98. qboolean SNDDMA_Init(void);
  99. // gets the current DMA position
  100. int SNDDMA_GetDMAPos(void);
  101. // shutdown the DMA xfer.
  102. void SNDDMA_Shutdown(void);
  103. // ====================================================================
  104. // User-setable variables
  105. // ====================================================================
  106. #define MAX_CHANNELS 128
  107. #define MAX_DYNAMIC_CHANNELS 8
  108. extern channel_t channels[MAX_CHANNELS];
  109. // 0 to MAX_DYNAMIC_CHANNELS-1 = normal entity sounds
  110. // MAX_DYNAMIC_CHANNELS to MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS -1 = water, etc
  111. // MAX_DYNAMIC_CHANNELS + NUM_AMBIENTS to total_channels = static sounds
  112. extern int total_channels;
  113. //
  114. // Fake dma is a synchronous faking of the DMA progress used for
  115. // isolating performance in the renderer. The fakedma_updates is
  116. // number of times S_Update() is called per second.
  117. //
  118. extern qboolean fakedma;
  119. extern int fakedma_updates;
  120. extern int paintedtime;
  121. extern vec3_t listener_origin;
  122. extern vec3_t listener_forward;
  123. extern vec3_t listener_right;
  124. extern vec3_t listener_up;
  125. extern volatile dma_t *shm;
  126. extern volatile dma_t sn;
  127. extern vec_t sound_nominal_clip_dist;
  128. extern cvar_t loadas8bit;
  129. extern cvar_t bgmvolume;
  130. extern cvar_t volume;
  131. extern qboolean snd_initialized;
  132. extern int snd_blocked;
  133. void S_LocalSound (char *s);
  134. sfxcache_t *S_LoadSound (sfx_t *s);
  135. wavinfo_t GetWavinfo (char *name, byte *wav, int wavlength);
  136. void SND_InitScaletable (void);
  137. void SNDDMA_Submit(void);
  138. void S_AmbientOff (void);
  139. void S_AmbientOn (void);
  140. #endif