All of lore.kernel.org
 help / color / mirror / Atom feed
From: Carlo Wood <carlo@alinoe.com>
To: alsa-devel@lists.sourceforge.net
Subject: Bug in OSS simulation (ALSA 0.9.4)
Date: Thu, 10 Jul 2003 03:33:26 +0200	[thread overview]
Message-ID: <20030710013326.GA12086@alinoe.com> (raw)

I pinpointed the problem and wrote a small program
to illustrate the problem.

When compiling the program given below with:

  gcc -DUSE_DSP_SETFMT=0 troep.c

it runs fine.

But, when compiling it with:

  gcc -DUSE_DSP_SETFMT=1 troep.c

It stops rather quickly with reading data.

Example output of the latter:

~>a.out
Fragment size: 1024
Number of fragments: 32767
Number of channels: 1
Sample rate: 22050
Read 1024 bytes.
Number of full fragments that can be read or written without blocking: 0
Total number of fragments allocated for buffering: 2
Size of a fragment in bytes: 1024
Number of bytes that can be read or written immediately without blocking: 0
#fragments, #bytes: 0, 0
#fragments, #bytes: 1, 1632
Read 1024 bytes.
#fragments, #bytes: 2, 2048
Read 1024 bytes.
#fragments, #bytes: 1, 1024
Read 1024 bytes.
#fragments, #bytes: 0, 0
#fragments, #bytes: 0, 0
#fragments, #bytes: 0, 0
...etc

-- 
Carlo Wood <carlo@alinoe.com>


The program:


#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <linux/soundcard.h>
#include <time.h>

int main(void)
{
  int res;
  char buf[1024];

  int fd = open("/dev/dsp", O_RDONLY);
  if (fd == -1)
  {
    perror("open");
    exit(1);
  }

  res = 0x7fff000a;
  if (ioctl(fd, SNDCTL_DSP_SETFRAGMENT, &res) == -1)
  {
    perror("ioctl");
    exit(1);
  }
  printf("Fragment size: %d\n", 1 << (res & 0xffff));
  printf("Number of fragments: %d\n", res >> 16);

#if USE_DSP_SETFMT
  res = AFMT_S16_LE;
  if (ioctl(fd, SNDCTL_DSP_SETFMT, &res) == -1)
  {
    perror("ioctl");
    exit(1);
  }
#endif

  res = 0;	// Not stereo (1 channel).
  if (ioctl(fd, SNDCTL_DSP_STEREO, &res) == -1)
  {
    perror("ioctl");
    exit(1);
  }
  printf("Number of channels: %d\n", res ? 2 : 1);

  res = 22050;
  if (ioctl(fd, SOUND_PCM_READ_RATE, 0xbfffdcfc) == -1)
  {
    perror("ioctl");
    exit(1);
  }
  printf("Sample rate: %d\n", res);

  ssize_t rlen = read(fd, buf, sizeof(buf));
  if (rlen <= 0)
  {
    perror("read");
    exit(1);
  }
  printf("Read %d bytes.\n", rlen);

  audio_buf_info info;

  if (ioctl(fd, SNDCTL_DSP_GETISPACE, &info) == -1)
  {
    perror("read");
    exit(1);
  }
  printf("Number of full fragments that can be read or written without blocking: %d\n", info.fragments);
  printf("Total number of fragments allocated for buffering: %d\n", info.fragstotal);
  printf("Size of a fragment in bytes: %d\n", info.fragsize);
  printf("Number of bytes that can be read or written immediately without blocking: %d\n", info.bytes);

  int i;
  for (i = 0; i < 100; ++i)
  {
    if (ioctl(fd, SNDCTL_DSP_GETISPACE, &info) == -1)
    {
      perror("read");
      exit(1);
    }
    printf("#fragments, #bytes: %d, %d\n", info.fragments, info.bytes);
    if (info.fragments > 0)
    {
      ssize_t rlen = read(fd, buf, sizeof(buf));
      if (rlen <= 0)
      {
	perror("read");
	exit(1);
      }
      printf("Read %d bytes.\n", rlen);
    }
    static struct timespec naptime = { 0, 100000000 };
    nanosleep(&naptime, 0);
  }

  close(fd);
  return 0;
}


-------------------------------------------------------
This SF.Net email sponsored by: Parasoft
Error proof Web apps, automate testing & more.
Download & eval WebKing and get a free book.
www.parasoft.com/bulletproofapps

             reply	other threads:[~2003-07-10  1:33 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-07-10  1:33 Carlo Wood [this message]
2003-07-10  1:51 ` Bug in OSS simulation (ALSA 0.9.4) Carlo Wood
2003-07-10 22:54   ` Kai Vehmanen
2003-07-10 23:43     ` Carlo Wood
2003-07-11  0:05       ` Kai Vehmanen
2003-07-11  1:41         ` Carlo Wood
2003-07-10 13:15 ` James Courtier-Dutton
2003-07-10 22:36   ` Carlo Wood
2003-07-10 22:49 ` Kai Vehmanen
2003-07-10 23:07   ` James Courtier-Dutton
2003-07-11  0:00   ` Carlo Wood
2003-07-11  0:21     ` Kai Vehmanen
2003-07-10 23:09 ` Kai Vehmanen
2003-07-11  0:28   ` Carlo Wood
2003-07-11  0:44     ` Kai Vehmanen
2003-07-11  2:03       ` Carlo Wood

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030710013326.GA12086@alinoe.com \
    --to=carlo@alinoe.com \
    --cc=alsa-devel@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.