All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lars Magne Ingebrigtsen <larsi@gnus.org>
To: alsa-devel@alsa-project.org
Subject: aplay patch to add a --seek parameter
Date: Fri, 15 Apr 2011 01:53:48 +0200	[thread overview]
Message-ID: <m38vvc9ypf.fsf@quimbies.gnus.org> (raw)

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

             reply	other threads:[~2011-04-14 23:54 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-14 23:53 Lars Magne Ingebrigtsen [this message]
2011-04-15  7:44 ` aplay patch to add a --seek parameter Clemens Ladisch
2011-04-16  0:54   ` Lars Magne Ingebrigtsen
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=m38vvc9ypf.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.