All of lore.kernel.org
 help / color / mirror / Atom feed
* How to stop a device immediately??
@ 2006-08-04 12:51 Eric Peters
  2006-08-04 13:03 ` Jaroslav Kysela
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Peters @ 2006-08-04 12:51 UTC (permalink / raw)
  To: alsa-devel

Dear all,

I have a PCM device which is playing some PCM samples. The soundbuffer
is pretty full. And now I want to pause the buffer immediately (as
fast as possible) and sometime later I want to resume at exactly this
sample I paused.

Now I found the two functions snd_pcm_pause and snd_pcm_resume. But
unfortunately these functions aren't supported by all hardware. Do you
know if modern hardware like different sound blaster cards supports
this functions?

Or do you have an idea how to implement such a feature? I also found
the two functions snd_pcm_drain and snd_pcm_drop. But when I use this
functions the sound buffer will be empty if I resume. And with
snd_pcm_drain there will be a delay between I pause the playback and
there are no more samples out of my spaekers.

Thanks in advance
Eric

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

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

* Re: How to stop a device immediately??
  2006-08-04 12:51 How to stop a device immediately?? Eric Peters
@ 2006-08-04 13:03 ` Jaroslav Kysela
  2006-08-04 14:18   ` Eric Peters
  0 siblings, 1 reply; 4+ messages in thread
From: Jaroslav Kysela @ 2006-08-04 13:03 UTC (permalink / raw)
  To: Eric Peters; +Cc: alsa-devel

On Fri, 4 Aug 2006, Eric Peters wrote:

> Dear all,
> 
> I have a PCM device which is playing some PCM samples. The soundbuffer
> is pretty full. And now I want to pause the buffer immediately (as
> fast as possible) and sometime later I want to resume at exactly this
> sample I paused.
> 
> Now I found the two functions snd_pcm_pause and snd_pcm_resume. But
> unfortunately these functions aren't supported by all hardware.

Right.

> Or do you have an idea how to implement such a feature? I also found
> the two functions snd_pcm_drain and snd_pcm_drop. But when I use this
> functions the sound buffer will be empty if I resume. And with
> snd_pcm_drain there will be a delay between I pause the playback and
> there are no more samples out of my spaekers.

If hw pause/resume is supported - check snd_pcm_hw_params_can_pause(), 
then you may use it, otherwise you should implement the pause in this way:

on pause:

1) remember the current position in playback buffer (using snd_pcm_delay())
2) use snd_pcm_drop() to stop the stream immediately

on resume:

3) fill ring buffer from the position saved in 1)
4) restart playback

In other words, if hardware does not support pause, application must 
"emulate" this behaviour.

						Jaroslav

-----
Jaroslav Kysela <perex@suse.cz>
Linux Kernel Sound Maintainer
ALSA Project, SUSE Labs

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

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

* Re: How to stop a device immediately??
  2006-08-04 13:03 ` Jaroslav Kysela
@ 2006-08-04 14:18   ` Eric Peters
  2006-08-04 14:23     ` Jaroslav Kysela
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Peters @ 2006-08-04 14:18 UTC (permalink / raw)
  To: alsa-devel

Thanks Jaroslav for your fast reply,

Jaroslav Kysela wrote:
> On Fri, 4 Aug 2006, Eric Peters wrote:
> 
> 
>>Dear all,
>>
>>I have a PCM device which is playing some PCM samples. The soundbuffer
>>is pretty full. And now I want to pause the buffer immediately (as
>>fast as possible) and sometime later I want to resume at exactly this
>>sample I paused.
>>
>>Now I found the two functions snd_pcm_pause and snd_pcm_resume. But
>>unfortunately these functions aren't supported by all hardware.
> 
> 
> Right.
> 
> 
>>Or do you have an idea how to implement such a feature? I also found
>>the two functions snd_pcm_drain and snd_pcm_drop. But when I use this
>>functions the sound buffer will be empty if I resume. And with
>>snd_pcm_drain there will be a delay between I pause the playback and
>>there are no more samples out of my spaekers.
> 
> 
> If hw pause/resume is supported - check snd_pcm_hw_params_can_pause(), 
> then you may use it, otherwise you should implement the pause in this way:
> 
> on pause:
> 
> 1) remember the current position in playback buffer (using snd_pcm_delay())
> 2) use snd_pcm_drop() to stop the stream immediately
> 
> on resume:
> 
> 3) fill ring buffer from the position saved in 1)
> 4) restart playback
> 
> In other words, if hardware does not support pause, application must 
> "emulate" this behaviour.

