small sound tweaks

This commit is contained in:
2026-06-24 19:32:46 -05:00
parent e94d4c980e
commit 5bd347de83
3 changed files with 10 additions and 9 deletions

View File

@@ -37,14 +37,14 @@ void PianoString::noteOn(float frequency, float velocity) {
}
// apply the velocity impulse
for(size_t i = 0; i < segmentCount_ + 1; i++) {
float v0 = impulseVelocity_ * std::exp(-1.0f * (stringX_[i] - strikePosition_)*(stringX_[i] - strikePosition_) / ((2.0f * impulseWidth_)*(2.0f * impulseWidth_)));
float v0 = impulseVelocity_ * std::exp(-1.0f * (stringX_[i] - strikePosition_*L_)*(stringX_[i] - strikePosition_*L_) / ((2.0f * impulseWidth_)*(2.0f * impulseWidth_)));
stringY_current_[i] = stringY_current_[i] + dt_ * v0;
}
}
void PianoString::noteOff() {
damping_ = 10.0f;
damping_ = 8.0f;
recalculateConstants();
}
@@ -89,11 +89,11 @@ float PianoString::process(bool& scopeTrigger) {
scopeTrigger = true;
}
float sampleOut = stringY_next_[static_cast<size_t>(samplePosition_*L_*segmentCount_)];
float sampleOut = stringY_next_[static_cast<size_t>(samplePosition_*segmentCount_)];
rms_ = 0.99f * rms_ + 0.01f * sampleOut*sampleOut;
return sampleOut;
return sampleOut * gain_;
}
@@ -117,7 +117,7 @@ void PianoString::recalculateConstants() {
segmentCount_ = static_cast<size_t>(std::sqrt((-a+std::sqrt(a*a+4.0*b))/(2.0*b))) - 1;
}
} while (segmentCount_ < 80);
} while (segmentCount_ < 60);
segmentCount_ = std::min(segmentCount_, static_cast<size_t>(80));

View File

@@ -42,14 +42,15 @@ private:
static constexpr float stiffness_ = 0.0f; // stiffness coefficient
float damping_ = 0.5f; // damping coefficient
static constexpr float stringLength_ = 4.0f; // length of string at lowest frequency (20 hz)
static constexpr float strikePosition_ = 0.2f; // x of impulse location
static constexpr float impulseWidth_ = 0.1f; // x of impulse width
static constexpr float strikePosition_ = 0.8f; // x of impulse location
static constexpr float impulseWidth_ = 0.1f; // x% of impulse width
static constexpr float impulseVelocity_ = 10000.0f; // x/t of impulse magnitude
static constexpr float samplePosition_ = 0.1f; // percentage along L of sampling for audio
static constexpr float samplePosition_ = 0.2f; // percentage along L of sampling for audio
float crossSectionalArea_ = pi * std::pow(radius_, 2.0f); // string cross sectional area, assuming circular
float mu_ = crossSectionalArea_ * rho_; // linear mass density
float waveVelocity_ = std::sqrt(stringTension_ / mu_); // transverse wave velocity
float L_ = 1.0f; // length of string at a given frequency
float gain_ = 0.3f;
// f0_ = waveVelocity_ / (2.0f * stringLength_); // fundamental frequency of a non-stiff string
// f1_ = f0_ * std::sqrt(1.0f + stiffness_); // fundamental frequency of the stiff string

View File

@@ -7,7 +7,7 @@ Synth::Synth(ConfigService* config, LoggerService* logger, ScopeBuffer* scope, N
voices_.fill(Voice(config_, logger_));
filter_.setSampleRate(44100.0f);
filter_.setParams(Filter::Type::BiquadLowpass, 1000.0f, 0.707f);
filter_.setParams(Filter::Type::BiquadLowpass, 4000.0f, 0.707f);
}