88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * CDDL HEADER START
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * The contents of this file are subject to the terms of the
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * Common Development and Distribution License (the "License").
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * You may not use this file except in compliance with the License.
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * or http://www.opensolaris.org/os/licensing.
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * See the License for the specific language governing permissions
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * and limitations under the License.
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * When distributing Covered Code, include this CDDL HEADER in each
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * If applicable, add the following below this CDDL HEADER, with the
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * fields enclosed by brackets "[]" replaced with your own identifying
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * information: Portions Copyright [yyyy] [name of copyright owner]
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * CDDL HEADER END
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * Copyright (C) 4Front Technologies 1996-2008.
a33ad26ef1f3b7a3fcf2fad564e6bd3798fdcbaeZhao Edgar Liu - Sun Microsystems * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * This program is a general purpose test facility for audio output.
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * It does not test record.
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * The wavedata.c and wavedata.h files contain the actual samples compressed
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * using the MS ADPCM algorithm.
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore#if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore#define TEXT_DOMAIN "SYS_TEST" /* Use this only if it weren't */
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore#define _(s) gettext(s)
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * Channel selectors
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore#define CH_LREAR4 (1 << 2) /* quadraphonic */
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore#define CH_RREAR4 (1 << 3) /* quadraphonic */
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore#define CH_4 (CH_STEREO | CH_LREAR4 | CH_RREAR4)
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore#define CH_5 (CH_STEREO | CH_CENTER | CH_LSURR | CH_RSURR)
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore#define CFLAG_LFE 0x1 /* lfe channel - not full range */
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * TRANSLATION_NOTE : The following strings are displayed during progress.
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * Its important for alignment that they have the same displayed length.
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore#define NM_CENTER "\t<center> .............."
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore#define NM_STEREO "\t<stereo> .............."
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amorechancfg_t ch_right = { CH_RIGHT, NM_RIGHT, 0 };
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amorechancfg_t ch_stereo = { CH_STEREO, NM_STEREO, 0 };
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amorechancfg_t ch_center = { CH_CENTER, NM_CENTER, 0 };
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amorechancfg_t ch_lfe = { CH_LFE, NM_LFE, CFLAG_LFE };
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amorechancfg_t ch_lsurr_4 = { (1 << 2), NM_LREAR, 0 };
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amorechancfg_t ch_rsurr_4 = { (1 << 3), NM_RREAR, 0 };
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amorechancfg_t ch_lsurr_5 = { CH_LSURR, NM_LREAR, 0 };
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amorechancfg_t ch_rsurr_5 = { CH_RSURR, NM_RREAR, 0 };
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amorechancfg_t ch_lsurr_7 = { CH_LSURR, NM_LSIDE, 0 };
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amorechancfg_t ch_rsurr_7 = { CH_RSURR, NM_RSIDE, 0 };
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amorechancfg_t ch_lrear_7 = { CH_LREAR, NM_LREAR, 0 };
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amorechancfg_t ch_rrear_7 = { CH_RREAR, NM_RREAR, 0 };
a33ad26ef1f3b7a3fcf2fad564e6bd3798fdcbaeZhao Edgar Liu - Sun Microsystems 2, 48000, { &ch_left, &ch_right, &ch_stereo, NULL }
a33ad26ef1f3b7a3fcf2fad564e6bd3798fdcbaeZhao Edgar Liu - Sun Microsystems 4, 48000, { &ch_left, &ch_right, &ch_stereo,
a33ad26ef1f3b7a3fcf2fad564e6bd3798fdcbaeZhao Edgar Liu - Sun Microsystems 6, 48000, { &ch_left, &ch_right, &ch_stereo,
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore &ch_lsurr_5, &ch_rsurr_5, &ch_center, &ch_lfe, &ch_5, NULL }
a33ad26ef1f3b7a3fcf2fad564e6bd3798fdcbaeZhao Edgar Liu - Sun Microsystems 8, 48000, { &ch_left, &ch_right, &ch_stereo,
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore &ch_lsurr_7, &ch_rsurr_7, &ch_lrear_7, &ch_rrear_7,
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * uncompress_wave() is defined in wavedata.c. It expands the audio
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * samples stored in wavedata.h and returns the lenghth of the
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * uncompressed version in bytes.
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * The uncompressed wave data format is 16 bit (native) stereo
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * recorded at 48000 Hz.
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amoreextern void describe_error(int);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * Operating mode flags (set from the command line).
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore#define TF_LOOP 0x00000010 /* Loop until interrupted */
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if ((sample_buf = malloc(2000000)) == NULL) {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore nsamples = (data_len / sizeof (int16_t)) / 2;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore for (i = 0; (ccfg = tcfg->tests[i]) != NULL; i++) {
a33ad26ef1f3b7a3fcf2fad564e6bd3798fdcbaeZhao Edgar Liu - Sun Microsystems rate_multiple = tcfg->rate / 48000;
a33ad26ef1f3b7a3fcf2fad564e6bd3798fdcbaeZhao Edgar Liu - Sun Microsystems ccfg->len = nsamples * tcfg->nchan *
a33ad26ef1f3b7a3fcf2fad564e6bd3798fdcbaeZhao Edgar Liu - Sun Microsystems sizeof (int16_t) * rate_multiple;
a33ad26ef1f3b7a3fcf2fad564e6bd3798fdcbaeZhao Edgar Liu - Sun Microsystems for (j = 0; j < rate_multiple; j++) {
a33ad26ef1f3b7a3fcf2fad564e6bd3798fdcbaeZhao Edgar Liu - Sun Microsystems *dst = ((1U << ch) & ccfg->mask)
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore /* Skip LFE for now */
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * The testdsp() routine checks the capabilities of a given audio device number
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * (parameter n) and decides if the test sound needs to be played.
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore unsigned long t;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if (ioctl(hd, SNDCTL_DSP_GETCAPS, &caps) == -1) {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * Setup the sample format. Since OSS will support AFMT_S16_NE
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * regardless of the device we do not need to support any
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * other formats.
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if (ioctl(hd, SNDCTL_DSP_SETFMT, &tmp) == -1 || tmp != AFMT_S16_NE) {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore (void) printf(_("Device doesn't support native 16-bit PCM\n"));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * Setup the device for channels. Once again we can simply
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * assume that stereo will always work before OSS takes care
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * of this by emulation if necessary.
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if (ioctl(hd, SNDCTL_DSP_CHANNELS, &tmp) == -1 || tmp != tcfg->nchan) {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore (void) printf(_("The device doesn't support %d channels\n"),
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * Set up the sample rate.
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if (ioctl(hd, SNDCTL_DSP_SPEED, &tmp) == -1) {
a33ad26ef1f3b7a3fcf2fad564e6bd3798fdcbaeZhao Edgar Liu - Sun Microsystems if (sample_rate != tcfg->rate) {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore (void) printf(_("The device doesn't support %d Hz\n"),
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * This program will measure the real sampling rate by
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * computing the total time required to play the sample.
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * This is not terribly presice with short test sounds but it
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * can be used to detect if the sampling rate badly
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * wrong. Errors of few percents is more likely to be caused
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * by poor accuracy of the system clock rather than problems
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * with the sampling rate.
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore for (i = 0; (ccfg = tcfg->tests[i]) != NULL; i++) {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore (void) ioctl(hd, SNDCTL_DSP_GETODELAY, &delay); /* Ignore errors */
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * Perform the time computations using milliseconds.
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore total_bytes /= (tcfg->nchan * sizeof (int16_t));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore ratio = ((float)total_bytes / (float)sample_rate) * 100.0;
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore (void) printf(_("\t<measured sample rate %8.2f Hz (%4.2f%%)>\n"),
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore (float)sample_rate * ratio / 100.0, ratio - 100.0);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * Find out the number of available audio devices by calling
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * SNDCTL_SYSINFO.
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if (ioctl(mixerfd, SNDCTL_SYSINFO, &info) == -1) {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore _("No supported sound hardware detected.\n"));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore (void) printf(_("Cannot get system information.\n"));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore (void) printf(_("Sound subsystem and version: %s %s (0x%08X)\n"),
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore info.product, info.version, info.versionnum);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore un.sysname, un.release, un.version, un.machine);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * The test_device() routine checks certain information about the device
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * and calls testdsp() to play the test sound.
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amoretest_device(char *dn, int flags, testcfg_t *tcfg)
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if (ioctl(fd, SNDCTL_AUDIOINFO, &ainfo) == -1) {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore (void) printf(_("\n*** Scanning sound adapter #%d ***\n"),
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore (void) printf(_("%s (audio engine %d): %s\n"), ainfo.devnode, ainfo.dev,
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore (void) printf(_(" - Device not present - Skipping\n"));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore (void) printf(_(" - Skipping input only device\n"));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore (void) printf(_(" - Performing audio playback test... "));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore _("The device file was found in /dev but\n"
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore "the driver was not loaded.\n"));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore _("There are no sound devices available.\n"
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore "The most likely reason is that the device you have\n"
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore "is malfunctioning or it's not supported.\n"
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore "It's also possible that you are trying to use the wrong "
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore "device file.\n"));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore _("Your system cannot allocate memory for the device\n"
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore "buffers. Reboot your machine and try again.\n"));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore _("The device file is missing from /dev.\n"));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore _("The device is busy. There is some other application\n"
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore "using it.\n"));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * Simple command line switch handling.
a33ad26ef1f3b7a3fcf2fad564e6bd3798fdcbaeZhao Edgar Liu - Sun Microsystems while ((i = getopt(argc, argv, "l2457r:")) != EOF) {
a33ad26ef1f3b7a3fcf2fad564e6bd3798fdcbaeZhao Edgar Liu - Sun Microsystems tcfg->rate = atoi(optarg);
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore (void) printf(_("Usage: %s [options...] [device]\n"
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore " -2 Stereo test\n"
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore " -4 Quadraphonic 4.0 test\n"
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore " -5 Surround 5.1 test\n"
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore " -7 Surround 7.1 test\n"
a33ad26ef1f3b7a3fcf2fad564e6bd3798fdcbaeZhao Edgar Liu - Sun Microsystems " -r Sample Rate (48000|96000|192000)\n"
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * Open the mixer device used for calling SNDCTL_SYSINFO and
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * SNDCTL_AUDIOINFO.
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore if ((mixerfd = open("/dev/mixer", O_RDWR, 0)) == -1) {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore * Enumerate all devices and play the test sounds.
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore (void) printf(_("\n*** No audio hardware available ***\n"));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore for (t = 0; t < numdev; t++) {
68c47f65208790c466e5e484f2293d3baed71c6aGarrett D'Amore } else if (rv) {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore for (t = 0; t < maxdev; t++) {
68c47f65208790c466e5e484f2293d3baed71c6aGarrett D'Amore } else if (rv) {
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore (void) printf(_("\n*** All tests completed OK ***\n"));
88447a05f537aabe9a1bc3d5313f22581ec992a7Garrett D'Amore (void) printf(_("\n*** Errors were detected ***\n"));