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.

63 lines
1.1KB

  1. #include <vector>
  2. #include <algorithm>
  3. namespace rack_plugin_BaconMusic {
  4. template< typename TBase >
  5. struct SampleDelay : virtual TBase {
  6. enum ParamIds {
  7. DELAY_KNOB,
  8. NUM_PARAMS
  9. };
  10. enum InputIds {
  11. SIGNAL_IN,
  12. NUM_INPUTS
  13. };
  14. enum OutputIds {
  15. SIGNAL_OUT,
  16. NUM_OUTPUTS
  17. };
  18. enum LightIds {
  19. DELAY_VALUE_LIGHT,
  20. NUM_LIGHTS
  21. };
  22. using TBase::params;
  23. using TBase::inputs;
  24. using TBase::outputs;
  25. using TBase::lights;
  26. std::vector< float > ring;
  27. size_t ringSize;
  28. size_t pos;
  29. SampleDelay() : TBase( NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS )
  30. {
  31. params[ DELAY_KNOB ].value = 1;
  32. ringSize = 100;
  33. ring.resize( ringSize );
  34. std::fill( ring.begin(), ring.end(), 0 );
  35. pos = 0;
  36. }
  37. void step() override
  38. {
  39. int del = params[ DELAY_KNOB ].value - 1;
  40. int dpos = ( (int)pos - del );
  41. if( dpos < 0 ) dpos += ringSize;
  42. ring[ pos ] = inputs[ SIGNAL_IN ].value;
  43. outputs[ SIGNAL_OUT ].value = ring[ dpos ];
  44. lights[ DELAY_VALUE_LIGHT ].value = del + 1;
  45. pos++;
  46. if( pos >= ringSize ) pos = 0;
  47. }
  48. };
  49. } // namespace rack_plugin_BaconMusic