Linux Sound subsystem development
 help / color / mirror / Atom feed
From: Andy Lo A Foe <andy@alsa-project.org>
To: linux-sound@vger.kernel.org
Subject: Re: streaming from disk to terminatorX added (via mmap)
Date: Tue, 26 Oct 1999 07:50:37 +0000	[thread overview]
Message-ID: <marc-linux-sound-94092433921273@msgid-missing> (raw)
In-Reply-To: <marc-linux-sound-94077890409185@msgid-missing>

On Mon, 25 Oct 1999, Benno Senoner wrote:

> for mp3:
> if this is really true that Andy has managed to play mp3s backwards *CORRECTLY*
> without any distortion, then if I were You, I would include his mp3 code.
> 
> Andy are you saving filterstate information in your alsa player ?

No

> that means what happens if I play the file from the beginning to almost the end,
> and then I reverse the playing direction and play the file until it reaches the
> start ? Does all this process sound 100% correctly ?

Yes

> It would require to save the filter state of every played MPEG frame right ?

It works like this: the ringbuffer I use is segmented;

		
	disk/cdrom based mp3/cdda/wav/etc		
		|
		|
	audio decoder thread
	decodes mp3/cdda/wav/etc
	fills the framebuffer segments
		|
		|

[|---------|---------|---------|----------|---------|] ringbuffer
             segment			
					|
					|
				audio reader thread
				reads framebuffer segments
				and feeds the soundcard
					|
					|
				    soundcard	


A segment holds a number of decoded frames (usually 2 or 3) and also
remembers the number of the first frame. So lets say we want to play 
a mp3 backwards starting at frame 1000. The tricky part is to keep the
ringbuffer full with the right frames all the time. As soon as one segment
is used up by the audio reader thread it releases a semaphore on which the
audio decoder thread is blocking on. The audio decoder thread wakes up and
check if there are any segments that needs to be filled. But wait you say,
what if you need to fill a segment with frames 1000 to 998? Decoding frame
1000, then 999 and then 998 won't work because of the way mp3s are
encoded. What do you do then? You seek to frame 995 and start decoding
from there. You throw all data away up to and including frame 997. By this
time your mp3 decoding engine is recovered from the 'seek' operation. Now
you store the next 3 frames in your ringbuffer. The audio reader thread,
when detecting negative speed, simply reads a segment backwards so in
this case it starts at frame 1000. The segment before the current one
must contain frame 995 to 997 (first jump to frame 992, decode 3
frames and discard them, decode the needed data), and so on...
The decoder thread is also a couple of segments ahead of the reader
thread. So when you do rapid positive and negative speed switching
(scratching) the decoder thread is actually idling since none of the
segments get discarded. 

Comments? :)

Andy

PS. On my lowly PII 233 I can actually play quite a few mp3's (tested with
7), each with different speed, simultaneously. This is with ALSA and a Trident
4DWave NX card that does hardware mixing.
--
AlsaPlayer, http://www.alsa-project.org/~andy/

  parent reply	other threads:[~1999-10-26  7:50 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-10-24 15:14 streaming from disk to terminatorX added (via mmap) Benno Senoner
1999-10-24 17:42 ` David Olofson
1999-10-24 23:26 ` Juhana Sadeharju
1999-10-25  0:29 ` Alexander König
1999-10-25 13:32 ` Benno Senoner
1999-10-25 14:32 ` Benno Senoner
1999-10-26  7:50 ` Andy Lo A Foe [this message]
1999-10-26 20:34 ` Alexander König
1999-10-27 14:05 ` Andy Lo A Foe
1999-10-27 20:10 ` Benno Senoner

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=marc-linux-sound-94092433921273@msgid-missing \
    --to=andy@alsa-project.org \
    --cc=linux-sound@vger.kernel.org \
    /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