Dependencies: mbed USBDevice PinDetect
Diff: Audio/KarplusStrong.cpp
- Revision:
- 15:aa5a4c350251
- Parent:
- 13:bb0ec927e458
- Child:
- 16:b25ca34a705f
--- a/Audio/KarplusStrong.cpp Sun Apr 17 21:38:57 2016 +0000 +++ b/Audio/KarplusStrong.cpp Sun Apr 17 21:59:03 2016 +0000 @@ -32,9 +32,15 @@ // Copy over the calculated filter coefficient. filterCoefficient = nextFilterCoefficient; - // Get the noise sample from the static noise seed. - lastOutput = noiseSeed[bufferIndex] * velocity; - return lastOutput; + // Get the noise sample from the static noise seed while making room for character variation. + float noiseSample = noiseSeed[bufferIndex] * (1.0 - C::CHARACTER_VARIATION); + // Add in some character randomness to make it more realistic. + noiseSample += getRandSample() * C::CHARACTER_VARIATION; + // Account for velocity. + noiseSample *= velocity; + + lastOutput = noiseSample; + return noiseSample; } float KarplusStrong::processBuffer(const float inputSample) { @@ -50,7 +56,7 @@ int seedLength = (C::SAMPLE_RATE / C::MIN_FREQUENCY) + 1; for (int i = 0; i < seedLength; i++) { // Create a random number in [-1.0, 1.0] - noiseSeed[i] = 1.0 - 2.0 * getRand(); + noiseSeed[i] = getRandSample(); } }