]> Nishi Git Mirror - ksynth.git/commitdiff
Fix velocity calculation and swapped if check
authorkazu <kazu@7b47e76f-e598-2f43-bc14-414d160cc389>
Tue, 16 Apr 2024 03:50:31 +0000 (03:50 +0000)
committerkazu <kazu@7b47e76f-e598-2f43-bc14-414d160cc389>
Tue, 16 Apr 2024 03:50:31 +0000 (03:50 +0000)
git-svn-id: file:///raid/svn-main/kazu-ksynth/trunk@21 7b47e76f-e598-2f43-bc14-414d160cc389

src/ksynth.c

index 6ef285d3615659ffe42f8f3aa52e63b20e84e6db..4faa444fea86dfc1a5aa736bff3b9e37d512fad2 100644 (file)
@@ -217,19 +217,21 @@ float* ksynth_generate_buffer(struct KSynth* ksynth_instance, unsigned short buf
 
                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