From a5c7387a2383e2c18f6a7c4c9d5eb9e769b349cb Mon Sep 17 00:00:00 2001 From: AliceLR Date: Fri, 18 Jun 2021 20:11:42 -0600 Subject: [PATCH] Allow up to 255 sequences to be scanned. --- src/common.h | 16 +++++++++------- src/load_helpers.c | 4 ++++ src/scan.c | 14 ++++++++++++++ test-dev/data/scan_240_seq.it | Bin 0 -> 5416 bytes test-dev/test_api_scan_module.c | 17 +++++++++++++++++ 5 files changed, 44 insertions(+), 7 deletions(-) create mode 100644 test-dev/data/scan_240_seq.it diff --git a/src/common.h b/src/common.h index 2f5cbaeb1..7ed5b4255 100644 --- a/src/common.h +++ b/src/common.h @@ -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 @@ -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; @@ -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; diff --git a/src/load_helpers.c b/src/load_helpers.c index a4fb6aee7..e871f66ba 100644 --- a/src/load_helpers.c +++ b/src/load_helpers.c @@ -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; @@ -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 */ diff --git a/src/scan.c b/src/scan.c index 79f3c3bda..0e808c57e 100644 --- a/src/scan.c +++ b/src/scan.c @@ -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). */ @@ -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 */ diff --git a/test-dev/data/scan_240_seq.it b/test-dev/data/scan_240_seq.it new file mode 100644 index 0000000000000000000000000000000000000000..32f3e609adfce78e76edaa02111bb7d460a8ac77 GIT binary patch literal 5416 zcmbu@<#W|&0L9_7lu|SWid%8N!5vbZ0+$q8T0FQzaEG+G2X_eW5ZocSLvV-S4%z(+ zvWI0qz?s=kyfeR#2`8VE$2!9DBTSkS(3gJR>x$yDH|9xHw z#wA3r{j(GEherqrO%;|pJWWK}bm=o>%p^u;&XP4MTlO3|bLGyHH(&k&(FF??E>g5u z@e(CVl`c~@AeAd$p<<=VRjO92UZZBM+I8fZy7lTeXxON6lh~%sng?4baV=ZLC$vsX zYSXq|`wksDshzuY?bf|V&tARz^zGMwz(8%#;2}eY4IeRb)aWr|$Bmz$C#OuDGEI`O4L6*Kgc(Zr#3f_ul;n4<9{#^7PsB7w*efuiw0V z_x{7jPoKYh{r27S_0)pkAQySaM`E}j6hIP^k%CmDAsrdWL>97fj-9T~_(7P66pT;w4ii4oW%3CT!7D$PZSkc^z>BvAP zvXG4&7dbaM4>>P6A2~m{06Cgm zkX(pdm|TQhlw6EloLqujl3a>hnp}olmK-2U4u1BssAJStAc3 z4<-*G4*Qo|3V9-V5_vLt3VAAd8hJW-26-lV z7I`*#4tXxwAkQPuCodo`BrhT_CNCi`B`+f{C$Au{B(EZ`Ca)oz1M)-iBl2VN z6Y^8?GxBrt3$jaoNq$9sO@2duOMXXwPyRsuNd83rO#VXtO8!RvPWFWOgt%ZJ5U3xD zJ9Z!tOb8K#Krk2=_V2YgkeE~-*W<{NA&E)x&3`@x>c+)~3FUBUPE3eT{P`4U6d%ka Qr1(D${#_H2LvDrq1F5=EHvj+t literal 0 HcmV?d00001 diff --git a/test-dev/test_api_scan_module.c b/test-dev/test_api_scan_module.c index 4619860e1..0962df368 100644 --- a/test-dev/test_api_scan_module.c +++ b/test-dev/test_api_scan_module.c @@ -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(); @@ -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