Skip to content

Commit 356c62f

Browse files
HunterZsezero
authored andcommitted
Fix stdout output to support specified driver, and add loop-until feature:
- common.h: - add loop_time to struct options - main.c: - allow loop if loop_time defined and playtime has not exceeded it - options.c: - add "loop-until" feature - change '-c' and '-o' logic to record output driver as a "guess" that only gets applied if no driver is explicitly specified
1 parent 64e02f7 commit 356c62f

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

src/common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ struct options {
3939
int interp; /* interpolation type */
4040
int dsp; /* dsp effects */
4141
int loop; /* loop module */
42+
int loop_time; /* loop until time */
4243
int random; /* play in random order */
4344
int reverse; /* reverse stereo channels */
4445
int vblank; /* vblank flag */

src/main.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -529,15 +529,17 @@ int main(int argc, char **argv)
529529
play_sequence:
530530
while (!opt.info && xmp_play_frame(xc) == 0) {
531531
int old_loop = fi.loop_count;
532-
532+
533533
xmp_get_frame_info(xc, &fi);
534534
control.mixer_type = xmp_get_player(
535535
xc, XMP_PLAYER_MIXER_TYPE);
536536

537537
/* Check loop */
538538

539539
if (old_loop != fi.loop_count) {
540-
if (control.loop == 1) {
540+
if (control.loop == 1 ||
541+
(opt.loop_time > 0 &&
542+
control.time < opt.loop_time)) {
541543
info_message("Loop sequence %d", control.sequence);
542544
} else {
543545
break;

src/options.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,10 @@ static void usage(char *s, struct options *options)
9292
" -S --solo ch-list Set channels to solo mode\n"
9393
" -s --start num Start from the specified order\n"
9494
" -t --time num Maximum playing time in seconds\n"
95+
" -U --loop-until num Loop until time in seconds exceeded\n"
9596
" --vblank Force vblank timing in Amiga modules\n"
9697
" -Z --all-sequences Play all sequences (subsongs) in module\n"
97-
" -z --sequence num Play the specified sequence (0=main)\n"
98+
" -z --sequence num Play the specified sequence (0=main)\n"
9899
"\nMixer options:\n"
99100
" -A --amiga Use Paula simulation mixer in Amiga formats\n"
100101
" -a --amplify {0|1|2|3} Amplification factor: 0=Normal, 1=x2, 2=x4, 3=x8\n"
@@ -140,6 +141,7 @@ static const struct option lopt[] = {
140141
{ "list-formats", 0, 0, 'L' },
141142
{ "loop", 0, 0, 'l' },
142143
{ "loop-all", 0, 0, OPT_LOOPALL },
144+
{ "loop-until", 1, 0, 'U' },
143145
{ "mixer-voices", 1, 0, OPT_NUMVOICES },
144146
{ "mono", 0, 0, 'm' },
145147
{ "mute", 1, 0, 'M' },
@@ -179,8 +181,9 @@ void get_options(int argc, char **argv, struct options *options)
179181
struct player_mode *pm;
180182
int optidx = 0;
181183
int o;
184+
char const* driver_guess = NULL;
182185

183-
#define OPTIONS "Aa:b:CcD:d:e:Ff:hI:i:LlM:mNo:P:p:qRrS:s:T:t:uVvZz:"
186+
#define OPTIONS "Aa:b:CcD:d:e:Ff:hI:i:LlM:mNo:P:p:qRrS:s:T:t:U:uVvZz:"
184187
while ((o = getopt_long(argc, argv, OPTIONS, lopt, &optidx)) != -1) {
185188
switch (o) {
186189
case 'A':
@@ -198,7 +201,7 @@ void get_options(int argc, char **argv, struct options *options)
198201
options->show_comment = 1;
199202
break;
200203
case 'c':
201-
options->driver_id = "file";
204+
driver_guess = "file";
202205
options->out_file = "-";
203206
break;
204207
case 'D':
@@ -278,12 +281,12 @@ void get_options(int argc, char **argv, struct options *options)
278281
options->out_file = optarg;
279282
if (strlen(optarg) >= 4 &&
280283
!xmp_strcasecmp(optarg + strlen(optarg) - 4, ".wav")) {
281-
options->driver_id = "wav";
284+
driver_guess = "wav";
282285
} else if (strlen(optarg) >= 5 &&
283286
!xmp_strcasecmp(optarg + strlen(optarg) - 5, ".aiff")) {
284-
options->driver_id = "aiff";
287+
driver_guess = "aiff";
285288
} else {
286-
options->driver_id = "file";
289+
driver_guess = "file";
287290
}
288291
break;
289292
/*
@@ -353,6 +356,9 @@ void get_options(int argc, char **argv, struct options *options)
353356
case 'u':
354357
options->format |= XMP_FORMAT_UNSIGNED;
355358
break;
359+
case 'U':
360+
options->loop_time = strtoul(optarg, NULL, 0) * 1000;
361+
break;
356362
case OPT_VBLANK:
357363
options->vblank = 1;
358364
break;
@@ -381,4 +387,8 @@ void get_options(int argc, char **argv, struct options *options)
381387
options->rate = 1000; /* Min. rate 1 kHz */
382388
if (options->rate > 48000)
383389
options->rate = 48000; /* Max. rate 48 kHz */
390+
391+
/* apply guess if no driver selected */
392+
if (!options->driver_id)
393+
options->driver_id = driver_guess;
384394
}

0 commit comments

Comments
 (0)