lmms_basics.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * lmms_basics.h - typedefs for common types that are used in the whole app
  3. *
  4. * Copyright (c) 2004-2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
  5. *
  6. * This file is part of LMMS - https://lmms.io
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2 of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public
  19. * License along with this program (see COPYING); if not, write to the
  20. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21. * Boston, MA 02110-1301 USA.
  22. *
  23. */
  24. #ifndef TYPES_H
  25. #define TYPES_H
  26. #include <limits>
  27. #include "lmmsconfig.h"
  28. #ifdef LMMS_HAVE_STDINT_H
  29. #include <stdint.h>
  30. #endif
  31. typedef int32_t tact_t;
  32. typedef int32_t tick_t;
  33. typedef uint8_t volume_t;
  34. typedef int8_t panning_t;
  35. typedef float sample_t; // standard sample-type
  36. typedef int16_t int_sample_t; // 16-bit-int-sample
  37. typedef uint32_t sample_rate_t; // sample-rate
  38. typedef int16_t fpp_t; // frames per period (0-16384)
  39. typedef int32_t f_cnt_t; // standard frame-count
  40. typedef uint8_t ch_cnt_t; // channel-count (0-SURROUND_CHANNELS)
  41. typedef uint16_t bpm_t; // tempo (MIN_BPM to MAX_BPM)
  42. typedef uint16_t bitrate_t; // bitrate in kbps
  43. typedef uint16_t fx_ch_t; // FX-channel (0 to MAX_EFFECT_CHANNEL)
  44. typedef uint32_t jo_id_t; // (unique) ID of a journalling object
  45. // use for improved branch prediction
  46. #define likely(x) __builtin_expect((x),1)
  47. #define unlikely(x) __builtin_expect((x),0)
  48. template<typename T>
  49. struct typeInfo
  50. {
  51. static inline T min()
  52. {
  53. return std::numeric_limits<T>::min();
  54. }
  55. static inline T max()
  56. {
  57. return std::numeric_limits<T>::max();
  58. }
  59. static inline T minEps()
  60. {
  61. return 1;
  62. }
  63. static inline bool isEqual( T x, T y )
  64. {
  65. return x == y;
  66. }
  67. static inline T absVal( T t )
  68. {
  69. return t >= 0 ? t : -t;
  70. }
  71. } ;
  72. template<>
  73. inline float typeInfo<float>::minEps()
  74. {
  75. return 1.0e-10;
  76. }
  77. template<>
  78. inline bool typeInfo<float>::isEqual( float x, float y )
  79. {
  80. if( x == y )
  81. {
  82. return true;
  83. }
  84. return absVal( x - y ) < minEps();
  85. }
  86. const ch_cnt_t DEFAULT_CHANNELS = 2;
  87. const ch_cnt_t SURROUND_CHANNELS =
  88. #define LMMS_DISABLE_SURROUND
  89. #ifndef LMMS_DISABLE_SURROUND
  90. 4;
  91. #else
  92. 2;
  93. #endif
  94. #ifdef LMMS_BUILD_WIN32
  95. #define LADSPA_PATH_SEPERATOR ';'
  96. #else
  97. #define LADSPA_PATH_SEPERATOR ':'
  98. #endif
  99. typedef sample_t sampleFrame[DEFAULT_CHANNELS];
  100. typedef sample_t surroundSampleFrame[SURROUND_CHANNELS];
  101. #define ALIGN_SIZE 16
  102. #if __GNUC__
  103. typedef sample_t sampleFrameA[DEFAULT_CHANNELS] __attribute__((__aligned__(ALIGN_SIZE)));
  104. #endif
  105. #define STRINGIFY(s) STR(s)
  106. #define STR(PN) #PN
  107. #endif