public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Nathan Bryant <nbryant@allegientsystems.com>
To: Thomas Gschwind <tom@infosys.tuwien.ac.at>
Cc: linux-kernel@vger.kernel.org, Doug Ledford <dledford@redhat.com>
Subject: Re: i810_audio
Date: Mon, 07 Jan 2002 14:32:29 -0500	[thread overview]
Message-ID: <3C39F7CD.8010607@allegientsystems.com> (raw)
In-Reply-To: <20020105031329.B6158@infosys.tuwien.ac.at>

Thomas Gschwind wrote:

>
>+		/* TG: can this possibly be correct? 
>+		 * according to OSS doc, cinfo.blocks should return the
>+		 * number of fragment transitions since the previous call
>+		 * to this ioctl. Shouldn't it be better to set 
>+		 * cinfo.blocks to 0 if we do not support this?
>+		 * Why would we want to update the playback pointer? This
>+		 * is not mentioned in the OSS doc!
>+		 * val==number_free_bytes, hence we increase swptr by val.
>+		 * This means that we set the buffer to full.  It is 
>+		 * likely, however, that the hwptr has increased since the 
>+		 * call to this ioctl, hence part of the buffer is being
>+		 * played twice!
>+		 */
>
It is correct. MMAP mode doesn't work without it, and we only care about 
this IOCTL during mmap mode. I think you'll find that it should have 
been setting blocks correctly in mmap mode, the api sequence look like 
this (pseudocode:)

open("/dev/dsp");
mmap(...);
// apps that use mmap mode (only Quake* AFAIK, maybe some other games) 
will write zeroes to fill mmap buffer at this point

ioctl(SNDCTL_DSP_SETTRIGGER, &PCM_ENABLE_OUTPUT); // this updates LVI to 
point to entire 64K buffer and starts DAC. card begins playing silence. 
at this point, dmabuf->count = 64K and begins counting down to zero.

ioctl(SNDCTL_DSP_GETOPTR, &foo); // Quake will call this right before it 
needs to actually start playing sound (several seconds after the initial 
SETTRIGGER call, long enough for the 64K of silence to be played and for 
the DAC to stop with DCH interrupt.) Since the game *needs* to have the 
current output pointer before it can start writing data to be played, we 
take this as a signal that it *intends to do so*, and update the LVI to 
play the next 64K of ring-buffer. Note that the mmap-api spec in OSS 
docs says that the hardware should be set to loop around the ring buffer 
*ad infinitum* in mmap mode, with no further input, so setting it to 
simply play the first 64K--intead of infinity--can't hurt. (We can't 
tell the hardware to loop around the buffer forever since there is no 
command to do so. The only other way to handle that would be to make the 
completition interrupt handlers take care of it, which is more error 
prone in my opinion, interrupts could be missed plus it pays to keep the 
interrupt handlers as simple as possible.) So we rely on the app calling 
GETOPTR often enough to keep the LVI chasing around the buffer - which 
is *has* to do anyway if it wants to play meaningful data. If it stops 
calling GETOPTR, that means it has frozen or slowed down to much to 
handle audio anyway. Neat solution, no? ;-)

Note that, after every call to GETOPTR, dmabuf->count gets set to 64K, 
and the returned value for blocks is based on dmabuf->count, so the 
semantics should actually be correct; we do:

cinfo.blocks = (dmabuf->dmasize - dmabuf->count)/dmabuf->userfragsize;

initially after GETOPTR, count = 64K, so blocks = (64K - 64K) / 
fragsize; ( = 0, correct according to docs)
count winds down to zero, updated by i810_update_ptr: assume next call 
to GETOPTR occurs exactly 64K later:

blocks = (64K - 0) / userfragsize = the number of blocks played since 
last call

so, please put it back the way it was ;)

>
>+#ifndef USE_ORIGINAL_SNDCTL_DSP_GETxPTR_CODE
>+		cinfo.blocks = 0;
>+#else
>+		cinfo.blocks = val/dmabuf->userfragsize;
>+		if (dmabuf->mapped && (dmabuf->trigger & PCM_ENABLE_OUTPUT)) {
>+			dmabuf->count += val;
>+			dmabuf->swptr = (dmabuf->swptr + val) % dmabuf->dmasize;
> 			__i810_update_lvi(state, 0);
> 		}
>+#endif
>



  reply	other threads:[~2002-01-07 19:34 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <3C338217.1080207@allegientsystems.com>
2002-01-05  2:13 ` i810_audio Thomas Gschwind
2002-01-07 19:32   ` Nathan Bryant [this message]
2002-01-07 23:12   ` i810_audio Nathan Bryant
2002-01-07 23:32     ` i810_audio Doug Ledford
2002-01-08  7:59       ` i810_audio Doug Ledford
2002-01-08  8:11         ` i810_audio Doug Ledford
2002-01-08  9:02           ` i810_audio Doug Ledford
2002-01-08 15:11             ` i810_audio Mario Mikocevic
2002-01-08 19:21               ` i810_audio Doug Ledford
2002-01-08 19:22               ` i810_audio Nathan Bryant
2002-01-09 15:47             ` i810_audio Mario Mikocevic
2002-01-08 20:01         ` i810_audio Nathan Bryant
2002-01-08 20:15           ` i810_audio Doug Ledford
2002-01-08 20:23           ` i810_audio Nathan Bryant
2002-01-08  8:22   ` i810_audio Martin Dalecki
2002-01-08 16:31 i810_audio willy tarreau
2002-01-08 19:58 ` i810_audio Doug Ledford
2002-01-08 23:03   ` i810_audio willy tarreau
2002-01-09  6:28   ` i810_audio Nick Papadonis
2002-01-09  7:16   ` i810_audio willy tarreau
  -- strict thread matches above, loose matches on Subject: below --
2002-01-09  7:09 i810_audio reddog83
     [not found] <3C3BFF98.9080309@redhat.com>
2002-01-09  9:08 ` i810_audio willy tarreau
2002-01-10  6:42 i810_audio reddog83
2002-01-10 18:59 i810_audio reddog83
2002-01-10 19:21 i810_audio reddog83
2002-01-11  0:33 ` i810_audio Doug Ledford
2002-11-10 23:37 i810 audio Alan Cox
2002-11-12 23:06 ` Brian C. Huffman
2002-11-12 23:38   ` Alan Cox
2002-11-12 23:43     ` Doug Ledford
2002-11-13  0:04       ` Peter Kundrat
2002-11-13  0:43         ` Alan Cox
2002-11-13 12:08           ` Brian C. Huffman
2002-11-12 23:52     ` Peter Kundrat
2002-11-11 21:16 i810_audio Rus Foster

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=3C39F7CD.8010607@allegientsystems.com \
    --to=nbryant@allegientsystems.com \
    --cc=dledford@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tom@infosys.tuwien.ac.at \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox