Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

124 lines
3.0KB

  1. /*
  2. ZynAddSubFX - a software synthesizer
  3. Util.h - Miscellaneous functions
  4. Copyright (C) 2002-2005 Nasca Octavian Paul
  5. Author: Nasca Octavian Paul
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of version 2 of the GNU General Public License
  8. as published by the Free Software Foundation.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License (version 2 or later) for more details.
  13. You should have received a copy of the GNU General Public License (version 2)
  14. along with this program; if not, write to the Free Software Foundation,
  15. Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. */
  17. #ifndef UTIL_H
  18. #define UTIL_H
  19. #include <string>
  20. #include <sstream>
  21. #include <stdint.h>
  22. #include "Config.h"
  23. #include "../globals.h"
  24. //Velocity Sensing function
  25. extern float VelF(float velocity, unsigned char scaling);
  26. bool fileexists(const char *filename);
  27. #define N_DETUNE_TYPES 4 //the number of detune types
  28. extern float getdetune(unsigned char type,
  29. unsigned short int coarsedetune,
  30. unsigned short int finedetune);
  31. /**Try to set current thread to realtime priority program priority
  32. * \todo see if the right pid is being sent
  33. * \todo see if this is having desired effect, if not then look at
  34. * pthread_attr_t*/
  35. void set_realtime();
  36. /**Os independent sleep in microsecond*/
  37. void os_sleep(long length);
  38. std::string legalizeFilename(std::string filename);
  39. extern float *denormalkillbuf; /**<the buffer to add noise in order to avoid denormalisation*/
  40. extern class Config config;
  41. void invSignal(float *sig, size_t len);
  42. //Memory pool for temporary buffers
  43. //No allocation in *normal* case
  44. //All should be sized to synth->buffersize
  45. float *getTmpBuffer();
  46. void returnTmpBuffer(float *buf);
  47. void clearTmpBuffers(void);
  48. template<class T>
  49. std::string stringFrom(T x)
  50. {
  51. std::stringstream ss;
  52. ss << x;
  53. return ss.str();
  54. }
  55. template<class T>
  56. T stringTo(const char *x)
  57. {
  58. std::string str = x != NULL ? x : "0"; //should work for the basic float/int
  59. std::stringstream ss(str);
  60. T ans;
  61. ss >> ans;
  62. return ans;
  63. }
  64. template<class T>
  65. T limit(T val, T min, T max)
  66. {
  67. return val < min ? min : (val > max ? max : val);
  68. }
  69. //Random number generator
  70. typedef uint32_t prng_t;
  71. extern prng_t prng_state;
  72. // Portable Pseudo-Random Number Generator
  73. inline prng_t prng_r(prng_t &p)
  74. {
  75. return p = p * 1103515245 + 12345;
  76. }
  77. inline prng_t prng(void)
  78. {
  79. return prng_r(prng_state) & 0x7fffffff;
  80. }
  81. inline void sprng(prng_t p)
  82. {
  83. prng_state = p;
  84. }
  85. /*
  86. * The random generator (0.0f..1.0f)
  87. */
  88. # define INT32_MAX (2147483647)
  89. #define RND (prng() / (INT32_MAX * 1.0f))
  90. //Linear Interpolation
  91. float interpolate(const float *data, size_t len, float pos);
  92. //Linear circular interpolation
  93. float cinterpolate(const float *data, size_t len, float pos);
  94. #endif