OVOLUME.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Seven Kingdoms: Ancient Adversaries
  3. *
  4. * Copyright 1997,1998 Enlight Software Ltd.
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. */
  20. // Filename : OVOLUME.CPP
  21. // Description : volume unit type
  22. #include <OAUDIO.h>
  23. #include <OCONFIG.h>
  24. #include <OVOLUME.h>
  25. const int DEFAULT_VOL_DROP = 100; // distance 100, no sound
  26. const int DEFAULT_DIST_LIMIT = 40;
  27. const int DEFAULT_PAN_DROP = 100; // distance 100, extreme left or extreme right
  28. RelVolume DEF_REL_VOLUME(100,0);
  29. DsVolume::DsVolume(long dsVol, long dsPan) : ds_vol(dsVol), ds_pan(dsPan)
  30. {
  31. }
  32. DsVolume::DsVolume(AbsVolume &absVolume) : ds_vol(absVolume.abs_vol*100-10000), ds_pan(absVolume.ds_pan)
  33. {
  34. }
  35. DsVolume::DsVolume(RelVolume &relVolume)
  36. : ds_vol(audio.vol_multiply(relVolume.rel_vol)), ds_pan(relVolume.ds_pan)
  37. {
  38. }
  39. AbsVolume::AbsVolume(long absVol, long dsPan)
  40. : abs_vol(absVol), ds_pan(dsPan)
  41. {
  42. }
  43. AbsVolume::AbsVolume(DsVolume &dsVolume)
  44. : abs_vol((dsVolume.ds_vol+10000)/100), ds_pan(dsVolume.ds_pan)
  45. {
  46. }
  47. RelVolume::RelVolume(long relVol, long dsPan)
  48. : rel_vol(relVol), ds_pan(dsPan)
  49. {
  50. }
  51. RelVolume::RelVolume(PosVolume &posVolume)
  52. {
  53. long absX = posVolume.x >= 0 ? posVolume.x : -posVolume.x;
  54. long absY = posVolume.y >= 0 ? posVolume.y : -posVolume.y;
  55. long dist = absX >= absY ? absX :absY;
  56. if( dist <= DEFAULT_DIST_LIMIT )
  57. rel_vol = rel_vol = 100 - dist * 100 / DEFAULT_VOL_DROP;
  58. else
  59. rel_vol = 0;
  60. if( posVolume.x >= DEFAULT_PAN_DROP )
  61. ds_pan = 10000;
  62. else if( posVolume.x <= -DEFAULT_PAN_DROP )
  63. ds_pan = -10000;
  64. else
  65. ds_pan = 10000 / DEFAULT_PAN_DROP * posVolume.x;
  66. }
  67. RelVolume::RelVolume(PosVolume &posVolume, int drop, int limit)
  68. {
  69. long absX = posVolume.x >= 0 ? posVolume.x : -posVolume.x;
  70. long absY = posVolume.y >= 0 ? posVolume.y : -posVolume.y;
  71. long dist = absX >= absY ? absX :absY;
  72. if( dist <= limit )
  73. rel_vol = 100 - dist * 100 / drop;
  74. else
  75. rel_vol = 0;
  76. if( posVolume.x >= DEFAULT_PAN_DROP )
  77. ds_pan = 10000;
  78. else if( posVolume.x <= -DEFAULT_PAN_DROP )
  79. ds_pan = -10000;
  80. else
  81. ds_pan = 10000 / DEFAULT_PAN_DROP * posVolume.x;
  82. }
  83. PosVolume::PosVolume(long relLocX, long relLocY) : x(relLocX), y(relLocY)
  84. {
  85. }