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.

92 lines
2.3KB

  1. #pragma once
  2. #include "NoisePlethoraPlugin.hpp"
  3. class BasuraTotal : public NoisePlethoraPlugin {
  4. public:
  5. BasuraTotal()
  6. // : patchCord1(waveformMod1, freeverb1)
  7. {}
  8. ~BasuraTotal() override {}
  9. BasuraTotal(const BasuraTotal&) = delete;
  10. BasuraTotal& operator=(const BasuraTotal&) = delete;
  11. dsp::Timer timer;
  12. void init() override {
  13. freeverb1.roomsize(0);
  14. timer.reset();
  15. waveformMod1.begin(1, 500, WAVEFORM_SINE);
  16. }
  17. void process(float k1, float k2) override {
  18. float knob_1 = k1;
  19. float knob_2 = k2;
  20. float pitch1 = pow(knob_1, 2);
  21. float pitch2 = pow(knob_2, 2);
  22. float timeMicros = timer.time * 1000000;
  23. if (timeMicros > 100000 * pitch2) { // Changing this value changes the frequency.
  24. timer.reset();
  25. waveformMod1.begin(1, 500, WAVEFORM_SQUARE);
  26. waveformMod1.frequency(generateNoise() * (200 + (pitch1 * 5000))) ;
  27. freeverb1.roomsize(1);
  28. }
  29. }
  30. void processGraphAsBlock(TeensyBuffer& blockBuffer) override {
  31. const float blockTime = APP->engine->getSampleTime() * AUDIO_BLOCK_SAMPLES;
  32. timer.process(blockTime);
  33. waveformMod1.update(nullptr, nullptr, &waveformOut);
  34. freeverb1.update(&waveformOut, &freeverbOut);
  35. blockBuffer.pushBuffer(freeverbOut.data, AUDIO_BLOCK_SAMPLES);
  36. }
  37. AudioStream& getStream() override {
  38. return freeverb1;
  39. }
  40. unsigned char getPort() override {
  41. return 0;
  42. }
  43. private:
  44. static unsigned int generateNoise() {
  45. // See https://en.wikipedia.org/wiki/Linear_feedback_shift_register#Galois_LFSRs
  46. /* initialize with any 32 bit non-zero unsigned long value. */
  47. static unsigned long int lfsr = 0xfeddfaceUL; /* 32 bit init, nonzero */
  48. static unsigned long mask = ((unsigned long)(1UL << 31 | 1UL << 15 | 1UL << 2 | 1UL << 1));
  49. /* If the output bit is 1, apply toggle mask.
  50. * The value has 1 at bits corresponding
  51. * to taps, 0 elsewhere. */
  52. if (lfsr & 1) {
  53. lfsr = (lfsr >> 1) ^ mask;
  54. return (1);
  55. }
  56. else {
  57. lfsr >>= 1;
  58. return (0);
  59. }
  60. }
  61. audio_block_t waveformOut, freeverbOut;
  62. AudioSynthWaveformModulated waveformMod1; //xy=216.88888549804688,217.9999988898635
  63. AudioEffectFreeverb freeverb1; //xy=374.8888854980469,153.88888549804688
  64. // AudioConnection patchCord1;
  65. // unsigned long lastClick;
  66. };
  67. REGISTER_PLUGIN(BasuraTotal);