snd_loc.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. Copyright (C) 1997-2001 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. // snd_loc.h -- private sound functions
  16. // !!! if this is changed, the asm code must change !!!
  17. typedef struct
  18. {
  19. int left;
  20. int right;
  21. } portable_samplepair_t;
  22. typedef struct
  23. {
  24. int length;
  25. int loopstart;
  26. int speed; // not needed, because converted on load?
  27. int width;
  28. int stereo;
  29. byte data[1]; // variable sized
  30. } sfxcache_t;
  31. typedef struct sfx_s
  32. {
  33. char name[MAX_QPATH];
  34. int registration_sequence;
  35. sfxcache_t *cache;
  36. char *truename;
  37. } sfx_t;
  38. // a playsound_t will be generated by each call to S_StartSound,
  39. // when the mixer reaches playsound->begin, the playsound will
  40. // be assigned to a channel
  41. typedef struct playsound_s
  42. {
  43. struct playsound_s *prev, *next;
  44. sfx_t *sfx;
  45. float volume;
  46. float attenuation;
  47. int entnum;
  48. int entchannel;
  49. qboolean fixed_origin; // use origin field instead of entnum's origin
  50. vec3_t origin;
  51. unsigned begin; // begin on this sample
  52. } playsound_t;
  53. typedef struct
  54. {
  55. int channels;
  56. int samples; // mono samples in buffer
  57. int submission_chunk; // don't mix less than this #
  58. int samplepos; // in mono samples
  59. int samplebits;
  60. int speed;
  61. byte *buffer;
  62. } dma_t;
  63. // !!! if this is changed, the asm code must change !!!
  64. typedef struct
  65. {
  66. sfx_t *sfx; // sfx number
  67. int leftvol; // 0-255 volume
  68. int rightvol; // 0-255 volume
  69. int end; // end time in global paintsamples
  70. int pos; // sample position in sfx
  71. int looping; // where to loop, -1 = no looping OBSOLETE?
  72. int entnum; // to allow overriding a specific sound
  73. int entchannel; //
  74. vec3_t origin; // only use if fixed_origin is set
  75. vec_t dist_mult; // distance multiplier (attenuation/clipK)
  76. int master_vol; // 0-255 master volume
  77. qboolean fixed_origin; // use origin instead of fetching entnum's origin
  78. qboolean autosound; // from an entity->sound, cleared each frame
  79. } channel_t;
  80. typedef struct
  81. {
  82. int rate;
  83. int width;
  84. int channels;
  85. int loopstart;
  86. int samples;
  87. int dataofs; // chunk starts this many bytes from file start
  88. } wavinfo_t;
  89. /*
  90. ====================================================================
  91. SYSTEM SPECIFIC FUNCTIONS
  92. ====================================================================
  93. */
  94. // initializes cycling through a DMA buffer and returns information on it
  95. qboolean SNDDMA_Init(void);
  96. // gets the current DMA position
  97. int SNDDMA_GetDMAPos(void);
  98. // shutdown the DMA xfer.
  99. void SNDDMA_Shutdown(void);
  100. void SNDDMA_BeginPainting (void);
  101. void SNDDMA_Submit(void);
  102. //====================================================================
  103. #define MAX_CHANNELS 32
  104. extern channel_t channels[MAX_CHANNELS];
  105. extern int paintedtime;
  106. extern int s_rawend;
  107. extern vec3_t listener_origin;
  108. extern vec3_t listener_forward;
  109. extern vec3_t listener_right;
  110. extern vec3_t listener_up;
  111. extern dma_t dma;
  112. extern playsound_t s_pendingplays;
  113. #define MAX_RAW_SAMPLES 8192
  114. extern portable_samplepair_t s_rawsamples[MAX_RAW_SAMPLES];
  115. extern cvar_t *s_volume;
  116. extern cvar_t *s_nosound;
  117. extern cvar_t *s_loadas8bit;
  118. extern cvar_t *s_khz;
  119. extern cvar_t *s_show;
  120. extern cvar_t *s_mixahead;
  121. extern cvar_t *s_testsound;
  122. extern cvar_t *s_primary;
  123. wavinfo_t GetWavinfo (char *name, byte *wav, int wavlength);
  124. void S_InitScaletable (void);
  125. sfxcache_t *S_LoadSound (sfx_t *s);
  126. void S_IssuePlaysound (playsound_t *ps);
  127. void S_PaintChannels(int endtime);
  128. // picks a channel based on priorities, empty slots, number of channels
  129. channel_t *S_PickChannel(int entnum, int entchannel);
  130. // spatializes a channel
  131. void S_Spatialize(channel_t *ch);