Skip to content

Commit

Permalink
Closes #185, #186
Browse files Browse the repository at this point in the history
Fixes #186
Fixes #185

Additionally fixed a bug cause by some guspats having sustain data
mixed up.

Helps if we’re using the proper envelopes.
  • Loading branch information
chrisisonwildcode committed May 19, 2018
1 parent d4d0fe8 commit 1ed3336
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 23 deletions.
25 changes: 19 additions & 6 deletions src/gus_pat.c
Original file line number Diff line number Diff line change
Expand Up @@ -825,12 +825,25 @@ struct _sample * _WM_load_gus_pat(const char *filename, int fix_release) {
| ((gus_sample->loop_fraction & 0xf0) >> 4);
}

// kill "echo" envelopes because users dont want/like them
// and this is what timidity does which is why we sounded different
// NOTE: This may cause some pats to sound different to what their authers intended
gus_patch[gus_ptr + 41] = 0x3f;
gus_patch[gus_ptr + 42] = 0x3f;

{
// All sorts of annoying things happen with pat files.
// One of them is that the sustained release time and
// normal release time gets mixed up because software got muddled
uint8_t envsusreltime = gus_patch[gus_ptr + 40];
uint8_t envreltime = gus_patch[gus_ptr + 41];
if (envsusreltime < envreltime) {
// EXPERIMENTAL
gus_patch[gus_ptr + 40] = envreltime;
gus_patch[gus_ptr + 41] = 0x3f; // timidity does this
gus_patch[gus_ptr + 42] = 0x3f; // timidity does this

gus_patch[gus_ptr + 46] = gus_patch[gus_ptr + 47];
gus_patch[gus_ptr + 47] = 0;
gus_patch[gus_ptr + 48] = 0;

}
}

// lets set up the envelope data
for (i = 0; i < 6; i++) {
GUSPAT_INT_DEBUG("Envelope #",i);
Expand Down
10 changes: 5 additions & 5 deletions src/internal_midi.c
Original file line number Diff line number Diff line change
Expand Up @@ -586,12 +586,12 @@ void _WM_do_note_off_extra(struct _note *nte) {
nte->env_inc = nte->sample->env_rate[5];
}
}
} else if (nte->env < 3) {
nte->env = 3;
if (nte->env_level > nte->sample->env_target[3]) {
nte->env_inc = -nte->sample->env_rate[3];
} else if (nte->env < 4) {
nte->env = 4;
if (nte->env_level > nte->sample->env_target[4]) {
nte->env_inc = -nte->sample->env_rate[4];
} else {
nte->env_inc = nte->sample->env_rate[3];
nte->env_inc = nte->sample->env_rate[4];
}
}
}
Expand Down
34 changes: 22 additions & 12 deletions src/wildmidi_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ static int add_handle(void * handle) {

static int WM_GetOutput_Linear(midi * handle, int8_t *buffer, uint32_t size) {
uint32_t buffer_used = 0;
uint32_t i;
uint32_t i, env_ptr;
struct _mdi *mdi = (struct _mdi *) handle;
uint32_t real_samples_to_mix = 0;
uint32_t data_pos;
Expand Down Expand Up @@ -992,15 +992,20 @@ static int WM_GetOutput_Linear(midi * handle, int8_t *buffer, uint32_t size) {
note_data = note_data->next;
RESAMPLE_DEBUGS("Next Note: SAMPLE_SUSTAIN");
continue;
} else if (note_data->modes & SAMPLE_CLAMPED) {
note_data->env = 5;
} else {
if (note_data->modes & SAMPLE_CLAMPED) {
env_ptr = 5;
} else {
env_ptr = 4;
}
note_data->env = env_ptr;
if (note_data->env_level
> note_data->sample->env_target[5]) {
> note_data->sample->env_target[env_ptr]) {
note_data->env_inc =
-note_data->sample->env_rate[5];
-note_data->sample->env_rate[env_ptr];
} else {
note_data->env_inc =
note_data->sample->env_rate[5];
note_data->sample->env_rate[env_ptr];
}
continue;
}
Expand Down Expand Up @@ -1135,7 +1140,7 @@ static int WM_GetOutput_Linear(midi * handle, int8_t *buffer, uint32_t size) {

static int WM_GetOutput_Gauss(midi * handle, int8_t *buffer, uint32_t size) {
uint32_t buffer_used = 0;
uint32_t i;
uint32_t i, env_ptr;
struct _mdi *mdi = (struct _mdi *) handle;
uint32_t real_samples_to_mix = 0;
uint32_t data_pos;
Expand Down Expand Up @@ -1337,15 +1342,20 @@ static int WM_GetOutput_Gauss(midi * handle, int8_t *buffer, uint32_t size) {
note_data->env_inc = 0;
note_data = note_data->next;
continue;
} else if (note_data->modes & SAMPLE_CLAMPED) {
note_data->env = 5;
} else {
if (note_data->modes & SAMPLE_CLAMPED) {
env_ptr = 5;
} else {
env_ptr = 4;
}
note_data->env = env_ptr;
if (note_data->env_level
> note_data->sample->env_target[5]) {
> note_data->sample->env_target[env_ptr]) {
note_data->env_inc =
-note_data->sample->env_rate[5];
-note_data->sample->env_rate[env_ptr];
} else {
note_data->env_inc =
note_data->sample->env_rate[5];
note_data->sample->env_rate[env_ptr];
}
continue;
}
Expand Down

0 comments on commit 1ed3336

Please sign in to comment.