PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

effect_granular.h 2.2KB

3 лет назад
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Copyright (c) 2018 John-Michael Reed
  3. * bleeplabs.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 all
  13. * 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 THE
  21. * SOFTWARE.
  22. */
  23. #include "AudioStream.h"
  24. class AudioEffectGranular : public AudioStream
  25. {
  26. public:
  27. AudioEffectGranular(void): AudioStream(1,inputQueueArray) { }
  28. void begin(int16_t *sample_bank_def, int16_t max_len_def);
  29. void setSpeed(float ratio) {
  30. if (ratio < 0.125) ratio = 0.125;
  31. else if (ratio > 8.0) ratio = 8.0;
  32. playpack_rate = ratio * 65536.0 + 0.499;
  33. }
  34. void beginFreeze(float grain_length) {
  35. if (grain_length <= 0.0) return;
  36. beginFreeze_int(grain_length * (AUDIO_SAMPLE_RATE_EXACT * 0.001) + 0.5);
  37. }
  38. void beginPitchShift(float grain_length) {
  39. if (grain_length <= 0.0) return;
  40. beginPitchShift_int(grain_length * (AUDIO_SAMPLE_RATE_EXACT * 0.001) + 0.5);
  41. }
  42. void stop();
  43. virtual void update(void);
  44. private:
  45. void beginFreeze_int(int grain_samples);
  46. void beginPitchShift_int(int grain_samples);
  47. audio_block_t *inputQueueArray[1];
  48. int16_t *sample_bank;
  49. uint32_t playpack_rate;
  50. uint32_t accumulator;
  51. int16_t max_sample_len;
  52. int16_t write_head;
  53. int16_t read_head;
  54. int16_t grain_mode;
  55. int16_t freeze_len;
  56. int16_t prev_input;
  57. int16_t glitch_len;
  58. bool allow_len_change;
  59. bool sample_loaded;
  60. bool write_en;
  61. bool sample_req;
  62. };