plan 9 kernel history: overview | file list | diff list

1995/0221/port/devaudio.c (diff list | history)

1995/0217/sys/src/9/port/devaudio.c:15,211995/0221/sys/src/9/port/devaudio.c:15,20 (short | long | prev | next)
1995/0119    
 
1995/0217    
typedef struct	AQueue	AQueue; 
1995/0119    
typedef struct	Buf	Buf; 
typedef struct	Level	Level; 
 
enum 
{ 
1995/0217/sys/src/9/port/devaudio.c:24,341995/0221/sys/src/9/port/devaudio.c:23,46
1995/0119    
	Qvolume, 
 
	Fmono		= 1, 
1995/0221    
	Fin		= 2, 
	Fout		= 4, 
1995/0119    
 
1995/0214    
	Aclosed		= 0, 
	Aread, 
1995/0119    
	Awrite, 
 
1995/0221    
	Vaudio		= 0, 
	Vsynth, 
	Vcd, 
	Vline, 
	Vmic, 
	Vspeaker, 
	Vtreb, 
	Vbass, 
	Vspeed, 
	Nvol, 
 
1995/0119    
	Speed		= 44100, 
	Ncmd		= 50,		/* max volume command words */ 
}; 
1995/0217/sys/src/9/port/devaudio.c:40,581995/0221/sys/src/9/port/devaudio.c:52,57
1995/0119    
	"volume",	{Qvolume},		0,	0666, 
}; 
 
