cp_player_data_utils.cpp 5.5 KB

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