comparison projects/d-box/FeedbackOscillator.cpp @ 108:3068421c0737 ultra-staging

Merged default into ultra-staging
author Giulio Moro <giuliomoro@yahoo.it>
date Tue, 18 Aug 2015 00:35:15 +0100
parents 4f8db16f17b5
children
comparison
equal deleted inserted replaced
54:d3f869b98147 108:3068421c0737
56 sampleCount = lastTriggerCount = 0; 56 sampleCount = lastTriggerCount = 0;
57 } 57 }
58 58
59 // Process one sample and store the output value 59 // Process one sample and store the output value
60 // Returns true if the wavetable needs rendering 60 // Returns true if the wavetable needs rendering
61 int FeedbackOscillator::process(uint16_t input, uint16_t *output) { 61 int FeedbackOscillator::process(float input, float *output) {
62 float inFloat = input / 65536.0; 62 float outFloat = coeffs[COEFF_B0] * input + coeffs[COEFF_B1] * lastInput - coeffs[COEFF_A1] * lastOutput;
63 float outFloat = coeffs[COEFF_B0] * inFloat + coeffs[COEFF_B1] * lastInput - coeffs[COEFF_A1] * lastOutput;
64 int requestRenderLength = 0; 63 int requestRenderLength = 0;
65 64
66 //outFloat *= 2.0; 65 if(outFloat < -0.5)
67 66 *output = 0;
68 int intOut = outFloat * 65536.0 + 32768; 67 else if(outFloat > 0.5)
69 if(intOut > 65535) 68 *output = 1;
70 intOut = 65535; 69 else
71 if(intOut < 0) 70 *output = outFloat + 0.5;
72 intOut = 0;
73 //intOut = (intOut & 0xFF) << 8;
74 //if(intOut > 65535)
75 // intOut = 65535;
76
77 *output = (uint16_t)intOut;
78 71
79 if(canTrigger && outFloat > 0 && lastOutput <= 0) { 72 if(canTrigger && outFloat > 0 && lastOutput <= 0) {
80 triggered = true; 73 triggered = true;
81 requestRenderLength = wavetableWritePointer; // How many samples stored thus far? 74 requestRenderLength = wavetableWritePointer; // How many samples stored thus far?
82 if(requestRenderLength < 4) 75 if(requestRenderLength < 4)
104 canTrigger = true; 97 canTrigger = true;
105 98
106 sampleCount++; 99 sampleCount++;
107 100
108 lastOutput = outFloat; 101 lastOutput = outFloat;
109 lastInput = inFloat; 102 lastInput = input;
110 103
111 return requestRenderLength; 104 return requestRenderLength;
112 } 105 }