* aplay patch to add a --seek parameter
@ 2011-04-14 23:53 Lars Magne Ingebrigtsen
2011-04-15 7:44 ` Clemens Ladisch
2011-04-15 22:46 ` Raymond Yau
0 siblings, 2 replies; 4+ messages in thread
From: Lars Magne Ingebrigtsen @ 2011-04-14 23:53 UTC (permalink / raw)
To: alsa-devel
[-- Attachment #1: Type: text/plain, Size: 257 bytes --]
I'm using aplay in a sound editor to play PCM files. But I need to be
able to say "start playing at point X" to be able to skip around in the
file.
I've used the following patch for years, but I think I forgot to submit
it for inclusion into alsa-utils.
[-- Attachment #2: aplay-diff --]
[-- Type: application/octet-stream, Size: 2391 bytes --]
--- aplay.c.orig 2011-01-31 15:19:55.000000000 +0100
+++ aplay.c 2011-04-15 01:44:05.000000000 +0200
@@ -86,6 +86,7 @@
unsigned int rate;
} hwparams, rhwparams;
static int timelimit = 0;
+static int seek_length = 0;
static int quiet_mode = 0;
static int file_type = FORMAT_DEFAULT;
static int open_mode = 0;
@@ -186,6 +187,7 @@
"-c, --channels=# channels\n"
"-f, --format=FORMAT sample format (case insensitive)\n"
"-r, --rate=# sample rate\n"
+"-S, --seek=# seek to position # before playing\n"
"-d, --duration=# interrupt after # seconds\n"
"-M, --mmap mmap stream\n"
"-N, --nonblock nonblocking mode\n"
@@ -404,7 +406,7 @@
int main(int argc, char *argv[])
{
int option_index;
- static const char short_options[] = "hnlLD:qt:c:f:r:d:MNF:A:R:T:B:vV:IPC";
+ static const char short_options[] = "hnlLD:qt:c:f:r:S:d:MNF:A:R:T:B:vV:IPC";
static const struct option long_options[] = {
{"help", 0, 0, 'h'},
{"version", 0, 0, OPT_VERSION},
@@ -417,6 +419,7 @@
{"channels", 1, 0, 'c'},
{"format", 1, 0, 'f'},
{"rate", 1, 0, 'r'},
+ {"seek", 1, 0, 'S'},
{"duration", 1, 0 ,'d'},
{"mmap", 0, 0, 'M'},
{"nonblock", 0, 0, 'N'},
@@ -550,6 +553,9 @@
return 1;
}
break;
+ case 'S':
+ seek_length = atoi(optarg);
+ break;
case 'd':
timelimit = strtol(optarg, NULL, 0);
break;
@@ -2457,6 +2463,8 @@
}
if (test_au(fd, audiobuf) >= 0) {
rhwparams.format = hwparams.format;
+ if (seek_length != 0)
+ lseek(fd, seek_length, SEEK_SET);
pbrec_count = calc_count();
playback_go(fd, 0, pbrec_count, FORMAT_AU, name);
goto __end;
@@ -2468,17 +2476,23 @@
prg_exit(EXIT_FAILURE);;
}
if ((ofs = test_vocfile(audiobuf)) >= 0) {
+ if (seek_length != 0)
+ lseek(fd, seek_length, SEEK_SET);
pbrec_count = calc_count();
voc_play(fd, ofs, name);
goto __end;
}
/* read bytes for WAVE-header */
if ((dtawave = test_wavefile(fd, audiobuf, dta)) >= 0) {
+ if (seek_length != 0)
+ lseek(fd, seek_length, SEEK_SET);
pbrec_count = calc_count();
playback_go(fd, dtawave, pbrec_count, FORMAT_WAVE, name);
} else {
/* should be raw data */
init_raw_data();
+ if (seek_length != 0)
+ lseek(fd, seek_length, SEEK_SET);
pbrec_count = calc_count();
playback_go(fd, dta, pbrec_count, FORMAT_RAW, name);
}
[-- Attachment #3: Type: text/plain, Size: 103 bytes --]
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog http://lars.ingebrigtsen.no/
[-- Attachment #4: Type: text/plain, Size: 160 bytes --]
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: aplay patch to add a --seek parameter 2011-04-14 23:53 aplay patch to add a --seek parameter Lars Magne Ingebrigtsen @ 2011-04-15 7:44 ` Clemens Ladisch 2011-04-16 0:54 ` Lars Magne Ingebrigtsen 2011-04-15 22:46 ` Raymond Yau 1 sibling, 1 reply; 4+ messages in thread From: Clemens Ladisch @ 2011-04-15 7:44 UTC (permalink / raw) To: alsa-devel Lars Magne Ingebrigtsen wrote: > I'm using aplay in a sound editor to play PCM files. But I need to be > able to say "start playing at point X" to be able to skip around in the > file. > > I've used the following patch for years, but I think I forgot to submit > it for inclusion into alsa-utils. Thanks. Please provide a Signed-off-by tag, document whether this option takes samples, frames, or (milli)seconds, and add this option to the man page. Furthermore, the code doesn't look as if it correctly skips over chunks in VOC files. Regards, Clemens ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: aplay patch to add a --seek parameter 2011-04-15 7:44 ` Clemens Ladisch @ 2011-04-16 0:54 ` Lars Magne Ingebrigtsen 0 siblings, 0 replies; 4+ messages in thread From: Lars Magne Ingebrigtsen @ 2011-04-16 0:54 UTC (permalink / raw) To: alsa-devel [-- Attachment #1: Type: text/plain, Size: 772 bytes --] Clemens Ladisch <clemens@ladisch.de> writes: > Please provide a Signed-off-by tag, document whether this option takes > samples, frames, or (milli)seconds, and add this option to the man page. > Furthermore, the code doesn't look as if it correctly skips over chunks > in VOC files. The --seek number is in bytes, so it assumes that the caller knows what the internal structure of the file is. For my usage (which is a simple visual wave form editor), this makes sense, but specifying it in milliseconds would probably be even more useful, I guess? I'm not that familiar with the aplay internals, but so if someone who are familiar were to transform the patch into "seek to millisecond X", that would be nice. Signed-off-by: Lars Magne Ingebrigtsen <larsi@gnus.org> [-- Attachment #2: aplay-diff --] [-- Type: application/octet-stream, Size: 2878 bytes --] --- aplay.c.orig 2011-01-31 15:19:55.000000000 +0100 +++ aplay.c 2011-04-16 02:45:43.000000000 +0200 @@ -86,6 +86,7 @@ unsigned int rate; } hwparams, rhwparams; static int timelimit = 0; +static int seek_length = 0; static int quiet_mode = 0; static int file_type = FORMAT_DEFAULT; static int open_mode = 0; @@ -186,6 +187,7 @@ "-c, --channels=# channels\n" "-f, --format=FORMAT sample format (case insensitive)\n" "-r, --rate=# sample rate\n" +"-S, --seek=# seek to position # (in bytes) before playing\n" "-d, --duration=# interrupt after # seconds\n" "-M, --mmap mmap stream\n" "-N, --nonblock nonblocking mode\n" @@ -404,7 +406,7 @@ int main(int argc, char *argv[]) { int option_index; - static const char short_options[] = "hnlLD:qt:c:f:r:d:MNF:A:R:T:B:vV:IPC"; + static const char short_options[] = "hnlLD:qt:c:f:r:S:d:MNF:A:R:T:B:vV:IPC"; static const struct option long_options[] = { {"help", 0, 0, 'h'}, {"version", 0, 0, OPT_VERSION}, @@ -417,6 +419,7 @@ {"channels", 1, 0, 'c'}, {"format", 1, 0, 'f'}, {"rate", 1, 0, 'r'}, + {"seek", 1, 0, 'S'}, {"duration", 1, 0 ,'d'}, {"mmap", 0, 0, 'M'}, {"nonblock", 0, 0, 'N'}, @@ -550,6 +553,9 @@ return 1; } break; + case 'S': + seek_length = atoi(optarg); + break; case 'd': timelimit = strtol(optarg, NULL, 0); break; @@ -2457,6 +2463,8 @@ } if (test_au(fd, audiobuf) >= 0) { rhwparams.format = hwparams.format; + if (seek_length != 0) + lseek(fd, seek_length, SEEK_SET); pbrec_count = calc_count(); playback_go(fd, 0, pbrec_count, FORMAT_AU, name); goto __end; @@ -2468,17 +2476,23 @@ prg_exit(EXIT_FAILURE);; } if ((ofs = test_vocfile(audiobuf)) >= 0) { + if (seek_length != 0) + lseek(fd, seek_length, SEEK_SET); pbrec_count = calc_count(); voc_play(fd, ofs, name); goto __end; } /* read bytes for WAVE-header */ if ((dtawave = test_wavefile(fd, audiobuf, dta)) >= 0) { + if (seek_length != 0) + lseek(fd, seek_length, SEEK_SET); pbrec_count = calc_count(); playback_go(fd, dtawave, pbrec_count, FORMAT_WAVE, name); } else { /* should be raw data */ init_raw_data(); + if (seek_length != 0) + lseek(fd, seek_length, SEEK_SET); pbrec_count = calc_count(); playback_go(fd, dta, pbrec_count, FORMAT_RAW, name); } --- aplay.1.orig 2011-04-16 02:46:57.000000000 +0200 +++ aplay.1 2011-04-16 02:49:55.000000000 +0200 @@ -77,6 +77,9 @@ A value of zero means infinity. The default is zero, so if this option is omitted then the arecord process will run until it is killed. .TP +\fI\-S, \-\-seek=#\fP +Seek to position # (in bytes) before starting to play. This option mostly makes sense on raw files. +.TP \fI\-s, \-\-sleep\-min=#\fP Min ticks to sleep. The default is not to sleep. .TP [-- Attachment #3: Type: text/plain, Size: 104 bytes --] -- (domestic pets only, the antidote for overdose, milk.) bloggy blog http://lars.ingebrigtsen.no/ [-- Attachment #4: Type: text/plain, Size: 0 bytes --] ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: aplay patch to add a --seek parameter 2011-04-14 23:53 aplay patch to add a --seek parameter Lars Magne Ingebrigtsen 2011-04-15 7:44 ` Clemens Ladisch @ 2011-04-15 22:46 ` Raymond Yau 1 sibling, 0 replies; 4+ messages in thread From: Raymond Yau @ 2011-04-15 22:46 UTC (permalink / raw) To: alsa-devel 2011/4/15 Lars Magne Ingebrigtsen <larsi@gnus.org> > I'm using aplay in a sound editor to play PCM files. But I need to be > able to say "start playing at point X" to be able to skip around in the > file. > > I've used the following patch for years, but I think I forgot to submit > it for inclusion into alsa-utils. > > it depend on X is byte or frame when X is an odd number and the format is S16_LE , aplay just produce noise ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-04-16 0:55 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2011-04-14 23:53 aplay patch to add a --seek parameter Lars Magne Ingebrigtsen 2011-04-15 7:44 ` Clemens Ladisch 2011-04-16 0:54 ` Lars Magne Ingebrigtsen 2011-04-15 22:46 ` Raymond Yau
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.