int sample_position = voice->sample_position;
int sample_length = ksynth_instance->samples[voice->noteNumber]->length;
+ float logVel = (float)voice->velocity / 127.0f;
+ float velocity = fmin(pow(logVel, 2.5) + 0.03, 1.0);
char killed = 0;
for(int j = 0; j < buffer_size; ++j) {
float sample = ksynth_instance->samples[voice->noteNumber]->sample[sample_position];
for(int c = 0; c < num_channels; ++c) {
- buffer[j * num_channels + c] += sample * (float)voice->velocity / 127.0f;
+ buffer[j * num_channels + c] += sample * velocity;
}
sample_position++;
// If sample_position exceeds sample_length, the voice has finished playing
- if(sample_position >= sample_length && ksynth_instance->voices[i] != NULL) {
+ if(ksynth_instance->voices[i] != NULL && sample_position >= sample_length) {
voice_free(voice);
// Shift remaining voices to fill the gap