All of lore.kernel.org
 help / color / mirror / Atom feed
* 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

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.