72 lines · 1.1 KB · C
RawDownload
#include <u.h>#include <libc.h> static voidusage(void){	print("usage: %s -l len_frames [-t times] [-c channels] [-f file]\n", argv0);	exits("usage");} voidmain(int argc, char **argv){	int length, chan, t, f, r, n;	u8int *b; 	length = 0;	chan = 1;	t = -1;	f = 0; 	ARGBEGIN{	case 'l':		length = atoi(EARGF(usage()));		break;	case 't':		t = atoi(EARGF(usage()));		break; 	case 'c':		chan = atoi(EARGF(usage()));		break;	case 'f':		if ((f = open(EARGF(usage()), OREAD)) < 0)			sysfatal("%r");		break;	default:		usage();	}ARGEND 	if (length < 1)		sysfatal("invalid length: %d frames", length);	if (chan < 1)		sysfatal("invalid number of channels: %d", chan); 	length *= chan * 4;	if ((b = malloc(length)) == nil)		sysfatal("couldn't allocate %d bytes", length); 	n = 0;	while (t != 0) {		if (f != 0 || n == 0) {			seek(f, 0, 0); 			for (n = 0; n < length; n += r) {				r = read(f, b+n, length-n);				if (r < 0)					exits("read failed");				else if (r == 0)					break;			}			memset(b+n, 0, length-n);		} 		if (write(1, b, length) != length)			break; 		if (t > 0)			t--;	} 	exits(nil);}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t