72 lines · 1.1 KB · C
RawDownload
#include <u.h>#include <libc.h> static voidusage(void){	print("usage: %s [-b buf_frames] [-c channels]\n", argv0);	exits("usage");} voidmain(int argc, char **argv){	int bufsz, bufframes, framesz, chan, n, r, end, i;	float f;	u8int *b; 	bufframes = 2048;	chan = 1; 	ARGBEGIN{	case 'b':		bufframes = atoi(EARGF(usage()));		break;	case 'c':		chan = atoi(EARGF(usage()));		break;	default:		usage();	}ARGEND 	if (bufframes < 1)		sysfatal("invalid buffer size: %d frames", bufframes);	if (chan < 1)		sysfatal("invalid number of channels: %d", chan); 	framesz = chan * 4;	bufsz = bufframes * framesz;	b = malloc(bufsz); 	n = 0;	for (;;) {		r = read(0, b+n, bufsz-n);		if (r < 0)			exits("read failed");		else if (r == 0)			break;		n += r; 		end = n & ~(framesz-1);		if (end < 1)			continue; 		for (; end > 0; end -= framesz) {			for (i = 0; i < chan; i++) {				f = *(float*)(b + end - framesz - i*4);				if (f != 0)					goto out;			}		}out:		if (end == 0)			break; 		if (write(1, b, end) != end)			exits("write failed");		n -= end;		memmove(b, b+end, n);	} 	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