Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: James Courtier-Dutton <James@superbug.demon.co.uk>
To: Jaroslav Kysela <perex@suse.cz>
Cc: Glenn Maynard <g_sf@zewt.org>,
	ALSA development <alsa-devel@alsa-project.org>
Subject: Re: [PATCH] Fixes: Re: intel8x0 has stopped working.
Date: Thu, 05 Feb 2004 20:44:33 +0000	[thread overview]
Message-ID: <4022AB31.6070807@superbug.demon.co.uk> (raw)
In-Reply-To: <Pine.LNX.4.58.0402052030370.1864@pnote.perex-int.cz>

Jaroslav Kysela wrote:
> On Thu, 5 Feb 2004, Glenn Maynard wrote:
> 
> 
>>On Thu, Feb 05, 2004 at 12:01:28PM +0100, Jaroslav Kysela wrote:
>>
>>>>My point is, I don't think setting start_threshold to buffer_size is 
>>>>even "wrong" at all. Some people might want the buffer to be full before 
>>>>it starts, and my patch allows for that.
>>>
>>>It's not wrong semantics. I see - it's logical, but I don't want to follow
>>>some rule as some API designers does - control magically some things. I
>>>want that developer which uses our API knows what the library / driver
>>>exactly does.
>>>
>>>We have clear conditions when the stream is started. That's it.
>>
>>If this isn't guaranteed to work, I'd suggest making it never work.
> 
> 
> It's guaranteed to work.
> 
> 
>>Otherwise, programs will work on some hardware and not others, which is
>>a case that should be minimized as much as possible; it's these kinds
>>of subtle differences that make it very hard to write reliable (sound,
>>video, etc) code.  I've had to play games with setting hardware settings:
>>always set the sample rate even if I don't care, use a 32k buffer size
>>and not a 4k or 8k one--in order to make it work on as many systems as
>>possible without failing mysteriously or triggering alsa-lib asserts.
> 
> 
> Send us bug-reports if you have problems. We have not a magic ball.
> 
> 
>>(I don't quite understand why start_threashold == buffer_size doessn't
>>mean "start when the buffer is full", though.)
> 
> 
> Because we have the avail_min threshold which says that we don't want to
> write new data when buffer can accept less samples than this threshold. So
> if start_threshold is greather than '(buffer_size / avail_min) *
> avail_min' expression, then stream won't be automatically started, because
> we cannot fill data in read/write operations to satisfy the requirement
> that start_threshold == buffer_size.
> 
> Isn't this clear and right?

What you say is clear, but I don't think it is right.
If I understand it, you don't want to write samples into the buffer if 
less that X samples are free in the buffer.
We then have 2 possible situations: -
1) We wish to write more frames than X
In this case, we know that we wish to write enough frames to fill the 
buffer, so theoretically, the buffer is full, and thus start_threshold 
has been reached even before the actual alsa-lib internal write 
operation has happened. So, we could call snd_pcm_start() at this point.

2) We wish to write less frames than X
In this case, we know that if the write theoretically succeeded, we 
would not have a full buffer, so should not call snd_pcm_start(). But we 
are in catch22 here, because we cannot write any frames until we have X 
free frames in the buffer, but in SND_STATE_PREPARED (i.e. not RUNNING) 
the amount of free frames in the buffer will never change.

Conclusion: -
Due to the problem (2), we have to have start_threshold <= (buffer_size 
- avail_min) if we wish snd_pcm_start() to be automatically called in 
both case (1) and case(2).
If start_threshold > buffer_size, snd_pcm_start will never be called, 
and that is correct because some applications might want to manually 
control snd_pcm_start(). So, we will need range checks in the 
snd_pcm_sw_params_set_start_threshold() call so that the application 
writer is informed at a early stage about wrong settings, rather than 
finding out that snd_pcm_writei() fails on some sound cards but not others!
Summary: -
By me trying to argue that you are wrong, I have proved you right!

> 
> Of course, the "endless loop" is questionable in this case when the stream 
> is not running and we should probably return from the write function.
> 
> 						Jaroslav
> 

Cheers
James


-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn

  parent reply	other threads:[~2004-02-05 20:37 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-02-02 17:41 intel8x0 has stopped working James Courtier-Dutton
2004-02-02 17:59 ` Takashi Iwai
2004-02-02 19:34   ` Prakash K. Cheemplavam
2004-02-02 19:42   ` James Courtier-Dutton
2004-02-02 23:12     ` [PATCH] Fixes: " James Courtier-Dutton
2004-02-03 16:22       ` Jaroslav Kysela
2004-02-03 22:21         ` James Courtier-Dutton
2004-02-05 11:01           ` Jaroslav Kysela
2004-02-05 19:15             ` Glenn Maynard
2004-02-05 19:25               ` Takashi Iwai
2004-02-05 19:38               ` Jaroslav Kysela
2004-02-05 19:58                 ` Glenn Maynard
2004-02-05 20:44                 ` James Courtier-Dutton [this message]
2004-02-04 19:35     ` Takashi Iwai
2004-02-04 23:03       ` James Courtier-Dutton
2004-02-05 18:49         ` Takashi Iwai
2004-02-05 19:42         ` Takashi Iwai
2004-02-05 22:28           ` James Courtier-Dutton
2004-02-06 11:29             ` Takashi Iwai
2004-02-06 20:05               ` James Courtier-Dutton
2004-02-09 10:56                 ` Takashi Iwai

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=4022AB31.6070807@superbug.demon.co.uk \
    --to=james@superbug.demon.co.uk \
    --cc=alsa-devel@alsa-project.org \
    --cc=g_sf@zewt.org \
    --cc=perex@suse.cz \
    /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