Linux Sound subsystem development
 help / color / mirror / Atom feed
* successive mmap()s will not work to record sound?
@ 1999-02-11  5:18 Britton
  1999-02-11 16:39 ` Zygo Blaxell
  1999-02-11 18:37 ` Zygo Blaxell
  0 siblings, 2 replies; 3+ messages in thread
From: Britton @ 1999-02-11  5:18 UTC (permalink / raw)
  To: linux-sound


I have been trying to write a brec-like program that will record long
tracks of raw sound using many successive mmap()s of the same file, but it
isn't working.  I get stuff like this:

incorrect number of bytes written: Interrupted system call
Sound: Recording overrun 
<DMA somethingorother times> out - IRQ/DRQ config error?

ad nauseum

Does this mean that my code is not keeping up with the sound card?

Is this approach not feasible?  Here are the salient features of the
program: 

/* appropriate headers */

int target[10];               /* current file descriptors to write to */
char *region[10];             /* pointers to the current mapped file */
int nblocks;                  /* the total number of 65536 byte "blocks" */
int cblock;                   /* the current block less than nblocks */
int cmmap;                    /* the current mmap in 10 block loop */
pid_t pid;                    /* the pid of the msyncing munmaping child */

/* ioctrl dsp device with RATE BITS TIME and STEREO */

  /* figure out how many 65536 byte mmaps we will need */
  nblocks = (LENGTH*RATE*SIZE*CHANNELS)/(8*65536) ;

  for (cblock = 0; cblock < nblocks; cblock++) {
    cmmap = cblock % 10;
    printf("cmmap: %d       looping: %d\n", cmmap, cblock);
    /* open, make zero hole, and mmap the target region */
    status = target[cmmap] = open("targetfile", O_CREAT | O_RDWR,
             0644);
    if (status < 0) {
      perror("error opening target file");
      exit(1);
    }
    if (lseek(target[cmmap], 65535, SEEK_END) = (off_t) (-1)) {
      perror("lseek() error");
      exit(1);
    }
    if (write(target[cmmap], "", 1) < 0) {
      perror("write() error");
      exit(1);
    }

    region[cmmap] = mmap(NULL, 65536, PROT_WRITE, MAP_SHARED, target[cmmap],
                             65536*cblock);
    if (region[cmmap] = (caddr_t) (-1)) {
      perror("mmap error");
      exit(1);
    }

    /* record sound into mmaped region */
    status = read(dsp, (region[cmmap]), 65536);
    if (status != 65536) {
      perror("incorrect number of bytes written");
      exit(1);
    }

    /* fork a low priority child for msync with disk */
    if ((pid = fork()) < 0)
      perror("fork error");
    else if (pid = 0) {        /* child */

      /* make ourselves very nice */
      if (nice(19) = -1)
        perror("nice error");

      /* make sure the mmaped stuff gets written to disk "soon" */
      msync(region[cmmap], 65536, MS_ASYNC);

      /* unmap the current region, so it can be reused next time around */
      if (munmap(region[cmmap], 65536) = -1) {
        perror("munmap error");
        exit(1);
      }

      /* close the file descriptor to the cmmap */
      if (close(target[cmmap]) = -1) {
        perror("close error");
        exit(1);
      }
    }
  }
}


Any help or advice greatly appreciated.

Britton Kerin

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: successive mmap()s will not work to record sound?
  1999-02-11  5:18 successive mmap()s will not work to record sound? Britton
@ 1999-02-11 16:39 ` Zygo Blaxell
  1999-02-11 18:37 ` Zygo Blaxell
  1 sibling, 0 replies; 3+ messages in thread
From: Zygo Blaxell @ 1999-02-11 16:39 UTC (permalink / raw)
  To: linux-sound

In article <Pine.OSF.3.96.990210195646.13922A-100000@aurora.alaska.edu>,
Britton  <fsblk@aurora.alaska.edu> wrote:
>I have been trying to write a brec-like program that will record long
>tracks of raw sound using many successive mmap()s of the same file, but it
>isn't working.  I get stuff like this:
>
>incorrect number of bytes written: Interrupted system call
>Sound: Recording overrun 
><DMA somethingorother times> out - IRQ/DRQ config error?
>
>ad nauseum
>
>Does this mean that my code is not keeping up with the sound card?
>
>Is this approach not feasible?  Here are the salient features of the
>program: 

No, it's not feasible.

The filesystem will block at inconvenient times sometimes for up to fives
seconds (this on 33MB/s UDMA AT drives).  This only gets worse if you are
doing mmap().

What you want to do is read into shared memory with one process or
thread and write to disk with another process or thread.  Depending on
your performance requirements even just two processes with select() is
enough.

-- 
Zygo Blaxell, Linux Engineer, Corel Corporation, zygob@corel.ca (work),
zblaxell@furryterror.org (play).  It's my opinion, I tell you! Mine! All MINE!
Size of 'diff -Nurw [...] winehq corel' as of Thu Feb 11 11:14:01 EST 1999
Lines/files:  In 489 / 13, Out 6321 / 74, Both 6807 / 86

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: successive mmap()s will not work to record sound?
  1999-02-11  5:18 successive mmap()s will not work to record sound? Britton
  1999-02-11 16:39 ` Zygo Blaxell
@ 1999-02-11 18:37 ` Zygo Blaxell
  1 sibling, 0 replies; 3+ messages in thread
From: Zygo Blaxell @ 1999-02-11 18:37 UTC (permalink / raw)
  To: linux-sound

In article <79v13d$1vp$1@naga.corel.eng>,
Zygo Blaxell <u81ib6r2@umail.furryterror.org> wrote:
>In article <Pine.OSF.3.96.990210195646.13922A-100000@aurora.alaska.edu>,
>Britton  <fsblk@aurora.alaska.edu> wrote:
>>I have been trying to write a brec-like program that will record long
>>tracks of raw sound using many successive mmap()s of the same file, but it
>>isn't working.  I get stuff like this:

Come to think of it, if you _really_ want to do this, why don't you mmap()
the entire file and just read() into that?

Also, make sure that the file is already large enough to hold the data you
are writing; otherwise you'll get a segfault.

-- 
Zygo Blaxell, Linux Engineer, Corel Corporation, zygob@corel.ca (work),
zblaxell@furryterror.org (play).  It's my opinion, I tell you! Mine! All MINE!
Size of 'diff -Nurw [...] winehq corel' as of Thu Feb 11 13:14:02 EST 1999
Lines/files:  In 489 / 13, Out 6383 / 76, Both 6869 / 88

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1999-02-11 18:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1999-02-11  5:18 successive mmap()s will not work to record sound? Britton
1999-02-11 16:39 ` Zygo Blaxell
1999-02-11 18:37 ` Zygo Blaxell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox