handle polyphony

This commit is contained in:
thib8956 committed 2026-10-30 13:32:57 +01:00
1 parent 91a1e2e312
commit 003fc0cb1b
4 files changed
+96 -26

No files matched your search

+3 -2
View File
@@ -2,7 +2,7 @@
#include <math.h>
#define SAMPLE_RATE 44100.0f
void play_note(Note *note, int16_t *buffer, int buffer_size) {
void play_note(Note *note, float *buffer, int buffer_size) {
for (int i = 0; i < buffer_size; i++) {
// update phase counter
note->phase = fmodf(note->phase + note->freq / SAMPLE_RATE, 1.0f);
@@ -28,7 +28,8 @@ void play_note(Note *note, int16_t *buffer, int buffer_size) {
? fminf(note->gain + attack_step, 0.2f) // attack
: fmaxf(note->gain - release_step, 0); // release
buffer[i] += sample * note->gain;
// convert sample to 16-bit signed integer and apply gain
buffer[i] = (int16_t) (note->gain * sample * (float) INT16_MAX);
//buffer[i] = (int16_t) (note->gain * sample * (float) INT16_MAX);
}
}