Yes, you're right. But I'm not sure if I understand your suggestion.

In 1) I will remember the current position of the playback buffer.

If I use snd_pcm_drop in 2) I will lose all frames I already put into
the playback buffer, or not?

If so, for 3) I have to know which samples I dropped so I can rewrite
them to the playback buffer, right? Or aren't the frames which I
already have written into the sound buffer lost if I call
snd_pcm_drop?? If so, I can write new frames to the position I
remembered in 1).

Best regards,
Eric

> 
> 						Jaroslav
> 
> -----
> Jaroslav Kysela <perex@suse.cz>
> Linux Kernel Sound Maintainer
> ALSA Project, SUSE Labs

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

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

* Re: How to stop a device immediately??
  2006-08-04 14:18   ` Eric Peters
@ 2006-08-04 14:23     ` Jaroslav Kysela
  0 siblings, 0 replies; 4+ messages in thread
From: Jaroslav Kysela @ 2006-08-04 14:23 UTC (permalink / raw)
  To: Eric Peters; +Cc: alsa-devel

On Fri, 4 Aug 2006, Eric Peters wrote:

> Thanks Jaroslav for your fast reply,
> 
> Jaroslav Kysela wrote:
> > On Fri, 4 Aug 2006, Eric Peters wrote:
> > 
> > 
> >>Dear all,
> >>
> >>I have a PCM device which is playing some PCM samples. The soundbuffer
> >>is pretty full. And now I want to pause the buffer immediately (as
> >>fast as possible) and sometime later I want to resume at exactly this
> >>sample I paused.
> >>
> >>Now I found the two functions snd_pcm_pause and snd_pcm_resume. But
> >>unfortunately these functions aren't supported by all hardware.
> > 
> > 
> > Right.
> > 
> > 
> >>Or do you have an idea how to implement such a feature? I also found
> >>the two functions snd_pcm_drain and snd_pcm_drop. But when I use this
> >>functions the sound buffer will be empty if I resume. And with
> >>snd_pcm_drain there will be a delay between I pause the playback and
> >>there are no more samples out of my spaekers.
> > 
> > 
> > If hw pause/resume is supported - check snd_pcm_hw_params_can_pause(), 
> > then you may use it, otherwise you should implement the pause in this way:
> > 
> > on pause:
> > 
> > 1) remember the current position in playback buffer (using snd_pcm_delay())
> > 2) use snd_pcm_drop() to stop the stream immediately
> > 
> > on resume:
> > 
> > 3) fill ring buffer from the position saved in 1)
> > 4) restart playback
> > 
> > In other words, if hardware does not support pause, application must 
> > "emulate" this behaviour.
> 
> Yes, you're right. But I'm not sure if I understand your suggestion.
> 
> In 1) I will remember the current position of the playback buffer.
> 
> If I use snd_pcm_drop in 2) I will lose all frames I already put into
> the playback buffer, or not?

Yes, exactly.

> If so, for 3) I have to know which samples I dropped so I can rewrite
> them to the playback buffer, right?

Right.

						Jaroslav

-----
Jaroslav Kysela <perex@suse.cz>
Linux Kernel Sound Maintainer
ALSA Project, SUSE Labs

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

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

end of thread, other threads:[~2006-08-04 14:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-08-04 12:51 How to stop a device immediately?? Eric Peters
2006-08-04 13:03 ` Jaroslav Kysela
2006-08-04 14:18   ` Eric Peters
2006-08-04 14:23     ` Jaroslav Kysela

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.