[SunHELP] Audio applications for Sun/Solaris?

Francois Dion fdion at atriumwindows.com
Thu Oct 9 20:34:48 CDT 2003


Dale Ghent <daleg at elemental.org> said:
> /dev/audio gets you only 8bit 11khz 5-law format audio. This is
> telephone quality.

Actually, this is a common misconception about the /dev/audio device.

/dev/audioctl is configured by default for 8bit, 11KHz ULAW (mu law) on your
machine. However, /dev/audio supports all the way to 48KHz if your hardware
supports it. On old Sparcs, .au was all that you could play, but the Ultra 30 is
a modern machine that can play 44KHz, 16 bit linear without problems.

As some of you know from the rescue mailing list my Ultra is faced with a kernel
panic and dead video card so I cant test anything, so dont jump on me if this
dont compile (this is from memory, at least 6 years ago), but let me give an
example of C code that reads the settings on the /dev/audioctl. Without too much
work one can do something that assigns the values instead of reading them. I'm
just illustrating the flexibility of this device.

So here we go:
--cut here beginning of testaudio.c--
#include <fcntl.h>
#include <stdio.h>
#include <sys/audioio.h>

int audioctl;
int main()
{
audio_info_t info;

	if((audioctl = open("/dev/audioctl", O_RDWR)) < 0)
	{
		printf("Cant use /dev/audioctl...\n");
		return 0;
	}
	if(ioctl(audioctl, AUDIO_GETINFO, &info) < 0)
	{
		printf("Cannot get device info.\n");
		close(audioctl);
 		return 0;
	}
	/* 	check the various parameters for audio playback.
		Audio recording also has similar parameters. One can
	         also go the other way and set these parameters. */

	printf("Sampling rate (Hz): %d\n,info.play.sample_rate);
	printf("Number of channels: %d\n,info.play.channels);
	printf("Bits per sample: %d\n", info.play.precision);
         return 0;
}
--cut here end of testaudio.c--

save this to testaudio.c, then run:
gcc -o testaudio testaudio.c
(replace gcc by cc if that is your compiler of choice) and finally execute
./testaudio and it'll tell you what are the default values for audio playback.

Other fun stuff one can check:
info.play.port, which can be a combination of AUDIO_SPEAKER, AUDIO_HEADPHONE and
AUDIO_LINE_OUT)

info.play.encoding, would be typically AUDIO_ENCODING_LINEAR for 16 bit audio,
while for .au files, it would need to be AUDIO_ENCODING_ULAW

info.play.gain, info.play.balance, etc.

Francois



More information about the SunHELP mailing list