From owner-FreeBSD-users-jp@jp.freebsd.org  Tue Nov  3 08:07:15 1998
Received: (from daemon@localhost)
	by jaz.jp.freebsd.org (8.9.1+3.1W/8.7.3) id IAA03544;
	Tue, 3 Nov 1998 08:07:15 +0900 (JST)
	(envelope-from owner-FreeBSD-users-jp@jp.FreeBSD.org)
Received: from funasoul.aa.cs.keio.ac.jp (funasoul.am.ics.keio.ac.jp [131.113.69.51])
	by jaz.jp.freebsd.org (8.9.1+3.1W/8.7.3) with ESMTP id IAA03539
	for <FreeBSD-users-jp@jp.freebsd.org>; Tue, 3 Nov 1998 08:07:14 +0900 (JST)
	(envelope-from funa@aa.cs.keio.ac.jp)
Received: from localhost (localhost [127.0.0.1])
	by funasoul.aa.cs.keio.ac.jp (8.8.8/8.8.8) with ESMTP id IAA01561
	for <FreeBSD-users-jp@jp.freebsd.org>; Tue, 3 Nov 1998 08:07:13 +0900 (JST)
	(envelope-from funa@aa.cs.keio.ac.jp)
To: FreeBSD-users-jp@jp.freebsd.org
X-Mailer: Mew version 1.93 on Emacs 19.34 / Mule 2.3 (SUETSUMUHANA)
Mime-Version: 1.0
Content-Type: Multipart/Mixed;
	boundary="--Next_Part(Tue_Nov__3_08:01:53_1998_809)--"
Content-Transfer-Encoding: 7bit
Message-Id: <19981103080712Y.funa@aa.cs.keio.ac.jp>
Date: Tue, 03 Nov 1998 08:07:12 +0900
From: Akira Funahashi <funa@aa.cs.keio.ac.jp>
X-Dispatcher: imput version 980905(IM100)
Lines: 133
Reply-To: FreeBSD-users-jp@jp.freebsd.org
Precedence: list
X-Distribute: distribute version 2.1 (Alpha) patchlevel 24e+980914
X-Sequence: FreeBSD-users-jp 34713
Subject: [FreeBSD-users-jp 34713] read() system call for Voxware & Luigi's
Errors-To: owner-FreeBSD-users-jp@jp.freebsd.org
Sender: owner-FreeBSD-users-jp@jp.freebsd.org

----Next_Part(Tue_Nov__3_08:01:53_1998_809)--
Content-Type: Text/Plain; charset=iso-2022-jp
Content-Transfer-Encoding: 7bit

