PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

synth_simple_drum.h 2.8KB

hace 3 años
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /* Audio Library for Teensy 3.X
  2. * Copyright (c) 2016, Byron Jacquot, SparkFun Electronics
  3. *
  4. * Development of this audio library was funded by PJRC.COM, LLC by sales of
  5. * Teensy and Audio Adaptor boards. Please support PJRC's efforts to develop
  6. * open source software by purchasing Teensy or other PJRC products.
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice, development funding notice, and this permission
  16. * notice shall be included in all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. */
  26. #pragma once
  27. #ifndef _SYNTH_SIMPLE_DRUM_H_
  28. #define _SYNTH_SIMPLE_DRUM_H_
  29. #include "AudioStream.h"
  30. #include "utility/dspinst.h"
  31. class AudioSynthSimpleDrum : public AudioStream
  32. {
  33. public:
  34. AudioSynthSimpleDrum() : AudioStream(1, inputQueueArray)
  35. {
  36. length(600);
  37. frequency(60);
  38. pitchMod(0x200);
  39. wav_amplitude1 = 0x7fff;
  40. wav_amplitude2 = 0;
  41. }
  42. void noteOn();
  43. void frequency(float freq)
  44. {
  45. if(freq < 0.0)
  46. freq = 0;
  47. else if(freq > (AUDIO_SAMPLE_RATE_EXACT/2))
  48. freq = AUDIO_SAMPLE_RATE_EXACT/2;
  49. wav_increment = (freq * (0x7fffffffLL/AUDIO_SAMPLE_RATE_EXACT)) + 0.5;
  50. }
  51. void length(int32_t milliseconds)
  52. {
  53. if(milliseconds < 0)
  54. return;
  55. if(milliseconds > 5000)
  56. milliseconds = 5000;
  57. int32_t len_samples = milliseconds*(AUDIO_SAMPLE_RATE_EXACT/1000.0);
  58. env_decrement = (0x7fff0000/len_samples);
  59. };
  60. void secondMix(float level);
  61. void pitchMod(float depth);
  62. using AudioStream::release;
  63. virtual void update(void);
  64. private:
  65. audio_block_t *inputQueueArray[1];
  66. // Envelope params
  67. int32_t env_lin_current; // present value of linear slope.
  68. int32_t env_decrement; // how each sample deviates from previous.
  69. // Waveform params
  70. uint32_t wav_phasor;
  71. uint32_t wav_phasor2;
  72. int16_t wav_amplitude1;
  73. int16_t wav_amplitude2;
  74. uint32_t wav_increment;
  75. int32_t wav_pitch_mod;
  76. };
  77. #endif