mixer applet.

tito farmatito at tiscali.it
Sat Jul 5 22:15:49 UTC 2014


On Saturday 05 July 2014 20:32:18 bifferos wrote:
> Here's a mixer applet (OSS).  It gets the list of mixer devices, gets and sets individual device values.
> 
> 
> 
> / # mixer --help
> BusyBox v1.22.1 (2014-06-23 15:19:41 BST) multi-call binary.
> 
> Usage: mixer [-d DEVICE] [MIXER [LEVEL]]
> 
> Sets the mixer volume at a specific level (0-100)
> 
>         -d DEVICE    use given mixer device (default /dev/mixer)
> 
> / # mixer
> Mixer: speaker mic phout
> 
> / # mixer speaker
> Level (L/R): 99/99
> 
> / # mixer speaker 20
> Level (L/R): 20/20
> 
> It adds about about 2.6k to Busybox and I don't really understand why.  Even with the list of mixers it should only be ~500 bytes.
> If anyone has any suggestions I can try to fix that.
> 
> 
> regards,
> Biff.

Hi,
just for fun some size reduction. 
Tested it a little bit and it seems to work.

Ciao,
Tito

scripts/bloat-o-meter busybox_old busybox_unstripped
function                                             old     new   delta
pr_level_exit                                         27       -     -27
mixer_main                                           385     335     -50
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 0/1 up/down: 0/-77)             Total: -77 bytes

int mixer_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int mixer_main(int argc, char **argv)
{
	int fd_mixer;
	char* device = (char*)"/dev/mixer";
	uint32_t level;
	int devmask, n_dev;
	const char *m_names[SOUND_MIXER_NRDEVICES] = SOUND_DEVICE_NAMES ;

	/* option handling */
	opt_complementary = "?2";  /* must have no more than 2 */
	getopt32(argv, "d:", &device);
	argc -= optind;
	argv += optind;

	fd_mixer = xopen(device, O_RDWR);
	ioctl_or_perror_and_die(fd_mixer, SOUND_MIXER_READ_DEVMASK, &devmask, "DEVMASK");

	switch (argc) {
		case 2:
			level = xatoi_range(argv[1], 1, 100);
			break;
		case 0:
			printf("Mixer:");
	}

	/* mixer device enumeration */
	for (n_dev = 0; n_dev < SOUND_MIXER_NRDEVICES; ++n_dev) {
		if ((1 << n_dev) & devmask) {
			if (*argv) {
				if (strcmp(m_names[n_dev], *argv) == 0)
					break;
			} else {
				printf(" %s", m_names[n_dev]);
			}
		}
	}

	if (!*argv) {
		putchar('\n');
	} else {
		if (argc == 2) {
			/* mixer device setting */
			level = (level << 8) + level;
			ioctl_or_perror_and_die(fd_mixer, MIXER_WRITE(n_dev), &level, "MIXER_WRITE");
		} else {
			/* mixer device reading */
			ioctl_or_perror_and_die(fd_mixer, MIXER_READ(n_dev), &level, "MIXER_READ");
		}
		printf("Level (l/r): %d/%d\n", level & 0xff, ((level & 0xff00) >> 8));
	}
	return 0;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mixer.c
Type: text/x-csrc
Size: 2021 bytes
Desc: not available
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20140706/a73c197c/attachment-0001.c>


More information about the busybox mailing list