$B=.66(B@$B7DXf$G$9(B.

$B8=:_(B,Dynabook SS3010 + FreeBSD 2.2.7-RELEASE + PAO-981019 $B$G(B
/dev/dsp $B$r;H$C$?%W%m%0%i%`$r=q$$$F$$$k(B($BJY6/Cf(B)$B$N$G$9$,(B,

 o Voxware $B$r;H$C$?>l9g(B  $B$H(B
 o Luigi's Sound Driver$B$r;H$C$?>l9g(B

$B$G$O(B,

 read("dev/dsp", buf, sizeof(buf));

$B$N;EMM$,0[$J$k$h$&$K;W$($^$9(B.$B%W%m%0%i%`$OC1=c$J$b$N$G(B,
$B%^%$%/$+$i$NF~NO(B(3$BIC4V(B)$B$rO?2;$7(B,$B$=$N$^$^=PNO$9$k$b$N$G$9(B.
$B%W%m%0%i%`$O$3$N%a!<%k$KE:IU$7$^$9(B.

$B<B:]$N<j=g$H$7$F$O(B

 o /dev/dsp $B$r(B open() (read & write$B$G(B open)
 o ioctl() $B$G(B 8 or 16bit, stereo or mono, Sampling rate $B$r;XDj(B
 o /dev/dsp $B$r(B read() ($B%^%$%/$+$iF~NO(B)
 o /dev/dsp $B$K(B write()

$B$H$$$&$b$N$G$9(B.
$B!V(BLinux $B%^%k%A%a%G%#%"%,%$%I!W$H$$$&K\$K:\$C$F$$$k%W%m%0%i%`$r(B
$B$[$\$=$N$^$^;H$C$F$$$k(B(Voxware$B$rBP>]$H$7$F$$$k$?$a(B)$B$N$G$9$,(B,
read() $B$G0lEY$KFI$_9~$a$k%P%$%H?t$,0[$J$j$^$9(B.

Voxware $B$G$O(B
   read("/dev/dsp", wavebuf, sizeof(wavebuf));

$B$H<B9T$9$k$H(B,$B0lEY$K(B sizeof(wavebuf) $B$NBg$-$5$N%G!<%?$r(B
$B<hF@$9$k$3$H$,$G$-(B,$B$3$N%W%m%0%i%`$OF0:n$9$k$N$G$9$,(B,

Luigi's $B$G$O(B
   read("/dev/dsp", wavebuf, sizeof(wavebuf));

$B$r<B9T$9$k$H(B 2000byte(8KHz, 8bit $B%G!<%?$N>l9g(B)$B$7$+0lEY$KFI$_9~$a$^$;$s(B.
$B$=$N$?$a$3$N%a!<%k$KE:IU$7$?%W%m%0%i%`$r<B9T$7$F$b(B
$B:G=i$N(B 0.25$BIC$7$+%5%s%W%j%s%0$5$l$^$;$s(B.

$B%W%m%0%i%`$r=q$-49$($l$P$$$$(B(while() $B$G%P%C%U%!%5%$%:$K$J$k$^$G(B
read$B$9$l$P$$$$(B)$B$3$H$O$o$+$C$?$N$G$9$,(B,
read() $B$N;EMM$,0[$J$k$H$$$&;v$O(B
$B:#$^$G(B Voxware$BMQ$K=q$+$l$?%3!<%I$O(B Luigi's$B$G$OF0$+$J$$$3$H$,(B
$B$"$j$=$&$J5$$,$7$^$9(B.

$B;d$NG'<1$O4V0c$C$F$$$k$N$G$7$g$&$+(B.
$B65$($FD:$1$l$P9,$$$G$9(B.

$B$J$*(B, Dynabook SS3010$B$G$O(B

 o Voxware -> mss0 (suspend -> resume $B;~$KLdBj$"$j(B)
 o Luigi's -> pcm0

$B$H$7$FG'<1$5$l$F$$$^$9(B.
-- 
Akira Funahashi/$B=.66(B $B7<(B
[funa@aa.cs.keio.ac.jp]

----Next_Part(Tue_Nov__3_08:01:53_1998_809)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename=test.c

/*
	Sound Record Test Program
	Recorded sound is played from /dev/dsp.
*/
#include<stdio.h>
#include<sys/types.h>
#include<sys/ioctl.h>
#include<fcntl.h>
#include<unistd.h>
#include<machine/soundcard.h>

#define LENGTH 3	/* Sampling time (sec) */
#define RATE 8000	/* Sampling rate */
#define SIZE 8		/* 8 or 16 bit */
#define CHANNELS 1	/* 1 = mono, 2 = stereo */

unsigned char wavbuf[LENGTH*RATE*SIZE*CHANNELS/8];

int main(int argc, char *argv[])
{
	int wavdev;
	int arg;
	int status;

	wavdev = open("/dev/dsp", O_RDWR);
	if (wavdev < 0) {
		perror("open /dev/dsp failed");
		exit(1);
	}

	arg = SIZE;
	status = ioctl(wavdev, SOUND_PCM_WRITE_BITS, &arg);
	if(status == -1)
		perror("SOUND_PCM_WRITE_BITS ioctl failed");
	if(arg != SIZE)
		perror("unable to set sample size");
	
	arg = CHANNELS;
	status = ioctl(wavdev, SOUND_PCM_WRITE_CHANNELS, &arg);
	if (status == -1)
		perror("SOUND_PCM_WRITE_CHANNELS ioctl failed");
	if (arg != CHANNELS)
		perror("unable to set number of channels");

	arg = RATE;
	status = ioctl(wavdev, SOUND_PCM_WRITE_RATE, &arg);
	if (status == -1)
		perror("SOUND_PCM_WRITE_RATE ioctl failed");

	printf("Say something:\n");
	status = read(wavdev, wavbuf, sizeof(wavbuf));
	if (status != sizeof(wavbuf)) {
		perror("read wrong number of bytes");
	}
	printf("You said:\n");
	status = write(wavdev, wavbuf, sizeof(wavbuf));
	if (status != sizeof(wavbuf))
		perror("wrote wrong number of bytes");

	close(wavdev);
	return 0;
}

----Next_Part(Tue_Nov__3_08:01:53_1998_809)----
