1 // Copyright 2014 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 // Granular diffuser. 28 29 #ifndef ELEMENTS_DSP_FX_DIFFUSER_H_ 30 #define ELEMENTS_DSP_FX_DIFFUSER_H_ 31 32 #include "stmlib/stmlib.h" 33 34 #include "elements/dsp/fx/fx_engine.h" 35 36 namespace elements { 37 38 class Diffuser { 39 public: Diffuser()40 Diffuser() { } ~Diffuser()41 ~Diffuser() { } 42 Init(float * buffer)43 void Init(float* buffer) { 44 engine_.Init(buffer); 45 } 46 Process(float * in_out,size_t size)47 void Process(float* in_out, size_t size) { 48 typedef E::Reserve<126, 49 E::Reserve<180, 50 E::Reserve<269, 51 E::Reserve<444> > > > Memory; 52 E::DelayLine<Memory, 0> ap1; 53 E::DelayLine<Memory, 1> ap2; 54 E::DelayLine<Memory, 2> ap3; 55 E::DelayLine<Memory, 3> ap4; 56 E::Context c; 57 const float kap = 0.625f; 58 while (size--) { 59 engine_.Start(&c); 60 c.Read(*in_out); 61 c.Read(ap1 TAIL, kap); 62 c.WriteAllPass(ap1, -kap); 63 c.Read(ap2 TAIL, kap); 64 c.WriteAllPass(ap2, -kap); 65 c.Read(ap3 TAIL, kap); 66 c.WriteAllPass(ap3, -kap); 67 c.Read(ap4 TAIL, kap); 68 c.WriteAllPass(ap4, -kap); 69 c.Write(*in_out, 0.0f); 70 ++in_out; 71 } 72 } 73 74 private: 75 typedef FxEngine<1024, FORMAT_32_BIT> E; 76 E engine_; 77 78 DISALLOW_COPY_AND_ASSIGN(Diffuser); 79 }; 80 81 } // namespace elements 82 83 #endif // ELEMENTS_DSP_FX_DIFFUSER_H_ 84