struct	Level 
{ 
	int	master;		/* mixer output volume control */ 
	int	ogain;		/* extra gain after master */ 
	int	pcm;		/* mixer volume on D/A (voice) */ 
	int	synth;		/* mixer volume on synthesizer (MIDI) */ 
	int	cd;		/* mixer volume on cd */ 
	int	line;		/* mixer volume on line */ 
	int	igain;		/* mixer volume to A/D */ 
	int	treb;		/* treb control */ 
	int	bass;		/* bass control */ 
	int	iswitch;	/* input on/off switches */ 
}; 
struct	Buf 
{ 
	uchar*	virt; 
1995/0217/sys/src/9/port/devaudio.c:74,851995/0221/sys/src/9/port/devaudio.c:73,82
1995/0119    
	int	active;		/* boolean dma running */ 
	int	intr;		/* boolean an interrupt has happened */ 
1995/0214    
	int	amode;		/* Aclosed/Aread/Awrite for /audio */ 
1995/0119    
	Level	left;		/* all of left volumes */ 
	Level	right;		/* all of right volumes */ 
	int	mic;		/* mono level */ 
	int	speaker;	/* mono level */ 
	int	oswitch;	/* output on/off switches */ 
	int	speed;		/* pcm sample rate, doesnt change w stereo */ 
1995/0221    
	int	rivol[Nvol];		/* right/left input/output volumes */ 
	int	livol[Nvol]; 
	int	rovol[Nvol]; 
	int	lovol[Nvol]; 
1995/0119    
	int	major;		/* SB16 major version number (sb 4) */ 
	int	minor;		/* SB16 minor version number */ 
 
1995/0217/sys/src/9/port/devaudio.c:93,1231995/0221/sys/src/9/port/devaudio.c:90,111
1995/0119    
static	struct 
{ 
	char*	name; 
	int*	ptr1; 
	int*	ptr2; 
	int	flag; 
	int	ilval; 
1995/0221    
	int	ilval;		/* initial values */ 
1995/0119    
	int	irval; 
} volumes[] = 
{ 
	"master",	&audio.left.master,	&audio.right.master,	0,	50,	50, 
	"ogain",	&audio.left.ogain,	&audio.right.ogain,	0, 	0,	0, 
	"igain",	&audio.left.igain,	&audio.right.igain,	0, 	0,	0, 
1995/0221    
[Vaudio]		"audio",		Fout, 		50,	50, 
[Vsynth]		"synth",		Fin|Fout,		0,	0, 
[Vcd]		"cd",		Fin|Fout,		0,	0, 
[Vline]		"line",		Fin|Fout,		0,	0, 
[Vmic]		"mic",		Fin|Fout|Fmono,	0,	0, 
[Vspeaker]	"speaker",	Fout|Fmono,	0,	0, 
1995/0119    
 
	"treb",		&audio.left.treb,	&audio.right.treb,	0, 	50,	50, 
	"bass",		&audio.left.bass,	&audio.right.bass,	0, 	50,	50, 
1995/0221    
[Vtreb]		"treb",		Fout, 		50,	50, 
[Vbass]		"bass",		Fout, 		50,	50, 
1995/0119    
 
	"pcm",		&audio.left.pcm,	&audio.right.pcm,	0, 	90,	90, 
	"synth",	&audio.left.synth,	&audio.right.synth,	0,	90,	90, 
	"cd",		&audio.left.cd,		&audio.right.cd,	0,	81,	81, 
	"line",		&audio.left.line,	&audio.right.line,	0,	65,	65, 
                 
	"mic",		&audio.mic,		&audio.mic,		Fmono,	0,	0, 
	"speaker",	&audio.speaker,		&audio.speaker,		Fmono,	0,	0, 
	"oswitch",	&audio.oswitch,		&audio.oswitch,		Fmono,	31,	31, 
	"iswitch",	&audio.left.iswitch,	&audio.right.iswitch,	0,	85,	43, 
                 
	"speed",	&audio.speed,		&audio.speed,		Fmono,	Speed,	Speed, 
1995/0221    
[Vspeed]		"speed",		Fin|Fout|Fmono,	Speed,	Speed, 
1995/0119    
	0 
}; 
 
1995/0217/sys/src/9/port/devaudio.c:229,2671995/0221/sys/src/9/port/devaudio.c:217,284
1995/0119    
static	void 
mxvolume(void) 
{ 
1995/0221    
	int *left, *right; 
	int source; 
 
	if(audio.amode == Aread){ 
		left = audio.livol; 
		right = audio.rivol; 
	}else{ 
		left = audio.lovol; 
		right = audio.rovol; 
	} 
 
1995/0214    
	ilock(&blaster); 
1995/0119    
	mxcmds(0x30, audio.left.master); 
	mxcmds(0x31, audio.right.master); 
 
	mxcmdt(0x32, audio.left.pcm); 
	mxcmdt(0x33, audio.right.pcm); 
1995/0221    
	mxcmd(0x30, 255);		/* left master */ 
	mxcmd(0x31, 255);		/* right master */ 
	mxcmd(0x3f, 0);		/* left igain */ 
	mxcmd(0x40, 0);		/* right igain */ 
	mxcmd(0x41, 0);		/* left ogain */ 
	mxcmd(0x42, 0);		/* right ogain */ 
1995/0119    
 
	mxcmdt(0x34, audio.left.synth); 
	mxcmdt(0x35, audio.right.synth); 
1995/0221    
	mxcmds(0x32, left[Vaudio]); 
	mxcmds(0x33, right[Vaudio]); 
1995/0119    
 
	mxcmdt(0x36, audio.left.cd); 
	mxcmdt(0x37, audio.right.cd); 
1995/0221    
	mxcmds(0x34, left[Vsynth]); 
	mxcmds(0x35, right[Vsynth]); 
1995/0119    
 
	mxcmdt(0x38, audio.left.line); 
	mxcmdt(0x39, audio.right.line); 
1995/0221    
	mxcmds(0x36, left[Vcd]); 
	mxcmds(0x37, right[Vcd]); 
1995/0119    
 
	mxcmdt(0x3a, audio.mic); 
	mxcmdt(0x3b, audio.speaker); 
1995/0221    
	mxcmds(0x38, left[Vline]); 
	mxcmds(0x39, right[Vline]); 
1995/0119    
 
	mxcmds(0x3f, audio.left.igain); 
	mxcmds(0x40, audio.right.igain); 
	mxcmds(0x41, audio.left.ogain); 
	mxcmds(0x42, audio.right.ogain); 
1995/0221    
	mxcmds(0x3a, left[Vmic]); 
	mxcmds(0x3b, left[Vspeaker]); 
1995/0119    
 
	mxcmdu(0x44, audio.left.treb); 
	mxcmdu(0x45, audio.right.treb); 
1995/0221    
	mxcmdu(0x44, left[Vtreb]); 
	mxcmdu(0x45, right[Vtreb]); 
1995/0119    
 
	mxcmdu(0x46, audio.left.bass); 
	mxcmdu(0x47, audio.right.bass); 
1995/0221    
	mxcmdu(0x46, left[Vbass]); 
	mxcmdu(0x47, right[Vbass]); 
1995/0119    
 
	mxcmd(0x3c, audio.oswitch); 
	mxcmd(0x3d, audio.left.iswitch); 
	mxcmd(0x3e, audio.right.iswitch); 
1995/0221    
	source = 0; 
	if(left[Vsynth]) 
		source |= 1<<6; 
	if(right[Vsynth]) 
		source |= 1<<5; 
	if(left[Vaudio]) 
		source |= 1<<4; 
	if(right[Vaudio]) 
		source |= 1<<3; 
	if(left[Vcd]) 
		source |= 1<<2; 
	if(right[Vcd]) 
		source |= 1<<1; 
	if(left[Vmic]) 
		source |= 1<<0; 
	if(audio.amode == Aread) 
		mxcmd(0x3c, 0);		/* output switch */ 
	else 
		mxcmd(0x3c, source); 
	mxcmd(0x3d, source);		/* input left switch */ 
	mxcmd(0x3e, source);		/* input right switch */ 
1995/0214    
	iunlock(&blaster); 
1995/0119    
} 
 
1995/0217/sys/src/9/port/devaudio.c:337,3511995/0221/sys/src/9/port/devaudio.c:354,372
1995/0119    
startdma(void) 
{ 
	ulong count; 
1995/0221    
	int speed; 
1995/0119    
 
1995/0214    
	ilock(&blaster); 
	dmaend(Dma); 
	if(audio.amode == Aread) 
1995/0221    
	if(audio.amode == Aread) { 
1995/0119    
		sbcmd(0x42);			/* input sampling rate */ 
1995/0214    
	else 
1995/0221    
		speed = audio.livol[Vspeed]; 
	} else { 
1995/0119    
		sbcmd(0x41);			/* output sampling rate */ 
	sbcmd(audio.speed>>8); 
	sbcmd(audio.speed); 
1995/0221    
		speed = audio.lovol[Vspeed]; 
	} 
	sbcmd(speed>>8); 
	sbcmd(speed); 
1995/0119    
 
	count = (Bufsize >> 1) - 1; 
	if(audio.amode == Aread) 
1995/0217/sys/src/9/port/devaudio.c:479,4861995/0221/sys/src/9/port/devaudio.c:500,509
1995/0119    
	int i; 
 
	for(i=0; volumes[i].name; i++) { 
		*volumes[i].ptr1 = volumes[i].ilval; 
		*volumes[i].ptr2 = volumes[i].irval; 
1995/0221    
		audio.lovol[i] = volumes[i].ilval; 
		audio.rovol[i] = volumes[i].irval; 
		audio.livol[i] = volumes[i].ilval; 
		audio.rivol[i] = volumes[i].irval; 
1995/0119    
	} 
} 
 
1995/0217/sys/src/9/port/devaudio.c:629,6341995/0221/sys/src/9/port/devaudio.c:652,658
1995/0119    
		setempty(); 
		audio.curcount = 0; 
1995/0214    
		qunlock(&audio); 
1995/0221    
		mxvolume(); 
1995/0119    
		break; 
	} 
	c = devopen(c, omode, audiodir, NPORT, devgen); 
