cp_player_data_utils.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*************************************************************************/
  2. /* cp_player_data_utils.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #include "cp_player_data.h"
  30. uint8_t CPPlayer::vibrato_table[32]={
  31. 0, 24, 49, 74, 97,120,141,161,180,197,212,224,235,244,250,253,
  32. 255,253,250,244,235,224,212,197,180,161,141,120, 97, 74, 49, 24
  33. };
  34. uint8_t CPPlayer::auto_vibrato_table[128]={
  35. 0, 1, 3, 4, 6, 7, 9,10,12,14,15,17,18,20,21,23,
  36. 24,25,27,28,30,31,32,34,35,36,38,39,40,41,42,44,
  37. 45,46,47,48,49,50,51,52,53,54,54,55,56,57,57,58,
  38. 59,59,60,60,61,61,62,62,62,63,63,63,63,63,63,63,
  39. 64,63,63,63,63,63,63,63,62,62,62,61,61,60,60,59,
  40. 59,58,57,57,56,55,54,54,53,52,51,50,49,48,47,46,
  41. 45,44,42,41,40,39,38,36,35,34,32,31,30,28,27,25,
  42. 24,23,21,20,18,17,15,14,12,10, 9, 7, 6, 4, 3, 1
  43. };
  44. int8_t CPPlayer::panbrello_table[256]={
  45. 0, 2, 3, 5, 6, 8, 9, 11, 12, 14, 16, 17, 19, 20, 22, 23,
  46. 24, 26, 27, 29, 30, 32, 33, 34, 36, 37, 38, 39, 41, 42, 43, 44,
  47. 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 56, 57, 58, 59,
  48. 59, 60, 60, 61, 61, 62, 62, 62, 63, 63, 63, 64, 64, 64, 64, 64,
  49. 64, 64, 64, 64, 64, 64, 63, 63, 63, 62, 62, 62, 61, 61, 60, 60,
  50. 59, 59, 58, 57, 56, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46,
  51. 45, 44, 43, 42, 41, 39, 38, 37, 36, 34, 33, 32, 30, 29, 27, 26,
  52. 24, 23, 22, 20, 19, 17, 16, 14, 12, 11, 9, 8, 6, 5, 3, 2,
  53. 0,- 2,- 3,- 5,- 6,- 8,- 9,-11,-12,-14,-16,-17,-19,-20,-22,-23,
  54. -24,-26,-27,-29,-30,-32,-33,-34,-36,-37,-38,-39,-41,-42,-43,-44,
  55. -45,-46,-47,-48,-49,-50,-51,-52,-53,-54,-55,-56,-56,-57,-58,-59,
  56. -59,-60,-60,-61,-61,-62,-62,-62,-63,-63,-63,-64,-64,-64,-64,-64,
  57. -64,-64,-64,-64,-64,-64,-63,-63,-63,-62,-62,-62,-61,-61,-60,-60,
  58. -59,-59,-58,-57,-56,-56,-55,-54,-53,-52,-51,-50,-49,-48,-47,-46,
  59. -45,-44,-43,-42,-41,-39,-38,-37,-36,-34,-33,-32,-30,-29,-27,-26,
  60. -24,-23,-22,-20,-19,-17,-16,-14,-12,-11,- 9,- 8,- 6,- 5,- 3,- 2
  61. };
  62. int32_t CPPlayer::get_period(uint16_t p_note,int32_t p_c5speed) {
  63. if (song->has_linear_slides()) {
  64. return CPTables::get_linear_period(p_note,0);
  65. } else {
  66. return CPTables::get_log_period(p_note>>1,p_c5speed >>1);
  67. }
  68. }
  69. int32_t CPPlayer::get_frequency(int32_t period) {
  70. if (song->has_linear_slides()) {
  71. return CPTables::get_linear_frequency(period);
  72. } else {
  73. return CPTables::get_old_frequency(period);
  74. }
  75. }
  76. int CPPlayer::find_empty_voice() {
  77. int i;
  78. int min_priority,min_priority_chan=0,priority;
  79. for (i=0;i<control.max_voices;i++) {
  80. if ( ((voice[i].kick==KICK_NOTHING)||(voice[i].kick==KICK_ENVELOPE))&&!mixer->is_voice_active(i) ) {
  81. return i;
  82. }
  83. }
  84. // todo more
  85. for (i=0;i<control.max_voices;i++) {
  86. /* allow us to take over a nonexisting sample */
  87. /*
  88. if ((voice[i].s==NULL)
  89. return k;
  90. */
  91. if ((voice[i].kick==KICK_NOTHING)||(voice[i].kick==KICK_ENVELOPE)) {
  92. priority=voice[i].total_volume<<((CPSampleManager::get_singleton()->get_loop_type( voice[i].sample_ptr->get_sample_data())!=CP_LOOP_NONE)?1:0);
  93. if ((voice[i].has_master_channel)&&(&voice[i]==voice[i].master_channel->slave_voice)) {
  94. priority<<=2;
  95. }
  96. if ((i==0) || (priority<min_priority)) {
  97. min_priority=priority;
  98. min_priority_chan=i;
  99. }
  100. }
  101. }
  102. if (min_priority>8000*7) return -1; /* what the fuck is this? */
  103. return min_priority_chan;
  104. }