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.

81 lines
2.6KB

  1. // Copyright 2012 Olivier Gillet.
  2. //
  3. // Author: Olivier Gillet (ol.gillet@gmail.com)
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. // See http://creativecommons.org/licenses/MIT/ for more information.
  24. //
  25. // -----------------------------------------------------------------------------
  26. //
  27. // A noise source used to add jitter to the VCO.
  28. #ifndef BRAIDS_VCO_JITTER_SOURCE_H_
  29. #define BRAIDS_VCO_JITTER_SOURCE_H_
  30. #include "stmlib/stmlib.h"
  31. #include <cstring>
  32. #include "braids/resources.h"
  33. #include "stmlib/utils/dsp.h"
  34. #include "stmlib/utils/random.h"
  35. namespace braids {
  36. using namespace stmlib;
  37. class VcoJitterSource {
  38. public:
  39. VcoJitterSource() { }
  40. ~VcoJitterSource() { }
  41. inline void Init() {
  42. external_temperature_ = 0;
  43. room_temperature_ = 0;
  44. phase_ = 0;
  45. phase_step_ = 0;
  46. }
  47. inline int16_t Render(int32_t intensity) {
  48. // External temperature change, with 1-order filtering.
  49. uint16_t external_temperature_toss = Random::GetWord();
  50. if (external_temperature_toss == 0) {
  51. phase_step_ = phase_step_ * 1664525L + 1013904223L;
  52. phase_ += (phase_step_ >> 16) * (phase_step_ >> 16);
  53. external_temperature_ = wav_sine[phase_ >> 24] << 8;
  54. }
  55. room_temperature_ += (external_temperature_ - room_temperature_) >> 16;
  56. int32_t pitch_noise = room_temperature_ * intensity >> 19;
  57. return pitch_noise;
  58. }
  59. private:
  60. uint32_t phase_step_;
  61. uint32_t phase_;
  62. int32_t external_temperature_;
  63. int32_t room_temperature_;
  64. DISALLOW_COPY_AND_ASSIGN(VcoJitterSource);
  65. };
  66. } // namespace braids
  67. #endif // BRAIDS_VCO_JITTER_SOURCE_H_