All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lars Magne Ingebrigtsen <larsi@gnus.org>
To: alsa-devel@alsa-project.org
Subject: Re: aplay patch to add a --seek parameter
Date: Sat, 16 Apr 2011 02:54:49 +0200	[thread overview]
Message-ID: <m3mxjryq06.fsf@quimbies.gnus.org> (raw)
In-Reply-To: 4DA7F76F.5090702@ladisch.de

[-- 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 --]



  reply	other threads:[~2011-04-16  0:55 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2011-04-15 22:46 ` Raymond Yau

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m3mxjryq06.fsf@quimbies.gnus.org \
    --to=larsi@gnus.org \
    --cc=alsa-devel@alsa-project.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.