Subject: (no subject)
To: None <tech-kern@netbsd.org, port-i386@netbsd.org>
From: Sachin Goel <sgoel@liberate.com>
List: tech-kern
Date: 09/23/1999 18:41:58
Guys,

I am seeing problem with audio recording in non blocking mode with
netbsd1.3I on the x86 platform [I tried with sb and mss dvice and it
occurs on both]. If i open the device in read mode and do a select  on
the fd, the select times out. See the small program and its output at
the end of the e-mail

If there is fix / workaround, please let me know.

Thanks in advance,
Sachin (sgoel@liberate.com)

-------------------------------------------------------------------------------------

#include <fcntl.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/uio.h>
#include <unistd.h>
#include <sys/audioio.h>
#include <sys/ioctl.h>
#include <stdio.h>
#include <string.h>


int fd;

int open_recorder( void )
{
  audio_info_t info;

  char buffer[512];

    AUDIO_INITINFO( &info );

    info.blocksize = 128;
    info.mode = AUMODE_PLAY;
    info.play.encoding = AUDIO_ENCODING_ULAW;
    info.play.sample_rate = 8000;
    info.play.precision = 8;
    info.play.channels = 1;
    info.hiwat = 34;
    info.lowat = 5;


    if( ( fd = open( "/dev/audio", O_RDONLY | O_NONBLOCK) ) == -1 )
    {
      perror( "open device" );
      return( -1 );
    }

    if (ioctl(fd, AUDIO_SETINFO, &info) == -1)
    {
         perror("set info");
         return(-1);
     }

    return 0;
}

main( int argc, char** argv )
{
int outfd, nbytes;
fd_set readfds;
struct timeval to;
int err, bufout;
char buf[512];

  if( open_recorder() == -1 )
    exit(0);

  to.tv_sec = 10;
  to.tv_usec = 0;
  FD_ZERO( &readfds );
  FD_SET( fd, &readfds );


  if( ( outfd = open( "/nchome/sac.au", O_WRONLY | O_CREAT)) < 0 ) {
    perror( "test.out");
    exit(0);
  }
  while( (err = select( fd+1, &readfds, NULL, NULL, &to ) ) > 0 )
  {
    nbytes = read(fd, buf, 512);
    bufout = write( outfd, buf, nbytes);
    printf("no. of bytes written = %d\n", bufout);
  }

  close( outfd );
  close( fd );
    if( err < 0 ) perror( "select");
    if( err == 0 ) printf( "timeout\n");
    else printf( "number of fds: %d\n",err);

}



OUPPUT is "timeout"

-------------------------------------------------------------------------------------