1995/0217/sys/src/9/port/devaudio.c:684,6911995/0221/sys/src/9/port/devaudio.c:708,716
1995/0119    
long 
audioread(Chan *c, char *a, long n, ulong offset) 
{ 
	long m, o, n0, bn; 
	char buf[256]; 
1995/0221    
	int liv, riv, lov, rov; 
	long m, n0; 
	char buf[300]; 
1995/0119    
	Buf *b; 
	int j; 
 
1995/0217/sys/src/9/port/devaudio.c:737,7541995/0221/sys/src/9/port/devaudio.c:762,797
1995/0119    
 
	case Qvolume: 
		j = 0; 
		for(m=0; volumes[m].name; m++) { 
			o = *volumes[m].ptr1; 
			if(volumes[m].flag & Fmono) 
				j += snprint(buf+j, sizeof(buf)-j, "%s %d\n", volumes[m].name, o); 
			else { 
				bn = *volumes[m].ptr2; 
				if(o == bn) 
					j += snprint(buf+j, sizeof(buf)-j, "%s both %d\n", volumes[m].name, o); 
				else 
					j += snprint(buf+j, sizeof(buf)-j, "%s left %d right %d\n", 
						volumes[m].name, o, bn); 
1995/0221    
		buf[0] = 0; 
		for(m=0; volumes[m].name; m++){ 
			liv = audio.livol[m]; 
			riv = audio.rivol[m]; 
			lov = audio.lovol[m]; 
			rov = audio.rovol[m]; 
			j += snprint(buf+j, sizeof(buf)-j, "%s", volumes[m].name); 
			if((volumes[m].flag & Fmono) || liv==riv && lov==rov){ 
				if((volumes[m].flag&(Fin|Fout))==(Fin|Fout) && liv==lov) 
					j += snprint(buf+j, sizeof(buf)-j, " %d", liv); 
				else{ 
					if(volumes[m].flag & Fin) 
						j += snprint(buf+j, sizeof(buf)-j, " in %d", liv); 
					if(volumes[m].flag & Fout) 
						j += snprint(buf+j, sizeof(buf)-j, " out %d", lov); 
				} 
			}else{ 
				if((volumes[m].flag&(Fin|Fout))==(Fin|Fout) && liv==lov && riv==rov) 
					j += snprint(buf+j, sizeof(buf)-j, " left %d right %d", 
						liv, riv); 
				else{ 
					if(volumes[m].flag & Fin) 
						j += snprint(buf+j, sizeof(buf)-j, " in left %d right %d", 
							liv, riv); 
					if(volumes[m].flag & Fout) 
						j += snprint(buf+j, sizeof(buf)-j, " out left %d right %d", 
							lov, rov); 
				} 
1995/0119    
			} 
1995/0221    
			j += snprint(buf+j, sizeof(buf)-j, "\n"); 
1995/0119    
		} 
 
		return readstr(offset, a, n, buf); 
1995/0217/sys/src/9/port/devaudio.c:766,7721995/0221/sys/src/9/port/devaudio.c:809,815
1995/0119    
audiowrite(Chan *c, char *a, long n, ulong offset) 
{ 
	long m, n0; 
	int i, nf, v, left, right; 
1995/0221    
	int i, nf, v, left, right, in, out; 
1995/0119    
	char buf[255], *field[Ncmd]; 
	Buf *b; 
 
1995/0217/sys/src/9/port/devaudio.c:779,7871995/0221/sys/src/9/port/devaudio.c:822,832
1995/0119    
		break; 
 
	case Qvolume: 
		v = 0; 
1995/0221    
		v = Vaudio; 
1995/0119    
		left = 1; 
		right = 1; 
1995/0221    
		in = 1; 
		out = 1; 
1995/0119    
		if(n > sizeof(buf)-1) 
			n = sizeof(buf)-1; 
		memmove(buf, a, n); 
1995/0217/sys/src/9/port/devaudio.c:794,8031995/0221/sys/src/9/port/devaudio.c:839,852
1995/0119    
			 */ 
			if(field[i][0] >= '0' && field[i][0] <= '9') { 
				m = strtoul(field[i], 0, 10); 
				if(left) 
					*volumes[v].ptr1 = m; 
				if(right) 
					*volumes[v].ptr2 = m; 
1995/0221    
				if(left && out) 
					audio.lovol[v] = m; 
				if(left && in) 
					audio.livol[v] = m; 
				if(right && out) 
					audio.rovol[v] = m; 
				if(right && in) 
					audio.rivol[v] = m; 
1995/0119    
				mxvolume(); 
				goto cont0; 
			} 
1995/0217/sys/src/9/port/devaudio.c:805,8101995/0221/sys/src/9/port/devaudio.c:854,863
1995/0119    
			for(m=0; volumes[m].name; m++) { 
				if(strcmp(field[i], volumes[m].name) == 0) { 
					v = m; 
1995/0221    
					in = 1; 
					out = 1; 
					left = 1; 
					right = 1; 
1995/0119    
					goto cont0; 
				} 
			} 
1995/0217/sys/src/9/port/devaudio.c:814,8191995/0221/sys/src/9/port/devaudio.c:867,882
1995/0119    
				mxvolume(); 
				goto cont0; 
			} 
1995/0221    
			if(strcmp(field[i], "in") == 0) { 
				in = 1; 
				out = 0; 
				goto cont0; 
			} 
			if(strcmp(field[i], "out") == 0) { 
				in = 0; 
				out = 1; 
				goto cont0; 
			} 
1995/0119    
			if(strcmp(field[i], "left") == 0) { 
				left = 1; 
				right = 0; 
1995/0217/sys/src/9/port/devaudio.c:821,8311995/0221/sys/src/9/port/devaudio.c:884,889
1995/0119    
			} 
			if(strcmp(field[i], "right") == 0) { 
				left = 0; 
				right = 1; 
				goto cont0; 
			} 
			if(strcmp(field[i], "both") == 0) { 
				left = 1; 
				right = 1; 
				goto cont0; 
			} 


source code copyright © 1990-2005 Lucent Technologies; see license
Plan 9 distribution
comments to russ cox (rsc@swtch.com)