Skip to content

Commit

Permalink
Allow up to 255 sequences to be scanned.
Browse files Browse the repository at this point in the history
  • Loading branch information
AliceLR committed Jun 19, 2021
1 parent e9a07ee commit a5c7387
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/common.h
Expand Up @@ -233,7 +233,7 @@ int libxmp_snprintf (char *, size_t, const char *, ...);
#define DEFAULT_TIME_FACTOR 10.0
#define MED_TIME_FACTOR 2.64

#define MAX_SEQUENCES 16
#define MAX_SEQUENCES 255
#define MAX_SAMPLE_SIZE 0x10000000
#define MAX_SAMPLES 1024
#define MAX_INSTRUMENTS 255
Expand Down Expand Up @@ -348,6 +348,13 @@ struct virt_channel {
int map;
};

struct scan_data {
int time; /* replay time in ms */
int row;
int ord;
int num;
};

struct player_data {
int ord;
int pos;
Expand All @@ -372,12 +379,7 @@ struct player_data {

struct flow_control flow;

struct {
int time; /* replay time in ms */
int ord;
int row;
int num;
} scan[MAX_SEQUENCES];
struct scan_data *scan;

struct channel_data *xc_data;

Expand Down
4 changes: 4 additions & 0 deletions src/load_helpers.c
Expand Up @@ -309,6 +309,7 @@ int libxmp_prepare_scan(struct context_data *ctx)

void libxmp_free_scan(struct context_data *ctx)
{
struct player_data *p = &ctx->p;
struct module_data *m = &ctx->m;
struct xmp_module *mod = &m->mod;
int i;
Expand All @@ -320,6 +321,9 @@ void libxmp_free_scan(struct context_data *ctx)
free(m->scan_cnt);
m->scan_cnt = NULL;
}

free(p->scan);
p->scan = NULL;
}

/* Process player personality flags */
Expand Down
14 changes: 14 additions & 0 deletions src/scan.c
Expand Up @@ -525,10 +525,18 @@ int libxmp_scan_sequences(struct context_data *ctx)
struct player_data *p = &ctx->p;
struct module_data *m = &ctx->m;
struct xmp_module *mod = &m->mod;
struct scan_data *s;
int i, ep;
int seq;
unsigned char temp_ep[XMP_MAX_MOD_LENGTH];

s = realloc(p->scan, MAX(1, mod->len) * sizeof(struct scan_data));
if (!s) {
D_(D_CRIT "failed to allocate scan data");
return -1;
}
p->scan = s;

/* Initialize order data to prevent overwrite when a position is used
* multiple times at different starting points (see janosik.xm).
*/
Expand Down Expand Up @@ -567,6 +575,12 @@ int libxmp_scan_sequences(struct context_data *ctx)
}
}

if (seq < mod->len) {
s = realloc(p->scan, seq * sizeof(struct scan_data));
if (s != NULL) {
p->scan = s;
}
}
m->num_sequences = seq;

/* Now place entry points in the public accessible array */
Expand Down
Binary file added test-dev/data/scan_240_seq.it
Binary file not shown.
17 changes: 17 additions & 0 deletions test-dev/test_api_scan_module.c
Expand Up @@ -5,7 +5,9 @@ TEST(test_api_scan_module)
{
xmp_context opaque;
struct context_data *ctx;
struct xmp_module_info minfo;
struct xmp_frame_info info;
int ret;
int i;

opaque = xmp_create_context();
Expand All @@ -32,6 +34,21 @@ TEST(test_api_scan_module)
fail_unless(info.total_time == 5720, "total time error");
}

xmp_release_module(opaque);

/* Load something with an absurd number of sequences. */
ret = xmp_load_module(opaque, "data/scan_240_seq.it");
fail_unless(ret == 0, "load module");

xmp_scan_module(opaque);

xmp_get_module_info(opaque, &minfo);
fail_unless(minfo.num_sequences == 240, "should have 240 sequences");

for (i = 0; i < minfo.num_sequences; i++) {
fail_unless(minfo.seq_data[i].entry_point == i, "entry point");
}
xmp_release_module(opaque);
xmp_free_context(opaque);
}
END_TEST

0 comments on commit a5c7387

Please sign in to comment.