Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 6 Dec 1996 21:46:44 -0600
From:      dnelson@emsphone.com (Dan Nelson)
To:        S.Brandenburg@tu-bs.de
Cc:        freebsd-questions@freebsd.org
Subject:   Re: O si o [sound question]
Message-ID:  <Mutt.19961206214644.dan@dan.emsphone.com>
In-Reply-To: <32A8CD96.41C67EA6@algieba.ts.rz.tu-bs.de>; from "Sven Brandenburg" on Dec 7, 1996 02:51:18 %2B0100
References:  <199612062248.RAA08354@dyson.iquest.net> <32A8CD96.41C67EA6@algieba.ts.rz.tu-bs.de>

next in thread | previous in thread | raw e-mail | index | archive | help
In the last eposode (Dec 7), Sven Brandenburg said:
> What do you use to play/record ? 
> (which program and how configured, tell me everything :) 
> Should a "cat iama16bitsample.au > /dev/audio" give you 16 bit output? 
> (A BIG candidate for the lame-question-of-the-year, sorry!)

Here are the ones I use.  'listen' is mono-only, but that's only
another ioctl() away. 'play' will also play to the speaker with the -s
switch.

	-Dan Nelson
	dnelson@emsphone.com

--- listen.c ---
#include <machine/soundcard.h>
#include <stdlib.h>
#include <fcntl.h>
#include <stdio.h>

main(int argc, char *argv[])
{
	int fd = open("/dev/dsp", O_RDONLY);
	int rate = 8012;
	int bits = 8;
	int c;
	int len;
	char buf[1024];

	while ((c = getopt(argc, argv, "hr:b:")) != EOF)
	{
		switch (c)
		{
		    case 'r':
			rate = atoi(optarg);
			break;
		    case 'b':
			bits = atoi(optarg);
			break;
			case '?':
			case 'h':
			printf ("listen -r rate -b bits\n");
			exit(1);
			break;
		}
	}

	ioctl(fd, SNDCTL_DSP_SETFMT, &bits);
	ioctl(fd, SOUND_PCM_WRITE_RATE, &rate);

	while ((len = read(fd, buf, sizeof(buf))) > 0)
		write(fileno(stdout), buf, len);
}
--- END ---

--- play.c ---
#include <machine/soundcard.h>
#include <machine/pcaudioio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <stdio.h>

main(int argc, char *argv[])
{
	int fd;
	int rate = 8012;
	int bits = 8;
	int speaker = 0;
	int channels = 1;
	int c;
	int len;
	char buf[1024];

	while ((c = getopt(argc, argv, "r:b:c:s")) != EOF)
	{
		switch (c)
		{
			case 's':
			speaker = 1;
			break;
		    case 'r':
			rate = atoi(optarg);
			break;
		    case 'c':
			channels = atoi(optarg);
			break;
		    case 'b':
			bits = atoi(optarg);
			break;
			case '?':
			case 'h':
			printf ("play [-s] [-c channels] [-r rate] [-b bits]\n");
			exit(1);
			break;
		}
	}

	if (speaker)
	{
		audio_info_t ait;
		ait.play.sample_rate = rate;
		ait.play.encoding = AUDIO_ENCODING_RAW;
		ait.play.gain = 150;
		ait.play.pause = -1;
		fd = open("/dev/pcaudio", O_WRONLY);
		ioctl(fd, AUDIO_SETINFO, &ait);	
	} else
	{
		fd = open("/dev/dsp", O_WRONLY);
		ioctl(fd, SNDCTL_DSP_SETFMT, &bits);
		ioctl(fd, SOUND_PCM_WRITE_RATE, &rate);
		ioctl(fd, SOUND_PCM_WRITE_CHANNELS, &channels);
	}

	while ((len = read(fileno(stdin), buf, sizeof(buf))) > 0)
		write(fd, buf, len);
}
---END---



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Mutt.19961206214644.dan>